terom@0: #ifndef PNGTILE_CACHE_H terom@0: #define PNGTILE_CACHE_H terom@0: terom@0: /** terom@0: * @file terom@0: * terom@0: * Internal image cache implementation terom@0: */ terom@0: #include "image.h" terom@0: terom@1: #include terom@1: #include terom@1: terom@1: #include terom@1: terom@0: /** terom@0: * State for cache access terom@0: */ terom@0: struct pt_cache { terom@1: /** Filesystem path to cache file */ terom@1: char *path; terom@0: terom@1: /** The mode we are operating in, bitmask of PT_IMG_* */ terom@1: int mode; terom@1: terom@1: /** Opened file */ terom@1: int fd; terom@1: terom@1: /** Memory-mapped file data, from the second page on */ terom@1: uint8_t *mmap; terom@1: terom@1: /** Size of the mmap'd segment in bytes */ terom@1: size_t size; terom@0: }; terom@0: terom@0: /** terom@1: * Size of a cache file page in bytes terom@1: */ terom@1: #define PT_CACHE_PAGE 4096 terom@1: terom@1: /** terom@0: * On-disk header terom@0: */ terom@0: struct pt_cache_header { terom@0: /** Pixel dimensions of image */ terom@0: uint32_t width, height; terom@0: terom@0: /** Pixel format */ terom@0: uint8_t bit_depth, color_type; terom@0: terom@0: /** Convenience field for number of bytes per row */ terom@0: uint32_t row_bytes; terom@0: }; terom@0: terom@0: /** terom@0: * Construct the image cache info object associated with the given image. terom@0: */ terom@1: int pt_cache_open (struct pt_cache **cache_ptr, const char *path, int mode); terom@0: terom@0: /** terom@1: * Verify if the cached data has become stale compared to the given original file. terom@0: */ terom@1: int pt_cache_stale (struct pt_cache *cache, const char *orig_path); terom@0: terom@0: /** terom@0: * Update the cache data from the given PNG image. terom@0: */ terom@0: int pt_cache_update_png (struct pt_cache *cache, png_structp png, png_infop info); terom@0: terom@1: /** terom@1: * Release all resources associated with the given cache object without any cleanup. terom@1: */ terom@1: void pt_cache_destroy (struct pt_cache *cache); terom@1: terom@0: #endif