int image_width;
int image_height;
-void Image_CopyMux(qbyte *outpixels, const qbyte *inpixels, int width, int height, int flipx, int flipy, int flipdiagonal, int numincomponents, int numoutcomponents, int *inputcomponentindices)
+#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(qbyte *outpixels, const qbyte *inpixels, int inputwidth, int inputheight, qboolean inputflipx, qboolean inputflipy, qboolean inputflipdiagonal, int numoutputcomponents, int numinputcomponents, int *outputinputcomponentindices)
+{
+ int index, c, x, y;
+ const qbyte *in, *line;
+ int row_inc = (inputflipy ? -inputwidth : inputwidth) * numinputcomponents, col_inc = (inputflipx ? -1 : 1) * numinputcomponents;
+ int row_ofs = (inputflipy ? (inputheight - 1) * inputwidth * numinputcomponents : 0), col_ofs = (inputflipx ? (inputwidth - 1) * numinputcomponents : 0);
+
+ for (c = 0; c < numoutputcomponents; c++)
+ if (outputinputcomponentindices[c] & 0x80000000)
+ break;
+ if (c < numoutputcomponents)
+ {
+ // special indices used
+ if (inputflipdiagonal)
+ {
+ for (x = 0, line = inpixels + col_ofs; x < inputwidth; x++, line += col_inc)
+ for (y = 0, in = line + row_ofs; y < inputheight; y++, in += row_inc, outpixels += numinputcomponents)
+ for (c = 0; c < numoutputcomponents; c++)
+ outpixels[c] = ((index = outputinputcomponentindices[c]) & 0x80000000) ? index : in[index];
+ }
+ else
+ {
+ for (y = 0, line = inpixels + row_ofs; y < inputheight; y++, line += row_inc)
+ for (x = 0, in = line + col_ofs; x < inputwidth; x++, in += col_inc, outpixels += numinputcomponents)
+ for (c = 0; c < numoutputcomponents; c++)
+ outpixels[c] = ((index = outputinputcomponentindices[c]) & 0x80000000) ? index : in[index];
+ }
+ }
+ else
+ {
+ // special indices not used
+ if (inputflipdiagonal)
+ {
+ for (x = 0, line = inpixels + col_ofs; x < inputwidth; x++, line += col_inc)
+ for (y = 0, in = line + row_ofs; y < inputheight; y++, in += row_inc, outpixels += numinputcomponents)
+ for (c = 0; c < numoutputcomponents; c++)
+ outpixels[c] = in[outputinputcomponentindices[c]];
+ }
+ else
+ {
+ for (y = 0, line = inpixels + row_ofs; y < inputheight; y++, line += row_inc)
+ for (x = 0, in = line + col_ofs; x < inputwidth; x++, in += col_inc, outpixels += numinputcomponents)
+ for (c = 0; c < numoutputcomponents; c++)
+ outpixels[c] = in[outputinputcomponentindices[c]];
+ }
+ }
+}
+#else
+// intentionally readable version
+void Image_CopyMux(qbyte *outpixels, const qbyte *inpixels, int inputwidth, int inputheight, qboolean inputflipx, qboolean inputflipy, qboolean inputflipdiagonal, int numoutputcomponents, int numinputcomponents, int *outputinputcomponentindices)
{
int index, c, x, y;
const qbyte *in, *inrow, *incolumn;
- if (flipdiagonal)
+ if (inputflipdiagonal)
{
- for (y = 0;y < height;y++)
+ for (x = 0;x < inputwidth;x++)
{
- incolumn = inpixels + (flipx ? width - 1 - y : y) * numincomponents;
- for (x = 0;x < width;x++)
+ for (y = 0;y < inputheight;y++)
{
- in = incolumn + (flipy ? height - 1 - x : x) * width * numincomponents;
- for (c = 0;c < numoutcomponents;c++)
+ in = inpixels + ((inputflipy ? inputheight - 1 - y : y) * inputwidth + (inputflipx ? inputwidth - 1 - x : x)) * numinputcomponents;
+ for (c = 0;c < numoutputcomponents;c++)
{
- index = inputcomponentindices[c];
- *outpixels++ = (index & 0x80000000) ? (index - 0x8000000) : in[index];
+ index = outputinputcomponentindices[c];
+ if (index & 0x80000000)
+ *outpixels++ = index;
+ else
+ *outpixels++ = in[index];
}
}
}
}
else
{
- for (y = 0;y < height;y++)
+ for (y = 0;y < inputheight;y++)
{
- inrow = inpixels + (flipy ? height - 1 - y : y) * width * numincomponents;
- for (x = 0;x < width;x++)
+ for (x = 0;x < inputwidth;x++)
{
- in = inrow + (flipx ? width - 1 - x : x) * numincomponents;
- for (c = 0;c < numoutcomponents;c++)
+ in = inpixels + ((inputflipy ? inputheight - 1 - y : y) * inputwidth + (inputflipx ? inputwidth - 1 - x : x)) * numinputcomponents;
+ for (c = 0;c < numoutputcomponents;c++)
{
- index = inputcomponentindices[c];
- *outpixels++ = (index & 0x80000000) ? (index - 0x8000000) : in[index];
+ index = outputinputcomponentindices[c];
+ if (index & 0x80000000)
+ *outpixels++ = index;
+ else
+ *outpixels++ = in[index];
}
}
}
}
}
+#endif
void Image_GammaRemapRGB(const qbyte *in, qbyte *out, int pixels, const qbyte *gammar, const qbyte *gammag, const qbyte *gammab)
{
for (i = 0;imageformats[i].formatstring;i++)
{
sprintf (name, imageformats[i].formatstring, basename);
- if ((f = FS_LoadFile(name, true)) && (data = imageformats[i].loadfunc(f, matchwidth, matchheight)))
+ f = FS_LoadFile(name, tempmempool, true);
+ if (f)
{
+ data = imageformats[i].loadfunc(f, matchwidth, matchheight);
Mem_Free(f);
- Con_DPrintf("loaded image %s (%dx%d)\n", name, image_width, image_height);
- if (developer_memorydebug.integer)
- Mem_CheckSentinelsGlobal();
- return data;
+ if (data)
+ {
+ Con_DPrintf("loaded image %s (%dx%d)\n", name, image_width, image_height);
+ if (developer_memorydebug.integer)
+ Mem_CheckSentinelsGlobal();
+ return data;
+ }
}
}
if (complain)
return rt;
}
-qboolean Image_WriteTGARGB_preflipped (const char *filename, int width, int height, const qbyte *data)
+qboolean Image_WriteTGARGB_preflipped (const char *filename, int width, int height, const qbyte *data, qbyte *buffer)
{
qboolean ret;
- qbyte *buffer, *out;
+ qbyte *out;
const qbyte *in, *end;
- buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
-
memset (buffer, 0, 18);
buffer[2] = 2; // uncompressed type
buffer[12] = (width >> 0) & 0xFF;
}
ret = FS_WriteFile (filename, buffer, width*height*3 + 18 );
- Mem_Free(buffer);
return ret;
}
buffer[14] = (height >> 0) & 0xFF;
buffer[15] = (height >> 8) & 0xFF;
buffer[16] = 32; // pixel size
+ buffer[17] = 8; // transparent flag? (seems to be needed by gimp)
// swap rgba to bgra and flip upside down
out = buffer + 18;
Mem_Free(resamplerow1);
resamplerowsize = outwidth*4;
if (!resamplemempool)
- resamplemempool = Mem_AllocPool("Image Scaling Buffer");
+ resamplemempool = Mem_AllocPool("Image Scaling Buffer", 0, NULL);
resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
resamplerow2 = resamplerow1 + resamplerowsize;
}
n[1] = dv[0][2]*dv[1][0]-dv[0][0]*dv[1][2];
n[2] = dv[0][0]*dv[1][1]-dv[0][1]*dv[1][0];
*/
- n[0] = ((p1[0] + p1[1] + p1[2]) - (p0[0] + p0[1] + p0[2]));
- n[1] = ((p0[0] + p0[1] + p0[2]) - (p2[0] + p2[1] + p2[2]));
+ n[0] = ((p0[0] + p0[1] + p0[2]) - (p1[0] + p1[1] + p1[2]));
+ n[1] = ((p2[0] + p2[1] + p2[2]) - (p0[0] + p0[1] + p0[2]));
n[2] = ibumpscale;
VectorNormalize(n);
/*