///
// esLoadTGA()
//
//    Loads a 8-bit, 24-bit or 32-bit TGA image from a file
//
char * esLoadTGA ( void *ioContext, const char *fileName, int *width, int *height )
{
    char        *buffer;
    void        *fp;
    TGA_HEADER   Header;
    int          bytesRead;

    // Open the file for reading
    fp = esFileOpen ( ioContext, fileName );

    if ( fp == NULL )
    {
        // Log error as 'error in opening the input file from apk'
        LOGI ( "esLoadTGA FAILED to load : { %s }\n", fileName );
        return NULL;
    }

    bytesRead = esFileRead ( ioContext, fp, sizeof ( TGA_HEADER ), &Header );

    *width = Header.Width;
    *height = Header.Height;

    LOGE("bytesRead is %d", bytesRead);
    LOGE("{IdSize:%d\nMapType:%d\nImageType:%d\nPaletteStart:%d\n"
                 "PaletteSize:%d\nPaletteEntryDepth:%d\nX:%d\n"
                 "Y:%d\nWidth:%d\nHeight:%d\n"
                 "ColorDepth:%d\nDescriptor:%d\n}",
         Header.IdSize, Header.MapType, Header.ImageType, Header.PaletteStart, Header.PaletteSize,
         Header.PaletteEntryDepth, Header.X, Header.Y, Header.Width, Header.Height,
         Header.ColorDepth, Header.Descriptor);

    if ( Header.ColorDepth == 8 ||
         Header.ColorDepth == 24 || Header.ColorDepth == 32 )
    {
        int bytesToRead = sizeof ( char ) * ( *width ) * ( *height ) * Header.ColorDepth / 8;

        LOGE("bytesToRead is %d", bytesToRead);

        // Allocate the image data buffer
        buffer = ( char * ) malloc ( bytesToRead );

        if ( buffer )
        {
            bytesRead = esFileRead ( ioContext, fp, bytesToRead, buffer );
            esFileClose ( ioContext, fp );

            LOGI ( "esLoadTGA success to load : { %s }\n", fileName );

            return ( buffer );
        }
    }

    LOGE ( "esLoadTGA fail to load : { %s }\n", fileName );
    return ( NULL );
}
Exemple #2
0
///
// esLoadTGA()
//
//    Loads a 8-bit, 24-bit or 32-bit TGA image from a file
//
char *ESUTIL_API esLoadTGA ( void *ioContext, const char *fileName, int *width, int *height )
{
   char        *buffer;
   esFile      *fp;
   TGA_HEADER   Header;
   size_t          bytesRead;

   // Open the file for reading
   fp = esFileOpen ( ioContext, fileName );

   if ( fp == NULL )
   {
      // Log error as 'error in opening the input file from apk'
      esLogMessage ( "esLoadTGA FAILED to load : { %s }\n", fileName );
      return NULL;
   }

   bytesRead = esFileRead ( fp, sizeof ( TGA_HEADER ), &Header );

   *width = Header.Width;
   *height = Header.Height;

   if ( Header.ColorDepth == 8 ||
         Header.ColorDepth == 24 || Header.ColorDepth == 32 )
   {
      int bytesToRead = sizeof ( char ) * ( *width ) * ( *height ) * Header.ColorDepth / 8;

      // Allocate the image data buffer
      buffer = ( char * ) malloc ( bytesToRead );

      if ( buffer )
      {
         bytesRead = esFileRead ( fp, bytesToRead, buffer );
         esFileClose ( fp );

         return ( buffer );
      }
   }

   return ( NULL );
}