src/lib/png.h
changeset 56 d5e3089906da
child 69 1d188aa94aee
equal deleted inserted replaced
55:a3542e78ecd8 56:d5e3089906da
       
     1 #ifndef PNGTILE_PNG_H
       
     2 #define PNGTILE_PNG_H
       
     3 
       
     4 /**
       
     5  * @file
       
     6  * PNG-specific handling
       
     7  */
       
     8 #include <png.h>
       
     9 #include <stdint.h>
       
    10 
       
    11 /**
       
    12  * Handle sparse data at this granularity (pixels)
       
    13  */
       
    14 #define PT_IMG_BLOCK_SIZE 64
       
    15 
       
    16 /**
       
    17  * PNG img state
       
    18  */
       
    19 struct pt_png_img {
       
    20     /** libpng state */
       
    21     png_struct *png;
       
    22     png_info *info;
       
    23 
       
    24 };
       
    25 
       
    26 /**
       
    27  * Cache header layout for PNG-format images
       
    28  */
       
    29 struct pt_png_header {
       
    30     /** Pixel dimensions of image */
       
    31     uint32_t width, height;
       
    32     
       
    33     /** Pixel format */
       
    34     uint8_t bit_depth, color_type;
       
    35 
       
    36     /** Number of png_color entries that follow */
       
    37     uint16_t num_palette;
       
    38 
       
    39     /** Number of bytes per row */
       
    40     uint32_t row_bytes;
       
    41     
       
    42     /** Number of bytes per pixel */
       
    43     uint8_t col_bytes;
       
    44 
       
    45     /** Palette entries, up to 256 entries used */
       
    46     png_color palette[PNG_MAX_PALETTE_LENGTH];
       
    47 };
       
    48 
       
    49 
       
    50 #include "image.h"
       
    51 #include "tile.h"
       
    52 
       
    53 
       
    54 /**
       
    55  * Open the given .png image, and read info
       
    56  */
       
    57 int pt_png_open (struct pt_image *image, struct pt_png_img *img);
       
    58 
       
    59 /**
       
    60  * Fill in the PNG header and return the size of the pixel data
       
    61  */
       
    62 int pt_png_read_header (struct pt_png_img *img, struct pt_png_header *header, size_t *data_size);
       
    63 
       
    64 /**
       
    65  * Decode the PNG data into the given data segment, using the header as decoded by pt_png_read_header
       
    66  */
       
    67 int pt_png_decode (struct pt_png_img *img, const struct pt_png_header *header, const struct pt_image_params *params, uint8_t *out);
       
    68 
       
    69 /**
       
    70  * Fill in img_* fields of pt_image_info from header
       
    71  */
       
    72 int pt_png_info (struct pt_png_header *header, struct pt_image_info *info);
       
    73 
       
    74 /**
       
    75  * Render out a tile
       
    76  */
       
    77 int pt_png_tile (struct pt_png_header *header, uint8_t *data, struct pt_tile *tile);
       
    78 
       
    79 /**
       
    80  * Release pt_png_ctx resources as allocated by pt_png_open
       
    81  */
       
    82 void pt_png_release_read (struct pt_png_img *img);
       
    83 
       
    84 /**
       
    85  * Release pt_png_ctx resources as allocated by pt_png_...
       
    86  */
       
    87 void pt_png_release_write (struct pt_png_img *img);
       
    88 
       
    89 #endif