}
-void Image_StripImageExtension (const char *in, char *out)
+static void Image_StripImageExtension (const char *in, char *out, size_t size_out)
{
const char *end, *temp;
+
+ if (size_out == 0)
+ return;
+
end = in + strlen(in);
if ((end - in) >= 4)
{
|| strcmp(temp, ".png") == 0
|| strcmp(temp, ".jpg") == 0)
end = temp;
- while (in < end)
+ while (in < end && size_out > 1)
+ {
*out++ = *in++;
+ size_out--;
+ }
*out++ = 0;
}
else
- strcpy(out, in);
+ strlcpy(out, in, size_out);
}
typedef struct imageformat_s
Mem_CheckSentinelsGlobal();
if (developer_texturelogging.integer)
Log_Printf("textures.log", "%s\n", filename);
- strlcpy(basename, filename, sizeof(basename));
- Image_StripImageExtension(basename, basename); // strip filename extensions to allow replacement by other types
+ Image_StripImageExtension(filename, basename, sizeof(basename)); // strip filename extensions to allow replacement by other types
// replace *'s with #, so commandline utils don't get confused when dealing with the external files
for (c = basename;*c;c++)
if (*c == '*')
// in can be the same as out
void Image_MipReduce(const unsigned char *in, unsigned char *out, int *width, int *height, int *depth, int destwidth, int destheight, int destdepth, int bytesperpixel)
{
+ const unsigned char *inrow;
int x, y, nextrow;
if (*depth != 1 || destdepth != 1)
{
*depth >>= 1;
return;
}
+ // note: if given odd width/height this discards the last row/column of
+ // pixels, rather than doing a proper box-filter scale down
+ inrow = in;
nextrow = *width * bytesperpixel;
if (*width > destwidth)
{
*height >>= 1;
if (bytesperpixel == 4)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
out[1] = (unsigned char) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
out += 4;
in += 8;
}
- in += nextrow; // skip a line
}
}
else if (bytesperpixel == 3)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
out[1] = (unsigned char) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
out += 3;
in += 6;
}
- in += nextrow; // skip a line
}
}
else
// reduce width
if (bytesperpixel == 4)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[4]) >> 1);
out[1] = (unsigned char) ((in[1] + in[5]) >> 1);
}
else if (bytesperpixel == 3)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[3]) >> 1);
out[1] = (unsigned char) ((in[1] + in[4]) >> 1);
*height >>= 1;
if (bytesperpixel == 4)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[nextrow ]) >> 1);
out[1] = (unsigned char) ((in[1] + in[nextrow+1]) >> 1);
out += 4;
in += 4;
}
- in += nextrow; // skip a line
}
}
else if (bytesperpixel == 3)
{
- for (y = 0;y < *height;y++)
+ for (y = 0;y < *height;y++, inrow += nextrow * 2)
{
- for (x = 0;x < *width;x++)
+ for (in = inrow, x = 0;x < *width;x++)
{
out[0] = (unsigned char) ((in[0] + in[nextrow ]) >> 1);
out[1] = (unsigned char) ((in[1] + in[nextrow+1]) >> 1);
out += 3;
in += 3;
}
- in += nextrow; // skip a line
}
}
else
unsigned char *bumppixels;
int bumppixels_width, bumppixels_height;
char name[MAX_QPATH];
- strlcpy(name, shadername, sizeof(name));
- Image_StripImageExtension(name, name);
+ Image_StripImageExtension(shadername, name, sizeof(name));
memset(s, 0, sizeof(*s));
s->basepixels = loadimagepixels(name, false, 0, 0);
if (s->basepixels == NULL)