decoder.h (3732B)
1 #ifndef DECODER_H 2 #define DECODER_H 3 4 #include <stdint.h> 5 #include <lua.h> 6 7 /* Image structure - common format for all decoders */ 8 typedef struct { 9 uint32_t width; 10 uint32_t height; 11 uint8_t bpp; // Bits per pixel (8, 24, 32) 12 uint8_t* data; // Pixel data (RGB or RGBA format) 13 uint32_t data_size; // Size of data in bytes 14 int has_alpha; // 1 if image has alpha channel 15 } image_t; 16 17 /* Scaling modes */ 18 typedef enum { 19 SCALE_NEAREST, // Nearest neighbor (fast, pixelated) 20 SCALE_BILINEAR, // Bilinear interpolation (smooth) 21 SCALE_FIT, // Fit to dimensions (maintain aspect ratio) 22 SCALE_FILL, // Fill dimensions (may stretch) 23 SCALE_COVER // Cover dimensions (may crop) 24 } scale_mode_t; 25 26 /* Image drawing options */ 27 typedef struct { 28 int x; // Destination X coordinate 29 int y; // Destination Y coordinate 30 int width; // Destination width (0 = original) 31 int height; // Destination height (0 = original) 32 scale_mode_t scale_mode; // Scaling algorithm 33 int flip_horizontal; // Flip horizontally 34 int flip_vertical; // Flip vertically 35 uint8_t alpha; // Global alpha/opacity (0-255) 36 } draw_options_t; 37 38 /* Image creation and destruction */ 39 image_t* image_create(uint32_t width, uint32_t height, uint8_t bpp); 40 void image_destroy(image_t* img); 41 42 /* Image manipulation */ 43 image_t* image_scale(image_t* src, uint32_t new_width, uint32_t new_height, scale_mode_t mode); 44 image_t* image_flip(image_t* src, int horizontal, int vertical); 45 void image_convert_to_rgb(image_t* img); 46 47 /* Drawing functions */ 48 void image_draw(image_t* img, int x, int y); 49 void image_draw_scaled(image_t* img, int x, int y, int width, int height, scale_mode_t mode); 50 void image_draw_with_options(image_t* img, draw_options_t* options); 51 52 /* Pixel access helpers */ 53 void image_get_pixel(image_t* img, uint32_t x, uint32_t y, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); 54 void image_set_pixel(image_t* img, uint32_t x, uint32_t y, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 55 56 /* Color conversion */ 57 uint32_t rgb_to_color(uint8_t r, uint8_t g, uint8_t b); 58 void color_to_rgb(uint32_t color, uint8_t* r, uint8_t* g, uint8_t* b); 59 60 /* Scaling algorithms */ 61 image_t* scale_nearest_neighbor(image_t* src, uint32_t new_width, uint32_t new_height); 62 image_t* scale_bilinear(image_t* src, uint32_t new_width, uint32_t new_height); 63 64 /* Aspect ratio calculations */ 65 void calculate_fit_dimensions(uint32_t src_w, uint32_t src_h, 66 uint32_t dst_w, uint32_t dst_h, 67 uint32_t* out_w, uint32_t* out_h); 68 void calculate_cover_dimensions(uint32_t src_w, uint32_t src_h, 69 uint32_t dst_w, uint32_t dst_h, 70 uint32_t* out_w, uint32_t* out_h); 71 72 /* Rotation */ 73 typedef enum { 74 ROTATE_NONE = 0, 75 ROTATE_90_CW = 90, // 90 degrees clockwise 76 ROTATE_180 = 180, // 180 degrees 77 ROTATE_270_CW = 270, // 270 degrees clockwise (90 CCW) 78 ROTATE_90_CCW = -90 // 90 degrees counter-clockwise 79 } rotation_angle_t; 80 81 image_t* image_rotate(image_t* src, rotation_angle_t angle); 82 83 /* Lua bindings */ 84 int lua_image_draw(lua_State* L); 85 int lua_image_draw_scaled(lua_State* L); 86 int lua_image_get_info(lua_State* L); 87 int lua_image_destroy(lua_State* L); 88 int lua_image_rotate(lua_State* L); 89 int lua_image_get_width(lua_State* L); 90 int lua_image_get_height(lua_State* L); 91 int lua_image_get_pixel(lua_State* L); 92 int lua_image_create(lua_State* L); 93 int lua_image_set_pixel(lua_State* L); 94 95 #endif /* DECODER_H */