library: Cleanup palette loading functions

This commit is contained in:
Antonio Niño Díaz 2022-10-31 00:27:25 +00:00
parent 6e53a01d83
commit 2ced018926
5 changed files with 43 additions and 19 deletions

View File

@ -9,6 +9,8 @@
#include <nds.h>
#include "NEPolygon.h"
/// @file NEPalette.h
/// @brief Functions for loading, using and deleting palettes.
@ -36,16 +38,30 @@ NE_Palette *NE_PaletteCreate(void);
/// @param path Path of the palette.
/// @param format Format of the palette.
/// @return It returns 1 on success, 0 on error.
int NE_PaletteLoadFAT(NE_Palette *pal, char *path, int format);
int NE_PaletteLoadFAT(NE_Palette *pal, char *path, NE_TextureFormat format);
/// Assign a palette in RAM to a palette object.
/// Assign a palette in RAM to a palette object, given its number of colors.
///
/// @param pal Pointer to the palette object.
/// @param pointer Pointer to the palette in RAM.
/// @param numcolor Number of colors of the palette.
/// @param format Format of the palette.
/// @return It returns 1 on success, 0 on error.
int NE_PaletteLoad(NE_Palette *pal, u16 *pointer, u16 numcolor, int format);
int NE_PaletteLoad(NE_Palette *pal, u16 *pointer, u16 numcolor,
NE_TextureFormat format);
/// Assign a palette in RAM to a palette object, given its size.
///
/// This function is like NE_PaletteLoad(), but it takes the size of the texture
/// instead of the size.
///
/// @param pal Pointer to the palette object.
/// @param pointer Pointer to the palette in RAM.
/// @param size Size of the palette in bytes.
/// @param format Format of the palette.
/// @return It returns 1 on success, 0 on error.
int NE_PaletteLoadSize(NE_Palette *pal, u16 *pointer, size_t size,
NE_TextureFormat format);
/// Deletes a palette object.
///

View File

@ -42,6 +42,18 @@ typedef enum {
NE_Black = RGB15(0, 0, 0) ///< Black
} NE_ColorEnum;
/// Supported texture formats
typedef enum {
NE_A3PAL32 = 1, ///< 32 color palette, 3 bits of alpha
NE_PAL4 = 2, ///< 4 color palette
NE_PAL16 = 3, ///< 16 color palette
NE_PAL256 = 4, ///< 256 color palette
NE_COMPRESSED = 5, ///< 4x4 compressed format
NE_A5PAL8 = 6, ///< 8 color palette, 5 bits of alpha
NE_A1RGB5 = 7, ///< Direct color (5 bits per channel), 1 bit of alpha
NE_RGB5 = 8 ///< Don't use it. Like NE_A1RGB5, but sets alpha to 1 when loading
} NE_TextureFormat;
/// Switch off a light.
///
/// @param index Index of the light to switch off (0 - 3).

View File

@ -8,7 +8,9 @@
#define NE_TEXTURE_H__
#include <nds.h>
#include "NEPalette.h"
#include "NEPolygon.h"
/// @file NETexture.h
/// @brief Texture and material functions.
@ -33,18 +35,6 @@ typedef struct {
u32 specular_emission; ///< Specular and emission lighting material color
} NE_Material;
/// Supported texture formats
typedef enum {
NE_A3PAL32 = 1, ///< 32 color palette, 3 bits of alpha
NE_PAL4 = 2, ///< 4 color palette
NE_PAL16 = 3, ///< 16 color palette
NE_PAL256 = 4, ///< 256 color palette
NE_COMPRESSED = 5, ///< Compressed (not supported yet)
NE_A5PAL8 = 6, ///< 8 color palette, 5 bits of alpha
NE_A1RGB5 = 7, ///< Direct color (5 bits per channel), 1 bit of alpha
NE_RGB5 = 8 ///< Direct color (5 bits per channel), alpha set to 1
} NE_TextureFormat;
/// Supported texture options
typedef enum {
NE_TEXTURE_WRAP_S = (1U << 16), ///< Wrap/repeat texture on S axis

View File

@ -45,7 +45,7 @@ NE_Palette *NE_PaletteCreate(void)
return NULL;
}
int NE_PaletteLoadFAT(NE_Palette *pal, char *path, int format)
int NE_PaletteLoadFAT(NE_Palette *pal, char *path, NE_TextureFormat format)
{
if (!ne_palette_system_inited)
return 0;
@ -62,13 +62,14 @@ int NE_PaletteLoadFAT(NE_Palette *pal, char *path, int format)
char *ptr = NE_FATLoadData(path);
NE_AssertPointer(ptr, "Couldn't load file from FAT");
int ret = NE_PaletteLoad(pal, (u16 *) ptr, size >> 1, format);
int ret = NE_PaletteLoadSize(pal, (u16 *)ptr, size, format);
free(ptr);
return ret;
}
int NE_PaletteLoad(NE_Palette *pal, u16 *pointer, u16 numcolor, int format)
int NE_PaletteLoad(NE_Palette *pal, u16 *pointer, u16 numcolor,
NE_TextureFormat format)
{
if (!ne_palette_system_inited)
return 0;
@ -119,6 +120,12 @@ int NE_PaletteLoad(NE_Palette *pal, u16 *pointer, u16 numcolor, int format)
return 1;
}
int NE_PaletteLoadSize(NE_Palette *pal, u16 *pointer, size_t size,
NE_TextureFormat format)
{
return NE_PaletteLoad(pal, pointer, size >> 1, format);
}
void NE_PaletteDelete(NE_Palette *pal)
{
if (!ne_palette_system_inited)

View File

@ -244,7 +244,6 @@ int NE_MaterialTexLoad(NE_Material *tex, NE_TextureFormat fmt,
}
else
{
// For everything else, we do a straight copy
swiCopy((u32 *)texture, addr, (size >> 2) | COPY_MODE_WORD);
}