开发者

List of Image "modes"

Looking through PIL (and related to this question), where can I get a comprehensive list of Image modes? I see "RGB", "RGBX", my code has "BGRX" somehow even though it's not mentioned in the PIL docs that I can see. How can I see which is which, what PIL supports, and what proper modes to select when interacting with windows API calls, for example?

Basically I know very little about开发者_如何学编程 image modes and would like to learn more than just what letters to put in to make it magically work.


There are two distinct concepts in Pillow, with confusingly similar names:

"Modes"

These are listed at https://pillow.readthedocs.io/en/latest/handbook/concepts.html#modes.

Per those docs:

The mode of an image defines the type and depth of a pixel in the image.

This kind of "mode" is what is exposed through an Image's .mode attribute, can be changed through the .convert() method, and can be passed to methods that take a mode parameter. They are not the same as "raw modes".

"Raw modes"

These are used internally by the raw decoder, which converts uncompressed data from an image file into a format that a PIL Image object can understand. There are several times more "raw modes" than "modes", and they convey information about not only the type (colored or grayscale) and bit depth of pixels in an image, but also their layout in the file. For example, raw mode RGB;L is documented as meaning "24-bit true colour, line interleaved (first all red pixels, then all green pixels, finally all blue pixels)."

As noted in the docs linked above (and also in the old PIL documentation), a list of raw modes can be found in Unpack.c. You'll find the list near the end of the file.

Unpack.c from the current main branch of Pillow: https://github.com/python-pillow/Pillow/blob/main/src/libImaging/Unpack.c

Unpack.c from the final release of PIL: http://svn.effbot.org/public/tags/pil-1.1.7/libImaging/Unpack.c

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜