Giter Site home page Giter Site logo

Make Palette handle greyscale about hitherdither HOT 4 OPEN

hbldh avatar hbldh commented on June 15, 2024
Make Palette handle greyscale

from hitherdither.

Comments (4)

vitorio avatar vitorio commented on June 15, 2024

I noticed this! As a (temporary?) workaround, I'm currently converting my grayscale image to RGB before dithering it.

from hitherdither.

hbldh avatar hbldh commented on June 15, 2024

Ah, of course. That should work; feels somewhat dirty though.
A grayscale palette might be easy to create though, since a grayscale value x maps to RGB tuple (x, x, x) and then handling the ugly conversions behind the scenes...

from hitherdither.

llamasoft avatar llamasoft commented on June 15, 2024

I was working on a unrelated project. Honestly, I think converting to RGB (or telling the user to do so) is probably the only way to go.
PIL will load images of any "mode" and modes return pixels in different forms. For example:

  • 1 and L return raw 8-bit ints.
  • LA returns a 2-tuple of 8-bit ints.
  • RGB, HSV, LAB, and YCbCr return a 3-tuple of 8-byte ints, but the values all represent something different.
  • RGBA and CMYK returns a 4-tuple of 8-bit ints, again with different meanings.
  • F returns a 32-bit floating point value.

I don't think it's the code's responsibility to handle the conversion for the user, but if the user passes an Image type not in RGB mode or sequences of non-3 length, an exception should probably be raised.

from hitherdither.

tatarize avatar tatarize commented on June 15, 2024
if image.mode !=' RGB':
    image.convert('RGB')

It not very harsh with regards to responsibility.

from hitherdither.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.