1 #include <bz/renderer/palette_internal.h>
3 #include <bz/gfx/aseprite_internal.h>
4 #include <bz/memory/allocator.h>
5 #include <bz/resources/resource.h>
6 #include <bz/types/identifier_internal.h>
9 BZRendererPaletteID
bzRendererLoadPalette(BZMemoryArenaID arena
, const char *identifierFmt
, ...) {
10 bzMakeIdentifier(identifier
, identifierFmt
);
12 BZResourceID handle
= bzResourcesOpenResource("palettes", "assets/palettes/%s.palette.json", identifier
);
13 size_t length
= bzResourcesFileLength(handle
);
15 char *data
= bzMemoryAllocTmp(arena
, length
);
16 bzResourcesReadBytes(handle
, data
, length
);
17 bzResourcesCloseResource(handle
);
19 //json_set_allocation_functions
20 JSON_Value
*paletteJson
= json_parse_string(data
);
21 JSON_Object
*paletteJsonObject
= json_object(paletteJson
);
23 JSON_Array
*colorNameArray
= json_object_get_array(paletteJsonObject
, "colors");
24 size_t colorCount
= json_array_get_count(colorNameArray
);
26 BZRendererPaletteID palette
= bzMemoryAlloc(arena
, sizeof(BZRendererPalette
) + colorCount
* sizeof(uint32_t));
28 const char *asepriteFilename
= json_object_get_string(paletteJsonObject
, "file");
30 palette
->numColors
= bzGfxLoadAsepritePalette(palette
->colors
, colorCount
, asepriteFilename
);
32 json_value_free(paletteJson
);
33 bzMemoryArenaResetTmp(arena
);
39 #define bzPaletteMakeColor(r, g, b) ((r)&0xFF) << 0 | ((g)&0xFF) << 8 | ((b)&0xFF) << 16 | (0xFF) << 24
43 "file" : "main.aseprite",