diff options
Diffstat (limited to 'apps/plugins/imageviewer/png/png_decoder.h')
-rw-r--r-- | apps/plugins/imageviewer/png/png_decoder.h | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/apps/plugins/imageviewer/png/png_decoder.h b/apps/plugins/imageviewer/png/png_decoder.h new file mode 100644 index 0000000000..4ca2a51277 --- /dev/null +++ b/apps/plugins/imageviewer/png/png_decoder.h | |||
@@ -0,0 +1,141 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$id $ | ||
9 | * | ||
10 | * Copyright (C) 2009 by Christophe Gouiran <bechris13250 -at- gmail -dot- com> | ||
11 | * | ||
12 | * Based on lodepng, a lightweight png decoder/encoder | ||
13 | * (c) 2005-2008 Lode Vandevenne | ||
14 | * | ||
15 | * Copyright (c) 2010 Marcin Bukat | ||
16 | * - pixel format conversion & transparency handling | ||
17 | * - adaptation of tinf (tiny inflate library) | ||
18 | * - code refactoring & cleanups | ||
19 | * | ||
20 | * This program is free software; you can redistribute it and/or | ||
21 | * modify it under the terms of the GNU General Public License | ||
22 | * as published by the Free Software Foundation; either version 2 | ||
23 | * of the License, or (at your option) any later version. | ||
24 | * | ||
25 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
26 | * KIND, either express or implied. | ||
27 | * | ||
28 | ****************************************************************************/ | ||
29 | |||
30 | #define OUT_OF_MEMORY 9900 | ||
31 | #define FILE_TOO_LARGE 9910 | ||
32 | |||
33 | /* PNG chunk types signatures */ | ||
34 | /* critical chunks */ | ||
35 | #define PNG_CHUNK_IHDR 0x49484452 | ||
36 | #define PNG_CHUNK_PLTE 0x504c5445 | ||
37 | #define PNG_CHUNK_IDAT 0x49444154 | ||
38 | #define PNG_CHUNK_IEND 0x49454e44 | ||
39 | |||
40 | /* ancillary chunks */ | ||
41 | #define PNG_CHUNK_bKGD 0x624b4744 | ||
42 | #define PNG_CHUNK_cHRM 0x6348524d | ||
43 | #define PNG_CHUNK_gAMA 0x67414d41 | ||
44 | #define PNG_CHUNK_hIST 0x68495354 | ||
45 | #define PNG_CHUNK_iCCP 0x69434350 | ||
46 | #define PNG_CHUNK_pHYs 0x70485973 | ||
47 | #define PNG_CHUNK_sBIT 0x73424954 | ||
48 | #define PNG_CHUNK_sPLT 0x73504c54 | ||
49 | #define PNG_CHUNK_sRGB 0x73524742 | ||
50 | #define PNG_CHUNK_tEXt 0x74455874 | ||
51 | #define PNG_CHUNK_tIME 0x74494d45 | ||
52 | #define PNG_CHUNK_tRNS 0x74524e53 | ||
53 | #define PNG_CHUNK_zTXt 0x7a545874 | ||
54 | |||
55 | /* PNG color types */ | ||
56 | #define PNG_COLORTYPE_GREY 0 | ||
57 | #define PNG_COLORTYPE_RGB 2 | ||
58 | #define PNG_COLORTYPE_PALETTE 3 | ||
59 | #define PNG_COLORTYPE_GREYA 4 | ||
60 | #define PNG_COLORTYPE_RGBA 6 | ||
61 | |||
62 | /* PNG filter types */ | ||
63 | #define PNG_FILTERTYPE_NONE 0 | ||
64 | #define PNG_FILTERTYPE_SUB 1 | ||
65 | #define PNG_FILTERTYPE_UP 2 | ||
66 | #define PNG_FILTERTYPE_AVERAGE 3 | ||
67 | #define PNG_FILTERTYPE_PAETH 4 | ||
68 | |||
69 | #define PNG_ERROR_MIN 27 | ||
70 | #define PNG_ERROR_MAX 74 | ||
71 | |||
72 | /* Typedefs */ | ||
73 | typedef struct LodePNG_InfoColor /*info about the color type of an image*/ | ||
74 | { | ||
75 | /*header (IHDR)*/ | ||
76 | unsigned colorType; /*color type*/ | ||
77 | unsigned bitDepth; /*bits per sample*/ | ||
78 | |||
79 | /*palette (PLTE)*/ | ||
80 | unsigned char palette[256 * 4]; /*palette in RGBARGBA... order*/ | ||
81 | size_t palettesize; /* palette size in number of colors | ||
82 | * (amount of bytes is 4 * palettesize) | ||
83 | */ | ||
84 | |||
85 | /*transparent color key (tRNS)*/ | ||
86 | unsigned key_defined; /*is a transparent color key given?*/ | ||
87 | unsigned key_r; /*red component of color key*/ | ||
88 | unsigned key_g; /*green component of color key*/ | ||
89 | unsigned key_b; /*blue component of color key*/ | ||
90 | } LodePNG_InfoColor; | ||
91 | |||
92 | typedef struct LodePNG_InfoPng /*information about the PNG image, except pixels and sometimes except width and height*/ | ||
93 | { | ||
94 | /*header (IHDR), palette (PLTE) and transparency (tRNS)*/ | ||
95 | unsigned width; /*width of the image in pixels - filled in by decoder)*/ | ||
96 | unsigned height; /*height of the image in pixels - filled in by decoder)*/ | ||
97 | unsigned compressionMethod; /*compression method of the original file*/ | ||
98 | unsigned filterMethod; /*filter method of the original file*/ | ||
99 | unsigned interlaceMethod; /*interlace method of the original file*/ | ||
100 | LodePNG_InfoColor color; /*color type and bits, palette, transparency*/ | ||
101 | |||
102 | /*suggested background color (bKGD)*/ | ||
103 | unsigned background_r; /*red component of suggested background color*/ | ||
104 | unsigned background_g; /*green component of suggested background color*/ | ||
105 | unsigned background_b; /*blue component of suggested background color*/ | ||
106 | |||
107 | } LodePNG_InfoPng; | ||
108 | |||
109 | typedef struct LodePNG_Decoder | ||
110 | { | ||
111 | unsigned char *buf; /* pointer to the buffer allocated for decoder | ||
112 | * filled by LodePNG_Decoder_init() | ||
113 | */ | ||
114 | size_t buf_size; /* size of the buffer decoder is free to use | ||
115 | * filled by LodePNG_Decoder_init() | ||
116 | */ | ||
117 | unsigned char *file; /* ptr to raw png file loaded */ | ||
118 | size_t file_size; /* size of the raw png file in mem */ | ||
119 | unsigned char *decoded_img; /* ptr to decoded PNG image in PNG pixel | ||
120 | * format. set by decodeGeneric() | ||
121 | */ | ||
122 | unsigned int native_img_size; /* size of the image in native pixel | ||
123 | * format | ||
124 | */ | ||
125 | LodePNG_InfoPng infoPng; /*info of the PNG image obtained after decoding*/ | ||
126 | long error; | ||
127 | } LodePNG_Decoder; | ||
128 | |||
129 | /* Public functions prototypes */ | ||
130 | void LodePNG_Decoder_init(LodePNG_Decoder* decoder, | ||
131 | uint8_t *buf, | ||
132 | size_t buf_size); | ||
133 | |||
134 | void LodePNG_decode(LodePNG_Decoder* decoder, | ||
135 | uint8_t* in, | ||
136 | size_t insize, | ||
137 | void (*pf_progress)(int current, int total)); | ||
138 | |||
139 | void LodePNG_inspect(LodePNG_Decoder* decoder, uint8_t *in, size_t inlength); | ||
140 | |||
141 | const char* LodePNG_perror(LodePNG_Decoder *decoder); | ||