Skip to content

Commit

Permalink
UI: implemented image.draw(), fix image.save in andoid smallbasic#115
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisws committed Jun 6, 2021
1 parent 0d02d9b commit c8eb696
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/platform/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.android.tools.build:gradle:4.2.1'
classpath "com.github.ben-manes:gradle-versions-plugin:0.22.0"
}
}
Expand Down
23 changes: 18 additions & 5 deletions src/ui/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,21 @@ ImageBuffer *load_image(var_t *var) {
uint8_t r, g, b;
GET_RGB2(px, r, g, b);
int offs = yoffs + (4 * x);
image[offs + 0] = r;
image[offs + 1] = g;
image[offs + 2] = b;
image[offs + 3] = 255;
#if defined(PIXELFORMAT_RGBA8888)
int r_offs = offs + 2;
int g_offs = offs + 1;
int b_offs = offs + 0;
#else
int r_offs = offs + 0;
int g_offs = offs + 1;
int b_offs = offs + 2;
#endif
int a_offs = offs + 3;
int a = (px & 0xff000000) >> 24;
image[r_offs] = r;
image[g_offs] = g;
image[b_offs] = b;
image[a_offs] = a;
}
}
result = new ImageBuffer();
Expand Down Expand Up @@ -420,10 +431,12 @@ void cmd_image_save(var_s *self, var_s *) {
int g_offs = offs + 1;
int b_offs = offs + 2;
#endif
int a_offs = offs + 3;
uint8_t r = image->_image[r_offs];
uint8_t g = image->_image[g_offs];
uint8_t b = image->_image[b_offs];
pixel_t px = SET_RGB(r, g, b);
uint8_t a = image->_image[a_offs];
pixel_t px = (a << 24) | SET_RGB(r, g, b);
int pos = y * w + x;
var_t *elem = v_elem(array, pos);
v_setint(elem, -px);
Expand Down

0 comments on commit c8eb696

Please sign in to comment.