RSE-Texture/src/RS_images.h

75 lines
2.4 KiB
C

#ifndef RS_IMAGES_H_
#define RS_IMAGES_H_
#include <stdio.h>
#include <stdlib.h>
#if defined(_WIN32)
#define OS 1
#include <windows.h>
#else
#define OS 2
#include <sys/types.h>
#include <sys/stat.h>
#endif
/////////////////////////////
///// 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 */
unsigned char palette[256][3]; /**< Image palette definition */ //TODO: Create union struct type instead
}RS_IMAGE;
typedef struct RSImage_desc {
int palette_enties;
int sample_bits;
}RS_IMAGE_DESC;
/////////////////////////////
///// Declare functions /////
/////////////////////////////
RS_IMAGE_DESC getImageDescFromType(unsigned char type); //TODO: Optimise function
int isTransparentColor(PIXEL_A *testColor, PIXEL_A *transp_color);
void convert4bitsGreyto8bitsRGB(unsigned char *samples_tab, PIXEL_A *pixels_tab, int sampling, PIXEL_A *transp_color);
void unpack4To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]);
void unpack8To24bitsRGB(unsigned char *samples_tab, unsigned char *pixels_tab, int size, unsigned char pal[256][3]);
void useOddBytes(unsigned char *src, unsigned char *dst, int size);
void decodePixels(RS_IMAGE *img);
PIXEL_A *pixelAt(RS_IMAGE *img, int posX , int posY);
int getPaletteFromFile(RS_IMAGE *img, FILE *f);
int getSamplesFromFile(RS_IMAGE *img, FILE *f);
#endif