+ // if we SW decode, choose 2 sizes bigger
+ if(force_swdecode)
+ {
+ // this is quarter res, so do not scale down more than we have to
+ miplevel -= 2;
+
+ if(miplevel < 0)
+ Con_DPrintf("WARNING: fake software decoding of compressed texture %s degraded quality\n", filename);
+ }
+
+ // this is where we apply gl_picmip
+ mippixels_start = ddspixels;
+ mipwidth = dds_width;
+ mipheight = dds_height;
+ while(miplevel >= 1 && dds_miplevels >= 1)
+ {
+ if (mipwidth <= 1 && mipheight <= 1)
+ break;
+ mipsize = bytesperblock ? ((mipwidth+3)/4)*((mipheight+3)/4)*bytesperblock : mipwidth*mipheight*bytesperpixel;
+ mippixels_start += mipsize; // just skip
+ --dds_miplevels;
+ --miplevel;
+ if (mipwidth > 1)
+ mipwidth >>= 1;
+ if (mipheight > 1)
+ mipheight >>= 1;
+ }
+ mipsize_total = ddssize - 128 - (mippixels_start - ddspixels);
+ mipsize = bytesperblock ? ((mipwidth+3)/4)*((mipheight+3)/4)*bytesperblock : mipwidth*mipheight*bytesperpixel;
+
+ // from here on, we do not need the ddspixels and ddssize any more (apart from the statistics entry in glt)
+
+ // fake decode S3TC if needed
+ if(force_swdecode)
+ {
+ int mipsize_new = mipsize_total / bytesperblock * 4;
+ unsigned char *mipnewpixels = (unsigned char *) Mem_Alloc(tempmempool, mipsize_new);
+ unsigned char *p = mipnewpixels;
+ for (i = bytesperblock == 16 ? 8 : 0;i < (int)mipsize_total;i += bytesperblock, p += 4)
+ {
+ c = mippixels_start[i] + 256*mippixels_start[i+1] + 65536*mippixels_start[i+2] + 16777216*mippixels_start[i+3];
+ p[2] = (((c >> 11) & 0x1F) + ((c >> 27) & 0x1F)) * (0.5f / 31.0f * 255.0f);
+ p[1] = (((c >> 5) & 0x3F) + ((c >> 21) & 0x3F)) * (0.5f / 63.0f * 255.0f);
+ p[0] = (((c ) & 0x1F) + ((c >> 16) & 0x1F)) * (0.5f / 31.0f * 255.0f);
+ if(textype == TEXTYPE_DXT5)
+ p[3] = (0.5 * mippixels_start[i-8] + 0.5 * mippixels_start[i-7]);
+ else if(textype == TEXTYPE_DXT3)
+ p[3] = (
+ (mippixels_start[i-8] & 0x0F)
+ + (mippixels_start[i-8] >> 4)
+ + (mippixels_start[i-7] & 0x0F)
+ + (mippixels_start[i-7] >> 4)
+ + (mippixels_start[i-6] & 0x0F)
+ + (mippixels_start[i-6] >> 4)
+ + (mippixels_start[i-5] & 0x0F)
+ + (mippixels_start[i-5] >> 4)
+ ) * (0.125f / 15.0f * 255.0f);
+ else
+ p[3] = 255;
+ }
+
+ textype = TEXTYPE_BGRA;
+ bytesperblock = 0;
+ bytesperpixel = 4;
+
+ // as each block becomes a pixel, we must use pixel count for this
+ mipwidth = (mipwidth + 3) / 4;
+ mipheight = (mipheight + 3) / 4;
+ mipsize = bytesperpixel * mipwidth * mipheight;
+ mippixels_start = mipnewpixels;
+ mipsize_total = mipsize_new;
+ }
+
+ // start mip counting
+ mippixels = mippixels_start;
+