diff --git a/glide3x/cvg/glide3/src/g3df.c b/glide3x/cvg/glide3/src/g3df.c index 17aff4f..956ed47 100644 --- a/glide3x/cvg/glide3/src/g3df.c +++ b/glide3x/cvg/glide3/src/g3df.c @@ -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; } @@ -546,7 +513,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info)) packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } @@ -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; } diff --git a/glide3x/h3/glide3/src/g3df.c b/glide3x/h3/glide3/src/g3df.c index e18b608..e4d6e24 100644 --- a/glide3x/h3/glide3/src/g3df.c +++ b/glide3x/h3/glide3/src/g3df.c @@ -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; } @@ -551,7 +518,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info)) packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } @@ -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; } diff --git a/glide3x/h5/glide3/src/g3df.c b/glide3x/h5/glide3/src/g3df.c index 2277358..16c64a9 100644 --- a/glide3x/h5/glide3/src/g3df.c +++ b/glide3x/h5/glide3/src/g3df.c @@ -98,7 +98,6 @@ * Added GR_DIENTRY for di glide functions ** */ -#include #include #include #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; } @@ -656,7 +599,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info)) packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } @@ -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,115 +661,84 @@ 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; } - + /* ** read in I */ 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; } - + /* ** read in Q */ 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; } - + /* ** pack the table Y entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.yRGB[index*4+0]); packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } - + /* ** pack the table I entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.iRGB[index][0]) << 18; packedvalue |= ((FxU32) info->table.nccTable.iRGB[index][1]) << 9; packedvalue |= ((FxU32) info->table.nccTable.iRGB[index][2]) << 0; - + info->table.nccTable.packed_data[index+4] = packedvalue; } - + /* ** pack the table Q entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.qRGB[index][0]) << 18; packedvalue |= ((FxU32) info->table.nccTable.qRGB[index][1]) << 9;; packedvalue |= ((FxU32) info->table.nccTable.qRGB[index][2]) << 0; - + info->table.nccTable.packed_data[index+8] = packedvalue; } } - + if (!Read8Bit(info->data, image_file, 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: /* ** If necessary, read in the YIQ decompression table @@ -842,101 +750,73 @@ 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; } - + /* ** read in I */ 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; } - + /* ** read in Q */ 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; } - + /* ** pack the table Y entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.yRGB[index*4+0]); packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } - + /* ** pack the table I entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.iRGB[index][0]) << 18; packedvalue |= ((FxU32) info->table.nccTable.iRGB[index][1]) << 9; packedvalue |= ((FxU32) info->table.nccTable.iRGB[index][2]) << 0; - + info->table.nccTable.packed_data[index+4] = packedvalue; } - + /* ** pack the table Q entries */ for (index = 0; index < 4; index++) { FxU32 packedvalue; - + packedvalue = ((FxU32) info->table.nccTable.qRGB[index][0]) << 18; packedvalue |= ((FxU32) info->table.nccTable.qRGB[index][1]) << 9;; packedvalue |= ((FxU32) info->table.nccTable.qRGB[index][2]) << 0; - + info->table.nccTable.packed_data[index+8] = packedvalue; } } @@ -945,12 +825,9 @@ 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: /* ** If necessary, read in the Palette @@ -960,25 +837,18 @@ 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; } } - + if (!Read8Bit(info->data, image_file, 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: /* ** If necessary, read in the Palette @@ -988,34 +858,24 @@ 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; } } - + if (!Read16Bit(info->data, image_file, 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: if (!Read4Bit(info->data, image_file, 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; } diff --git a/glide3x/sst1/glide3/src/g3df.c b/glide3x/sst1/glide3/src/g3df.c index eeb1afd..d28dc89 100644 --- a/glide3x/sst1/glide3/src/g3df.c +++ b/glide3x/sst1/glide3/src/g3df.c @@ -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; } @@ -444,7 +411,7 @@ GR_DIENTRY(gu3dfLoad, FxBool, (const char *filename, Gu3dfInfo *info)) packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+1]) << 8; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+2]) << 16; packedvalue |= ((FxU32) info->table.nccTable.yRGB[index*4+3]) << 24; - + info->table.nccTable.packed_data[index] = packedvalue; } @@ -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; }