Jo Engine  2023.08.26
Jo Sega Saturn Engine
palette.h
Go to the documentation of this file.
1 /*
2 ** Jo Sega Saturn Engine
3 ** Copyright (c) 2012-2020, 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 */
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 
52 void jo_create_palette(jo_palette * const output);
53 
59 static __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 
70 static __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 
80 void jo_set_palette_register(const unsigned short palette_index, const jo_color color);
81 
86 jo_color jo_get_palette_register(const unsigned short palette_index);
87 
88 #ifdef JO_COMPILE_WITH_PRINTF_SUPPORT
89 
94 static __jo_force_inline void jo_set_printf_palette_color(const unsigned short index, const unsigned short color)
95 {
96  jo_set_palette_register(1 + JO_MULT_BY_256(index), color);
97 }
98 
99 #endif
100 
101 #endif /* !__JO_PALETTE_H__ */
102 
103 /*
104 ** END OF FILE
105 */
jo_get_palette_register
jo_color jo_get_palette_register(const unsigned short palette_index)
Get palette color from index.
jo_set_palette_register
void jo_set_palette_register(const unsigned short palette_index, const jo_color color)
Set palette index color.
jo_palette::data
jo_color * data
Definition: types.h:251
jo_palette
Palette contents struct.
Definition: types.h:250
jo_create_palette_from
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
JO_MULT_BY_256
#define JO_MULT_BY_256(X)
Multiply a variable by 256.
Definition: math.h:108
jo_color
unsigned short jo_color
15 bits color type
Definition: types.h:42
__jo_force_inline
#define __jo_force_inline
force inline attribute (and prevent Doxygen prototype parsing bug)
Definition: types.h:39
jo_palette_to_cram
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
jo_create_palette
void jo_create_palette(jo_palette *const output)
Create a new palette with 255 entries maximum.