-/* File: maid-x11.c */
+/* File: maid-x11.c */
/*
* Copyright (c) 1997 Ben Harrison, and others
#ifdef USE_X11
#include <math.h>
-
+#include "main/x11-gamma-builder.h"
/*
* This file defines some "XImage" manipulation functions for X11.
((unsigned)(keysym) >= 0xFF00)
-#ifdef SUPPORT_GAMMA
static bool gamma_table_ready = FALSE;
static int gamma_val = 0;
-#endif /* SUPPORT_GAMMA */
/*
* Hack -- Convert an RGB value to an X11 Pixel, or die.
*/
+#ifdef USE_XFT
+static XftColor create_pixel(Display *dpy, byte red, byte green, byte blue)
+#else
static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
+#endif
{
Colormap cmap = DefaultColormapOfScreen(DefaultScreenOfDisplay(dpy));
XColor xcolour;
-
-#ifdef SUPPORT_GAMMA
-
if (!gamma_table_ready)
{
- cptr str = getenv("ANGBAND_X11_GAMMA");
+ concptr str = getenv("ANGBAND_X11_GAMMA");
if (str != NULL) gamma_val = atoi(str);
gamma_table_ready = TRUE;
blue = gamma_table[blue];
}
-#endif /* SUPPORT_GAMMA */
-
/* Build the color */
xcolour.red = red * 255;
xcolour.blue = blue * 255;
xcolour.flags = DoRed | DoGreen | DoBlue;
+#ifdef USE_XFT
+ XftColor color;
+ XRenderColor xcol;
+ xcol.red = xcolour.red;
+ xcol.green = xcolour.green;
+ xcol.blue = xcolour.blue;
+ if (!XftColorAllocValue(dpy, DefaultVisual(dpy, 0), cmap, &xcol, &color))
+ {
+ quit_fmt("Couldn't allocate bitmap color '#%02x%02x%02x'\n",
+ red, green, blue);
+ }
+
+ return color;
+#else
/* Attempt to Allocate the Parsed color */
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);
+#endif
}
-
-#ifdef USE_GRAPHICS
+#ifndef USE_XFT
/*
* The Win32 "BITMAPFILEHEADER" type.
{
RGBQUAD clrg;
- /* Read an "RGBQUAD" */
- rd_byte(f, &(clrg.b));
- rd_byte(f, &(clrg.g));
- rd_byte(f, &(clrg.r));
- rd_byte(f, &(clrg.filler));
+ /* 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)
{
return Tmp;
}
-#endif /* USE_GRAPHICS */
-
+#endif /* !USE_XFT */
#endif /* USE_X11 */