:: END UPDATE ::
Ok weird problem, i have attached my function, bmp with alpha channel, and results. The image has only one pixel, and the pixel reads in hex (RGBA order) 'CAFEBABE' ( no i dont like java, thats the only think i took out of it :P ) of course in psp image format that would read 'BECAFEBA' since alpha comes first.
link to image
at any rate, when i read in the RGB values, data is ok, but when i read the A value, its modified or does not read correctly? It always reports a lower value that specified. If you open the image in photoshop, you can check the values, they are correct.
Just a quirk i also, noticed. The function sceGuTexMode accepts GU_PSM_8888 as a pixel format in 0xAARRGGBB order, but the function to set the texture sceGuTexImage takes a component flag GU_TCC_RGBA ( not say, GU_TCC_ARGB as the format for the other function ). I doubt it means anything, I just noticed it?
i appreciate any assistance on the matter,
thanks,
-stellar :)
Code: Select all
void ImageLoadBmp32(
char *filename,
ImageBmp32 **pImage
)
{
FILE *file;
FILE *fpLog;
unsigned short nBpp;
unsigned short nPlanes;
file = fopen( filename, "rb");
fpLog = fopen( "image.txt", "a" );
if ( file == NULL )
{
goto FN_EXIT;
}
if ( fpLog == NULL )
{
goto FN_EXIT;
}
fprintf( fpLog, "Loading Texture [%s]\n", filename );
*pImage = (ImageBmp32*) calloc( sizeof( ImageBmp32 ), 1 );
if ( *pImage == NULL )
{
fprintf( fpLog, " Failed to allocate [ImageBmp32]\n" );
goto FN_EXIT;
}
if ( 0 != fseek( file, 18, SEEK_CUR ) )
{
fprintf( fpLog, " Failed to fseek 18\n" );
goto FN_EXIT;
}
if ( 1 != fread( &(*pImage)->nWidth, sizeof( unsigned long ), 1, file ) )
{
fprintf( fpLog, " Failed to read width\n" );
goto FN_EXIT;
}
(*pImage)->nStride = (*pImage)->nWidth;
if ( 1 != fread(&((*pImage))->nHeight, 4, 1, file) )
{
fprintf( fpLog, " Failed to read height\n" );
goto FN_EXIT;
}
(*pImage)->nSize = (*pImage)->nWidth * (*pImage)->nHeight * 4; // 4 bytes per pixel XRGB
if ( 1 != fread(&nPlanes, 2, 1, file ) )
{
fprintf( fpLog, " Failed to read planes\n" );
goto FN_EXIT;
}
if ( 1 != fread( &nBpp, 2, 1, file ) )
{
fprintf( fpLog, " Failed to read bpp\n" );
goto FN_EXIT;
}
if ( nBpp != 32 )
{
fprintf( fpLog, " Failed : BPP != 32\n" );
goto FN_EXIT;
}
if ( nPlanes != 1 )
{
fprintf( fpLog, " Failed : Planes != 1\n" );
goto FN_EXIT;
}
if ( 0 != fseek( file, 24, SEEK_CUR ) )
{
fprintf( fpLog, " Failed to FSEEK 24\n" );
goto FN_EXIT;
}
// allocate for image pixels
(*pImage)->pData = ( unsigned char * ) memalign( 16, (*pImage)->nSize ); //
if ( (*pImage)->pData == NULL )
{
fprintf( fpLog, " Failed to allocate (%u) for pixels\n", (*pImage)->nSize );
goto FN_EXIT;
}
// read image
if ( 1 != fread( (*pImage)->pData, (*pImage)->nSize, 1, file ) )
{
fprintf( fpLog, " Failed to read pixels\n" );
goto FN_EXIT;
}
// reorder the bytes into correct format ///////////
for ( unsigned int i = 0; i < (*pImage)->nSize; i += 4 )
{ // x=3,r=2,b=0,g=1
unsigned char xrgb[4];
memset( xrgb, 0, sizeof( unsigned char ) * 4 );
xrgb[0] = (*pImage)->pData[i + 3]; // x
xrgb[1] = (*pImage)->pData[i + 2]; // r
xrgb[2] = (*pImage)->pData[i + 1]; // g
xrgb[3] = (*pImage)->pData[i + 0]; // b
if ( i == 0 )
{
fprintf(
fpLog,
"B(%X) G(%X) R(%X) A(%X) -> "
"A(%X) R(%X) G(%X) B(%X)\n", // BE CA FE BA
(*pImage)->pData[i + 0],
(*pImage)->pData[i + 1],
(*pImage)->pData[i + 2],
(*pImage)->pData[i + 3],
xrgb[0],
xrgb[1],
xrgb[2],
xrgb[3]
);
}
memcpy( &(*pImage)->pData[i], xrgb, sizeof( char ) * 4 );
}
fprintf( fpLog, " Texture Loaded\n" );
FN_EXIT :
if ( file != NULL )
{
fclose( file );
}
if ( fpLog != NULL )
{
fclose( fpLog );
}
}
Code: Select all
Loading Texture [test.bmp]
B(BA) G(FE) R(CA) A(AE) -> A(AE) R(CA) G(FE) B(BA)
Texture Loaded
or in decimal
B(186) G(254) R(202) A(174) -> A(174) R(202) G(254) B(186)
:: END UPDATE ::