Code:
if(!strcmp(dateiendung, "tga"))
{
FILE *hDatei = fopen(filename, "rb");
if(hDatei == NULL) return FALSE;
TGA tga;
TGAHeader tgaheader;
GLubyte uTGAcompare[12] = {0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0};
GLubyte cTGAcompare[12] = {0, 0, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if(!fread(&tgaheader, sizeof(TGAHeader), 1, hDatei))
return FALSE;
if(!fread(&tga, sizeof(TGAHeader), 1, hDatei))
return FALSE;
wWidth = tga.header[1] * 256 + tga.header[0];
wHeight = tga.header[3] * 256 + tga.header[2];
bbitCount = tga.header[4];
tga.Width = wWidth;
tga.Height = wHeight;
tga.Bpp = bbitCount;
if((wWidth <= 0) || (wHeight <= 0) || ((bbitCount != 24) && (bbitCount != 32)))
return FALSE;
if(!memcmp(uTGAcompare, &tgaheader, sizeof(tgaheader)))
{
if(fread(filedata, 1, tga.imageSize, hDatei) != tga.imageSize)
return FALSE;
}
else if(!memcmp(cTGAcompare, &tgaheader, sizeof(tgaheader))
{
GLuint pixelcount = tga.Width * tga.Height;
GLuint currentpixel = 0, currentbyte = 0;
GLubyte *colorbuffer = (GLubyte*)malloc(tga.bytesPerPixel);
do
{
GLubyte chunkheader = 0;
if(!fread(&chunkheader, sizeof(GLubyte), 1, hDatei))
return FALSE;
if(chunkheader < 128)
{
chunkheader++;
for(short counter = 0; counter < chunkheader; counter++)
{
if(fread(colorbuffer, 1, tga.bytesPerPixel, hDatei) != tga.bytesPerPixel)
return FALSE;
filedata[currentbyte] = colorbuffer[0];
filedata[currentbyte + 1] = colorbuffer[1];
filedata[currentbyte + 2] = colorbuffer[2];
if(tga.bytesPerPixel == 4)
filedata[currentbyte + 3] = colorbuffer[3];
currentbyte += tga.bytesPerPixel;
currentpixel++;
}
}
else
{
chunkheader -= 127;
if(fread(colorbuffer, 1, tga.bytesPerPixel, hDatei) != tga.bytesPerPixel)
return FALSE;
for(short counter = 0; counter < chunkheader; counter++)
{
if(tga.bytesPerPixel == 4)
filedata[currentbyte + 3] = colorbuffer[3];
currentbyte += tga.bytesPerPixel;
currentpixel++;
}
}
}while(currentpixel < pixelcount); // pixelcount undeclared
}
else return FALSE;
fclose(hDatei); // hDatei undeclared
}
unter windows läuft das so
Lesezeichen