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
a079c823
Commit
a079c823
authored
11 years ago
by
Micah Elizabeth Scott
Browse files
Options
Downloads
Patches
Plain Diff
Test harness for tweaking the dither algorithm
parent
ee6d9979
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Makefile
+1
-1
1 addition, 1 deletion
Makefile
src/hcolor.h
+10
-3
10 additions, 3 deletions
src/hcolor.h
src/main.cpp
+14
-5
14 additions, 5 deletions
src/main.cpp
with
25 additions
and
9 deletions
Makefile
+
1
−
1
View file @
a079c823
...
...
@@ -52,7 +52,7 @@ OBJS := $(C_FILES:.c=.o) $(CPP_FILES:.cpp=.o)
all
:
$(TARGET).hex
$(TARGET).elf
:
$(OBJS) $(LDSCRIPT)
$(
CC
)
$(
LDFLAGS
)
-o
$@
$(
OBJS
)
$(
CC
)
$(
LDFLAGS
)
-o
$@
$(
OBJS
)
$(
LIBS
)
%.hex
:
%.elf
$(
SIZE
)
$<
...
...
This diff is collapsed.
Click to expand it.
src/hcolor.h
+
10
−
3
View file @
a079c823
...
...
@@ -92,15 +92,22 @@ struct HPixel {
/// Temporal dithering algorithm. Returns a 24-bit RGB color.
uint32_t
dither
()
{
// Incorporate the residual from last frame
int
r16
=
color
.
r
+
residual
[
0
];
int
g16
=
color
.
g
+
residual
[
1
];
int
b16
=
color
.
b
+
residual
[
2
];
// Round to the nearest 8-bit value
int
r8
=
std
::
min
<
int
>
(
0xff
,
std
::
max
<
int
>
(
0
,
(
r16
+
0x80
)
>>
8
));
int
g8
=
std
::
min
<
int
>
(
0xff
,
std
::
max
<
int
>
(
0
,
(
g16
+
0x80
)
>>
8
));
int
b8
=
std
::
min
<
int
>
(
0xff
,
std
::
max
<
int
>
(
0
,
(
b16
+
0x80
)
>>
8
));
residual
[
0
]
=
r16
-
(
r8
|
(
r8
<<
8
));
residual
[
1
]
=
g16
-
(
g8
|
(
g8
<<
8
));
residual
[
2
]
=
b16
-
(
b8
|
(
b8
<<
8
));
// Compute the error, after expanding the 8-bit value back to 16-bit.
residual
[
0
]
=
r16
-
(
r8
*
257
);
residual
[
1
]
=
g16
-
(
g8
*
257
);
residual
[
2
]
=
b16
-
(
b8
*
257
);
return
(
r8
<<
16
)
|
(
g8
<<
8
)
|
b8
;
}
};
...
...
This diff is collapsed.
Click to expand it.
src/main.cpp
+
14
−
5
View file @
a079c823
...
...
@@ -6,9 +6,10 @@
*/
#include
<OctoWS2811.h>
#include
<math.h>
#include
"hcolor.h"
static
const
int
ledsPerStrip
=
6
4
;
static
const
int
ledsPerStrip
=
1
6
;
static
const
int
ledsTotal
=
ledsPerStrip
*
8
;
DMAMEM
int
displayMemory
[
ledsPerStrip
*
6
];
...
...
@@ -19,15 +20,23 @@ HPixelBuffer<ledsTotal> pixbuf;
void
setup
()
{
leds
.
begin
();
Serial
.
begin
(
115200
);
for
(
unsigned
i
=
0
;
i
<
ledsTotal
;
++
i
)
{
pixbuf
.
pixels
[
i
].
color
=
HColor16
(
0
x0080
,
0x0080
,
0x008
0
);
pixbuf
.
pixels
[
i
].
color
=
HColor16
(
0
,
0
,
0
);
}
}
void
loop
()
{
pixbuf
.
pixels
[
0
].
color
.
b
=
millis
()
&
0xffff
;
pixbuf
.
show
(
leds
);
// XXX: Proof of concept
for
(
int
i
=
0
;
i
<
16
;
i
++
)
{
unsigned
c
=
pow
(
sin
(
i
*
0.2
+
millis
()
*
0.0005
)
*
0.5
+
0.5
,
2.2
)
*
0x1000
;
pixbuf
.
pixels
[
i
].
color
=
HColor16
(
c
>>
2
,
c
,
c
>>
1
);
}
for
(
int
i
=
0
;
i
<
1000
;
i
++
)
{
pixbuf
.
show
(
leds
);
}
}
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