g3df.c: don't leak the FILE* in failure cases.

only h5 handled that but with inlined fclose() and FXFALSE returns.
used goto statements to simplify things.
This commit is contained in:
sezero
2018-08-22 02:06:40 +03:00
parent 5d1a34c31c
commit 7ced8d7f32
4 changed files with 141 additions and 438 deletions

View File

@@ -203,11 +203,9 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
};
GDBG_INFO(81,"gu3dfGetInfo(%s,0x%x)\n",FileName,Info);
/*
** open the filen
*/
if((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if ((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** grab statistics out of the header
@@ -217,13 +215,12 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
color_format,
&small_lod, &large_lod,
&aspect_width, &aspect_height) != 6)
return FXFALSE;
goto _loc1;
/*
** determine aspect ratio, height, and width
*/
i = 0;
ratio_found = FXFALSE;
while ((i < 4) && (!ratio_found)) {
if ((aspect_width << i) == aspect_height) {
Info->header.aspect_ratio = wh_aspect_table[i];
@@ -242,7 +239,7 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
i++;
}
if (!ratio_found) return FXFALSE;
if (!ratio_found) goto _loc1;
/*
** determine height and width of the mip map
@@ -414,7 +411,6 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
}
i = 0;
format_found = FXFALSE;
while ((cftable[i].name != 0) && (!format_found)) {
if (strcmp(color_format, cftable[i].name) == 0) {
Info->header.format = cftable[i].fmt;
@@ -427,7 +423,8 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
/*
** close the input file
*/
if (image_file != NULL) fclose(image_file);
_loc1:
fclose(image_file);
if (format_found) {
FxI32 lod;
@@ -459,11 +456,9 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
char buffer[100] = "";
GDBG_INFO(81,"gu3dfLoad(%s,0x%x)\n",filename,info);
/*
** open the file
*/
if ((image_file = fopen(filename, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** If necessary, read in the YIQ decompression table
@@ -477,11 +472,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -490,23 +481,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -515,23 +494,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -586,11 +553,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -610,10 +573,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_RGB_565:
@@ -627,21 +587,16 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
default:
_loc1:
fclose(image_file);
return FXFALSE;
}
/*
** close the file
*/
fclose(image_file);
return FXTRUE;
}

View File

@@ -208,11 +208,9 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
};
GDBG_INFO(81,"gu3dfGetInfo(%s,0x%x)\n",FileName,Info);
/*
** open the filen
*/
if((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if ((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** grab statistics out of the header
@@ -222,13 +220,12 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
color_format,
&small_lod, &large_lod,
&aspect_width, &aspect_height) != 6)
return FXFALSE;
goto _loc1;
/*
** determine aspect ratio, height, and width
*/
i = 0;
ratio_found = FXFALSE;
while ((i < 4) && (!ratio_found)) {
if ((aspect_width << i) == aspect_height) {
Info->header.aspect_ratio = wh_aspect_table[i];
@@ -247,7 +244,7 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
i++;
}
if (!ratio_found) return FXFALSE;
if (!ratio_found) goto _loc1;
/*
** determine height and width of the mip map
@@ -419,7 +416,6 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
}
i = 0;
format_found = FXFALSE;
while ((cftable[i].name != 0) && (!format_found)) {
if (strcmp(color_format, cftable[i].name) == 0) {
Info->header.format = cftable[i].fmt;
@@ -432,7 +428,8 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
/*
** close the input file
*/
if (image_file != NULL) fclose(image_file);
_loc1:
fclose(image_file);
if (format_found) {
FxI32 lod;
@@ -464,11 +461,9 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
char buffer[100] = "";
GDBG_INFO(81,"gu3dfLoad(%s,0x%x)\n",filename,info);
/*
** open the file
*/
if ((image_file = fopen(filename, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** If necessary, read in the YIQ decompression table
@@ -482,11 +477,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -495,23 +486,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -520,23 +499,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -591,11 +558,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -615,10 +578,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_RGB_565:
@@ -632,21 +592,16 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
default:
_loc1:
fclose(image_file);
return FXFALSE;
}
/*
** close the file
*/
fclose(image_file);
return FXTRUE;
}

View File

@@ -98,7 +98,6 @@
* Added GR_DIENTRY for di glide functions
**
*/
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <3dfx.h>
@@ -253,17 +252,9 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
};
GDBG_INFO(81,"gu3dfGetInfo(%s,0x%x)\n",FileName,Info);
/*
** open the file
*/
if((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) {
/*
** close the file
*/
fclose(image_file);
return FXFALSE;
}
if ((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** grab statistics out of the header
@@ -272,19 +263,13 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
version,
color_format,
&small_lod, &large_lod,
&aspect_width, &aspect_height) != 6) {
/*
** close the file
*/
fclose(image_file);
return FXFALSE;
}
&aspect_width, &aspect_height) != 6)
goto _loc1;
/*
** determine aspect ratio, height, and width
*/
i = 0;
ratio_found = FXFALSE;
while ((i < 4) && (!ratio_found)) {
if ((aspect_width << i) == aspect_height) {
Info->header.aspect_ratio = wh_aspect_table[i];
@@ -303,13 +288,7 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
i++;
}
if (!ratio_found) {
/*
** close the file
*/
fclose(image_file);
return FXFALSE;
}
if (!ratio_found) goto _loc1;
/*
** determine height and width of the mip map
@@ -523,7 +502,6 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
}
i = 0;
format_found = FXFALSE;
while ((cftable[i].name != 0) && (!format_found)) {
if (strcmp(color_format, cftable[i].name) == 0) {
Info->header.format = cftable[i].fmt;
@@ -536,7 +514,8 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
/*
** close the input file
*/
if (image_file != NULL) fclose(image_file);
_loc1:
fclose(image_file);
if (format_found) {
Info->mem_required = _grTexTextureMemRequired(Info->header.small_lod,
@@ -562,17 +541,9 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
char buffer[100] = "";
GDBG_INFO(81,"gu3dfLoad(%s,0x%x)\n",filename,info);
/*
** open the file
*/
if ((image_file = fopen(filename, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) {
/*
** close the file
*/
fclose(image_file);
return FXFALSE;
}
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
#if 0
/*
@@ -587,11 +558,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -600,23 +567,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -625,23 +580,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -696,11 +639,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -722,11 +661,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -735,23 +670,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -760,23 +683,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -825,10 +736,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_AYIQ_8422:
@@ -842,11 +750,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -855,23 +759,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -880,23 +772,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -945,10 +825,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_P_8:
@@ -960,11 +837,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -973,10 +846,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_AP_88:
@@ -988,11 +858,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -1001,10 +867,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_ARGB_CMP_FXT1:
@@ -1012,10 +875,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
/* TODO: to support DXTn, we need to read .dds files
case GR_TEXFMT_ARGB_CMP_DXT1:
@@ -1023,10 +883,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_ARGB_CMP_DXT2:
@@ -1037,10 +894,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
*/
case GR_TEXFMT_INTENSITY_8:
@@ -1053,10 +907,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_RGB_565:
@@ -1072,10 +923,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_ARGB_8888:
@@ -1084,26 +932,16 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
info->header.small_lod,
info->header.large_lod,
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
default:
/*
** close the file
*/
_loc1:
fclose(image_file);
return FXFALSE;
break;
}
/*
** close the file
*/
fclose(image_file);
return FXTRUE;
}

View File

@@ -187,11 +187,9 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
};
GDBG_INFO((81,"gu3dfGetInfo(%s,0x%x)\n",FileName,Info));
/*
** open the filen
*/
if((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if ((image_file = fopen(FileName, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** grab statistics out of the header
@@ -201,13 +199,12 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
color_format,
&small_lod, &large_lod,
&aspect_width, &aspect_height) != 6)
return FXFALSE;
goto _loc1;
/*
** determine aspect ratio, height, and width
*/
i = 0;
ratio_found = FXFALSE;
while ((i < 4) && (!ratio_found)) {
if ((aspect_width << i) == aspect_height) {
Info->header.aspect_ratio = wh_aspect_table[i];
@@ -226,7 +223,7 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
i++;
}
if (!ratio_found) return FXFALSE;
if (!ratio_found) goto _loc1;
/*
** determine height and width of the mip map
@@ -320,7 +317,6 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
}
i = 0;
format_found = FXFALSE;
while ((cftable[i].name != 0) && (!format_found)) {
if (strcmp(color_format, cftable[i].name) == 0) {
Info->header.format = cftable[i].fmt;
@@ -333,7 +329,8 @@ GR_DIENTRY(gu3dfGetInfo, FxBool,
/*
** close the input file
*/
if (image_file != NULL) fclose(image_file);
_loc1:
fclose(image_file);
if (format_found) {
FxI32 lod;
@@ -357,11 +354,9 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
char buffer[100] = "";
GDBG_INFO((81,"gu3dfLoad(%s,0x%x)\n",filename,info));
/*
** open the file
*/
if ((image_file = fopen(filename, openmode)) == NULL) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) return FXFALSE;
if (!_grGet3dfHeader(image_file, buffer, sizeof(buffer))) goto _loc1;
/*
** If necessary, read in the YIQ decompression table
@@ -375,11 +370,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for (index = 0; index < 16; index++)
{
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.yRGB[index] = val & 0xFF;
}
@@ -388,23 +379,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.iRGB[index][2] = val & 0x1FF;
}
@@ -413,23 +392,11 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
*/
for (index = 0; index < 4; index++) {
FxU16 val;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][0] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][1] = val & 0x1FF;
if (!ReadDataShort(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataShort(image_file, &val)) goto _loc1;
info->table.nccTable.qRGB[index][2] = val & 0x1FF;
}
@@ -484,11 +451,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
for(i = 0; i < 256; i++)
{
FxU32 val;
if (!ReadDataLong(image_file, &val))
{
fclose(image_file);
return FXFALSE;
}
if (!ReadDataLong(image_file, &val)) goto _loc1;
info->table.palette.data[i] = val;
}
}
@@ -508,10 +471,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
case GR_TEXFMT_RGB_565:
@@ -525,21 +485,16 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info))
G3_LOD_TRANSLATE(info->header.small_lod),
G3_LOD_TRANSLATE(info->header.large_lod),
G3_ASPECT_TRANSLATE(info->header.aspect_ratio)))
{
fclose(image_file);
return FXFALSE;
}
goto _loc1;
break;
default:
_loc1:
fclose(image_file);
return FXFALSE;
}
/*
** close the file
*/
fclose(image_file);
return FXTRUE;
}