|
From: Charles L. <cn...@us...> - 2009-04-17 17:33:30
|
Update of /cvsroot/hgengine/Mercury/src In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv31290/src Modified Files: ImageLoaders.cpp Log Message: Force use of RGBA over RGB. There's enough systems that have serious trouble with this so we are going to have to scrap it. This converts all images to RGBA before handing them off to the rest of the engine. Index: ImageLoaders.cpp =================================================================== RCS file: /cvsroot/hgengine/Mercury/src/ImageLoaders.cpp,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** ImageLoaders.cpp 6 Aug 2007 20:25:46 -0000 1.13 --- ImageLoaders.cpp 17 Apr 2009 17:33:19 -0000 1.14 *************** *** 105,112 **** png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); ! if (color_type & PNG_COLOR_MASK_ALPHA) ! image->attrs.m_ColorByteType = RGBA; ! else ! image->attrs.m_ColorByteType = RGB; // SAFE_DELETE(texture->m_data); --- 105,109 ---- png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); ! image->attrs.m_ColorByteType = RGBA; // SAFE_DELETE(texture->m_data); *************** *** 114,120 **** image->data = new unsigned char[sizeof(unsigned char) * image->attrs.m_height * image->attrs.m_width * 4]; ! switch (image->attrs.m_ColorByteType) { - case RGBA: for ( y=0; y < (unsigned)image->attrs.m_height; ++y) { png_byte* row = row_pointers[y]; --- 111,116 ---- image->data = new unsigned char[sizeof(unsigned char) * image->attrs.m_height * image->attrs.m_width * 4]; ! if( color_type & PNG_COLOR_MASK_ALPHA ) { for ( y=0; y < (unsigned)image->attrs.m_height; ++y) { png_byte* row = row_pointers[y]; *************** *** 127,146 **** } } ! break; ! case RGB: for ( y=0; y < (unsigned)image->attrs.m_height; y++) { png_byte* row = row_pointers[y]; for (int x=0; x<image->attrs.m_width; x++) { png_byte* ptr = &(row[x * 3]); ! image->data[(x + y * image->attrs.m_width) * 3] = ptr[0]; ! image->data[(x + y * image->attrs.m_width) * 3 + 1] = ptr[1]; ! image->data[(x + y * image->attrs.m_width) * 3 + 2] = ptr[2]; } } - break; - default: - LOG.Warn("Invalid color byte type for PNG."); - SAFE_DELETE_ARRAY( image ); - return false; } --- 123,139 ---- } } ! } ! else ! { for ( y=0; y < (unsigned)image->attrs.m_height; y++) { png_byte* row = row_pointers[y]; for (int x=0; x<image->attrs.m_width; x++) { png_byte* ptr = &(row[x * 3]); ! image->data[(x + y * image->attrs.m_width) * 4] = ptr[0]; ! image->data[(x + y * image->attrs.m_width) * 4 + 1] = ptr[1]; ! image->data[(x + y * image->attrs.m_width) * 4 + 2] = ptr[2]; ! image->data[(x + y * image->attrs.m_width) * 4 + 3] = 255; } } } *************** *** 263,267 **** //Allocate space SAFE_DELETE_ARRAY(image->data); ! image->data = new unsigned char[rawlength]; memset(image->data, 0, rawlength); --- 256,260 ---- //Allocate space SAFE_DELETE_ARRAY(image->data); ! image->data = new unsigned char[image->attrs.m_width * image->attrs.m_height * 4]; memset(image->data, 0, rawlength); *************** *** 269,273 **** //Get raw data and convert BGR->RGB file->Seek(offset); ! for (unsigned int x = 0; !file->Eof(); x += 3) { memset(b, 0, sizeof(unsigned char) * 3); --- 262,266 ---- //Get raw data and convert BGR->RGB file->Seek(offset); ! for (unsigned int x = 0; !file->Eof(); x += 4) { memset(b, 0, sizeof(unsigned char) * 3); *************** *** 277,282 **** image->data[x+1] = b[1]; image->data[x+2] = b[0]; } ! image->attrs.m_ColorByteType = RGB; SAFE_DELETE_ARRAY(tmp); LOG.Info( "BMP Load End" ); --- 270,276 ---- image->data[x+1] = b[1]; image->data[x+2] = b[0]; + image->data[x+3] = 255; //full alpha } ! image->attrs.m_ColorByteType = RGBA; SAFE_DELETE_ARRAY(tmp); LOG.Info( "BMP Load End" ); |