luajitos

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

decoder_PNG.h (2178B)


      1 #ifndef DECODER_PNG_H
      2 #define DECODER_PNG_H
      3 
      4 #include "decoder.h"
      5 #include <stdint.h>
      6 #include <lua.h>
      7 
      8 /* PNG Signature */
      9 #define PNG_SIGNATURE_SIZE 8
     10 static const uint8_t PNG_SIGNATURE[PNG_SIGNATURE_SIZE] = {
     11     0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A
     12 };
     13 
     14 /* PNG Chunk types */
     15 #define PNG_CHUNK_IHDR 0x49484452  // Image header
     16 #define PNG_CHUNK_PLTE 0x504C5445  // Palette
     17 #define PNG_CHUNK_IDAT 0x49444154  // Image data
     18 #define PNG_CHUNK_IEND 0x49454E44  // Image end
     19 
     20 /* PNG Color types */
     21 #define PNG_COLOR_GRAYSCALE       0
     22 #define PNG_COLOR_RGB             2
     23 #define PNG_COLOR_PALETTE         3
     24 #define PNG_COLOR_GRAYSCALE_ALPHA 4
     25 #define PNG_COLOR_RGBA            6
     26 
     27 /* PNG Filter types */
     28 #define PNG_FILTER_NONE    0
     29 #define PNG_FILTER_SUB     1
     30 #define PNG_FILTER_UP      2
     31 #define PNG_FILTER_AVERAGE 3
     32 #define PNG_FILTER_PAETH   4
     33 
     34 /* PNG Interlace methods */
     35 #define PNG_INTERLACE_NONE  0
     36 #define PNG_INTERLACE_ADAM7 1
     37 
     38 /* PNG Chunk structure */
     39 typedef struct {
     40     uint32_t length;
     41     uint32_t type;
     42     uint8_t* data;
     43     uint32_t crc;
     44 } png_chunk_t;
     45 
     46 /* PNG IHDR (Image Header) */
     47 typedef struct {
     48     uint32_t width;
     49     uint32_t height;
     50     uint8_t bit_depth;
     51     uint8_t color_type;
     52     uint8_t compression_method;
     53     uint8_t filter_method;
     54     uint8_t interlace_method;
     55 } png_ihdr_t;
     56 
     57 /* PNG decoder context */
     58 typedef struct {
     59     png_ihdr_t ihdr;
     60     uint8_t* palette;
     61     uint32_t palette_size;
     62     uint8_t* image_data;
     63     uint32_t image_data_size;
     64     uint32_t image_data_capacity;
     65 } png_context_t;
     66 
     67 /* PNG decoding functions */
     68 image_t* png_decode(const uint8_t* data, uint32_t data_size);
     69 image_t* png_load_file(const char* filename);
     70 
     71 /* PNG encoding functions (basic) */
     72 int png_encode(image_t* img, uint8_t** out_data, uint32_t* out_size);
     73 int png_save_file(image_t* img, const char* filename);
     74 
     75 /* Lua bindings */
     76 int lua_png_load(lua_State* L);
     77 // int lua_png_save(lua_State* L);
     78 
     79 /* Note: Full PNG support requires zlib for compression/decompression.
     80  * This implementation will support basic uncompressed/simple PNG files.
     81  * For production use, consider integrating miniz or stb_image libraries.
     82  */
     83 
     84 #endif /* DECODER_PNG_H */