Jo Engine 2026.11.6
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
43/* (JO_PALETTE_MAX, the maximum of palettes: see jo/sega_saturn.h, the functions of the sprites and of the 3D check the
44 ids of the palettes with it) */
45
51void jo_create_palette(jo_palette * const output);
52
62void jo_palette_set_light_shades(jo_palette * const palette, const int first, const jo_color * const colors,
63 const int count, const int levels);
64
66# define JO_PALETTE_LIGHT_COLOR(PALETTE_ID, FIRST, I) ((jo_color)((PALETTE_ID) * 256 + (FIRST) + (I)))
67
74static __jo_force_inline jo_color jo_palette_color(const jo_palette * const palette, const int index)
75{
76#ifdef JO_DEBUG
77 // (-1: the palette of jo_create_palette() with the color RAM full)
78 if (__JO_INDEX_IS_WRONG(palette->id, JO_PALETTE_MAX, "palette id") || __JO_INDEX_IS_WRONG(index, JO_PALETTE_MAX_COLORS + 1, "color index"))
79 return (0);
80#endif
81 return ((jo_color)(palette->id * 256 + index));
82}
83
89static __jo_force_inline void jo_palette_to_cram(unsigned short * restrict data, unsigned short * restrict cram_addr, unsigned int size)
90{
91 while (size-- > 0) *(cram_addr++) = *(data++);
92}
93
100static __jo_force_inline void jo_create_palette_from(jo_palette * const output, unsigned short *data, unsigned int size)
101{
102 jo_create_palette(output);
103 // (the color RAM full: written at the address 0)
104 if (output->data != JO_NULL)
105 jo_palette_to_cram(data, output->data, size);
106}
107
112void jo_set_palette_register(const unsigned short palette_index, const jo_color color);
113
118jo_color jo_get_palette_register(const unsigned short palette_index);
119
120#ifdef JO_COMPILE_WITH_PRINTF_SUPPORT
121
127static __jo_force_inline void jo_set_printf_palette_color(const unsigned short index, const unsigned short color)
128{
129 // Color 1 of the 16 colors palette "index"
130 jo_set_palette_register(1 + JO_MULT_BY_16(index), color);
131}
132
133#endif
134
135#endif /* !__JO_PALETTE_H__ */
136
137/*
138** END OF FILE
139*/
#define __JO_INDEX_IS_WRONG(INDEX, COUNT, WHAT)
Check an index given to a function of the engine (Internal usage, JO_DEBUG).
Definition core.h:55
void * data
Definition entity.h:19
#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:89
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:100
static __jo_force_inline jo_color jo_palette_color(const jo_palette *const palette, const int index)
Color code of a color of a palette: a polygon of this color (jo_3d_set_mesh_polygon_color()) has the ...
Definition palette.h:74
void jo_set_palette_register(const unsigned short palette_index, const jo_color color)
Set palette index color.
void jo_palette_set_light_shades(jo_palette *const palette, const int first, const jo_color *const colors, const int count, const int levels)
Write the shades of colors in a palette for the palette lighting (see jo_3d_set_palette_light()): the...
void jo_create_palette(jo_palette *const output)
Create a new palette with 255 entries maximum.
#define JO_PALETTE_MAX_COLORS
Define the maximum of color entry available on each palette.
Definition palette.h:41
jo_color jo_get_palette_register(const unsigned short palette_index)
Get palette color from index.
#define JO_PALETTE_MAX
Define the maximum of palette (the 256 colors palettes of the color RAM).
Definition sega_saturn.h:157
#define JO_NULL
NULL implementation.
Definition tools.h:261
#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:53
int id
Definition types.h:270
jo_color * data
Definition types.h:269
Palette contents struct.
Definition types.h:268