Jo Engine 2026.11.1
Jo Sega Saturn Engine
Loading...
Searching...
No Matches
palette.h
Go to the documentation of this file.
1/*
2** Jo Sega Saturn Engine
3** Copyright (c) 2012-2026, Johannes Fetz (johannesfetz@gmail.com)
4** All rights reserved.
5**
6** Redistribution and use in source and binary forms, with or without
7** modification, are permitted provided that the following conditions are met:
8** * Redistributions of source code must retain the above copyright
9** notice, this list of conditions and the following disclaimer.
10** * Redistributions in binary form must reproduce the above copyright
11** notice, this list of conditions and the following disclaimer in the
12** documentation and/or other materials provided with the distribution.
13** * Neither the name of the Johannes Fetz nor the
14** names of its contributors may be used to endorse or promote products
15** derived from this software without specific prior written permission.
16**
17** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20** DISCLAIMED. IN NO EVENT SHALL Johannes Fetz BE LIABLE FOR ANY
21** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
34
35#ifndef __JO_PALETTE_H__
36# define __JO_PALETTE_H__
37
41# define JO_PALETTE_MAX_COLORS (255)
42
46# define JO_PALETTE_MAX (8)
47
52void jo_create_palette(jo_palette * const output);
53
59static __jo_force_inline void jo_palette_to_cram(unsigned short * restrict data, unsigned short * restrict cram_addr, unsigned int size)
60{
61 while (size-- > 0) *(cram_addr++) = *(data++);
62}
63
70static __jo_force_inline void jo_create_palette_from(jo_palette * const output, unsigned short *data, unsigned int size)
71{
72 jo_create_palette(output);
73 jo_palette_to_cram(data, output->data, size);
74}
75
80void jo_set_palette_register(const unsigned short palette_index, const jo_color color);
81
86jo_color jo_get_palette_register(const unsigned short palette_index);
87
88#ifdef JO_COMPILE_WITH_PRINTF_SUPPORT
89
95static __jo_force_inline void jo_set_printf_palette_color(const unsigned short index, const unsigned short color)
96{
97 // Color 1 of the 16 colors palette "index"
98 jo_set_palette_register(1 + JO_MULT_BY_16(index), color);
99}
100
101#endif
102
103#endif /* !__JO_PALETTE_H__ */
104
105/*
106** END OF FILE
107*/
#define JO_MULT_BY_16(X)
Multiply a variable by 16.
Definition math.h:87
static __jo_force_inline void jo_palette_to_cram(unsigned short *restrict data, unsigned short *restrict cram_addr, unsigned int size)
Copies the image palette data to CRAM.
Definition palette.h:59
static __jo_force_inline void jo_create_palette_from(jo_palette *const output, unsigned short *data, unsigned int size)
Create a new palette from existing data.
Definition palette.h:70
void jo_set_palette_register(const unsigned short palette_index, const jo_color color)
Set palette index color.
void jo_create_palette(jo_palette *const output)
Create a new palette with 255 entries maximum.
jo_color jo_get_palette_register(const unsigned short palette_index)
Get palette color from index.
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition types.h:39
unsigned short jo_color
15 bits color type
Definition types.h:42
jo_color * data
Definition types.h:256
Palette contents struct.
Definition types.h:255