Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Fadecandy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
scanlime
Fadecandy
Commits
31b34b56
Commit
31b34b56
authored
11 years ago
by
Micah Elizabeth Scott
Browse files
Options
Downloads
Patches
Plain Diff
Warning and indentation cleanup
parent
0ea45790
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
firmware/src/hcolor.h
+23
-25
23 additions, 25 deletions
firmware/src/hcolor.h
with
23 additions
and
25 deletions
firmware/src/hcolor.h
+
23
−
25
View file @
31b34b56
...
...
@@ -28,9 +28,9 @@ static inline HColor HColor16(uint16_t r, uint16_t g, uint16_t b) {
/// Constructor for 8-bit colors
static
inline
HColor
HColor8
(
uint8_t
r
,
uint8_t
g
,
uint8_t
b
)
{
HColor
c
=
{
r
|
(
unsigned
(
r
)
<<
8
),
g
|
(
unsigned
(
g
)
<<
8
),
b
|
(
unsigned
(
b
)
<<
8
),
uint16_t
(
r
|
(
unsigned
(
r
)
<<
8
)
)
,
uint16_t
(
g
|
(
unsigned
(
g
)
<<
8
)
)
,
uint16_t
(
b
|
(
unsigned
(
b
)
<<
8
)
)
,
};
return
c
;
}
...
...
@@ -43,9 +43,9 @@ static inline HColor HColor8(uint32_t rgb) {
/// Constructor for float colors, with clamping.
static
inline
HColor
HColorF
(
float
r
,
float
g
,
float
b
)
{
HColor
c
=
{
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
r
*
65535.0
f
+
0.5
f
)),
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
g
*
65535.0
f
+
0.5
f
)),
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
b
*
65535.0
f
+
0.5
f
)),
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
r
*
65535.0
f
+
0.5
f
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
g
*
65535.0
f
+
0.5
f
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
b
*
65535.0
f
+
0.5
f
))
)
,
};
return
c
;
}
...
...
@@ -53,9 +53,9 @@ static inline HColor HColorF(float r, float g, float b) {
/// Add two colors, with saturation
static
inline
HColor
operator
+
(
HColor
a
,
HColor
b
)
{
HColor
c
=
{
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
r
)
+
unsigned
(
b
.
r
)),
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
g
)
+
unsigned
(
b
.
g
)),
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
b
)
+
unsigned
(
b
.
b
)),
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
r
)
+
unsigned
(
b
.
r
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
g
)
+
unsigned
(
b
.
g
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
unsigned
(
a
.
b
)
+
unsigned
(
b
.
b
))
)
,
};
return
c
;
}
...
...
@@ -65,24 +65,24 @@ static inline HColor operator + (HColor a, HColor b) {
* Returns c1 if alpha==0, or c2 if alpha==0x100. Values outside this range will extrapolate.
*/
static
inline
HColor
lerp8
(
HColor
c1
,
HColor
c2
,
int
alpha
)
{
int
invA
=
0x100
-
alpha
;
HColor
c
=
{
(
c1
.
r
*
invA
+
c2
.
r
*
alpha
)
>>
8
,
(
c1
.
g
*
invA
+
c2
.
g
*
alpha
)
>>
8
,
(
c1
.
b
*
invA
+
c2
.
b
*
alpha
)
>>
8
,
};
return
c
;
int
invA
=
0x100
-
alpha
;
HColor
c
=
{
uint16_t
(
(
c1
.
r
*
invA
+
c2
.
r
*
alpha
)
>>
8
)
,
uint16_t
(
(
c1
.
g
*
invA
+
c2
.
g
*
alpha
)
>>
8
)
,
uint16_t
(
(
c1
.
b
*
invA
+
c2
.
b
*
alpha
)
>>
8
)
,
};
return
c
;
}
/// Floating point linear interpolation, with clamping.
static
inline
HColor
lerp
(
HColor
c1
,
HColor
c2
,
float
alpha
)
{
float
invA
=
1.0
f
-
alpha
;
HColor
c
=
{
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
r
*
invA
+
c2
.
r
*
alpha
)),
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
g
*
invA
+
c2
.
g
*
alpha
)),
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
b
*
invA
+
c2
.
b
*
alpha
)),
};
return
c
;
float
invA
=
1.0
f
-
alpha
;
HColor
c
=
{
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
r
*
invA
+
c2
.
r
*
alpha
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
g
*
invA
+
c2
.
g
*
alpha
))
)
,
uint16_t
(
std
::
min
<
int
>
(
0xffff
,
std
::
max
<
int
>
(
0
,
c1
.
b
*
invA
+
c2
.
b
*
alpha
))
)
,
};
return
c
;
}
/// Data type for one display pixel
...
...
@@ -104,11 +104,9 @@ struct HPixel {
int
b8
=
std
::
min
<
int
>
(
0xff
,
std
::
max
<
int
>
(
0
,
(
b16
+
0x80
)
>>
8
));
// Compute the error, after expanding the 8-bit value back to 16-bit.
#if 1
residual
[
0
]
=
r16
-
(
r8
*
257
);
residual
[
1
]
=
g16
-
(
g8
*
257
);
residual
[
2
]
=
b16
-
(
b8
*
257
);
#endif
return
(
r8
<<
16
)
|
(
g8
<<
8
)
|
b8
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment