~groovestomp/gsnes

gsnes/color.h -rwxr-xr-x 3.4 KiB
9de07668 — GrooveStomp Foreground rendering works 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/******************************************************************************
  GrooveStomp's NES Emulator
  Copyright (c) 2019 Aaron Oman (GrooveStomp)

  File: color.h
  Created: 2019-08-15
  Updated: 2019-11-15
  Author: Aaron Oman
  Notice: GNU GPLv3 License

  This program comes with ABSOLUTELY NO WARRANTY.
  This is free software, and you are welcome to redistribute it under certain
  conditions; See LICENSE for details.
 ******************************************************************************/
//! \file color.h
//! This interface attempts to provide an intuitive wrapper around "raw"
//! unsigned integer colors.
//!
//! An unsigned integer color is packed 32-bit value consisting of 4 pixel
//! elements: RGBA.  These elements are stored as written: RGBA, or, visually
//! mapped as hex symbols: RRGGBBAA.
#include <stdint.h>

#ifndef COLOR_VERSION
#define COLOR_VERSION "0.2-gsnes" //!< include guard

//! RGBA color quad
struct color {
        uint32_t rgba;
};

//! \brief Initialize a new color with individual R, G, B, A components as floats.
//!
//! \param r Red component from 0 to 1
//! \param g Green componenet from 0 to 1
//! \param b Blue component from 0 to 1
//! \param a Alpha component, from 0 to 1
//! \return resulting color object
struct color
ColorInitFloats(float r, float g, float b, float a);

//! \brief Initialize a new color with individual R, G, B, A components as ints.
//!
//! \param r Red component from 0 to 255
//! \param g Green componenet from 0 to 255
//! \param b Blue component from 0 to 255
//! \param a Alpha component, from 0 to 255
//! \return resulting color object
struct color
ColorInitInts(uint8_t r, uint8_t g, uint8_t b, uint8_t a);

//! \brief Initialize a new color with an rgba component from a color
//!
//! \param rgba 32-bit r,g,b,a packed int.
//! \return resulting color object
struct color
ColorInitInt(uint32_t rgba);

//! \brief Get the color component
//!
//! The component is returned as the raw integer value, in the range [0,255]
//!
//! \param color color object to read
//! \param component 'r', 'g', 'b' or 'a' exclusively.
//! \return value of the color component
unsigned int
ColorGetInt(struct color color, char component);

//! \brief Get the color component
//!
//! The component is returned as a float in the range [0.0,1.0]
//!
//! \param color color object to read
//! \param component 'r', 'g', 'b' or 'a' exclusively.
//! \return value of the color component
float
ColorGetFloat(struct color color, char component);

//! \brief Set the color component
//!
//! The value should be an integer in the range [0,255]
//!
//! \param color pointer to the color object to write
//! \param component 'r', 'g', 'b' or 'a' exclusively.
//! \param value value of the color component to set
void
ColorSetInt(struct color *color, char component, unsigned int value);

//! \brief Set the color component
//!
//! The value should be a float in the range [0.0,1.0]
//!
//! \param color pointer to the color object to write
//! \param component 'r', 'g', 'b' or 'a' exclusively.
//! \param value value of the color component to set
void
ColorSetFloat(struct color *color, char component, float value);

extern struct color ColorWhite;
extern struct color ColorBlack;
extern struct color ColorRed;
extern struct color ColorGreen;
extern struct color ColorBlue;
extern struct color ColorPurple;
extern struct color ColorYellow;
extern struct color ColorCyan;
extern struct color ColorPink;
extern struct color ColorGray;

#endif // COLOR_VERSION