22 static png_structp png_ptr = 0;
23 static png_infop info_ptr = 0;
28 typedef struct my_png_file_ {
33 static void png_fileread_func(png_structp png_sp, png_bytep buf, png_size_t size)
35 my_png_file *png_file;
37 DTFPRINTF(0x02,
"size = %d\n", size);
39 png_file = (my_png_file *)png_get_io_ptr(png_sp);
43 XDUMP(0x02, buf, size);
46 static my_png_file png_file;
48 int get_png_file_info(
int fd,
short *png_width,
short *png_height)
51 #if 0 // png_read_info()で同様の処理は行っているので 52 unsigned char png_sig[8];
57 DTPRINTF(0x01,
"PNG file read error\n");
61 rt = png_check_sig(png_sig, 8);
63 DTPRINTF(0x01,
"png_check_sig() error\n");
68 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
70 DTFPRINTF(0x01,
"png_create_read_struct() error\n");
75 info_ptr = png_create_info_struct(png_ptr);
76 if(info_ptr == NULL) {
77 DTFPRINTF(0x01,
"png_create_info_struct() error\n");
82 if(setjmp(png_jmpbuf(png_ptr))) {
83 DTFPRINTF(0x01,
"decode error\n");
89 png_set_read_fn(png_ptr, (png_voidp)&png_file, (png_rw_ptr)png_fileread_func);
91 png_uint_32 width, height;
92 int bit_depth, color_type, interlace_type;
93 int compression_type, filter_type;
95 png_read_info(png_ptr, info_ptr);
96 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,&color_type,
97 &interlace_type, &compression_type, &filter_type);
98 DTPRINTF(0x01,
"width = %u, height = %u, bpp = %d, color_type = %d\n",
99 width, height, bit_depth, color_type);
102 *png_height = height;
107 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
117 unsigned char *data_ptr;
121 static void png_dataread_func(png_structp png_ptr, png_bytep buf, png_size_t size)
123 DTFPRINTF(0x02,
"size = %d\n", size);
125 struct my_png_data *png_data = (
struct my_png_data *)png_get_io_ptr(png_ptr);
128 png_data->data_ptr += size;
130 XDUMP(0x02, buf, size);
133 static struct my_png_data png_data;
135 int get_png_data_info(
unsigned char *data,
short *png_width,
short *png_height)
138 #if 0 // png_read_info()で同様の処理は行っているので 139 unsigned char png_sig[8];
144 DTPRINTF(0x01,
"PNG file read error\n");
148 rt = png_check_sig(png_sig, 8);
150 DTPRINTF(0x01,
"png_check_sig() error\n");
155 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
157 DTFPRINTF(0x01,
"png_create_read_struct() error\n");
162 info_ptr = png_create_info_struct(png_ptr);
163 if(info_ptr == NULL) {
164 DTFPRINTF(0x01,
"png_create_info_struct() error\n");
169 if(setjmp(png_jmpbuf(png_ptr))) {
170 DTFPRINTF(0x01,
"decode error\n");
175 png_data.data_ptr = data;
176 png_set_read_fn(png_ptr, (png_voidp)&png_data, (png_rw_ptr)png_dataread_func);
178 png_uint_32 width, height;
179 int bit_depth, color_type, interlace_type;
180 int compression_type, filter_type;
182 png_read_info(png_ptr, info_ptr);
183 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth,&color_type,
184 &interlace_type, &compression_type, &filter_type);
185 DTPRINTF(0x01,
"width = %u, height = %u bpp = %d color_type = %d\n",
186 width, height, bit_depth, color_type);
189 *png_height = height;
194 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
200 int decode_png(
void *image)
203 unsigned char **rowimage;
206 png_uint_32 width, height;
207 int bit_depth, color_type, interlace_type;
208 int compression_type, filter_type;
211 png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
212 &interlace_type, &compression_type, &filter_type);
215 case PNG_COLOR_TYPE_PALETTE:
216 DTPRINTF(0x01,
"PNG_COLOR_TYPE_PALETTE not supported\n");
221 case PNG_COLOR_TYPE_GRAY:
222 DTPRINTF(0x01,
"PNG_COLOR_TYPE_GRAY not supported\n");
226 case PNG_COLOR_TYPE_GRAY_ALPHA:
227 DTPRINTF(0x01,
"PNG_COLOR_TYPE_GRAY_ALPHA not supported\n");
232 case PNG_COLOR_TYPE_RGB:
233 DTPRINTF(0x01,
"PNG_COLOR_TYPE_RGB\n");
236 case PNG_COLOR_TYPE_RGB_ALPHA:
237 DTPRINTF(0x01,
"PNG_COLOR_TYPE_RGB_ALPHA\n");
241 DTPRINTF(0x01,
"Unknown type(%d)\n", color_type);
247 if(setjmp(png_jmpbuf(png_ptr))) {
248 DTFPRINTF(0x01,
"decode error\n");
253 rowimage = (png_bytepp)
alloc_memory(height *
sizeof(png_bytep));
254 rowbytes = png_get_rowbytes(png_ptr, info_ptr);
255 DTPRINTF(0x01,
"rowbytes = %d\n", rowbytes);
256 for(i=0; i<height; i++) {
260 png_read_image(png_ptr, rowimage);
262 for(i=0; i<height; i++) {
263 XDUMP(0x02, rowimage[i], width);
264 for(j=0; j<width; j++) {
266 case PNG_COLOR_TYPE_RGB_ALPHA:
267 pixel_p[width*i + j] = RGB(rowimage[i][j*4+0], rowimage[i][j*4+1], rowimage[i][j*4+2]);
270 case PNG_COLOR_TYPE_RGB:
271 pixel_p[width*i + j] = RGB(rowimage[i][j*3+0], rowimage[i][j*3+1], rowimage[i][j*3+2]);
282 for(i=0; i<height; i++) {
288 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
294 void dispose_png_info(
void)
296 png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
t_ssize seek_file(int fd, t_ssize offset, int whence)
ファイルアクセス位置の設定
void free_memory(void *ptr)
確保したメモリを開放する
void * alloc_memory(unsigned int size)
メモリを確保する
void * memorycopy(void *dest, const void *src, unsigned int count)
メモリコピー
t_ssize read_file(int fd, void *buf, t_size count)
ファイルからデータを読み出す
unsigned short PIXEL_DATA
$gsc グラフィックデバイスは24ビットカラー