OSDN Git Service

Merge pull request #41491 (taotao/hengband/fix-impure_calc_num_blow into develop).
[hengband/hengband.git] / src / maid-x11.c
index 244440c..1ec8cb2 100644 (file)
@@ -1,4 +1,4 @@
-/* File: maid-x11.c */
+/* File: maid-x11.c */
 
 /*
  * Copyright (c) 1997 Ben Harrison, and others
@@ -11,7 +11,7 @@
 #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;
@@ -103,8 +102,6 @@ static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
                blue = gamma_table[blue];
        }
 
-#endif /* SUPPORT_GAMMA */
-
        /* Build the color */
        
        xcolour.red = red * 255;
@@ -112,19 +109,33 @@ static unsigned long create_pixel(Display *dpy, byte red, byte green, byte blue)
        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.
@@ -275,11 +286,11 @@ static XImage *ReadBMP(Display *dpy, char *Name)
        {
                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);
@@ -295,8 +306,8 @@ static XImage *ReadBMP(Display *dpy, char *Name)
        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)
@@ -341,7 +352,7 @@ static XImage *ReadBMP(Display *dpy, char *Name)
                        {
                                /* Technically 1 bit is legal too */
                                quit_fmt("Illegal biBitCount %d in %s",
-                                        infoheader.biBitCount, Name);
+                                        infoheader.biBitCount, Name);
                        }
                }
        }
@@ -384,8 +395,8 @@ static bool smoothRescaling = TRUE;
  * 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;
@@ -526,8 +537,8 @@ static void GetScaledRow(XImage *Im, int x, int y, int iw, int ow,
  * 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;
@@ -552,7 +563,7 @@ static void PutRGBScan(XImage *Im, int x, int y, int w, int div,
  * 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;
@@ -585,9 +596,9 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                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)
@@ -617,7 +628,7 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                                {
                                        /* only get next row if in same icon */
                                        GetScaledRow(ImIn, x1, si + 1, ix, ox,
-                                                    nextRed, nextGreen, nextBlue);
+                                                    nextRed, nextGreen, nextBlue);
                                }
                        }
 
@@ -626,16 +637,16 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                        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;
@@ -686,7 +697,7 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                        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;
@@ -700,7 +711,7 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                        {
                                /* 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++)
@@ -711,7 +722,7 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
                        }
                        /* write row to output image: */
                        PutRGBScan(ImOut, x2, y2 + yi, ox, div,
-                                  tempRed, tempGreen, tempBlue);
+                                  tempRed, tempGreen, tempBlue);
                }
        }
 }
@@ -719,7 +730,7 @@ static void ScaleIcon(XImage *ImIn, XImage *ImOut,
 
 
 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));
 
@@ -739,8 +750,8 @@ static XImage *ResizeImageSmooth(Display *dpy, XImage *Im,
        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;
@@ -771,7 +782,7 @@ static XImage *ResizeImageSmooth(Display *dpy, XImage *Im,
                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);
                }
        }
 
@@ -785,7 +796,7 @@ static XImage *ResizeImageSmooth(Display *dpy, XImage *Im,
  * 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));
 
@@ -813,8 +824,8 @@ static XImage *ResizeImage(Display *dpy, XImage *Im,
        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)
        {
@@ -879,7 +890,6 @@ static XImage *ResizeImage(Display *dpy, XImage *Im,
        return Tmp;
 }
 
-#endif /* USE_GRAPHICS */
-
+#endif /* !USE_XFT */
 
 #endif /* USE_X11 */