Skip to content

Conversation

@CounterPillow
Copy link

@CounterPillow CounterPillow commented May 9, 2018

I ran into a bug today when my package manager automatically losslessly optimised the PNG images that PrusaControl uses: it doesn't have proper logic for loading them. So I've fixed it, and also optimised the PNGs inside the repo.

texture_from_png made several wrong assumptions:

  • 32 bits per pixel images must always be transparent (In PNGs case, maybe, but eeehhhhh)
  • anything with less than 32 bits per pixel must never be transparent (false, PNG has a tRNS chunk which allows for transparency in palette and grayscale modes.)
  • anything transparent will always be RGBA
  • anything not transparent will always be RGB
  • PNG has colour modes that it clearly doesn't have (floating point, 32 bit integer, CMYK, ...)
  • PNG doesn't have colour modes which it has (grayscale with alpha)

The fix is twofold:

  1. Don't care about bitness. It is unrelated to transparency; what we want to know is whether the images have an alpha channel at all.
  2. Make Pillow convert all images with transparency to RGBA, and all images without transparency to RGB. We tell GL we're handing it RGBA and RGB data respectively anyway.

texure_from_png assumed that everything 32 bit must be RGBA, and
everything less than that must be RGB. This is wrong. PNG allows
for transparency even in palette or grayscale mode using the
tRNS chunk.

Let's convert to RGBA if we have transparency, and convert to RGB
if we don't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant