summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2017-09-23 14:53:44 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2017-09-23 15:11:18 -0500
commit4b7635ce727a8826be8b102214aec85b5456f8cf (patch)
tree34f90ae1091b24c3920785417cc1679d8462afa9
parent96333b6bea59dd8d0659e46ec9426119d3fe5753 (diff)
parent95046512a4f7b63b78f8dcfee6462f375f129b44 (diff)
downloadlibpng-4b7635ce727a8826be8b102214aec85b5456f8cf.tar.gz
[libpng16] Support associated alpha in the simplified api
-rw-r--r--png.h2
-rw-r--r--pngread.c12
2 files changed, 13 insertions, 1 deletions
diff --git a/png.h b/png.h
index 81f61107d..7697c3c40 100644
--- a/png.h
+++ b/png.h
@@ -2819,6 +2819,8 @@ typedef struct
# define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */
#endif
+#define PNG_FORMAT_FLAG_ASSOCIATED_ALPHA 0x40U /* alpha channel is associated */
+
/* Commonly used formats have predefined macros.
*
* First the single byte (sRGB) formats:
diff --git a/pngread.c b/pngread.c
index e34ddd99a..6b9441384 100644
--- a/pngread.c
+++ b/pngread.c
@@ -3759,7 +3759,13 @@ png_image_read_direct(png_voidp argument)
mode = PNG_ALPHA_PNG;
output_gamma = PNG_DEFAULT_sRGB;
}
-
+
+ if ((change & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0)
+ {
+ mode = PNG_ALPHA_OPTIMIZED;
+ change &= ~PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
+ }
+
/* If 'do_local_background' is set check for the presence of gamma
* correction; this is part of the work-round for the libpng bug
* described above.
@@ -3985,6 +3991,10 @@ png_image_read_direct(png_voidp argument)
else if (do_local_compose != 0) /* internal error */
png_error(png_ptr, "png_image_read: alpha channel lost");
+ if ((format & PNG_FORMAT_FLAG_ASSOCIATED_ALPHA) != 0) {
+ info_format |= PNG_FORMAT_FLAG_ASSOCIATED_ALPHA;
+ }
+
if (info_ptr->bit_depth == 16)
info_format |= PNG_FORMAT_FLAG_LINEAR;