X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=image.c;h=1f15a2fce253d4d330d7edb1e05d5935d800222d;hb=b761eb6b6ce3048307c587f097d0c4f13f6cc0c4;hp=988fbef8e7f27b4a8abcfaf89edb8e92cecea14e;hpb=cfee52a1ec9db338098789cae89ae5cf1f7a6fbf;p=xonotic%2Fdarkplaces.git diff --git a/image.c b/image.c index 988fbef8..1f15a2fc 100644 --- a/image.c +++ b/image.c @@ -354,6 +354,19 @@ qboolean LoadPCX_QWSkin(const unsigned char *f, int filesize, unsigned char *pix return true; } +/* +============ +LoadPCX +============ +*/ +qboolean LoadPCX_PaletteOnly(const unsigned char *f, int filesize, unsigned char *palette768b) +{ + if (filesize < 768) + return false; + memcpy(palette768b, f + filesize - 768, 768); + return true; +} + /* ========================================================= @@ -423,6 +436,8 @@ unsigned char *LoadTGA_BGRA (const unsigned char *f, int filesize, int *miplevel return NULL; } + memset(palettei, 0, sizeof(palettei)); + // advance to end of header fin = f + 18; @@ -537,8 +552,6 @@ unsigned char *LoadTGA_BGRA (const unsigned char *f, int filesize, int *miplevel row_inci = 0; } - x = 0; - y = 0; pix_inc = 1; if ((targa_header.image_type & ~8) == 2) pix_inc = (targa_header.pixel_size + 7) / 8; @@ -765,7 +778,7 @@ static unsigned char *LoadWAL_BGRA (const unsigned char *f, int filesize, int *m return NULL; } - if (filesize < (int) sizeof(q2wal_t) + (int) LittleLong(inwal->offsets[0]) + image_width * image_height) + if (filesize < (int) LittleLong(inwal->offsets[0]) + image_width * image_height) { Con_Print("LoadWAL: invalid WAL file\n"); return NULL; @@ -777,10 +790,50 @@ static unsigned char *LoadWAL_BGRA (const unsigned char *f, int filesize, int *m Con_Printf("LoadWAL: not enough memory for %i by %i image\n", image_width, image_height); return NULL; } - Image_Copy8bitBGRA(f + LittleLong(inwal->offsets[0]), image_buffer, image_width * image_height, palette_bgra_complete); + Image_Copy8bitBGRA(f + LittleLong(inwal->offsets[0]), image_buffer, image_width * image_height, q2palette_bgra_complete); return image_buffer; } +qboolean LoadWAL_GetMetadata(const unsigned char *f, int filesize, int *retwidth, int *retheight, int *retflags, int *retvalue, int *retcontents, char *retanimname32c) +{ + const q2wal_t *inwal = (const q2wal_t *)f; + + if (filesize < (int) sizeof(q2wal_t)) + { + Con_Print("LoadWAL: invalid WAL file\n"); + if (retwidth) + *retwidth = 16; + if (retheight) + *retheight = 16; + if (retflags) + *retflags = 0; + if (retvalue) + *retvalue = 0; + if (retcontents) + *retcontents = 0; + if (retanimname32c) + memset(retanimname32c, 0, 32); + return false; + } + + if (retwidth) + *retwidth = LittleLong(inwal->width); + if (retheight) + *retheight = LittleLong(inwal->height); + if (retflags) + *retflags = LittleLong(inwal->flags); + if (retvalue) + *retvalue = LittleLong(inwal->value); + if (retcontents) + *retcontents = LittleLong(inwal->contents); + if (retanimname32c) + { + memcpy(retanimname32c, inwal->animname, 32); + retanimname32c[31] = 0; + } + return true; +} + void Image_StripImageExtension (const char *in, char *out, size_t size_out) { @@ -790,7 +843,7 @@ void Image_StripImageExtension (const char *in, char *out, size_t size_out) return; ext = FS_FileExtension(in); - if (ext && (!strcmp(ext, "tga") || !strcmp(ext, "pcx") || !strcmp(ext, "lmp") || !strcmp(ext, "png") || !strcmp(ext, "jpg"))) + if (ext && (!strcmp(ext, "tga") || !strcmp(ext, "pcx") || !strcmp(ext, "lmp") || !strcmp(ext, "png") || !strcmp(ext, "jpg") || !strcmp(ext, "wal"))) FS_StripExtension(in, out, size_out); else strlcpy(out, in, size_out); @@ -954,6 +1007,8 @@ unsigned char *loadimagepixelsbgra (const char *filename, qboolean complain, qbo if (f) { int mymiplevel = miplevel ? *miplevel : 0; + image_width = 0; + image_height = 0; data = format->loadfunc(f, (int)filesize, &mymiplevel); Mem_Free(f); if (data) @@ -965,12 +1020,18 @@ unsigned char *loadimagepixelsbgra (const char *filename, qboolean complain, qbo 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(mymiplevel != mymiplevel2) - Host_Error("loadimagepixelsbgra: miplevels differ"); + 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); - Image_CopyAlphaFromBlueBGRA(data, data2, image_width, image_height); - Mem_Free(data2); } } if (developer_loading.integer)