summaryrefslogtreecommitdiff
path: root/shared-module/vectorio
diff options
context:
space:
mode:
authorJeff Epler <jeff@adafruit.com>2021-03-15 13:50:49 -0500
committerGitHub <noreply@github.com>2021-03-15 13:50:49 -0500
commit05ed179e11599dd45a76dfb14ecf624d0ff96d68 (patch)
treea046c6d1f117814168150484ed1bf7840d3400d7 /shared-module/vectorio
parent3cbff45f9aac5ea2855bbc888083d356a91c80fe (diff)
parentf9b4189b4c640823dabb76de8effd2a836da2eb0 (diff)
Merge pull request #4362 from microDev1/code-formatting
Add code formatting and translations check
Diffstat (limited to 'shared-module/vectorio')
-rw-r--r--shared-module/vectorio/Circle.c14
-rw-r--r--shared-module/vectorio/Polygon.c64
-rw-r--r--shared-module/vectorio/VectorShape.c44
-rw-r--r--shared-module/vectorio/VectorShape.h2
4 files changed, 69 insertions, 55 deletions
diff --git a/shared-module/vectorio/Circle.c b/shared-module/vectorio/Circle.c
index 73629b8ce..9c7458065 100644
--- a/shared-module/vectorio/Circle.c
+++ b/shared-module/vectorio/Circle.c
@@ -25,10 +25,16 @@ uint32_t common_hal_vectorio_circle_get_pixel(void *obj, int16_t x, int16_t y) {
int16_t radius = abs(self->radius);
x = abs(x);
y = abs(y);
- if (x+y <= radius) return 1;
- if (x > radius) return 0;
- if (y > radius) return 0;
- const bool pythagorasSmallerThanRadius = (int32_t)x*x + (int32_t)y*y <= (int32_t)radius*radius;
+ if (x + y <= radius) {
+ return 1;
+ }
+ if (x > radius) {
+ return 0;
+ }
+ if (y > radius) {
+ return 0;
+ }
+ const bool pythagorasSmallerThanRadius = (int32_t)x * x + (int32_t)y * y <= (int32_t)radius * radius;
return pythagorasSmallerThanRadius ? 1 : 0;
}
diff --git a/shared-module/vectorio/Polygon.c b/shared-module/vectorio/Polygon.c
index e00a4696b..00af1e0d7 100644
--- a/shared-module/vectorio/Polygon.c
+++ b/shared-module/vectorio/Polygon.c
@@ -22,21 +22,21 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
mp_obj_list_get(points_tuple_list, &len, &items);
VECTORIO_POLYGON_DEBUG(" self.len: %d, len: %d, ", self->len, len);
- if ( len < 3 ) {
+ if (len < 3) {
mp_raise_TypeError_varg(translate("Polygon needs at least 3 points"));
}
- if ( self->len < 2*len ) {
- if ( self->points_list != NULL ) {
+ if (self->len < 2 * len) {
+ if (self->points_list != NULL) {
VECTORIO_POLYGON_DEBUG("free(%d), ", sizeof(self->points_list));
- gc_free( self->points_list );
+ gc_free(self->points_list);
}
- self->points_list = gc_alloc( 2 * len * sizeof(int), false, false );
+ self->points_list = gc_alloc(2 * len * sizeof(int), false, false);
VECTORIO_POLYGON_DEBUG("alloc(%p, %d)", self->points_list, 2 * len * sizeof(int));
}
- self->len = 2*len;
+ self->len = 2 * len;
- for ( size_t i = 0; i < len; ++i) {
+ for (size_t i = 0; i < len; ++i) {
size_t tuple_len = 0;
mp_obj_t *tuple_items;
mp_obj_tuple_get(items[i], &tuple_len, &tuple_items);
@@ -44,11 +44,11 @@ static void _clobber_points_list(vectorio_polygon_t *self, mp_obj_t points_tuple
if (tuple_len != 2) {
mp_raise_ValueError_varg(translate("%q must be a tuple of length 2"), MP_QSTR_point);
}
- if ( !mp_obj_get_int_maybe(tuple_items[ 0 ], &self->points_list[2*i ])
- || !mp_obj_get_int_maybe(tuple_items[ 1 ], &self->points_list[2*i + 1])
- ) {
+ if (!mp_obj_get_int_maybe(tuple_items[ 0 ], &self->points_list[2 * i ])
+ || !mp_obj_get_int_maybe(tuple_items[ 1 ], &self->points_list[2 * i + 1])
+ ) {
self->len = 0;
- gc_free( self->points_list );
+ gc_free(self->points_list);
self->points_list = NULL;
mp_raise_ValueError_varg(translate("unsupported %q type"), MP_QSTR_point);
}
@@ -62,27 +62,27 @@ void common_hal_vectorio_polygon_construct(vectorio_polygon_t *self, mp_obj_t po
self->points_list = NULL;
self->len = 0;
self->on_dirty.obj = NULL;
- _clobber_points_list( self, points_list );
+ _clobber_points_list(self, points_list);
VECTORIO_POLYGON_DEBUG("\n");
}
mp_obj_t common_hal_vectorio_polygon_get_points(vectorio_polygon_t *self) {
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_get_points {len: %d, points_list: %p}\n", self, self->len, self->points_list);
- mp_obj_t list = mp_obj_new_list(self->len/2, NULL);
+ mp_obj_t list = mp_obj_new_list(self->len / 2, NULL);
for (size_t i = 0; i < self->len; i += 2) {
- mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i+1]) };
+ mp_obj_t tuple[] = { mp_obj_new_int(self->points_list[i]), mp_obj_new_int(self->points_list[i + 1]) };
mp_obj_list_append(
list,
mp_obj_new_tuple(2, tuple)
- );
+ );
}
return list;
}
void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t points_list) {
VECTORIO_POLYGON_DEBUG("%p common_hal_vectorio_polygon_set_points: ", self);
- _clobber_points_list( self, points_list );
+ _clobber_points_list(self, points_list);
if (self->on_dirty.obj != NULL) {
self->on_dirty.event(self->on_dirty.obj);
}
@@ -90,7 +90,7 @@ void common_hal_vectorio_polygon_set_points(vectorio_polygon_t *self, mp_obj_t p
}
void common_hal_vectorio_polygon_set_on_dirty(vectorio_polygon_t *self, vectorio_event_t notification) {
- if ( self->on_dirty.obj != NULL ) {
+ if (self->on_dirty.obj != NULL) {
mp_raise_TypeError(translate("polygon can only be registered in one parent"));
}
self->on_dirty = notification;
@@ -104,14 +104,22 @@ void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *area)
area->y1 = SHRT_MAX;
area->x2 = SHRT_MIN;
area->y2 = SHRT_MIN;
- for (size_t i=0; i < self->len; ++i) {
+ for (size_t i = 0; i < self->len; ++i) {
int x = self->points_list[i];
++i;
int y = self->points_list[i];
- if (x <= area->x1) area->x1 = x-1;
- if (y <= area->y1) area->y1 = y-1;
- if (x >= area->x2) area->x2 = x+1;
- if (y >= area->y2) area->y2 = y+1;
+ if (x <= area->x1) {
+ area->x1 = x - 1;
+ }
+ if (y <= area->y1) {
+ area->y1 = y - 1;
+ }
+ if (x >= area->x2) {
+ area->x2 = x + 1;
+ }
+ if (y >= area->y2) {
+ area->y2 = y + 1;
+ }
}
}
@@ -119,9 +127,9 @@ void common_hal_vectorio_polygon_get_area(void *polygon, displayio_area_t *area)
// <0 if the point is to the left of the line vector
// 0 if the point is on the line
// >0 if the point is to the right of the line vector
-__attribute__((always_inline)) static inline int line_side( mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, int16_t px, int16_t py ) {
+__attribute__((always_inline)) static inline int line_side(mp_int_t x1, mp_int_t y1, mp_int_t x2, mp_int_t y2, int16_t px, int16_t py) {
return (px - x1) * (y2 - y1)
- - (py - y1) * (x2 - x1);
+ - (py - y1) * (x2 - x1);
}
@@ -136,19 +144,19 @@ uint32_t common_hal_vectorio_polygon_get_pixel(void *obj, int16_t x, int16_t y)
int winding_number = 0;
int x1 = self->points_list[0];
int y1 = self->points_list[1];
- for (size_t i=2; i <= self->len + 1; ++i) {
+ for (size_t i = 2; i <= self->len + 1; ++i) {
VECTORIO_POLYGON_DEBUG(" {(%3d, %3d),", x1, y1);
int x2 = self->points_list[i % self->len];
++i;
int y2 = self->points_list[i % self->len];
VECTORIO_POLYGON_DEBUG(" (%3d, %3d)}\n", x2, y2);
- if ( y1 <= y ) {
- if ( y2 > y && line_side(x1, y1, x2, y2, x, y) < 0 ) {
+ if (y1 <= y) {
+ if (y2 > y && line_side(x1, y1, x2, y2, x, y) < 0) {
// Wind up, point is to the left of the edge vector
++winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", 1, winding_number);
}
- } else if ( y2 <= y && line_side(x1, y1, x2, y2, x, y) > 0 ) {
+ } else if (y2 <= y && line_side(x1, y1, x2, y2, x, y) > 0) {
// Wind down, point is to the right of the edge vector
--winding_number;
VECTORIO_POLYGON_DEBUG(" wind:%2d winding_number:%2d\n", -1, winding_number);
diff --git a/shared-module/vectorio/VectorShape.c b/shared-module/vectorio/VectorShape.c
index b5d36339e..c6524af9d 100644
--- a/shared-module/vectorio/VectorShape.c
+++ b/shared-module/vectorio/VectorShape.c
@@ -38,16 +38,16 @@ static void _get_screen_area(vectorio_vector_shape_t *self, displayio_area_t *ou
VECTORIO_SHAPE_DEBUG("%p get_screen_area tform:{x:%d y:%d dx:%d dy:%d scl:%d w:%d h:%d mx:%d my:%d tr:%d}", self,
self->absolute_transform->x, self->absolute_transform->y, self->absolute_transform->dx, self->absolute_transform->dy, self->absolute_transform->scale,
self->absolute_transform->width, self->absolute_transform->height, self->absolute_transform->mirror_x, self->absolute_transform->mirror_y, self->absolute_transform->transpose_xy
- );
+ );
self->ishape.get_area(self->ishape.shape, out_area);
VECTORIO_SHAPE_DEBUG(" in:{(%5d,%5d), (%5d,%5d)}", out_area->x1, out_area->y1, out_area->x2, out_area->y2);
if (self->absolute_transform->transpose_xy) {
int16_t swap = out_area->x1;
out_area->x1 = (out_area->y1 + self->y) * self->absolute_transform->dx + self->absolute_transform->x;
- out_area->y1 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
+ out_area->y1 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
swap = out_area->x2;
out_area->x2 = (out_area->y2 + self->y) * self->absolute_transform->dx + self->absolute_transform->x;
- out_area->y2 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
+ out_area->y2 = (swap + self->x) * self->absolute_transform->dy + self->absolute_transform->y;
} else {
out_area->x1 = (out_area->x1 + self->x) * self->absolute_transform->dx + self->absolute_transform->x;
out_area->y1 = (out_area->y1 + self->y) * self->absolute_transform->dy + self->absolute_transform->y;
@@ -94,8 +94,8 @@ void common_hal_vectorio_vector_shape_set_dirty(void *vector_shape) {
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) {
+ vectorio_ishape_t ishape,
+ mp_obj_t pixel_shader, uint16_t x, uint16_t y) {
VECTORIO_SHAPE_DEBUG("%p vector_shape_construct x:%3d, y:%3d\n", self, x, y);
self->x = x;
self->y = y;
@@ -152,22 +152,22 @@ void common_hal_vectorio_vector_shape_set_pixel_shader(vectorio_vector_shape_t *
}
-bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displayio_colorspace_t* colorspace, const displayio_area_t* area, uint32_t* mask, uint32_t *buffer) {
+bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displayio_colorspace_t *colorspace, const displayio_area_t *area, uint32_t *mask, uint32_t *buffer) {
// Shape areas are relative to 0,0. This will allow rotation about a known axis.
// The consequence is that the area reported by the shape itself is _relative_ to 0,0.
// To make it relative to the VectorShape position, we must shift it.
// Pixels are drawn on the screen_area (shifted) coordinate space, while pixels are _determined_ from
// the shape_area (unshifted) space.
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t start = common_hal_time_monotonic_ns();
uint64_t pixel_time = 0;
-#endif
+ #endif
displayio_area_t overlap;
VECTORIO_SHAPE_DEBUG("%p fill_area dirty:%d fill: {(%5d,%5d), (%5d,%5d)} dirty: {(%5d,%5d), (%5d,%5d)}",
self, self->dirty,
area->x1, area->y1, area->x2, area->y2,
self->ephemeral_dirty_area.x1, self->ephemeral_dirty_area.y1, self->ephemeral_dirty_area.x2, self->ephemeral_dirty_area.y2
- );
+ );
if (!displayio_area_compute_overlap(area, &self->ephemeral_dirty_area, &overlap)) {
VECTORIO_SHAPE_DEBUG(" no overlap\n");
return false;
@@ -194,7 +194,7 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
// Check the mask first to see if the pixel has already been set.
uint32_t pixel_index = mask_start_px + (input_pixel.x - overlap.x1);
uint32_t *mask_doubleword = &(mask[pixel_index / 32]);
- uint8_t mask_bit = pixel_index % 32;
+ uint8_t mask_bit = pixel_index % 32;
VECTORIO_SHAPE_PIXEL_DEBUG("%p pixel_index: %5u mask_bit: %2u", self, pixel_index, mask_bit);
if ((*mask_doubleword & (1u << mask_bit)) != 0) {
VECTORIO_SHAPE_PIXEL_DEBUG(" masked\n");
@@ -213,14 +213,14 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
pixel_to_get_y = (input_pixel.y - self->absolute_transform->dy * self->y - self->absolute_transform->y) / self->absolute_transform->dy;
}
VECTORIO_SHAPE_PIXEL_DEBUG(" get_pixel %p (%3d, %3d) -> ( %3d, %3d )", self->ishape.shape, input_pixel.x, input_pixel.y, pixel_to_get_x, pixel_to_get_y);
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t pre_pixel = common_hal_time_monotonic_ns();
-#endif
+ #endif
input_pixel.pixel = self->ishape.get_pixel(self->ishape.shape, pixel_to_get_x, pixel_to_get_y);
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t post_pixel = common_hal_time_monotonic_ns();
pixel_time += post_pixel - pre_pixel;
-#endif
+ #endif
VECTORIO_SHAPE_PIXEL_DEBUG(" -> %d", input_pixel.pixel);
output_pixel.opaque = true;
@@ -238,10 +238,10 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
*mask_doubleword |= 1u << mask_bit;
if (colorspace->depth == 16) {
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %04x 16\n", output_pixel.pixel);
- *(((uint16_t*) buffer) + pixel_index) = output_pixel.pixel;
+ *(((uint16_t *)buffer) + pixel_index) = output_pixel.pixel;
} else if (colorspace->depth == 8) {
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %02x 8\n", output_pixel.pixel);
- *(((uint8_t*) buffer) + pixel_index) = output_pixel.pixel;
+ *(((uint8_t *)buffer) + pixel_index) = output_pixel.pixel;
} else if (colorspace->depth < 8) {
// Reorder the offsets to pack multiple rows into a byte (meaning they share a column).
if (!colorspace->pixels_in_byte_share_row) {
@@ -256,13 +256,13 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
shift = (pixels_per_byte - 1) * colorspace->depth - shift;
}
VECTORIO_SHAPE_PIXEL_DEBUG(" buffer = %2d %d\n", output_pixel.pixel, colorspace->depth);
- ((uint8_t*)buffer)[pixel_index / pixels_per_byte] |= output_pixel.pixel << shift;
+ ((uint8_t *)buffer)[pixel_index / pixels_per_byte] |= output_pixel.pixel << shift;
}
}
}
mask_start_px += linestride_px - column_dirty_offset_px;
}
-#ifdef VECTORIO_PERF
+ #ifdef VECTORIO_PERF
uint64_t end = common_hal_time_monotonic_ns();
uint32_t pixels = (overlap.x2 - overlap.x1) * (overlap.y2 - overlap.y1);
VECTORIO_PERF("draw %16s -> shape:{%4dpx, %4.1fms,%9.1fpps fill} shape_pixels:{%6.1fus total, %4.1fus/px}\n",
@@ -272,15 +272,15 @@ bool vectorio_vector_shape_fill_area(vectorio_vector_shape_t *self, const _displ
(double)(max(1, pixels * (1000000000.0 / (end - start)))),
(double)(pixel_time / 1000.0),
(double)(pixel_time / 1000.0 / pixels)
- );
-#endif
+ );
+ #endif
VECTORIO_SHAPE_DEBUG(" -> pixels:%4d\n");
return full_coverage;
}
void vectorio_vector_shape_finish_refresh(vectorio_vector_shape_t *self) {
- if ( !self->dirty ) {
+ if (!self->dirty) {
return;
}
VECTORIO_SHAPE_DEBUG("%p finish_refresh was:{(%3d,%3d), (%3d,%3d)}\n", self, self->ephemeral_dirty_area.x1, self->ephemeral_dirty_area.y1, self->ephemeral_dirty_area.x2, self->ephemeral_dirty_area.y2);
@@ -299,7 +299,7 @@ void vectorio_vector_shape_finish_refresh(vectorio_vector_shape_t *self) {
// Assembles a singly linked list of dirty areas from all components on the display.
-displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t* tail) {
+displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail) {
if (self->dirty
|| (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_palette_type) && displayio_palette_needs_refresh(self->pixel_shader))
|| (MP_OBJ_IS_TYPE(self->pixel_shader, &displayio_colorconverter_type) && displayio_colorconverter_needs_refresh(self->pixel_shader))
diff --git a/shared-module/vectorio/VectorShape.h b/shared-module/vectorio/VectorShape.h
index 56eb3d8a5..1896c72d6 100644
--- a/shared-module/vectorio/VectorShape.h
+++ b/shared-module/vectorio/VectorShape.h
@@ -38,7 +38,7 @@ typedef struct {
displayio_area_t ephemeral_dirty_area;
} vectorio_vector_shape_t;
-displayio_area_t* vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);
+displayio_area_t *vectorio_vector_shape_get_refresh_areas(vectorio_vector_shape_t *self, displayio_area_t *tail);
bool vectorio_vector_shape_get_dirty_area(vectorio_vector_shape_t *self, displayio_area_t *current_dirty_area);