[cairo-commit] 2 commits - src/cairo-png.c
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Mon Aug 23 16:31:59 UTC 2021
src/cairo-png.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
New commits:
commit 923715f2e9acec31f6af406f39e14c36f9f7365c
Merge: 9f44d4c7c 2fb156bdc
Author: Uli Schlachter <psychon at znc.in>
Date: Mon Aug 23 16:31:57 2021 +0000
Merge branch 'fix-png-write-endian' into 'master'
Read/write 16-bpc PNG data in native endian
Closes #501
See merge request cairo/cairo!230
commit 2fb156bdc0cc28227df80e9d59a58547283b50e1
Author: Manuel Stoeckl <code at mstoeckl.com>
Date: Fri Aug 6 18:35:01 2021 -0400
Read/write 16-bpc PNG data in native endian
The png_set_swap function does not affect 8-bpc data.
Signed-off-by: Manuel Stoeckl <code at mstoeckl.com>
diff --git a/src/cairo-png.c b/src/cairo-png.c
index f576047b1..4b7c34081 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -407,6 +407,14 @@ write_png (cairo_surface_t *surface,
*/
png_write_info (png, info);
+#ifndef WORDS_BIGENDIAN
+ /* libpng treats 16-bit data as big-endian by default. Swapping the
+ * byte-order on little endian ensures the native-endian data can be
+ * provided to png_write_image. This does not affect 8-bit data.
+ */
+ png_set_swap (png);
+#endif
+
if (png_color_type == PNG_COLOR_TYPE_RGB_ALPHA) {
if (clone->format != CAIRO_FORMAT_RGBA128F)
png_set_write_user_transform_fn (png, unpremultiply_data);
@@ -702,6 +710,14 @@ read_png (struct png_read_closure_t *png_closure)
png_read_info (png, info);
+#ifndef WORDS_BIGENDIAN
+ /* libpng treats 16-bit data as big-endian by default. Swapping the
+ * byte-order on little endian ensures the native-endian data can be
+ * provided to png_read_image. This does not affect 8-bit data.
+ */
+ png_set_swap (png);
+#endif
+
png_get_IHDR (png, info,
&png_width, &png_height, &depth,
&color_type, &interlace, NULL, NULL);
More information about the cairo-commit
mailing list