From: havoc Date: Thu, 30 Aug 2007 03:55:21 +0000 (+0000) Subject: save 24bit tga if alpha channel is entirely 255 X-Git-Tag: xonotic-v0.1.0preview~2929 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=18f504129443a62e1fa9f93e198df5879e4ffc86;p=xonotic%2Fdarkplaces.git save 24bit tga if alpha channel is entirely 255 git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7546 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/image.c b/image.c index be151e78..bc58a724 100644 --- a/image.c +++ b/image.c @@ -961,24 +961,54 @@ void Image_WriteTGARGBA (const char *filename, int width, int height, const unsi buffer[13] = (width >> 8) & 0xFF; buffer[14] = (height >> 0) & 0xFF; buffer[15] = (height >> 8) & 0xFF; - buffer[16] = 32; // pixel size - buffer[17] = 8; // 8 bits of alpha - // swap rgba to bgra and flip upside down - out = buffer + 18; - for (y = height - 1;y >= 0;y--) + for (y = 3;y < width*height*4;y += 4) + if (data[y] < 255) + break; + + if (y < width*height*4) { - in = data + y * width * 4; - end = in + width * 4; - for (;in < end;in += 4) + // save the alpha channel + buffer[16] = 32; // pixel size + buffer[17] = 8; // 8 bits of alpha + + // swap rgba to bgra and flip upside down + out = buffer + 18; + for (y = height - 1;y >= 0;y--) { - *out++ = in[2]; - *out++ = in[1]; - *out++ = in[0]; - *out++ = in[3]; + in = data + y * width * 4; + end = in + width * 4; + for (;in < end;in += 4) + { + *out++ = in[2]; + *out++ = in[1]; + *out++ = in[0]; + *out++ = in[3]; + } + } + FS_WriteFile (filename, buffer, width*height*4 + 18 ); + } + else + { + // save only the color channels + buffer[16] = 24; // pixel size + buffer[17] = 0; // 8 bits of alpha + + // swap rgba to bgr and flip upside down + out = buffer + 18; + for (y = height - 1;y >= 0;y--) + { + in = data + y * width * 4; + end = in + width * 4; + for (;in < end;in += 4) + { + *out++ = in[2]; + *out++ = in[1]; + *out++ = in[0]; + } } + FS_WriteFile (filename, buffer, width*height*3 + 18 ); } - FS_WriteFile (filename, buffer, width*height*4 + 18 ); Mem_Free(buffer); }