[libGD] #88 [Task opened] Bug loading png images in grayscale + alpha

[email protected] (libGD) Fri, 08 Jun 2007 08:29:16 +0000
Newsgroups php.gd.bugs
Message-ID <[email protected]>
THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

A new Flyspray task has been opened.  Details are below.

User who did this - Daniel Diaz (daniel.diaz)

Attached to Project - libGD
Summary - Bug loading png images in grayscale + alpha
Task Type - Bug Report
Category - General
Status - Unconfirmed
Assigned To - 
Operating System - All
Severity - Low
Priority - Normal
Reported Version - 2.0.34
Due in Version - Undecided
Due Date - Undecided
Details - Hi,

There is a bug in gd_png.c when dealing with a png in grayscale + alpha (color_type == PNG_COLOR_TYPE_GRAY_ALPHA). Tested version is last CVS (gd_png.c,1.23).

The existing does not make a difference between PNG_COLOR_TYPE_GRAY and PNG_COLOR_TYPE_GRAY_ALPHA. In the PNG_COLOR_TYPE_GRAY_ALPHA mode, row_pointers contain 2 bytes par pixel, (rowbytes = 2 *width) but existing code simply uses the first width bytes (forgetting the width next others). The result is a wrong image : only the left half is loaded in memory (but with wrong gray colors).

I attach an image.png file in this format. If you use:
  pngtogd image.png foo.gd
  gdtopng foo.gd new-image.png
you will see that new-mage1.png is wrong (see attached file).

A preliminar solution consists in adding the following code to gd_png.c:415 (just before the default:)

  case PNG_COLOR_TYPE_GRAY_ALPHA:
    for (h = 0; h < height; ++h) {
      int boffset = 0;
      for (w = 0; w < width; ++w) {
        register png_byte idx = row_pointers[h][boffset++];
        im->pixels[h][w] = idx;
        open[idx] = 0;
        // add code to deal with alpha at row_pointer[h][boffset]
        // for now we simply ignore it !
        boffset++;
      }
    }
    break;

Obviously I here simply ignore alpha bytes (I don't know how alpha channel is handled in libgd, sorry).


More information can be found at the following URL:
http://bugs.libgd.org/?do=details&task_id=88

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.