FLTK logo

Re: [fltk/fltk] Compatibility for Fl_PNG_Image, 4/8bit + alpha channel (#234)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.issues  ]
 
Previous Message ]New Message | Reply ]Next Message ]

Re: [fltk/fltk] Compatibility for Fl_PNG_Image, 4/8bit + alpha channel (#234) Albrecht Schlosser May 22, 2021  
 

Okay, I think I found the "problem". See original post above:

Fl_PNG_Image recognized this image as 2 depth ( as RGB555, or RGB565 ).

@rageworx: This seems to be a misunderstanding on your part. In Fl_Image and derived classes image "depth" d() == 2 is clearly defined as 2 channels (gray + alpha), each channel one byte (8 bits) , not - as you assume "RGB555, or RGB565". [ Note: 1 means gray only, 3 = RGB, 4 = RGBA]

I used the image tbbn1g04_depth2.png posted by Kevin (@fire-eggs) for my tests:

$ file tbbn1g04_depth2.png 
tbbn1g04_depth2.png: PNG image data, 32 x 32, 4-bit grayscale, non-interlaced

which is clearly a 4-bit grayscale image with alpha (the latter is not displayed by file but is true). I added a few printf statements to your patched version which (IMHO) clearly shows that the patch is not correct. Besides there being no need to make a 4-channel image from a 2-channel image, you seem to multiply the byte values of the gray and alpha channels by mulb = (8/bd); which is obviously not correct:

Image channels = 2, num_trans = 1, convreq = 1
[load_png_] /data/fltk/images/png/pngtest/fire-eggs/tbbn1g04_depth2.png(w,h,d,bd) = (32, 32, 2, 4)
C[  19] = (170, 255),  mulb = 2
C[  20] = (170, 255),  mulb = 2
C[  50] = (153, 255),  mulb = 2
C[  51] = ( 51, 255),  mulb = 2
C[  52] = (102, 255),  mulb = 2
C[  80] = (153, 255),  mulb = 2
C[  81] = ( 68, 255),  mulb = 2
C[  82] = (  0, 255),  mulb = 2
C[  83] = (  0, 255),  mulb = 2
...

The code in question is (slightly modified):

    uchar* p = (uchar*)array;
    if (array) {
      int mulb = (8/bd);
      for (i=0; i<w()*h(); i++) {
        int temp1 = int(pvarray[i*2])*mulb;
        int temp2 = int(pvarray[i*2+1])*mulb;
        if (temp1 > 255 || temp2 > 255)
          printf("C[%4d] = (%3d, %3d),  mulb = %d\n", i, pvarray[i*2], pvarray[i*2+1], mulb);
        p[i*4] = p[i*4+1] = p[i*4+2] = (pvarray[i*2]*mulb);
        p[i*4+3] = (pvarray[i*2+1]*mulb);
      }
      channels = 4;
      d(channels);
    }

As you can see the channel values * mulb (2) would obviously be > 255 which is wrong.

Conclusion: FLTK's code is correct WRT handling bit depth 4 gray+alpha PNG images and your patch can't be accepted.

As a proof here's a screenshot of four images:

tbbn1g04_views

image

  • left: FLTK original
  • middle: firefox
  • right: your patched version
  • bottom: eog (image viewer)

There are slight differences in brightness, maybe also caused by background diffs, but I'd say that your patched version is definitely the "worst" display and, as shown before, obviously not correct.

So, unless I missed something essential, FLTK is correct and this issue should be closed.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Direct Link to Message ]
 
     
Previous Message ]New Message | Reply ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.