From: divverent Date: Sat, 14 Nov 2009 21:39:35 +0000 (+0000) Subject: experimental feature to load the alpha channel of foo.jpg from foo_alpha.jpg (JPEG... X-Git-Tag: xonotic-v0.1.0preview~1150 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=faec30a77780d42d0ba107782bfb59394e6f05c0;p=xonotic%2Fdarkplaces.git experimental feature to load the alpha channel of foo.jpg from foo_alpha.jpg (JPEG specific) to allow transparency even when using JPEG git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@9492 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/image.c b/image.c index 2f805795..55828225 100644 --- a/image.c +++ b/image.c @@ -8,6 +8,14 @@ int image_width; int image_height; +void Image_CopyAlphaFromBlueBGRA(unsigned char *outpixels, const unsigned char *inpixels, int w, int h) +{ + int i, n; + n = w * h; + for(i = 0; i < n; ++i) + outpixels[4*i+3] = inpixels[4*i]; // blue channel +} + #if 1 // written by LordHavoc in a readable way, optimized by Vic, further optimized by LordHavoc (the non-special index case), readable version preserved below this void Image_CopyMux(unsigned char *outpixels, const unsigned char *inpixels, int inputwidth, int inputheight, qboolean inputflipx, qboolean inputflipy, qboolean inputflipdiagonal, int numoutputcomponents, int numinputcomponents, int *outputinputcomponentindices) @@ -850,8 +858,8 @@ unsigned char *loadimagepixelsbgra (const char *filename, qboolean complain, qbo { fs_offset_t filesize; imageformat_t *firstformat, *format; - unsigned char *f, *data = NULL; - char basename[MAX_QPATH], name[MAX_QPATH], *c; + unsigned char *f, *data = NULL, *data2 = NULL; + char basename[MAX_QPATH], name[MAX_QPATH], name2[MAX_QPATH], *c; //if (developer_memorydebug.integer) // Mem_CheckSentinelsGlobal(); if (developer_texturelogging.integer) @@ -890,6 +898,18 @@ unsigned char *loadimagepixelsbgra (const char *filename, qboolean complain, qbo { data = format->loadfunc(f, filesize); Mem_Free(f); + 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("%s_alpha", basename)); + f = FS_LoadFile(name2, tempmempool, true, &filesize); + if(f) + { + data2 = format->loadfunc(f, filesize); + Mem_Free(f); + Image_CopyAlphaFromBlueBGRA(data, data2, image_width, image_height); + Mem_Free(data2); + } + } if (data) { if (developer.integer >= 10)