terom@56: #ifndef PNGTILE_PNG_H terom@56: #define PNGTILE_PNG_H terom@56: terom@56: /** terom@56: * @file terom@56: * PNG-specific handling terom@56: */ terom@56: #include terom@56: #include terom@56: terom@56: /** terom@56: * Handle sparse data at this granularity (pixels) terom@56: */ terom@56: #define PT_IMG_BLOCK_SIZE 64 terom@56: terom@56: /** terom@56: * PNG img state terom@56: */ terom@56: struct pt_png_img { terom@56: /** libpng state */ terom@56: png_struct *png; terom@56: png_info *info; terom@56: terom@69: /** Possible opened I/O file */ terom@69: FILE *fh; terom@56: }; terom@56: terom@56: /** terom@56: * Cache header layout for PNG-format images terom@56: */ terom@56: struct pt_png_header { terom@56: /** Pixel dimensions of image */ terom@56: uint32_t width, height; terom@56: terom@56: /** Pixel format */ terom@56: uint8_t bit_depth, color_type; terom@56: terom@56: /** Number of png_color entries that follow */ terom@56: uint16_t num_palette; terom@56: terom@56: /** Number of bytes per row */ terom@56: uint32_t row_bytes; terom@56: terom@56: /** Number of bytes per pixel */ terom@56: uint8_t col_bytes; terom@56: terom@56: /** Palette entries, up to 256 entries used */ terom@56: png_color palette[PNG_MAX_PALETTE_LENGTH]; terom@56: }; terom@56: terom@56: terom@56: #include "image.h" terom@56: #include "tile.h" terom@56: terom@69: /** terom@69: * Check if the given path looks like a .png file. terom@69: * terom@69: * Returns 0 if ok, 1 if non-png file, -1 on error terom@69: */ terom@69: int pt_png_check (const char *path); terom@56: terom@56: /** terom@56: * Open the given .png image, and read info terom@56: */ terom@56: int pt_png_open (struct pt_image *image, struct pt_png_img *img); terom@56: terom@56: /** terom@56: * Fill in the PNG header and return the size of the pixel data terom@56: */ terom@56: int pt_png_read_header (struct pt_png_img *img, struct pt_png_header *header, size_t *data_size); terom@56: terom@56: /** terom@56: * Decode the PNG data into the given data segment, using the header as decoded by pt_png_read_header terom@56: */ terom@56: int pt_png_decode (struct pt_png_img *img, const struct pt_png_header *header, const struct pt_image_params *params, uint8_t *out); terom@56: terom@56: /** terom@56: * Fill in img_* fields of pt_image_info from header terom@56: */ terom@56: int pt_png_info (struct pt_png_header *header, struct pt_image_info *info); terom@56: terom@56: /** terom@56: * Render out a tile terom@56: */ terom@70: int pt_png_tile (const struct pt_png_header *header, const uint8_t *data, struct pt_tile *tile); terom@56: terom@56: /** terom@56: * Release pt_png_ctx resources as allocated by pt_png_open terom@56: */ terom@56: void pt_png_release_read (struct pt_png_img *img); terom@56: terom@56: /** terom@56: * Release pt_png_ctx resources as allocated by pt_png_... terom@56: */ terom@56: void pt_png_release_write (struct pt_png_img *img); terom@56: terom@56: #endif