kyamagu / skia-python

Python binding to Skia Graphics Library
https://kyamagu.github.io/skia-python/
BSD 3-Clause "New" or "Revised" License
245 stars 43 forks source link

Improve "convert to PIL" example #250

Closed lucach closed 3 months ago

lucach commented 5 months ago

The default color type of a skia.Image is platform dependent. On some systems (e.g., GitHub CI, and most Linux systems) the default color type is BGR (for endianness purposes).

See https://github.com/google/skia/blob/6ffe89f9b4cc8c1dae9c4a916f16f9c463e3fa6d/include/core/SkColorType.h#L58-L62

Thus, in general, not only one has to convert the alphaType to create a PIL image, but also the colorType.

HinTak commented 5 months ago

I am wondering if it is possible to detect what skia's image color type is (such as a class static method), and also adds a few more tests to the pytests.

HinTak commented 5 months ago

Oh, we do expose the kN32... type directly: https://github.com/kyamagu/skia-python/blob/e0b030c14e33f70880cfcc502eaeed898a77fc3c/src/skia/ImageInfo.cpp#L62 so it is possible to test if it is equal to either of the two, to detect endian.

HinTak commented 3 months ago

The merge commit failed CI because of the Centos EOL July 2024 issue - that's fixed by the m127/m128 pulls. we can ignore the failure.