Skip to content

Commit 9ea1fa1

Browse files
committed
UI: Allow RGB to be used with image array passed to IMAGE
1 parent 31e9b89 commit 9ea1fa1

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2021-07-28 (12.22)
2+
UI: Allow RGB to be used with image array passed to IMAGE
3+
14
2021-07-27 (12.22)
25
FLTK: Fix PSET display of extra pixel
36

src/platform/console/image.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ ImageBuffer *load_image(var_t *var) {
127127
for (int x = 0; x < w; x++) {
128128
int pos = y * w + x;
129129
uint8_t a, r, g, b;
130-
v_get_argb(-v_getint(v_elem(var, pos)), a, r, g, b);
130+
v_get_argb(v_getint(v_elem(var, pos)), a, r, g, b);
131131
SET_IMAGE_ARGB(image, yoffs + (x * 4), a, r, g, b);
132132
}
133133
}
@@ -492,3 +492,4 @@ extern "C" void v_create_image(var_p_t var) {
492492
err_throw(ERR_BAD_FILE_HANDLE);
493493
}
494494
}
495+

src/ui/rgb.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,24 @@ typedef uint32_t pixel_t;
1717
#define PIXELFORMAT AHARDWAREBUFFER_FORMAT_R8G8B8X8_UNORM
1818
#endif
1919

20-
inline void v_get_argb(pixel_t c, uint8_t &a, uint8_t &r, uint8_t &g, uint8_t &b) {
21-
a = (c & 0xff000000) >> 24;
22-
r = (c & 0xff0000) >> 16;
23-
g = (c & 0xff00) >> 8;
24-
b = (c & 0xff);
20+
inline void v_get_argb(int64_t c, uint8_t &a, uint8_t &r, uint8_t &g, uint8_t &b) {
21+
if (c == 0) {
22+
a = 0;
23+
r = 0;
24+
g = 0;
25+
b = 0;
26+
} if (c < 0) {
27+
// from RGB
28+
a = 255;
29+
r = (-c & 0xff0000) >> 16;
30+
g = (-c & 0xff00) >> 8;
31+
b = (-c & 0xff);
32+
} else {
33+
a = (c & 0xff000000) >> 24;
34+
r = (c & 0xff0000) >> 16;
35+
g = (c & 0xff00) >> 8;
36+
b = (c & 0xff);
37+
}
2538
}
2639

2740
#define v_get_argb_px(a, r, g, b) (a << 24 | (r << 16) | (g << 8) | (b))

0 commit comments

Comments
 (0)