Skip to content

Commit

Permalink
fixes:
Browse files Browse the repository at this point in the history
  • Loading branch information
black-ghost-off committed Mar 24, 2024
1 parent e46da3e commit 301ffde
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions firmware/keira/src/apps/lua/lualilka_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ int lualilka_display_drawImageTransformed(lua_State* L) {
lilka::Image* image = reinterpret_cast<lilka::Image*>(lua_touserdata(L, -1));
lua_pop(L, 1); // Pop the userdata pointer

int16_t x = luaL_checknumber(L, 2);
int16_t y = luaL_checknumber(L, 3);
int16_t d_x = luaL_checknumber(L, 2);
int16_t d_y = luaL_checknumber(L, 3);

int32_t imageWidth = image->width;
int32_t imageHeight = image->height;
Expand All @@ -280,12 +280,14 @@ int lualilka_display_drawImageTransformed(lua_State* L) {
lilka::int_vector_t v1 = transform.transform(lilka::int_vector_t{-image->pivotX, -image->pivotY});
lilka::int_vector_t v2 = transform.transform(lilka::int_vector_t{imageWidth - image->pivotX, -image->pivotY});
lilka::int_vector_t v3 = transform.transform(lilka::int_vector_t{-image->pivotX, imageHeight - image->pivotY});
lilka::int_vector_t v4 = transform.transform(lilka::int_vector_t{imageWidth - image->pivotX, imageHeight - image->pivotY});
lilka::int_vector_t v4 =
transform.transform(lilka::int_vector_t{imageWidth - image->pivotX, imageHeight - image->pivotY});

// Find the bounding box of the transformed image.
lilka::int_vector_t topLeft = lilka::int_vector_t{min(min(v1.x, v2.x), min(v3.x, v4.x)), min(min(v1.y, v2.y), min(v3.y, v4.y))};
lilka::int_vector_t topLeft =
lilka::int_vector_t{min(min(v1.x, v2.x), min(v3.x, v4.x)), min(min(v1.y, v2.y), min(v3.y, v4.y))};
lilka::int_vector_t bottomRight =
lilka::int_vector_t{max(max(v1.x, v2.x), max(v3.x, v4.x)), max(max(v1.y, v2.y), max(v3.y, v4.y))};
lilka::int_vector_t{max(max(v1.x, v2.x), max(v3.x, v4.x)), max(max(v1.y, v2.y), max(v3.y, v4.y))};

// Create a new image to hold the transformed image.
lilka::Image destImage(bottomRight.x - topLeft.x, bottomRight.y - topLeft.y, image->transparentColor, 0, 0);
Expand All @@ -309,10 +311,10 @@ int lualilka_display_drawImageTransformed(lua_State* L) {

if (destImage.transparentColor >= 0) {
getDrawable(L)->draw16bitRGBBitmapWithTranColor(
x, y, destImage.pixels, destImage.transparentColor, destImage.width, destImage.height
d_x, d_y, destImage.pixels, destImage.transparentColor, destImage.width, destImage.height
);
} else {
getDrawable(L)->draw16bitRGBBitmap(x, y, destImage.pixels, destImage.width, destImage.height);
getDrawable(L)->draw16bitRGBBitmap(d_x, d_y, destImage.pixels, destImage.width, destImage.height);
}

return 0;
Expand Down

0 comments on commit 301ffde

Please sign in to comment.