The code that actually reads the picture has already been uploaded into my resources, and the following example is posted:
unsigned char* esloadjpg (const char *filename, int *width, int *height, int *size)
{
FILE *f = fopen (FileName, "RB");
Fseek (f, 0, seek_end);
*size = Ftell (f);
Fseek (f, 0, seek_set);
unsigned char *data = (unsigned char*) malloc (*size);
Fread (data, 1, *size, f);
Jpegdecoder Dec (data, *size);
Dec.init ();
Dec.decodejpeg ();
*width = DEC.GETW ();
*height = Dec.geth ();
*size = Dec.getsize ();
unsigned char *buffer = (unsigned char*) malloc (*size);
memcpy (buffer, Dec.getbmpdata (), *size);
return buffer;
}
unsigned char* esloadtga (const char *filename, int *width, int *height, int *size)
{
unsigned char *buffer = NULL;
FILE *f;
unsigned char tgaheader[12];
unsigned char attributes[6];
unsigned int imagesize;
f = fopen (FileName, "RB");
if (f = = null) return null;
if (fread (&tgaheader, sizeof (Tgaheader), 1, f) = = 0)
{
Fclose (f);
return NULL;
}
if (fread (attributes, sizeof (attributes), 1, f) = = 0)
{
Fclose (f);
return 0;
}
*width = attributes[1] * + attributes[0];
*height = attributes[3] * + attributes[2];
ImageSize = attributes[4]/8 * *width * *height;
*size = ImageSize;
Buffer = (unsigned char*) malloc (imagesize);
if (buffer = = NULL)
{
Fclose (f);
return 0;
}
if (fread (buffer, 1, imagesize, f)! = ImageSize)
{
Free (buffer);
return NULL;
}
Fclose (f);
return buffer;
}
unsigned char* esloadpng (const char *filename, int *width, int *height, int *size)
{
FILE *f = fopen (FileName, "RB");
Fseek (f, 0, seek_end);
*size = Ftell (f);
Fseek (f, 0, seek_set);
unsigned char *data = (unsigned char*) malloc (*size);
Fread (data, 1, *size, f);
Pngdecoder Dec (data, *size);
Dec.init ();
Dec.decoderpng ();
*width = DEC.GETW ();
*height = Dec.geth ();
*size = Dec.getsize ();
unsigned char *buffer = (unsigned char*) malloc (*size);
memcpy (buffer, Dec.getbmpdata (), *size);
return buffer;
}
Linux under OpenGL read JPG, PNG, TAG texture data