+ if(FS_FileExists(name) && (f = FS_LoadFile(name, tempmempool, true, &filesize)) != NULL)
+ {
+ mymiplevel = miplevel ? *miplevel : 0;
+ image_width = 0;
+ image_height = 0;
+ data = format->loadfunc(f, (int)filesize, &mymiplevel);
+ Mem_Free(f);
+ if (data)
+ {
+ if(format->loadfunc == JPEG_LoadImage_BGRA) // jpeg can't do alpha, so let's simulate it by loading another jpeg
+ {
+ dpsnprintf (name2, sizeof(name2), format->formatstring, va(vabuf, sizeof(vabuf), "%s_alpha", basename));
+ f = FS_LoadFile(name2, tempmempool, true, &filesize);
+ if(f)
+ {
+ int mymiplevel2 = miplevel ? *miplevel : 0;
+ int image_width_save = image_width;
+ int image_height_save = image_height;
+ data2 = format->loadfunc(f, (int)filesize, &mymiplevel2);
+ if(data2 && mymiplevel == mymiplevel2 && image_width == image_width_save && image_height == image_height_save)
+ Image_CopyAlphaFromBlueBGRA(data, data2, image_width, image_height);
+ else
+ Con_Printf("loadimagepixelsrgba: corrupt or invalid alpha image %s_alpha\n", basename);
+ image_width = image_width_save;
+ image_height = image_height_save;
+ if(data2)
+ Mem_Free(data2);
+ Mem_Free(f);
+ }
+ }
+ if (developer_loading.integer)
+ Con_DPrintf("loaded image %s (%dx%d)\n", name, image_width, image_height);
+ if(miplevel)
+ *miplevel = mymiplevel;
+ //if (developer_memorydebug.integer)
+ // Mem_CheckSentinelsGlobal();
+ if(allowFixtrans && r_fixtrans_auto.integer)
+ {
+ int n = fixtransparentpixels(data, image_width, image_height);
+ if(n)
+ {
+ Con_Printf("- had to fix %s (%d pixels changed)\n", name, n);
+ if(r_fixtrans_auto.integer >= 2)
+ {
+ char outfilename[MAX_QPATH], buf[MAX_QPATH];
+ Image_StripImageExtension(name, buf, sizeof(buf));
+ dpsnprintf(outfilename, sizeof(outfilename), "fixtrans/%s.tga", buf);
+ Image_WriteTGABGRA(outfilename, image_width, image_height, data);
+ Con_Printf("- %s written.\n", outfilename);
+ }
+ }
+ }
+ if (convertsRGB)
+ Image_MakeLinearColorsFromsRGB(data, data, image_width * image_height);
+ return data;
+ }
+ else
+ Con_DPrintf("Error loading image %s (file loaded but decode failed)\n", name);
+ }
+ }
+ if (!strcasecmp(path, "gfx"))
+ {
+ unsigned char *lmpdata;
+ if ((lmpdata = W_GetLumpName(afterpath, &filesize)))
+ {
+ if (developer_loading.integer)
+ Con_Printf("loading gfx.wad lump \"%s\"\n", afterpath);
+
+ mymiplevel = miplevel ? *miplevel : 0;
+ if (!strcmp(afterpath, "conchars"))
+ {
+ // conchars is a raw image and with color 0 as transparent instead of 255
+ data = LoadConChars_BGRA(lmpdata, filesize, &mymiplevel);
+ }
+ else
+ data = LoadLMP_BGRA(lmpdata, filesize, &mymiplevel);
+ // no cleanup after looking up a wad lump - the whole gfx.wad is loaded at once
+ if (data)
+ return data;
+ Con_DPrintf("Error loading image %s (file loaded but decode failed)\n", name);
+ }
+ }