Lines 94-105
Comments:
Link Here
|
94 |
gray scale images with alpha components are converted to 32-bit images |
94 |
gray scale images with alpha components are converted to 32-bit images |
95 |
*/ |
95 |
*/ |
96 |
BMGError ReadPNG( const char *filename, |
96 |
BMGError ReadPNG( const char *filename, |
97 |
struct BMGImageStruct *img ) |
97 |
struct BMGImageStruct * volatile img ) |
98 |
{ |
98 |
{ |
99 |
jmp_buf err_jmp; |
99 |
jmp_buf err_jmp; |
100 |
int error; |
100 |
int error; |
101 |
|
101 |
|
102 |
FILE *file = NULL; |
102 |
FILE * volatile file = NULL; |
103 |
int BitDepth; |
103 |
int BitDepth; |
104 |
int BitsPerPixel; |
104 |
int BitsPerPixel; |
105 |
int FixedBitDepth; |
105 |
int FixedBitDepth; |
Lines 107-124
BMGError ReadPNG( const char *filename,
Link Here
|
107 |
int ImageChannels; |
107 |
int ImageChannels; |
108 |
int InterlaceType; |
108 |
int InterlaceType; |
109 |
unsigned char signature[8]; |
109 |
unsigned char signature[8]; |
110 |
png_structp png_ptr = NULL; |
110 |
png_structp volatile png_ptr = NULL; |
111 |
png_infop info_ptr = NULL; |
111 |
png_infop volatile info_ptr = NULL; |
|
|
112 |
png_infop volatile end_info = NULL; |
112 |
png_colorp PNGPalette = NULL; |
113 |
png_colorp PNGPalette = NULL; |
113 |
png_color_16 *ImageBackground = NULL; |
114 |
png_color_16 *ImageBackground = NULL; |
114 |
png_bytep trns = NULL; |
115 |
png_bytep trns = NULL; |
115 |
int NumTrans = 0; |
116 |
int NumTrans = 0; |
116 |
int i, j, k; |
117 |
int i, j, k; |
117 |
png_color_16p TransColors = NULL; |
118 |
png_color_16p TransColors = NULL; |
118 |
unsigned int Width, Height; |
119 |
png_uint_32 Width, Height; |
119 |
|
120 |
|
120 |
unsigned char *bits, *p, *q; |
121 |
unsigned char *bits, *p, *q; |
121 |
unsigned char** rows = NULL; |
122 |
unsigned char** volatile rows = NULL; |
122 |
int NumColors = 0; |
123 |
int NumColors = 0; |
123 |
unsigned char BgdRed = 0; |
124 |
unsigned char BgdRed = 0; |
124 |
unsigned char BgdGreen = 0; |
125 |
unsigned char BgdGreen = 0; |
Lines 130-149
BMGError ReadPNG( const char *filename,
Link Here
|
130 |
|
131 |
|
131 |
/* error handler */ |
132 |
/* error handler */ |
132 |
error = setjmp( err_jmp ); |
133 |
error = setjmp( err_jmp ); |
133 |
if ( error != 0 ) |
134 |
if (error != 0) |
134 |
{ |
135 |
{ |
135 |
if ( png_ptr != NULL ) |
136 |
if (end_info != NULL) |
136 |
png_destroy_read_struct( &png_ptr, NULL, NULL ); |
137 |
png_destroy_read_struct((png_structp *) &png_ptr, (png_infop *) &info_ptr, (png_infop *) &end_info); |
137 |
if ( rows ) |
138 |
else if (info_ptr != NULL) |
|
|
139 |
png_destroy_read_struct((png_structp *) &png_ptr, (png_infop *) &info_ptr, NULL); |
140 |
else if (png_ptr != NULL) |
141 |
png_destroy_read_struct((png_structp *) &png_ptr, NULL, NULL); |
142 |
if (rows) |
138 |
{ |
143 |
{ |
139 |
if ( rows[0] ) |
144 |
if (rows[0]) |
140 |
free( rows[0] ); |
145 |
free(rows[0]); |
141 |
free( rows ); |
146 |
free(rows); |
142 |
} |
147 |
} |
143 |
FreeBMGImage( img ); |
148 |
if (img) |
144 |
fclose( file ); |
149 |
FreeBMGImage(img); |
145 |
SetLastBMGError( (BMGError)error ); |
150 |
if (file) |
146 |
return (BMGError)error; |
151 |
fclose(file); |
|
|
152 |
SetLastBMGError((BMGError) error); |
153 |
return (BMGError) error; |
147 |
} |
154 |
} |
148 |
|
155 |
|
149 |
if ( img == NULL ) |
156 |
if ( img == NULL ) |
Lines 163-168
BMGError ReadPNG( const char *filename,
Link Here
|
163 |
if ( !png_ptr ) |
170 |
if ( !png_ptr ) |
164 |
longjmp( err_jmp, (int)errMemoryAllocation ); |
171 |
longjmp( err_jmp, (int)errMemoryAllocation ); |
165 |
|
172 |
|
|
|
173 |
/* create a pointer to the png info structure */ |
174 |
info_ptr = png_create_info_struct( png_ptr ); |
175 |
if ( !info_ptr ) |
176 |
longjmp( err_jmp, (int)errMemoryAllocation ); |
177 |
|
178 |
/* create a pointer to the png end-info structure */ |
179 |
end_info = png_create_info_struct(png_ptr); |
180 |
if (!end_info) |
181 |
longjmp( err_jmp, (int)errMemoryAllocation ); |
182 |
|
166 |
/* bamboozle the PNG longjmp buffer */ |
183 |
/* bamboozle the PNG longjmp buffer */ |
167 |
/*generic PNG error handler*/ |
184 |
/*generic PNG error handler*/ |
168 |
/* error will always == 1 which == errLib */ |
185 |
/* error will always == 1 which == errLib */ |
Lines 171-181
BMGError ReadPNG( const char *filename,
Link Here
|
171 |
if ( error > 0 ) |
188 |
if ( error > 0 ) |
172 |
longjmp( err_jmp, error ); |
189 |
longjmp( err_jmp, error ); |
173 |
|
190 |
|
174 |
/* create a pointer to the png info structure */ |
|
|
175 |
info_ptr = png_create_info_struct( png_ptr ); |
176 |
if ( !info_ptr ) |
177 |
longjmp( err_jmp, (int)errMemoryAllocation ); |
178 |
|
179 |
/* attach file buffer to the png read pointer */ |
191 |
/* attach file buffer to the png read pointer */ |
180 |
png_init_io( png_ptr, file ); |
192 |
png_init_io( png_ptr, file ); |
181 |
|
193 |
|
Lines 187-193
BMGError ReadPNG( const char *filename,
Link Here
|
187 |
|
199 |
|
188 |
/* extract the data we need to form the HBITMAP from the PNG header */ |
200 |
/* extract the data we need to form the HBITMAP from the PNG header */ |
189 |
png_get_IHDR( png_ptr, info_ptr, &Width, &Height, &BitDepth, &ColorType, |
201 |
png_get_IHDR( png_ptr, info_ptr, &Width, &Height, &BitDepth, &ColorType, |
190 |
&InterlaceType, NULL, NULL ); |
202 |
&InterlaceType, NULL, NULL); |
191 |
|
203 |
|
192 |
img->width = Width; |
204 |
img->width = Width; |
193 |
img->height = Height; |
205 |
img->height = Height; |
Lines 475-481
BMGError ReadPNG( const char *filename,
Link Here
|
475 |
free( rows[0] ); |
487 |
free( rows[0] ); |
476 |
free( rows ); |
488 |
free( rows ); |
477 |
png_read_end( png_ptr, info_ptr ); |
489 |
png_read_end( png_ptr, info_ptr ); |
478 |
png_destroy_read_struct( &png_ptr, &info_ptr, NULL ); |
490 |
png_destroy_read_struct((png_structp *) &png_ptr, (png_infop *) &info_ptr, (png_infop *) &end_info); |
479 |
fclose( file ); |
491 |
fclose( file ); |
480 |
|
492 |
|
481 |
return BMG_OK; |
493 |
return BMG_OK; |