MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / GenMipMapRGBA

Method GenMipMapRGBA

samples/hellovr_vulkan/hellovr_vulkan_main.cpp:2277–2327  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: generate next level mipmap for an RGBA image -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2275// Purpose: generate next level mipmap for an RGBA image
2276//-----------------------------------------------------------------------------
2277void CMainApplication::GenMipMapRGBA( const uint8_t *pSrc, uint8_t *pDst, int nSrcWidth, int nSrcHeight, int *pDstWidthOut, int *pDstHeightOut )
2278{
2279 *pDstWidthOut = nSrcWidth / 2;
2280 if ( *pDstWidthOut <= 0 )
2281 {
2282 *pDstWidthOut = 1;
2283 }
2284 *pDstHeightOut = nSrcHeight / 2;
2285 if ( *pDstHeightOut <= 0 )
2286 {
2287 *pDstHeightOut = 1;
2288 }
2289
2290 for ( int y = 0; y < *pDstHeightOut; y++ )
2291 {
2292 for ( int x = 0; x < *pDstWidthOut; x++ )
2293 {
2294 int nSrcIndex[4];
2295 float r = 0.0f;
2296 float g = 0.0f;
2297 float b = 0.0f;
2298 float a = 0.0f;
2299
2300 nSrcIndex[0] = ( ( ( y * 2 ) * nSrcWidth ) + ( x * 2 ) ) * 4;
2301 nSrcIndex[1] = ( ( ( y * 2 ) * nSrcWidth ) + ( x * 2 + 1 ) ) * 4;
2302 nSrcIndex[2] = ( ( ( ( y * 2 ) + 1 ) * nSrcWidth ) + ( x * 2 ) ) * 4;
2303 nSrcIndex[3] = ( ( ( ( y * 2 ) + 1 ) * nSrcWidth ) + ( x * 2 + 1 ) ) * 4;
2304
2305 // Sum all pixels
2306 for ( int nSample = 0; nSample < 4; nSample++ )
2307 {
2308 r += pSrc[ nSrcIndex[ nSample ] ];
2309 g += pSrc[ nSrcIndex[ nSample ] + 1 ];
2310 b += pSrc[ nSrcIndex[ nSample ] + 2 ];
2311 a += pSrc[ nSrcIndex[ nSample ] + 3 ];
2312 }
2313
2314 // Average results
2315 r /= 4.0;
2316 g /= 4.0;
2317 b /= 4.0;
2318 a /= 4.0;
2319
2320 // Store resulting pixels
2321 pDst[ ( y * ( *pDstWidthOut ) + x ) * 4 ] = ( uint8_t ) ( r );
2322 pDst[ ( y * ( *pDstWidthOut ) + x ) * 4 + 1] = ( uint8_t ) ( g );
2323 pDst[ ( y * ( *pDstWidthOut ) + x ) * 4 + 2] = ( uint8_t ) ( b );
2324 pDst[ ( y * ( *pDstWidthOut ) + x ) * 4 + 3] = ( uint8_t ) ( a );
2325 }
2326 }
2327}
2328
2329//-----------------------------------------------------------------------------
2330// Purpose: create a sea of cubes

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected