]> git.bts.cx Git - benzene.git/blob - src/bz/renderer/palette.c
Fixed Aseprite rendering system
[benzene.git] / src / bz / renderer / palette.c
1 #include <bz/renderer/palette_internal.h>
2
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>
7 #include <parson.h>
8
9 BZRendererPaletteID bzRendererLoadPalette(BZMemoryArenaID arena, const char *identifierFmt, ...) {
10 bzMakeIdentifier(identifier, identifierFmt);
11
12 BZResourceID handle = bzResourcesOpenResource("palettes", "assets/palettes/%s.palette.json", identifier);
13 size_t length = bzResourcesFileLength(handle);
14
15 char *data = bzMemoryAllocTmp(arena, length);
16 bzResourcesReadBytes(handle, data, length);
17 bzResourcesCloseResource(handle);
18
19 //json_set_allocation_functions
20 JSON_Value *paletteJson = json_parse_string(data);
21 JSON_Object *paletteJsonObject = json_object(paletteJson);
22
23 JSON_Array *colorNameArray = json_object_get_array(paletteJsonObject, "colors");
24 size_t colorCount = json_array_get_count(colorNameArray);
25
26 BZRendererPaletteID palette = bzMemoryAlloc(arena, sizeof(BZRendererPalette) + colorCount * sizeof(uint32_t));
27
28 const char *asepriteFilename = json_object_get_string(paletteJsonObject, "file");
29
30 palette->numColors = bzGfxLoadAsepritePalette(palette->colors, colorCount, asepriteFilename);
31
32 json_value_free(paletteJson);
33 bzMemoryArenaResetTmp(arena);
34
35 return palette;
36 }
37
38 /*
39 #define bzPaletteMakeColor(r, g, b) ((r)&0xFF) << 0 | ((g)&0xFF) << 8 | ((b)&0xFF) << 16 | (0xFF) << 24
40
41
42 {
43 "file" : "main.aseprite",
44 "colors" : [
45 "black",
46 "tone-1",
47 "tone-2",
48 "tone-3",
49 "tone-4",
50 "tone-5",
51 "tone-6",
52 "white",
53 "red-1",
54 "red-2",
55 "red-3",
56 "green-1",
57 "green-2",
58 "green-3",
59 "blue-1",
60 "blue-2",
61 "blue-3",
62 "orange-1",
63 "orange-2",
64 "orange-3",
65 "pink-1",
66 "pink-2",
67 "pink-3",
68 "yellow-1",
69 "yellow-2",
70 "yellow-3"
71 ]
72 }
73 */
74