X-Git-Url: http://git.xonotic.org/?a=blobdiff_plain;f=image.c;h=d72ceca744644700e558808c08a4dd86dc1fbd85;hb=dbc0ab84895b26254dd41c9b17cb16c77337e9a1;hp=4f85e83e43281148ab1be7af31913e56ce77f888;hpb=6c88529e0783c59bbb145a7d84b29127cfbcf4ef;p=xonotic%2Fdarkplaces.git diff --git a/image.c b/image.c index 4f85e83e..d72ceca7 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,36 @@ 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"); + *retwidth = 16; + *retheight = 16; + *retflags = 0; + *retvalue = 0; + *retcontents = 0; + memset(retanimname32c, 0, 32); + return false; + } + + *retwidth = LittleLong(inwal->width); + *retheight = LittleLong(inwal->height); + *retflags = LittleLong(inwal->flags); + *retvalue = LittleLong(inwal->value); + *retcontents = LittleLong(inwal->contents); + memcpy(retanimname32c, inwal->animname, 32); + retanimname32c[31] = 0; + return true; +} + void Image_StripImageExtension (const char *in, char *out, size_t size_out) { @@ -790,7 +829,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 +993,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,11 +1006,15 @@ 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(data2 && mymiplevel == 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);