Lines Matching defs:png

35 file_read(png_t *png, void *out, size_t size, size_t numel)
44 result = lseek(png->fd, offset, SEEK_CUR);
46 result = read(png->fd, out, size * numel);
53 file_read_ul(png_t *png, unsigned *out)
57 if (file_read(png, &buf, 1, 4) != 4)
72 png_get_bpp(png_t *png)
76 switch (png->color_type) {
91 bpp *= png->depth / 8;
97 png_read_ihdr(png_t *png)
104 if (file_read_ul(png, &length) != PNG_NO_ERROR)
110 if (file_read(png, ihdr, 1, 13+4) != 13+4)
113 if (file_read_ul(png, &orig_crc) != PNG_NO_ERROR)
123 png->width = get_ul(ihdr+4);
124 png->height = get_ul(ihdr+8);
125 png->depth = ihdr[12];
126 png->color_type = ihdr[13];
127 png->compression_method = ihdr[14];
128 png->filter_method = ihdr[15];
129 png->interlace_method = ihdr[16];
131 if (png->color_type == PNG_INDEXED)
134 if (png->depth != 8 && png->depth != 16)
137 if (png->interlace_method)
144 png_print_info(png_t *png)
147 printf("\twidth:\t\t%d\n", png->width);
148 printf("\theight:\t\t%d\n", png->height);
149 printf("\tdepth:\t\t%d\n", png->depth);
152 switch (png->color_type) {
168 png->compression_method?
171 png->filter_method? "unknown, this is not good":"adaptive");
173 png->interlace_method? "interlace":"no interlace");
177 png_open(png_t *png, const char *filename)
182 png->image = NULL;
183 png->fd = open(filename, O_RDONLY);
184 if (png->fd == -1)
187 if (file_read(png, header, 1, 8) != 8) {
197 result = png_read_ihdr(png);
199 result = png_get_bpp(png);
201 png->bpp = (uint8_t)result;
208 uint64_t size = png->width * png->height * png->bpp;
211 png->image = malloc(size);
212 if (png->image == NULL)
217 result = png_get_data(png, png->image);
220 free(png->image);
221 (void) close(png->fd);
222 png->fd = -1;
230 png_close(png_t *png)
232 (void) close(png->fd);
233 png->fd = -1;
234 free(png->image);
235 png->image = NULL;
241 png_init_inflate(png_t *png)
244 png->zs = calloc(1, sizeof (z_stream));
246 stream = png->zs;
252 free(png->zs);
253 png->zs = NULL;
257 stream->next_out = png->png_data;
258 stream->avail_out = png->png_datalen;
264 png_end_inflate(png_t *png)
266 z_stream *stream = png->zs;
277 free(png->zs);
278 png->zs = NULL;
284 png_inflate(png_t *png, uint8_t *data, int len)
287 z_stream *stream = png->zs;
309 png_read_idat(png_t *png, unsigned length)
315 if (!png->readbuf || png->readbuflen < length) {
316 png->readbuf = realloc(png->readbuf, length);
317 png->readbuflen = length;
320 if (!png->readbuf)
323 if (file_read(png, png->readbuf, 1, length) != len)
328 calc_crc = crc32(calc_crc, (uint8_t *)png->readbuf, length);
330 if (file_read_ul(png, &orig_crc) != PNG_NO_ERROR)
336 return (png_inflate(png, png->readbuf, length));
340 png_process_chunk(png_t *png)
346 if (file_read_ul(png, &length) != PNG_NO_ERROR)
349 if (file_read_ul(png, &type) != PNG_NO_ERROR)
357 if (!png->png_data) { /* first IDAT */
358 png->png_datalen = png->width * png->height *
359 png->bpp + png->height;
360 png->png_data = malloc(png->png_datalen);
363 if (!png->png_data)
366 if (!png->zs) {
367 result = png_init_inflate(png);
372 return (png_read_idat(png, length));
376 (void) file_read(png, 0, 1, length + 4); /* unknown chunk */
484 png_unfilter(png_t *png, uint8_t *data)
489 uint8_t *filtered = png->png_data;
490 unsigned stride = png->bpp;
492 while (pos < png->png_datalen) {
497 if (png->depth == 16) {
498 for (i = 0; i < png->width * stride; i += 2) {
506 memcpy(data+outpos, filtered+pos, png->width * stride);
510 png->width * stride);
515 data + outpos - (png->width*stride),
516 png->width*stride);
519 0, png->width*stride);
526 data + outpos - (png->width*stride),
527 png->width*stride);
530 data+outpos, 0, png->width*stride);
537 data + outpos - (png->width*stride),
538 png->width*stride);
541 data+outpos, 0, png->width*stride);
548 outpos += png->width * stride;
549 pos += png->width * stride;
556 png_get_data(png_t *png, uint8_t *data)
560 png->zs = NULL;
561 png->png_datalen = 0;
562 png->png_data = NULL;
563 png->readbuf = NULL;
564 png->readbuflen = 0;
567 result = png_process_chunk(png);
569 if (png->readbuf) {
570 free(png->readbuf);
571 png->readbuflen = 0;
573 if (png->zs)
574 (void) png_end_inflate(png);
577 free(png->png_data);
581 result = png_unfilter(png, data);
583 free(png->png_data);