Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lvandeve/lodepng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2019-08-02 17:46:43 +0300
committerLode <lvandeve@gmail.com>2019-08-02 17:59:15 +0300
commit165dfcffddc4bb31d32b90edc56bfb971ead9390 (patch)
tree724d57016f676bd91be4548f048b3eb8a0c572ed /lodepng.h
parenta4fb8c617ec2c8a3673c5a34732a3d5bb0c27372 (diff)
Allow colortype enum values up to 255
The enum has names for valid PNG color types, but is intended to be able to represent invalid byte values as well, which can be used to diagnose corrupted PNG files. This make sit able again to represent any invalid byte by adding a not-to-be-actually-used entry with numeric value 255, so usage in range 0-255 is guaranteed by the compiler. This makes it again possible to assign the byte value in lodepng_inspect to it directly, verified with clang++ -fsanitize=undefined. Also slightly update the order of assignments and error returns in lodepng_inspect: assign all output values before error checking, do error checking in the order the bytes appear in the PNG header.
Diffstat (limited to 'lodepng.h')
-rw-r--r--lodepng.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/lodepng.h b/lodepng.h
index e8e240e..b021b77 100644
--- a/lodepng.h
+++ b/lodepng.h
@@ -95,13 +95,19 @@ source files with custom allocators.*/
#endif /*LODEPNG_COMPILE_CPP*/
#ifdef LODEPNG_COMPILE_PNG
-/*The PNG color types (also used for raw).*/
+/*The PNG color types (also used for raw image).*/
typedef enum LodePNGColorType {
LCT_GREY = 0, /*grayscale: 1,2,4,8,16 bit*/
LCT_RGB = 2, /*RGB: 8,16 bit*/
LCT_PALETTE = 3, /*palette: 1,2,4,8 bit*/
LCT_GREY_ALPHA = 4, /*grayscale with alpha: 8,16 bit*/
- LCT_RGBA = 6 /*RGB with alpha: 8,16 bit*/
+ LCT_RGBA = 6, /*RGB with alpha: 8,16 bit*/
+ /*LCT_MAX_OCTET_VALUE lets the compiler allow this enum to represent any invalid
+ byte value from 0 to 255 that could be present in an invalid PNG file header. Do
+ not use, compare with or set the name LCT_MAX_OCTET_VALUE, instead either use
+ the valid color type names above, or numeric values like 1 or 7 when checking for
+ particular disallowed color type byte values, or cast to integer to print it.*/
+ LCT_MAX_OCTET_VALUE = 255
} LodePNGColorType;
#ifdef LODEPNG_COMPILE_DECODER