Make the algorithm used to convert a 32bit image to a 24bit one easier to understnad.

All it's doing is skipping the alpha channel when copying the data over
This commit is contained in:
Arthur Moore 2015-03-12 21:10:17 -04:00
parent aa98e8e7a9
commit ec041ec6ee
2 changed files with 16 additions and 11 deletions

View File

@ -23,3 +23,6 @@ cd build
cmake .. cmake ..
make make
#scan-build make #scan-build make
#For profiling:
#valgrind --tool=callgrind ./wxvbam

View File

@ -44,18 +44,20 @@ const std::map<std::string,FilterFunc> filters::filterMap = makeFilterMap();
//Convert a 32 bit image to a 24 bit one //Convert a 32 bit image to a 24 bit one
void convert32To24(u32* src,u8* dst,unsigned int width, unsigned int height) void convert32To24(u32* src,u8* dst,unsigned int width, unsigned int height)
{ {
// //Each pixel is 3 bytes, which is NOT a common unit, so have to use u8 and manually multiply //Need src as a single byte pointer for this to work
// for(unsigned int i=0;i<width*height;i++) u8 * u8src = (u8*)src;
// {
// dst[i*3]=((src[i])&0xFF) | ((src[i]>>8)&0xFF) | ((src[i]>>16)&0xFF);
// }
for(unsigned int y = 0; y < height ; y++) { for(unsigned int y = 0; y < height ; y++)
for(unsigned int x = 0; x < width; x++, src++) { {
*dst++ = *src; for(unsigned int x = 0; x < width; x++)
*dst++ = *src >> 8; {
*dst++ = *src >> 16; //For each pixel copy r,g,b one byte at a time
for(unsigned int i = 0; i<3; i++)
{
*dst++ = *u8src++;
}
//Skip the alpha channel
u8src++;
} }
// ++src; // skip rhs border
} }
} }