-/* File: maid-x11.c */
+/* File: maid-x11.c */
/*
* Copyright (c) 1997 Ben Harrison, and others
* are included in all such copies.
*/
+#ifdef USE_X11
+
#include <math.h>
#ifdef SUPPORT_GAMMA
static bool gamma_table_ready = FALSE;
+static int gamma_val = 0;
#endif /* SUPPORT_GAMMA */
#ifdef SUPPORT_GAMMA
- int gamma = 0;
-
if (!gamma_table_ready)
{
- cptr str = getenv("ANGBAND_X11_GAMMA");
- if (str != NULL) gamma = atoi(str);
+ concptr str = getenv("ANGBAND_X11_GAMMA");
+ if (str != NULL) gamma_val = atoi(str);
gamma_table_ready = TRUE;
/* Only need to build the table if gamma exists */
- if (gamma) build_gamma_table(gamma);
+ if (gamma_val) build_gamma_table(gamma_val);
}
/* Hack -- Gamma Correction */
- if (gamma > 0)
+ if (gamma_val > 0)
{
red = gamma_table[red];
green = gamma_table[green];
if (!(XAllocColor(dpy, cmap, &xcolour)))
{
quit_fmt("Couldn't allocate bitmap color '#%02x%02x%02x'\n",
- red, green, blue);
+ red, green, blue);
}
return (xcolour.pixel);
/*
* The Win32 "BITMAPFILEHEADER" type.
- *
- * Note the "bfAlign" field, which is a complete hack to ensure that the
- * "u32b" fields in the structure get aligned. Thus, when reading this
- * header from the file, we must be careful to skip this field.
*/
typedef struct BITMAPFILEHEADER
{
- u16b bfAlign; /* HATE this */
u16b bfType;
u32b bfSize;
u16b bfReserved1;
} RGBQUAD;
+/*** Helper functions for system independent file loading. ***/
+
+static byte get_byte(FILE *fff)
+{
+ /* Get a character, and return it */
+ return (getc(fff) & 0xFF);
+}
+
+static void rd_byte(FILE *fff, byte *ip)
+{
+ *ip = get_byte(fff);
+}
+
+static void rd_u16b(FILE *fff, u16b *ip)
+{
+ (*ip) = get_byte(fff);
+ (*ip) |= ((u16b)(get_byte(fff)) << 8);
+}
+
+static void rd_u32b(FILE *fff, u32b *ip)
+{
+ (*ip) = get_byte(fff);
+ (*ip) |= ((u32b)(get_byte(fff)) << 8);
+ (*ip) |= ((u32b)(get_byte(fff)) << 16);
+ (*ip) |= ((u32b)(get_byte(fff)) << 24);
+}
+
+
/*
* Read a Win32 BMP file.
*
BITMAPFILEHEADER fileheader;
BITMAPINFOHEADER infoheader;
- vptr fileheaderhack = (vptr)((char *)(&fileheader) + 2);
-
XImage *Res = NULL;
char *Data;
}
/* Read the "BITMAPFILEHEADER" */
- fread(fileheaderhack, sizeof(fileheader) - 2, 1, f);
+ rd_u16b(f, &(fileheader.bfType));
+ rd_u32b(f, &(fileheader.bfSize));
+ rd_u16b(f, &(fileheader.bfReserved1));
+ rd_u16b(f, &(fileheader.bfReserved2));
+ rd_u32b(f, &(fileheader.bfOffBits));
/* Read the "BITMAPINFOHEADER" */
- fread(&infoheader, sizeof(infoheader), 1, f);
+ rd_u32b(f, &(infoheader.biSize));
+ rd_u32b(f, &(infoheader.biWidth));
+ rd_u32b(f, &(infoheader.biHeight));
+ rd_u16b(f, &(infoheader.biPlanes));
+ rd_u16b(f, &(infoheader.biBitCount));
+ rd_u32b(f, &(infoheader.biCompresion));
+ rd_u32b(f, &(infoheader.biSizeImage));
+ rd_u32b(f, &(infoheader.biXPelsPerMeter));
+ rd_u32b(f, &(infoheader.biYPelsPerMeter));
+ rd_u32b(f, &(infoheader.biClrUsed));
+ rd_u32b(f, &(infoheader.biClrImportand));
/* Verify the header */
if (feof(f) ||
{
RGBQUAD clrg;
- fread(&clrg, 4, 1, f);
+ /* Read an "RGBQUAD" */
+ rd_byte(f, &(clrg.b));
+ rd_byte(f, &(clrg.g));
+ rd_byte(f, &(clrg.r));
+ rd_byte(f, &(clrg.filler));
/* Analyze the color */
clr_pixels[i] = create_pixel(dpy, clrg.r, clrg.g, clrg.b);
C_MAKE(Data, total, char);
Res = XCreateImage(dpy, visual, depth, ZPixmap, 0 /*offset*/,
- Data, infoheader.biWidth, infoheader.biHeight,
- 8 /*bitmap_pad*/, 0 /*bytes_per_line*/);
+ Data, infoheader.biWidth, infoheader.biHeight,
+ 8 /*bitmap_pad*/, 0 /*bytes_per_line*/);
/* Failure */
if (Res == NULL)
{
/* Technically 1 bit is legal too */
quit_fmt("Illegal biBitCount %d in %s",
- infoheader.biBitCount, Name);
+ infoheader.biBitCount, Name);
}
}
}
* redScan, greenScan and blueScan must be sufficiently sized
*/
static void GetScaledRow(XImage *Im, int x, int y, int iw, int ow,
- unsigned long *redScan, unsigned long *greenScan,
- unsigned long *blueScan)
+ unsigned long *redScan, unsigned long *greenScan,
+ unsigned long *blueScan)
{
int xi, si, sifrac, ci, cifrac, addWhole, addFrac;
unsigned long pix;
* are divided first.
*/
static void PutRGBScan(XImage *Im, int x, int y, int w, int div,
- unsigned long *redScan, unsigned long *greenScan,
- unsigned long *blueScan)
+ unsigned long *redScan, unsigned long *greenScan,
+ unsigned long *blueScan)
{
int xi;
unsigned long pix;
* vertical directions (eg. shrink horizontal, grow vertical).
*/
static void ScaleIcon(XImage *ImIn, XImage *ImOut,
- int x1, int y1, int x2, int y2,
+ int x1, int y1, int x2, int y2,
int ix, int iy, int ox, int oy)
{
int div;
for (yi = 0; yi < oy; yi++)
{
GetScaledRow(ImIn, x1, y1 + yi, ix, ox,
- tempRed, tempGreen, tempBlue);
+ tempRed, tempGreen, tempBlue);
PutRGBScan(ImOut, x2, y2 + yi, ox, div,
- tempRed, tempGreen, tempBlue);
+ tempRed, tempGreen, tempBlue);
}
}
else if (iy < oy)
{
/* only get next row if in same icon */
GetScaledRow(ImIn, x1, si + 1, ix, ox,
- nextRed, nextGreen, nextBlue);
+ nextRed, nextGreen, nextBlue);
}
}
for (xi = 0; xi < ox; xi++)
{
tempRed[xi] = (prevRed[xi] * (oy - sifrac) +
- nextRed[xi] * sifrac);
+ nextRed[xi] * sifrac);
tempGreen[xi] = (prevGreen[xi] * (oy - sifrac) +
- nextGreen[xi] * sifrac);
+ nextGreen[xi] * sifrac);
tempBlue[xi] = (prevBlue[xi] * (oy - sifrac) +
- nextBlue[xi] * sifrac);
+ nextBlue[xi] * sifrac);
}
/* write row to output image: */
PutRGBScan(ImOut, x2, y2 + yi, ox, div,
- tempRed, tempGreen, tempBlue);
+ tempRed, tempGreen, tempBlue);
/* advance sampling position: */
sifrac += iy;
while (si < ci)
{
GetScaledRow(ImIn, x1, si, ix, ox,
- nextRed, nextGreen, nextBlue);
+ nextRed, nextGreen, nextBlue);
for (xi = 0; xi < ox; xi++)
{
tempRed[xi] += nextRed[xi] * oy;
{
/* only get next row if still in icon: */
GetScaledRow(ImIn, x1, si, ix, ox,
- nextRed, nextGreen, nextBlue);
+ nextRed, nextGreen, nextBlue);
}
sifrac = cifrac;
for (xi = 0; xi < ox; xi++)
}
/* write row to output image: */
PutRGBScan(ImOut, x2, y2 + yi, ox, div,
- tempRed, tempGreen, tempBlue);
+ tempRed, tempGreen, tempBlue);
}
}
}
static XImage *ResizeImageSmooth(Display *dpy, XImage *Im,
- int ix, int iy, int ox, int oy)
+ int ix, int iy, int ox, int oy)
{
Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
Data = (char *)malloc(width2 * height2 * Im->bits_per_pixel / 8);
Tmp = XCreateImage(dpy, visual,
- Im->depth, ZPixmap, 0, Data, width2, height2,
- 32, 0);
+ Im->depth, ZPixmap, 0, Data, width2, height2,
+ 32, 0);
/* compute values for decomposing pixel into color values: */
redMask = Im->red_mask;
for (x1 = 0, x2 = 0; (x1 < width1) && (x2 < width2); x1 += ix, x2 += ox)
{
ScaleIcon(Im, Tmp, x1, y1, x2, y2,
- ix, iy, ox, oy);
+ ix, iy, ox, oy);
}
}
* Also appears in "main-xaw.c".
*/
static XImage *ResizeImage(Display *dpy, XImage *Im,
- int ix, int iy, int ox, int oy)
+ int ix, int iy, int ox, int oy)
{
Visual *visual = DefaultVisual(dpy, DefaultScreen(dpy));
Data = (char *)malloc(width2 * height2 * Im->bits_per_pixel / 8);
Tmp = XCreateImage(dpy, visual,
- Im->depth, ZPixmap, 0, Data, width2, height2,
- 32, 0);
+ Im->depth, ZPixmap, 0, Data, width2, height2,
+ 32, 0);
if (ix > ox)
{
#endif /* USE_GRAPHICS */
+#endif /* USE_X11 */