Skip to content

Commit c8eb696

Browse files
committed
UI: implemented image.draw(), fix image.save in andoid #115
1 parent 0d02d9b commit c8eb696

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/platform/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ buildscript {
55
jcenter()
66
}
77
dependencies {
8-
classpath 'com.android.tools.build:gradle:4.1.3'
8+
classpath 'com.android.tools.build:gradle:4.2.1'
99
classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0"
1010
}
1111
}

src/ui/image.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,21 @@ ImageBuffer *load_image(var_t *var) {
189189
uint8_t r, g, b;
190190
GET_RGB2(px, r, g, b);
191191
int offs = yoffs + (4 * x);
192-
image[offs + 0] = r;
193-
image[offs + 1] = g;
194-
image[offs + 2] = b;
195-
image[offs + 3] = 255;
192+
#if defined(PIXELFORMAT_RGBA8888)
193+
int r_offs = offs + 2;
194+
int g_offs = offs + 1;
195+
int b_offs = offs + 0;
196+
#else
197+
int r_offs = offs + 0;
198+
int g_offs = offs + 1;
199+
int b_offs = offs + 2;
200+
#endif
201+
int a_offs = offs + 3;
202+
int a = (px & 0xff000000) >> 24;
203+
image[r_offs] = r;
204+
image[g_offs] = g;
205+
image[b_offs] = b;
206+
image[a_offs] = a;
196207
}
197208
}
198209
result = new ImageBuffer();
@@ -420,10 +431,12 @@ void cmd_image_save(var_s *self, var_s *) {
420431
int g_offs = offs + 1;
421432
int b_offs = offs + 2;
422433
#endif
434+
int a_offs = offs + 3;
423435
uint8_t r = image->_image[r_offs];
424436
uint8_t g = image->_image[g_offs];
425437
uint8_t b = image->_image[b_offs];
426-
pixel_t px = SET_RGB(r, g, b);
438+
uint8_t a = image->_image[a_offs];
439+
pixel_t px = (a << 24) | SET_RGB(r, g, b);
427440
int pos = y * w + x;
428441
var_t *elem = v_elem(array, pos);
429442
v_setint(elem, -px);

0 commit comments

Comments
 (0)