wxPalette PNG and GIF images undocumented?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Mick P.
Experienced Solver
Experienced Solver
Posts: 75
Joined: Thu Jun 06, 2019 3:41 am
Contact:

wxPalette PNG and GIF images undocumented?

Post by Mick P. » Sat Aug 03, 2019 8:10 pm

Some of the documentation here is unclear:

https://docs.wxwidgets.org/trunk/classwx_palette.html

https://docs.wxwidgets.org/trunk/classw ... ndler.html

The first says PNG and GIF images with palettes will use wxPalette. I'm interested in this. Except I have yet to come across information about wxImage::GetData ever being 8-bit color indices. You have to read between the lines to figure out it can be RGB or RGBA, but nothing ever says it's just 1B indices.

Secondly, it's annoying that there isn't an option for loading these images without palettes (by converting to RGBA on the fly) and I can't see a workflow for ripping out the palette, assuming it's there. Will SetPalete(wxPalette()) convert to full color? If so, wouldn't it be better to do that while loading? Maybe there is an undocumented option. How to tell what is the size of GetData() pixels?

EDITED: wxIMAGE_OPTION_PNG_BITDEPTH exists: "Bit depth for every channel (R/G/B/A)."

I don't see a "GetDepth" method for wxImage. Or anything related to depth. So I assume it is guess based on HasAlpha and HasPalette :?:

User avatar
doublemax
Moderator
Moderator
Posts: 13902
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPalette PNG and GIF images undocumented?

Post by doublemax » Sat Aug 03, 2019 8:48 pm

In general, support for 8bit bitmaps is low. wxImage is always 24 or 32 bit. Only a wxBitmap can be 8bit.

I'd avoid using 8bit bitmaps all together.
Use the source, Luke!

Mick P.
Experienced Solver
Experienced Solver
Posts: 75
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: wxPalette PNG and GIF images undocumented?

Post by Mick P. » Sat Aug 03, 2019 9:45 pm

So how would GetPalette work? If the palette is saved, but the index image is not?

Any large image that is indexed can be large memory saving, which helps when transferring images, like loading a "texture" from system memory to video memory. (It's unpacked on the video side. Takes up less space backed in system memory. Faster transfer.)

In any case, according to the documentation, a PNG or GIF file that is indexed will generate an indexed wxImage file. There is a feature macro wxUSE_PALETTE that enables these features. I don't know off hand if it's on for the public release binaries. It would be pointless though to have such features if they are only available to custom builds.

(If the palette is only there to be reverse indexed I hope the documentation would not omit such important information! My sense of it is 8-bit is just undocumented. Waiting to crash someone's code. IntelliSense says wxUSE_PALETTE is 1. I will have to run tests I suppose. I am in the planning stages. It could be a while, but I will report my findings.)

User avatar
doublemax
Moderator
Moderator
Posts: 13902
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPalette PNG and GIF images undocumented?

Post by doublemax » Sat Aug 03, 2019 10:27 pm

So how would GetPalette work? If the palette is saved, but the index image is not?
Did you even read the documentation for wxImage::GetPalette and SetPalette?
In any case, according to the documentation, a PNG or GIF file that is indexed will generate an indexed wxImage file.
Where does it say that? That would be wrong. Like i said, *wxImage* is 24 or 32 bit, no exceptions.
Use the source, Luke!

Mick P.
Experienced Solver
Experienced Solver
Posts: 75
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: wxPalette PNG and GIF images undocumented?

Post by Mick P. » Sat Aug 03, 2019 11:14 pm

Did you even read the documentation for wxImage::GetPalette and SetPalette?
It's pretty unremarkable?
Where does it say that? That would be wrong. Like i said, *wxImage* is 24 or 32 bit, no exceptions.
"Some of the wxImage handlers have been modified to set the palette if one exists in the image file (usually 256 or less colour images in GIF or PNG format)" (https://docs.wxwidgets.org/trunk/classwx_image.html)

FWIW I did just look at wxPalette itself... it is strangely implemented. I expected something very basic. It seems weird if the palette is provided, and the only way to use it is to do a reverse look-up on individual pixels.
Last edited by Mick P. on Sat Aug 03, 2019 11:25 pm, edited 1 time in total.

User avatar
doublemax
Moderator
Moderator
Posts: 13902
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxPalette PNG and GIF images undocumented?

Post by doublemax » Sat Aug 03, 2019 11:20 pm

"Some of the wxImage handlers have been modified to set the palette if one exists in the image file (usually 256 or less colour images in GIF or PNG format)"
That just means that you can access the original palette of the image file, even if the image was converted to 24bit. I assume the palette will also be used when you save a wxImage as GIF.
Use the source, Luke!

Mick P.
Experienced Solver
Experienced Solver
Posts: 75
Joined: Thu Jun 06, 2019 3:41 am
Contact:

Re: wxPalette PNG and GIF images undocumented?

Post by Mick P. » Sat Aug 03, 2019 11:28 pm

It looks like maybe GetPixel (wxPalette) also finds closest matches. Maybe internally it is a spatial lookup system.

In my case it's not useful. It's funny wxWidgets implements saving images when the loading system is so fragile. Priorities.

Post Reply