use mode structs in Palette.c

This commit is contained in:
Yay295 2024-04-21 22:29:12 -05:00
parent c906098fec
commit c587ad10ab
2 changed files with 4 additions and 9 deletions

View File

@ -2,10 +2,6 @@
#define __MODE_H__
// Maximum length (including null terminator) for both mode and rawmode names.
#define IMAGING_MODE_LENGTH 6+1
typedef struct {
const char * const name;
} Mode;

View File

@ -21,13 +21,13 @@
#include <math.h>
ImagingPalette
ImagingPaletteNew(const char *mode) {
ImagingPaletteNew(const Mode *mode) {
/* Create a palette object */
int i;
ImagingPalette palette;
if (strcmp(mode, "RGB") && strcmp(mode, "RGBA")) {
if (mode != IMAGING_MODE_RGB && mode != IMAGING_MODE_RGBA) {
return (ImagingPalette)ImagingError_ModeError();
}
@ -36,8 +36,7 @@ ImagingPaletteNew(const char *mode) {
return (ImagingPalette)ImagingError_MemoryError();
}
strncpy(palette->mode, mode, IMAGING_MODE_LENGTH - 1);
palette->mode[IMAGING_MODE_LENGTH - 1] = 0;
palette->mode = mode;
palette->size = 0;
for (i = 0; i < 256; i++) {
@ -54,7 +53,7 @@ ImagingPaletteNewBrowser(void) {
int i, r, g, b;
ImagingPalette palette;
palette = ImagingPaletteNew("RGB");
palette = ImagingPaletteNew(IMAGING_MODE_RGB);
if (!palette) {
return NULL;
}