roo_display
API Documentation for roo_display
Loading...
Searching...
No Matches
compactor.h
Go to the documentation of this file.
1
#pragma once
2
3
#include "
roo_display/core/device.h
"
4
5
namespace
roo_display
{
6
7
// Helper class that can turn a streak of pixel writes that happen to be on a
8
// horizontal or vertical direction into a single write or fill request to the
9
// underlying device, minimizing address window changes.
10
//
11
// To use the compactor, call it from writePixels and fillPixels, and give it
12
// the following functor:
13
// void write(int16_t offset, int16_t x, int16_t y,
14
// Compactor::WriteDirection direction, int16_t count);
15
// };
16
//
17
// When called, the functor should write or fill the specified count of pixels,
18
// starting at x, y, and in the specified direction. The offset argument
19
// indicates the absolute pixel index in the input array. It can be used to
20
// determine colors for writing / filling. See addr_window_device.h for an
21
// example.
22
class
Compactor
{
23
public
:
24
Compactor
() {}
25
template
<
typename
Writer>
26
void
drawPixels
(
int16_t
*
xs
,
int16_t
*
ys
,
uint16_t
pixel_count
,
27
Writer
write =
Writer
()) {
28
if
(
pixel_count
== 0)
return
;
29
30
uint16_t
i
= 0;
31
uint16_t
count = 0;
32
uint16_t
x =
xs
[0];
33
uint16_t
y =
ys
[0];
34
uint16_t
x_start
;
35
uint16_t
y_start
;
36
37
while
(
i
<
pixel_count
) {
38
int
start
=
i
;
39
++
i
;
40
if
(
i
==
pixel_count
) {
41
write(
start
, x, y,
RIGHT
, 1);
42
return
;
43
}
44
x_start
= x;
45
y_start
= y;
46
x =
xs
[
i
];
47
y =
ys
[
i
];
48
count = 1;
49
if
(y ==
y_start
&& x ==
x_start
+ 1) {
50
// Horizontal streak.
51
do
{
52
++count;
53
++
i
;
54
if
(
i
==
pixel_count
)
break
;
55
x =
xs
[
i
];
56
y =
ys
[
i
];
57
}
while
(y ==
y_start
&& x ==
x_start
+ count);
58
write(
start
,
x_start
,
y_start
,
RIGHT
, count);
59
}
else
if
(x ==
x_start
&& y ==
y_start
+ 1) {
60
// Vertical streak.
61
do
{
62
++count;
63
++
i
;
64
if
(
i
==
pixel_count
)
break
;
65
x =
xs
[
i
];
66
y =
ys
[
i
];
67
}
while
(x ==
x_start
&& y ==
y_start
+ count);
68
write(
start
,
x_start
,
y_start
,
DOWN
, count);
69
}
else
if
(y ==
y_start
&& x ==
x_start
- 1) {
70
// Inverse horizontal streak.
71
do
{
72
++count;
73
++
i
;
74
if
(
i
==
pixel_count
)
break
;
75
x =
xs
[
i
];
76
y =
ys
[
i
];
77
}
while
(y ==
y_start
&& x ==
x_start
- count);
78
write(
start
,
x_start
,
y_start
,
LEFT
, count);
79
}
else
if
(x ==
x_start
&& y ==
y_start
- 1) {
80
// Vertical streak.
81
do
{
82
++count;
83
++
i
;
84
if
(
i
==
pixel_count
)
break
;
85
x =
xs
[
i
];
86
y =
ys
[
i
];
87
}
while
(x ==
x_start
&& y ==
y_start
- count);
88
write(
start
,
x_start
,
y_start
,
UP
, count);
89
}
else
{
90
write(
start
,
x_start
,
y_start
,
RIGHT
, 1);
91
}
92
}
93
}
94
95
enum
WriteDirection
{
RIGHT
,
DOWN
,
LEFT
,
UP
};
96
};
97
98
}
// namespace roo_display
roo_display::Compactor
Definition
compactor.h:22
roo_display::Compactor::Compactor
Compactor()
Definition
compactor.h:24
roo_display::Compactor::drawPixels
void drawPixels(int16_t *xs, int16_t *ys, uint16_t pixel_count, Writer write=Writer())
Definition
compactor.h:26
roo_display::Compactor::WriteDirection
WriteDirection
Definition
compactor.h:95
roo_display::Compactor::RIGHT
@ RIGHT
Definition
compactor.h:95
roo_display::Compactor::UP
@ UP
Definition
compactor.h:95
roo_display::Compactor::LEFT
@ LEFT
Definition
compactor.h:95
roo_display::Compactor::DOWN
@ DOWN
Definition
compactor.h:95
device.h
roo_display
Defines 140 opaque HTML named colors.
Definition
roo_display.cpp:7
roo_display::BlendOp
Definition
blending.h:200
temp_repos
roo_display
src
roo_display
driver
common
compactor.h
Generated by
1.9.8