aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c358
1 files changed, 179 insertions, 179 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
index 1ba2092..be9a56d 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
+++ b/libraries/irrlicht-1.8/source/Irrlicht/libpng/contrib/gregbook/readppm.c
@@ -1,179 +1,179 @@
1/*--------------------------------------------------------------------------- 1/*---------------------------------------------------------------------------
2 2
3 rpng - simple PNG display program readppm.c 3 rpng - simple PNG display program readppm.c
4 4
5 --------------------------------------------------------------------------- 5 ---------------------------------------------------------------------------
6 6
7 This is a special-purpose replacement for readpng.c that allows binary 7 This is a special-purpose replacement for readpng.c that allows binary
8 PPM files to be used in place of PNG images. 8 PPM files to be used in place of PNG images.
9 9
10 --------------------------------------------------------------------------- 10 ---------------------------------------------------------------------------
11 11
12 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved. 12 Copyright (c) 1998-2007 Greg Roelofs. All rights reserved.
13 13
14 This software is provided "as is," without warranty of any kind, 14 This software is provided "as is," without warranty of any kind,
15 express or implied. In no event shall the author or contributors 15 express or implied. In no event shall the author or contributors
16 be held liable for any damages arising in any way from the use of 16 be held liable for any damages arising in any way from the use of
17 this software. 17 this software.
18 18
19 The contents of this file are DUAL-LICENSED. You may modify and/or 19 The contents of this file are DUAL-LICENSED. You may modify and/or
20 redistribute this software according to the terms of one of the 20 redistribute this software according to the terms of one of the
21 following two licenses (at your option): 21 following two licenses (at your option):
22 22
23 23
24 LICENSE 1 ("BSD-like with advertising clause"): 24 LICENSE 1 ("BSD-like with advertising clause"):
25 25
26 Permission is granted to anyone to use this software for any purpose, 26 Permission is granted to anyone to use this software for any purpose,
27 including commercial applications, and to alter it and redistribute 27 including commercial applications, and to alter it and redistribute
28 it freely, subject to the following restrictions: 28 it freely, subject to the following restrictions:
29 29
30 1. Redistributions of source code must retain the above copyright 30 1. Redistributions of source code must retain the above copyright
31 notice, disclaimer, and this list of conditions. 31 notice, disclaimer, and this list of conditions.
32 2. Redistributions in binary form must reproduce the above copyright 32 2. Redistributions in binary form must reproduce the above copyright
33 notice, disclaimer, and this list of conditions in the documenta- 33 notice, disclaimer, and this list of conditions in the documenta-
34 tion and/or other materials provided with the distribution. 34 tion and/or other materials provided with the distribution.
35 3. All advertising materials mentioning features or use of this 35 3. All advertising materials mentioning features or use of this
36 software must display the following acknowledgment: 36 software must display the following acknowledgment:
37 37
38 This product includes software developed by Greg Roelofs 38 This product includes software developed by Greg Roelofs
39 and contributors for the book, "PNG: The Definitive Guide," 39 and contributors for the book, "PNG: The Definitive Guide,"
40 published by O'Reilly and Associates. 40 published by O'Reilly and Associates.
41 41
42 42
43 LICENSE 2 (GNU GPL v2 or later): 43 LICENSE 2 (GNU GPL v2 or later):
44 44
45 This program is free software; you can redistribute it and/or modify 45 This program is free software; you can redistribute it and/or modify
46 it under the terms of the GNU General Public License as published by 46 it under the terms of the GNU General Public License as published by
47 the Free Software Foundation; either version 2 of the License, or 47 the Free Software Foundation; either version 2 of the License, or
48 (at your option) any later version. 48 (at your option) any later version.
49 49
50 This program is distributed in the hope that it will be useful, 50 This program is distributed in the hope that it will be useful,
51 but WITHOUT ANY WARRANTY; without even the implied warranty of 51 but WITHOUT ANY WARRANTY; without even the implied warranty of
52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 52 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53 GNU General Public License for more details. 53 GNU General Public License for more details.
54 54
55 You should have received a copy of the GNU General Public License 55 You should have received a copy of the GNU General Public License
56 along with this program; if not, write to the Free Software Foundation, 56 along with this program; if not, write to the Free Software Foundation,
57 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 57 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
58 58
59 ---------------------------------------------------------------------------*/ 59 ---------------------------------------------------------------------------*/
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <stdlib.h> 62#include <stdlib.h>
63 63
64#include "readpng.h" /* typedefs, common macros, public prototypes */ 64#include "readpng.h" /* typedefs, common macros, public prototypes */
65 65
66 66
67ulg width, height; 67ulg width, height;
68int bit_depth, color_type, channels; 68int bit_depth, color_type, channels;
69uch *image_data = NULL; 69uch *image_data = NULL;
70FILE *saved_infile; 70FILE *saved_infile;
71 71
72 72
73void readpng_version_info() 73void readpng_version_info()
74{ 74{
75 fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n"); 75 fprintf(stderr, " Compiled without libpng, zlib or PBMPLUS/NetPBM.\n");
76} 76}
77 77
78 78
79/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */ 79/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */
80 80
81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight) 81int readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)
82{ 82{
83 static uch ppmline[256]; 83 static uch ppmline[256];
84 int maxval; 84 int maxval;
85 85
86 86
87 saved_infile = infile; 87 saved_infile = infile;
88 88
89 fgets(ppmline, 256, infile); 89 fgets(ppmline, 256, infile);
90 if (ppmline[0] != 'P' || ppmline[1] != '6') { 90 if (ppmline[0] != 'P' || ppmline[1] != '6') {
91 fprintf(stderr, "ERROR: not a PPM file\n"); 91 fprintf(stderr, "ERROR: not a PPM file\n");
92 return 1; 92 return 1;
93 } 93 }
94 /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */ 94 /* possible color types: P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */
95 if (ppmline[1] == '6') { 95 if (ppmline[1] == '6') {
96 color_type = 2; 96 color_type = 2;
97 channels = 3; 97 channels = 3;
98 } else if (ppmline[1] == '8') { 98 } else if (ppmline[1] == '8') {
99 color_type = 6; 99 color_type = 6;
100 channels = 4; 100 channels = 4;
101 } else /* if (ppmline[1] == '5') */ { 101 } else /* if (ppmline[1] == '5') */ {
102 color_type = 0; 102 color_type = 0;
103 channels = 1; 103 channels = 1;
104 } 104 }
105 105
106 do { 106 do {
107 fgets(ppmline, 256, infile); 107 fgets(ppmline, 256, infile);
108 } while (ppmline[0] == '#'); 108 } while (ppmline[0] == '#');
109 sscanf(ppmline, "%lu %lu", &width, &height); 109 sscanf(ppmline, "%lu %lu", &width, &height);
110 110
111 do { 111 do {
112 fgets(ppmline, 256, infile); 112 fgets(ppmline, 256, infile);
113 } while (ppmline[0] == '#'); 113 } while (ppmline[0] == '#');
114 sscanf(ppmline, "%d", &maxval); 114 sscanf(ppmline, "%d", &maxval);
115 if (maxval != 255) { 115 if (maxval != 255) {
116 fprintf(stderr, "ERROR: maxval = %d\n", maxval); 116 fprintf(stderr, "ERROR: maxval = %d\n", maxval);
117 return 2; 117 return 2;
118 } 118 }
119 bit_depth = 8; 119 bit_depth = 8;
120 120
121 *pWidth = width; 121 *pWidth = width;
122 *pHeight = height; 122 *pHeight = height;
123 123
124 return 0; 124 return 0;
125} 125}
126 126
127 127
128 128
129 129
130/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error; 130/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;
131 * scales values to 8-bit if necessary */ 131 * scales values to 8-bit if necessary */
132 132
133int readpng_get_bgcolor(uch *red, uch *green, uch *blue) 133int readpng_get_bgcolor(uch *red, uch *green, uch *blue)
134{ 134{
135 return 1; 135 return 1;
136} 136}
137 137
138 138
139 139
140 140
141/* display_exponent == LUT_exponent * CRT_exponent */ 141/* display_exponent == LUT_exponent * CRT_exponent */
142 142
143uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes) 143uch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)
144{ 144{
145 ulg rowbytes; 145 ulg rowbytes;
146 146
147 147
148 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits, 148 /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
149 * transparency chunks to full alpha channel; strip 16-bit-per-sample 149 * transparency chunks to full alpha channel; strip 16-bit-per-sample
150 * images to 8 bits per sample; and convert grayscale to RGB[A] */ 150 * images to 8 bits per sample; and convert grayscale to RGB[A] */
151 151
152 /* GRR WARNING: grayscale needs to be expanded and channels reset! */ 152 /* GRR WARNING: grayscale needs to be expanded and channels reset! */
153 153
154 *pRowbytes = rowbytes = channels*width; 154 *pRowbytes = rowbytes = channels*width;
155 *pChannels = channels; 155 *pChannels = channels;
156 156
157 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) { 157 if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {
158 return NULL; 158 return NULL;
159 } 159 }
160 160
161 Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height)); 161 Trace((stderr, "readpng_get_image: rowbytes = %ld, height = %ld\n", rowbytes, height));
162 162
163 163
164 /* now we can go ahead and just read the whole image */ 164 /* now we can go ahead and just read the whole image */
165 165
166 fread(image_data, 1L, rowbytes*height, saved_infile); 166 fread(image_data, 1L, rowbytes*height, saved_infile);
167 167
168 168
169 return image_data; 169 return image_data;
170} 170}
171 171
172 172
173void readpng_cleanup(int free_image_data) 173void readpng_cleanup(int free_image_data)
174{ 174{
175 if (free_image_data && image_data) { 175 if (free_image_data && image_data) {
176 free(image_data); 176 free(image_data);
177 image_data = NULL; 177 image_data = NULL;
178 } 178 }
179} 179}