3737#ifdef ASSERT
3838#undef ASSERT
3939#endif
40- #define ASSERT (X ) if(!(X)) goto error;
40+ #define ASSERT (X ) \
41+ if (!(X)) \
42+ goto error;
4143
4244#ifdef USE_LIBPNG
4345#include <png.h>
@@ -54,14 +56,14 @@ static void DestroyPNGReader(void *data)
5456{
5557 LCUI_PNGReader reader = data ;
5658 if (reader -> png_ptr ) {
57- png_destroy_read_struct (& reader -> png_ptr ,
58- & reader -> info_ptr , NULL );
59+ png_destroy_read_struct (& reader -> png_ptr , & reader -> info_ptr ,
60+ NULL );
5961 }
6062 free (reader );
6163}
6264
63- static void PNGReader_OnRead (png_structp png_ptr ,
64- png_bytep buffer , png_size_t size )
65+ static void PNGReader_OnRead (png_structp png_ptr , png_bytep buffer ,
66+ png_size_t size )
6567{
6668 size_t read_size ;
6769 LCUI_ImageReader reader = png_get_io_ptr (png_ptr );
@@ -84,8 +86,8 @@ int LCUI_InitPNGReader(LCUI_ImageReader reader)
8486{
8587#ifdef USE_LIBPNG
8688 ASSIGN (png_reader , LCUI_PNGReader );
87- png_reader -> png_ptr = png_create_read_struct ( PNG_LIBPNG_VER_STRING ,
88- NULL , NULL , NULL );
89+ png_reader -> png_ptr =
90+ png_create_read_struct ( PNG_LIBPNG_VER_STRING , NULL , NULL , NULL );
8991 ASSERT (png_reader -> png_ptr );
9092 png_reader -> info_ptr = png_create_info_struct (png_reader -> png_ptr );
9193 ASSERT (png_reader -> info_ptr );
@@ -122,11 +124,11 @@ int LCUI_ReadPNGHeader(LCUI_ImageReader reader)
122124 info_ptr = png_reader -> info_ptr ;
123125 n = reader -> fn_read (reader -> stream_data , buf , PNG_BYTES_TO_CHECK );
124126 if (n < PNG_BYTES_TO_CHECK ) {
125- return - ENODATA ;
127+ return -2 ;
126128 }
127129 /* 检测数据是否为PNG的签名 */
128130 if (!png_check_sig (buf , PNG_BYTES_TO_CHECK )) {
129- return - ENODATA ;
131+ return -2 ;
130132 }
131133 png_set_sig_bytes (png_reader -> png_ptr , PNG_BYTES_TO_CHECK );
132134 /* 读取PNG图片信息 */
@@ -175,7 +177,7 @@ int LCUI_ReadPNG(LCUI_ImageReader reader, LCUI_Graph *graph)
175177 info_ptr = png_reader -> info_ptr ;
176178 if (header -> type == LCUI_UNKNOWN_IMAGE ) {
177179 if (LCUI_ReadPNGHeader (reader ) != 0 ) {
178- return - ENODATA ;
180+ return -2 ;
179181 }
180182 }
181183 /* 根据不同的色彩类型进行相应处理 */
@@ -198,7 +200,7 @@ int LCUI_ReadPNG(LCUI_ImageReader reader, LCUI_Graph *graph)
198200 break ;
199201 default :
200202 /* 其它色彩类型的图像就不处理了 */
201- return - ENODATA ;
203+ return -2 ;
202204 }
203205 png_set_bgr (png_ptr );
204206 png_set_expand (png_ptr );
@@ -239,11 +241,13 @@ int LCUI_WritePNGFile(const char *file_name, const LCUI_Graph *graph)
239241 /* create file */
240242 fp = fopen (file_name , "wb" );
241243 if (!fp ) {
242- _DEBUG_MSG ("file %s could not be opened for writing\n" , file_name );
244+ _DEBUG_MSG ("file %s could not be opened for writing\n" ,
245+ file_name );
243246 return -1 ;
244247 }
245248 /* initialize stuff */
246- png_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING , NULL , NULL , NULL );
249+ png_ptr =
250+ png_create_write_struct (PNG_LIBPNG_VER_STRING , NULL , NULL , NULL );
247251 if (!png_ptr ) {
248252 fclose (fp );
249253 _DEBUG_MSG ("png_create_write_struct failed\n" );
@@ -269,9 +273,9 @@ int LCUI_WritePNGFile(const char *file_name, const LCUI_Graph *graph)
269273 color_type = PNG_COLOR_TYPE_RGB ;
270274 }
271275 /* write header */
272- png_set_IHDR (png_ptr , info_ptr , graph -> width , graph -> height ,
273- 8 , color_type , PNG_INTERLACE_NONE ,
274- PNG_COMPRESSION_TYPE_BASE , PNG_FILTER_TYPE_BASE );
276+ png_set_IHDR (png_ptr , info_ptr , graph -> width , graph -> height , 8 ,
277+ color_type , PNG_INTERLACE_NONE , PNG_COMPRESSION_TYPE_BASE ,
278+ PNG_FILTER_TYPE_BASE );
275279
276280 png_write_info (png_ptr , info_ptr );
277281 /* write bytes */
@@ -283,7 +287,8 @@ int LCUI_WritePNGFile(const char *file_name, const LCUI_Graph *graph)
283287
284288 row_size = png_get_rowbytes (png_ptr , info_ptr );
285289 px_row_ptr = graph -> argb + rect .y * graph -> width + rect .x ;
286- row_pointers = (png_bytep * )malloc (rect .height * sizeof (png_bytep ));
290+ row_pointers =
291+ (png_bytep * )malloc (rect .height * sizeof (png_bytep ));
287292 for (y = 0 ; y < rect .height ; ++ y ) {
288293 row_pointers [y ] = png_malloc (png_ptr , row_size );
289294 px_ptr = px_row_ptr ;
@@ -301,14 +306,15 @@ int LCUI_WritePNGFile(const char *file_name, const LCUI_Graph *graph)
301306 row_size = png_get_rowbytes (png_ptr , info_ptr );
302307 px_row_ptr = graph -> bytes + rect .y * graph -> bytes_per_row ;
303308 px_row_ptr += rect .x * graph -> bytes_per_pixel ;
304- row_pointers = (png_bytep * )malloc (rect .height * sizeof (png_bytep ));
309+ row_pointers =
310+ (png_bytep * )malloc (rect .height * sizeof (png_bytep ));
305311 for (y = 0 ; y < rect .height ; ++ y ) {
306312 row_pointers [y ] = (png_bytep )malloc (row_size );
307313 px_ptr = px_row_ptr ;
308314 for (x = 0 ; x < row_size ; x += 3 ) {
309- row_pointers [y ][x + 2 ] = * px_ptr ++ ; // blue
310- row_pointers [y ][x + 1 ] = * px_ptr ++ ; // green
311- row_pointers [y ][x ] = * px_ptr ++ ; // red
315+ row_pointers [y ][x + 2 ] = * px_ptr ++ ; // blue
316+ row_pointers [y ][x + 1 ] = * px_ptr ++ ; // green
317+ row_pointers [y ][x ] = * px_ptr ++ ; // red
312318 }
313319 px_row_ptr += graph -> bytes_per_row ;
314320 }
0 commit comments