Complete.Org: Mailing Lists: Archives: freeciv-dev: March 2005:
[Freeciv-Dev] Re: (PR#12111) Xaw3d client startup problem(png problem)
Home

[Freeciv-Dev] Re: (PR#12111) Xaw3d client startup problem(png problem)

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: infyquest@xxxxxxxxx
Subject: [Freeciv-Dev] Re: (PR#12111) Xaw3d client startup problem(png problem)
From: "Egor Vyscrebentsov" <evyscr@xxxxxxxxx>
Date: Sat, 5 Mar 2005 03:05:27 -0800
Reply-to: bugs@xxxxxxxxxxx

<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12111 >

On Fri, 4 Mar 2005 09:42:16 -0800
Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:

JS>Vijay Kiran Kamuju wrote:
JS>> i am trying to make necessary changes to graphics.c, 
JS>> by writing a new function generate_palette a modified version of entire 
pngquant
JS>> its quite a bit blown up, not completed, non working,etc
JS>> 
JS>> I am also trying to create a separete file for gen_pal.[ch] a modified
JS>> version of pngquant.[ch],  so that al the functions of orig pngquant
JS>> are encapsulated in one function,gen_palette
JS>> 
JS>> i thing it would better to call the function as convpng_rgba2rgbap()
JS>> or pngpalette_gen rather than gen_palette
JS>
JS>I'd suggest instead changing the code to work natively with non-paletted 
JS>PNGs.
JS>
JS>1.  Find some GPLd code that loads a PNG image into a simple graphics 
JS>format (4-channels, 8-bits per channel, rowstride, etc.).  I know Cairo 
JS>has such a utility function but it may not be GPL.
JS>
JS>2.  Once the image is loaded into this form, you can go over ALL the 
JS>colors to allocate them.  Possibly this should only be done on paletted 
JS>displays (there's probably a way to query this in X; I know GTK has it 
JS>so you can probably just look in the GTK code).
JS>
JS>3.  Eventually masks with alpha can be supported as well.

Well, i have part of graphics.c code which load RGBA images, but i haven't get 
it work full.
From last changes (grid?) i even can't get xaw client started. And don't know 
why.
And i don't understand now alpha masking...

But anyway, attached is a first attempt of patch (with codestyle and other 
errors).

Thanks, evyscr.

Index: client/gui-xaw/graphics.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/graphics.c,v
retrieving revision 1.56
diff -u -r1.56 graphics.c
--- client/gui-xaw/graphics.c   3 Mar 2005 17:18:30 -0000       1.56
+++ client/gui-xaw/graphics.c   5 Mar 2005 11:00:05 -0000
@@ -325,6 +325,7 @@
   struct Sprite *mysprite;
   XImage *xi;
   int has_mask;
+  png_byte color_type;
 
   fp = fopen(filename, "rb");
   if (!fp) {
@@ -357,7 +358,9 @@
   png_read_info(pngp, infop);
   width = png_get_image_width(pngp, infop);
   height = png_get_image_height(pngp, infop);
+  color_type = png_get_color_type(pngp, infop);
 
+  if (color_type == PNG_COLOR_TYPE_PALETTE) {
   if (png_get_PLTE(pngp, infop, &palette, &npalette)) {
     int i;
     XColor *mycolors;
@@ -398,6 +401,13 @@
     ptransarray = NULL;
   }
 
+  } else {
+    pcolorarray = NULL;
+    ptransarray = NULL;
+    npalette = 0;
+    has_mask = 0;
+  }
+
   png_read_update_info(pngp, infop);
 
   {
@@ -430,7 +440,12 @@
   pb = buf;
   for (y = 0; y < height; y++) {
     for (x = 0; x < width; x++) {
-      XPutPixel(xi, x, y, pcolorarray[pb[x]]);
+      if (pcolorarray) {
+       XPutPixel(xi, x, y, pcolorarray[pb[x]]);
+      } else {
+       XPutPixel(xi, x, y,
+                 (pb[4 * x] << 16) + (pb[4 * x + 1] << 8) + pb[4 * x + 2]);
+      }
     }
     pb += stride;
   }

[Prev in Thread] Current Thread [Next in Thread]