#ifndef RS_IMAGES_H_ #define RS_IMAGES_H_ #include #include #include //#include "options.h" /** * @brief Constant contain the number of channel inside a PIXEL definition. */ #define PIXEL_MEMBERS_NBR 4 ///////////////////////////// ///// Define new types ////// ///////////////////////////// /** * @brief RGBA pixel structure, used to store datas for implementation inside PNG files. */ typedef struct PixelRGBA { unsigned char _red; unsigned char _green; unsigned char _blue; unsigned char _alpha; }PIXEL_A; /** * @brief RGB pixel structure, used to store datas for implementation inside PNG files, optimised version without alpha channel support. */ typedef struct PixelRGB { unsigned char _red; unsigned char _green; unsigned char _blue; }PIXEL; /** * @brief Image definition from Rogue Squadron HMT files */ typedef struct RSImage { int data_size; /**< Image bytes size */ int width, height; unsigned char type_; /**< Image type (0 = RBG/4bits per pixel, 1 = RBG/8bpp, 3 = RGBA/32bpp , 4 = grayscale/4bpp, 5 = grayscale/8bpp */ unsigned char sampleBits; /**< Bits per samble */ int paletteEntries; PIXEL_A alpha_color; PIXEL_A *pixels; /**< Image pixels list, managed like an array and declared as a pointer */ unsigned char *samples; /**< Image samples list managed like an array and declared as a pointer */ PIXEL palette[256]; /**< Image palette definition */ //TODO: Create union struct type instead }RS_IMAGE; typedef struct RSImage_desc { int palette_entries; int sample_bits; }RS_IMAGE_DESC; ///////////////////////////// ///// Declare functions ///// ///////////////////////////// /** * @brief Conversion table for image type using RS_IMAGE_DESC. * Return RS_IMAGE_DESC by providing image type as int\n * * Detailed conversion:\n\n * Type 0 -> Palette entries: 16 ; Sample bits: 4\n * Type 1 -> Palette entries: 256 ; Sample bits: 8\n * Type 2 -> Palette entries: 0 ; Sample bits: 16\n * Type 3 -> Palette entries: 0 ; Sample bits: 32\n * Type 4 -> Palette entries: 0 ; Sample bits: 4\n * Type 5 -> Palette entries: 0 ; Sample bits: 8\n */ RS_IMAGE_DESC getImageDescFromType(unsigned char type); //TODO: Optimise function int isTransparentColor(PIXEL_A *testColor, PIXEL_A *transp_color); void convert4bitsGreyTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int sampling, PIXEL_A *transp_color); void convert4bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color); void convert8bitsTo32bitsRGBA(unsigned char *samples_tab, PIXEL_A *pixels_tab, int size, PIXEL *pal, PIXEL_A *transp_color); void useOddBytes(unsigned char *src, PIXEL_A *dst, int size); void decodePixels(RS_IMAGE *img); PIXEL_A *pixelAt(RS_IMAGE *img, int posX , int posY); #endif