forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help : alpha values not read correctly from bmp?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Stellar



Joined: 12 Dec 2005
Posts: 48

PostPosted: Tue Jan 17, 2006 4:35 am    Post subject: help : alpha values not read correctly from bmp? Reply with quote

:: UPDATE :: ok, i used a hex editor (xvi32, my fav) to check the image in binary, it actually reads BA FE CA AE. the AE at the end is what's important. when you edit in photoshop, it reads BE from the color 'info' toolbox. Perhaps i dont understand how to correctly set the values for the alpha mask. Ill have to look into it.
:: 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:

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 );
   }
}


results
Code:

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)


:: UPDATE :: ok, i used a hex editor (xvi32, my fav) to check the image in binary, it actually reads BA FE CA AE. the AE at the end is what's important. when you edit in photoshop, it reads BE from the color 'info' toolbox. Perhaps i dont understand how to correctly set the values for the alpha mask. Ill have to look into it.
:: END UPDATE ::
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group