+}
+
+void Image_HeightmapToNormalmap_BGRA(const unsigned char *inpixels, unsigned char *outpixels, int width, int height, int clamp, float bumpscale)
+{
+ int x, y, x1, x2, y1, y2;
+ const unsigned char *b, *row[3];
+ int p[5];
+ unsigned char *out;
+ float ibumpscale, n[3];
+ ibumpscale = (255.0f * 6.0f) / bumpscale;
+ out = outpixels;
+ for (y = 0, y1 = height-1;y < height;y1 = y, y++)
+ {
+ y2 = y + 1;if (y2 >= height) y2 = 0;
+ row[0] = inpixels + (y1 * width) * 4;
+ row[1] = inpixels + (y * width) * 4;
+ row[2] = inpixels + (y2 * width) * 4;
+ for (x = 0, x1 = width-1;x < width;x1 = x, x++)
+ {
+ x2 = x + 1;if (x2 >= width) x2 = 0;
+ // left, right
+ b = row[1] + x1 * 4;p[0] = (b[0] + b[1] + b[2]);
+ b = row[1] + x2 * 4;p[1] = (b[0] + b[1] + b[2]);
+ // above, below
+ b = row[0] + x * 4;p[2] = (b[0] + b[1] + b[2]);
+ b = row[2] + x * 4;p[3] = (b[0] + b[1] + b[2]);
+ // center
+ b = row[1] + x * 4;p[4] = (b[0] + b[1] + b[2]);
+ // calculate a normal from the slopes
+ n[0] = p[0] - p[1];
+ n[1] = p[3] - p[2];
+ n[2] = ibumpscale;
+ VectorNormalize(n);
+ // turn it into a dot3 rgb vector texture
+ out[2] = (int)(128.0f + n[0] * 127.0f);
+ out[1] = (int)(128.0f + n[1] * 127.0f);
+ out[0] = (int)(128.0f + n[2] * 127.0f);
+ out[3] = (p[4]) / 3;
+ out += 4;
+ }
+ }
+}
+
+
+#include "lhfont.h"
+
+static unsigned char *Image_GenerateConChars(void)
+{
+ int i;
+ unsigned char *data;
+ double random;
+
+ image_width = 256;
+ image_height = 256;
+
+ data = LoadTGA_BGRA(concharimage, sizeof(concharimage), NULL);
+ // Gold numbers
+ for (i = 0; i < 8192; i++)
+ {
+ random = lhrandom(0.0, 1.0);
+ data[i * 4 + 3] = data[i * 4 + 0];
+ data[i * 4 + 2] = 83 + (unsigned char)(random * 64);
+ data[i * 4 + 1] = 71 + (unsigned char)(random * 32);
+ data[i * 4 + 0] = 23 + (unsigned char)(random * 16);
+ }
+ // White chars
+ for (i = 8192; i < 32768; i++)
+ {
+ random = lhrandom(0.0, 1.0);
+ data[i * 4 + 3] = data[i * 4 + 0];
+ data[i * 4 + 2] = 95 + (unsigned char)(random * 64);
+ data[i * 4 + 1] = 95 + (unsigned char)(random * 64);
+ data[i * 4 + 0] = 95 + (unsigned char)(random * 64);
+ }
+ // Gold numbers
+ for (i = 32768; i < 40960; i++)
+ {
+ random = lhrandom(0.0, 1.0);
+ data[i * 4 + 3] = data[i * 4 + 0];
+ data[i * 4 + 2] = 83 + (unsigned char)(random * 64);
+ data[i * 4 + 1] = 71 + (unsigned char)(random * 32);
+ data[i * 4 + 0] = 23 + (unsigned char)(random * 16);
+ }
+ // Red chars
+ for (i = 40960; i < 65536; i++)
+ {
+ random = lhrandom(0.0, 1.0);
+ data[i * 4 + 3] = data[i * 4 + 0];
+ data[i * 4 + 2] = 96 + (unsigned char)(random * 64);
+ data[i * 4 + 1] = 43 + (unsigned char)(random * 32);
+ data[i * 4 + 0] = 27 + (unsigned char)(random * 32);
+ }
+
+#if 0
+ Image_WriteTGABGRA("gfx/generated_conchars.tga", 256, 256, data);
+#endif
+
+ return data;
+}
+
+static unsigned char *Image_GenerateDitherPattern(void)
+{
+ int x, y;
+ unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, 8 * 8 * 4);
+ image_width = 8;
+ image_height = 8;
+ for (y = 0; y < 8; y++)
+ {
+ for (x = 0; x < 8; x++)
+ {
+ data[(y * 8 + x) * 4 + 0] = ((x^y) & 4) ? 255 : 0;
+ data[(y * 8 + x) * 4 + 1] = ((x^y) & 4) ? 255 : 0;
+ data[(y * 8 + x) * 4 + 2] = ((x^y) & 4) ? 255 : 0;
+ data[(y * 8 + x) * 4 + 3] = 255;
+ }
+ }
+ return data;
+}
+
+// also used in R_SkinFrame code
+unsigned char *Image_GenerateNoTexture(void)
+{
+ int x, y;
+ unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, 16 * 16 * 4);
+ image_width = 16;
+ image_height = 16;
+ // this makes a light grey/dark grey checkerboard texture
+ for (y = 0; y < 16; y++)
+ {
+ for (x = 0; x < 16; x++)
+ {
+ data[(y * 16 + x) * 4 + 0] =
+ data[(y * 16 + x) * 4 + 1] =
+ data[(y * 16 + x) * 4 + 2] = (y < 8) ^ (x < 8) ? 128 : 64;
+ data[(y * 16 + x) * 4 + 3] = 255;
+ }
+ }
+ return data;
+}
+
+static unsigned char *Image_GenerateWhite(void)
+{
+ unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, 1 * 1 * 4);
+ image_width = 1;
+ image_height = 1;
+ data[0] = data[1] = data[2] = data[3] = 255;
+ return data;
+}
+
+typedef struct embeddedpic_s
+{
+const char *name;
+int width;
+int height;
+const char *pixels;
+}
+embeddedpic_t;
+
+static const embeddedpic_t embeddedpics[] =
+{
+ {
+ "gfx/prydoncursor001", 16, 16,
+ "477777774......."
+ "77.....6........"
+ "7.....6........."
+ "7....6.........."
+ "7.....6........."
+ "7..6...6........"
+ "7.6.6...6......."
+ "76...6...6......"
+ "4.....6.6......."
+ ".......6........"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ },
+ {
+ "ui/mousepointer", 16, 16,
+ "477777774......."
+ "77.....6........"
+ "7.....6........."
+ "7....6.........."
+ "7.....6........."
+ "7..6...6........"
+ "7.6.6...6......."
+ "76...6...6......"
+ "4.....6.6......."
+ ".......6........"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ },
+ {
+ "gfx/crosshair1", 16, 16,
+ "................"
+ "................"
+ "................"
+ "...33......33..."
+ "...355....553..."
+ "....577..775...."
+ ".....77..77....."
+ "................"
+ "................"
+ ".....77..77....."
+ "....577..775...."
+ "...355....553..."
+ "...33......33..."
+ "................"
+ "................"
+ "................"
+ },
+ {
+ "gfx/crosshair2", 16, 16,
+ "................"
+ "................"
+ "................"
+ "...3........3..."
+ "....5......5...."
+ ".....7....7....."
+ "......7..7......"
+ "................"
+ "................"
+ "......7..7......"
+ ".....7....7....."
+ "....5......5...."
+ "...3........3..."
+ "................"
+ "................"
+ "................"
+ },
+ {
+ "gfx/crosshair3", 16, 16,
+ "................"
+ ".......77......."
+ ".......77......."
+ "................"
+ "................"
+ ".......44......."
+ ".......44......."
+ ".77..44..44..77."
+ ".77..44..44..77."
+ ".......44......."
+ ".......44......."
+ "................"
+ "................"
+ ".......77......."
+ ".......77......."
+ "................"
+ },
+ {
+ "gfx/crosshair4", 16, 16,
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "................"
+ "........7777777."
+ "........752....."
+ "........72......"
+ "........7......."
+ "........7......."
+ "........7......."
+ "........7......."
+ "................"
+ },
+ {
+ "gfx/crosshair5", 8, 8,
+ "........"
+ "........"
+ "....7..."
+ "........"
+ "..7.7.7."
+ "........"
+ "....7..."
+ "........"
+ },
+ {
+ "gfx/crosshair6", 2, 2,
+ "77"
+ "77"
+ },
+ {
+ "gfx/crosshair7", 16, 16,
+ "................"
+ ".3............3."
+ "..5...2332...5.."
+ "...7.3....3.7..."
+ "....7......7...."
+ "...3.7....7.3..."
+ "..2...7..7...2.."
+ "..3..........3.."
+ "..3..........3.."
+ "..2...7..7...2.."
+ "...3.7....7.3..."
+ "....7......7...."
+ "...7.3....3.7..."
+ "..5...2332...5.."
+ ".3............3."
+ "................"
+ },
+ { NULL, 0, 0, NULL }
+};
+
+unsigned char *Image_GetEmbeddedPicBGRA(const char *name)
+{
+ const embeddedpic_t *p;
+ for (p = embeddedpics; p->name; p++)
+ {
+ if (!strcmp(name, p->name))
+ {
+ int i;
+ unsigned char *data = (unsigned char *)Mem_Alloc(tempmempool, p->width * p->height * 4);
+ image_width = p->width;
+ image_height = p->height;
+ for (i = 0; i < p->width * p->height; i++)
+ {
+ const unsigned char *c = (const unsigned char *)palette_bgra_embeddedpic + 4 * p->pixels[i];
+ Vector4Copy(c, data + 4 * i);
+ }
+ return data;
+ }
+ }
+ if (!strcmp(name, "white") || !strcmp(name, "#white") || !strcmp(name, "*white") || !strcmp(name, "$whiteimage"))
+ return Image_GenerateWhite();
+ if (!strcmp(name, "gfx/conchars"))
+ return Image_GenerateConChars();
+ if (!strcmp(name, "gfx/colorcontrol/ditherpattern"))
+ return Image_GenerateDitherPattern();
+ return NULL;