More fixes
This commit is contained in:
47
archive/assetpalette.c
Normal file
47
archive/assetpalette.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* Copyright (c) 2026 Dominic Masters
|
||||
*
|
||||
* This software is released under the MIT License.
|
||||
* https://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "assetpalette.h"
|
||||
#include "asset/assettype.h"
|
||||
#include "assert/assert.h"
|
||||
|
||||
errorret_t assetPaletteLoad(assetentire_t entire) {
|
||||
assertNotNull(entire.data, "Data pointer cannot be NULL.");
|
||||
assertNotNull(entire.output, "Output pointer cannot be NULL.");
|
||||
|
||||
assetpalette_t *assetData = (assetpalette_t *)entire.data;
|
||||
palette_t *palette = (palette_t *)entire.output;
|
||||
|
||||
// Read header and version (first 4 bytes)
|
||||
if(
|
||||
assetData->header[0] != 'D' ||
|
||||
assetData->header[1] != 'P' ||
|
||||
assetData->header[2] != 'F'
|
||||
) {
|
||||
errorThrow("Invalid palette header");
|
||||
}
|
||||
|
||||
// Version (can only be 1 atm)
|
||||
if(assetData->version != 0x01) {
|
||||
errorThrow("Unsupported palette version");
|
||||
}
|
||||
|
||||
// Check color count.
|
||||
if(
|
||||
assetData->colorCount == 0 ||
|
||||
assetData->colorCount > PALETTE_COLOR_COUNT_MAX
|
||||
) {
|
||||
errorThrow("Invalid palette color count");
|
||||
}
|
||||
|
||||
paletteInit(
|
||||
palette,
|
||||
assetData->colorCount,
|
||||
assetData->colors
|
||||
);
|
||||
errorOk();
|
||||
}
|
||||
Reference in New Issue
Block a user