project64/Source/Project64/UserInterface/Debugger/ScriptAPI/N64Image.h

112 lines
3.0 KiB
C
Raw Normal View History

#pragma once
#include "ScriptAPI.h"
2022-09-26 02:31:54 +00:00
enum
{
G_IM_FMT_RGBA,
G_IM_FMT_YUV,
G_IM_FMT_CI,
G_IM_FMT_IA,
G_IM_FMT_I
};
2022-09-26 02:31:54 +00:00
enum
{
G_IM_SIZ_4b,
G_IM_SIZ_8b,
G_IM_SIZ_16b,
G_IM_SIZ_32b
};
2022-09-26 02:31:54 +00:00
enum
{
G_TT_NONE = 0x0000,
G_TT_RGBA16 = 0x8000,
G_TT_IA16 = 0xC000,
};
2022-09-26 02:31:54 +00:00
enum
{
IMG_RGBA16 = (G_IM_FMT_RGBA << 3 | G_IM_SIZ_16b),
IMG_RGBA32 = (G_IM_FMT_RGBA << 3 | G_IM_SIZ_32b),
IMG_CI4_RGBA16 = (G_IM_FMT_CI << 3 | G_IM_SIZ_4b) | G_TT_RGBA16,
IMG_CI4_IA16 = (G_IM_FMT_CI << 3 | G_IM_SIZ_4b) | G_TT_IA16,
IMG_CI8_RGBA16 = (G_IM_FMT_CI << 3 | G_IM_SIZ_8b) | G_TT_RGBA16,
IMG_CI8_IA16 = (G_IM_FMT_CI << 3 | G_IM_SIZ_8b) | G_TT_IA16,
IMG_IA4 = (G_IM_FMT_IA << 3 | G_IM_SIZ_4b),
IMG_IA8 = (G_IM_FMT_IA << 3 | G_IM_SIZ_8b),
IMG_IA16 = (G_IM_FMT_IA << 3 | G_IM_SIZ_16b),
IMG_I4 = (G_IM_FMT_I << 3 | G_IM_SIZ_4b),
IMG_I8 = (G_IM_FMT_I << 3 | G_IM_SIZ_8b),
};
2022-09-26 02:31:54 +00:00
enum N64ImageResult
{
N64IMG_OK,
N64IMG_DATA_SIZE_INCORRECT,
N64IMG_INVALID_COLOR_INDEX,
N64IMG_INCOMPATIBLE_COLOR,
N64IMG_TOO_MANY_COLORS,
N64IMG_PNG_HEADER_MISSING,
N64IMG_PNG_OUT_OF_MEMORY,
N64IMG_PNG_EXCEPTION,
N64IMG_PNG_PARSER_FAILED
};
class CN64Image
{
private:
int m_PixelSize;
int m_Format;
bool m_bUsePalette;
size_t m_Width;
size_t m_Height;
size_t m_NumPixels;
std::vector<uint8_t> m_PixelData;
std::vector<uint8_t> m_PaletteData;
std::vector<uint8_t> m_BitmapRgba32;
public:
CN64Image();
int Init(int format, size_t width, size_t height,
2022-09-26 02:31:54 +00:00
void * pixelData = nullptr, size_t pixelDataSize = 0,
void * paletteData = nullptr, size_t paletteDataSize = 0);
2022-09-26 02:31:54 +00:00
int Init(int format, uint8_t * pngData, size_t pngSize);
void ToPNG(std::vector<uint8_t> & outPngImage);
int UpdateBitmap();
2022-09-26 02:31:54 +00:00
std::vector<uint8_t> & PaletteData();
std::vector<uint8_t> & PixelData();
std::vector<uint8_t> & Bitmap();
size_t Width();
size_t Height();
int Format();
bool UsesPalette();
2022-09-26 02:31:54 +00:00
static int ReadPNG(uint8_t * pngData, size_t pngSize, size_t * width, size_t * height, std::vector<uint8_t> & outRGBA32);
static void WritePNG(uint8_t * rgba32, size_t width, size_t height, std::vector<uint8_t> & buffer);
static unsigned int ColorFromRgba32(int dstFormat, uint32_t rgba32);
static uint32_t ColorToRgba32(int srcFormat, unsigned int color);
static int BitsPerPixel(int format);
static int PaletteColorCount(int format);
static bool UsesPalette(int format);
2022-09-26 02:31:54 +00:00
static const char * ResultCodeName(int resultCode);
private:
2022-09-26 02:31:54 +00:00
uint16_t * PalettePtr(size_t index);
void * TexelPtr(size_t index);
uint32_t * BitmapPtr(size_t index);
unsigned int GetTexel(size_t index);
void SetTexel(size_t index, unsigned int value);
2022-09-26 02:31:54 +00:00
bool GetPaletteColor(size_t index, unsigned int * color);
bool SetPaletteColor(size_t index, unsigned int color);
2022-09-26 02:31:54 +00:00
bool GetBitmapColor(size_t index, uint32_t * color);
bool SetBitmapColor(size_t index, unsigned int color);
int UpdatePixelsAndPaletteFromBitmap();
};