Skip to content

Tilegrid transpose fix #4331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ jobs:
id: idf-cache
with:
path: ${{ github.workspace }}/.idf_tools
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210303
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210304
- name: Clone IDF submodules
run: |
(cd $IDF_PATH && git submodule update --init)
Expand Down
2 changes: 1 addition & 1 deletion lib/tinyusb
Submodule tinyusb updated 218 files
35 changes: 25 additions & 10 deletions shared-module/displayio/TileGrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ void common_hal_displayio_tilegrid_construct(displayio_tilegrid_t *self, mp_obj_
self->flip_x = false;
self->flip_y = false;
self->transpose_xy = false;
self->absolute_transform = NULL;
}


Expand Down Expand Up @@ -110,17 +111,24 @@ void _update_current_x(displayio_tilegrid_t *self) {
} else {
width = self->pixel_width;
}
if (self->absolute_transform->transpose_xy) {
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->x;
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->x + width);

// If there's no transform, substitute an identity transform so the calculations will work.
const displayio_buffer_transform_t* absolute_transform =
self->absolute_transform == NULL
? &null_transform
: self->absolute_transform;

if (absolute_transform->transpose_xy) {
self->current_area.y1 = absolute_transform->y + absolute_transform->dy * self->x;
self->current_area.y2 = absolute_transform->y + absolute_transform->dy * (self->x + width);
if (self->current_area.y2 < self->current_area.y1) {
int16_t temp = self->current_area.y2;
self->current_area.y2 = self->current_area.y1;
self->current_area.y1 = temp;
}
} else {
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->x;
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->x + width);
self->current_area.x1 = absolute_transform->x + absolute_transform->dx * self->x;
self->current_area.x2 = absolute_transform->x + absolute_transform->dx * (self->x + width);
if (self->current_area.x2 < self->current_area.x1) {
int16_t temp = self->current_area.x2;
self->current_area.x2 = self->current_area.x1;
Expand All @@ -136,17 +144,24 @@ void _update_current_y(displayio_tilegrid_t *self) {
} else {
height = self->pixel_height;
}
if (self->absolute_transform->transpose_xy) {
self->current_area.x1 = self->absolute_transform->x + self->absolute_transform->dx * self->y;
self->current_area.x2 = self->absolute_transform->x + self->absolute_transform->dx * (self->y + height);

// If there's no transform, substitute an identity transform so the calculations will work.
const displayio_buffer_transform_t* absolute_transform =
self->absolute_transform == NULL
? &null_transform
: self->absolute_transform;

if (absolute_transform->transpose_xy) {
self->current_area.x1 = absolute_transform->x + absolute_transform->dx * self->y;
self->current_area.x2 = absolute_transform->x + absolute_transform->dx * (self->y + height);
if (self->current_area.x2 < self->current_area.x1) {
int16_t temp = self->current_area.x2;
self->current_area.x2 = self->current_area.x1;
self->current_area.x1 = temp;
}
} else {
self->current_area.y1 = self->absolute_transform->y + self->absolute_transform->dy * self->y;
self->current_area.y2 = self->absolute_transform->y + self->absolute_transform->dy * (self->y + height);
self->current_area.y1 = absolute_transform->y + absolute_transform->dy * self->y;
self->current_area.y2 = absolute_transform->y + absolute_transform->dy * (self->y + height);
if (self->current_area.y2 < self->current_area.y1) {
int16_t temp = self->current_area.y2;
self->current_area.y2 = self->current_area.y1;
Expand Down
14 changes: 14 additions & 0 deletions shared-module/displayio/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@

primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];

displayio_buffer_transform_t null_transform = {
.x = 0,
.y = 0,
.dx = 1,
.dy = 1,
.scale = 1,
.width = 0,
.height = 0,
.mirror_x = false,
.mirror_y = false,
.transpose_xy = false
};


#if CIRCUITPY_RGBMATRIX
STATIC bool any_display_uses_this_framebuffer(mp_obj_base_t *obj) {
for (uint8_t i = 0; i < CIRCUITPY_DISPLAY_LIMIT; i++) {
Expand Down
2 changes: 2 additions & 0 deletions shared-module/displayio/area.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ typedef struct {
bool transpose_xy;
} displayio_buffer_transform_t;

extern displayio_buffer_transform_t null_transform;

void displayio_area_union(const displayio_area_t* a,
const displayio_area_t* b,
displayio_area_t* u);
Expand Down
14 changes: 0 additions & 14 deletions shared-module/vectorio/VectorShape.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
}


static displayio_buffer_transform_t null_transform = {
.x = 0,
.y = 0,
.dx = 1,
.dy = 1,
.scale = 1,
.width = 0,
.height = 0,
.mirror_x = false,
.mirror_y = false,
.transpose_xy = false
};


void common_hal_vectorio_vector_shape_construct(vectorio_vector_shape_t *self,
vectorio_ishape_t ishape,
mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
Expand Down