mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-14 06:42:58 +08:00
Merge pull request #980 from littlevgl/move_canvas
Move lv_canvas_get_px/lv_canvas_set_px to lv_draw_img.c
This commit is contained in:
commit
37e873fa09
@ -143,8 +143,132 @@ lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the color of a pixel on the canvas
|
||||||
|
* @param canvas
|
||||||
|
* @param x x coordinate of the point to set
|
||||||
|
* @param y x coordinate of the point to set
|
||||||
|
* @return color of the point
|
||||||
|
*/
|
||||||
|
lv_color_t lv_img_buf_get_px(lv_img_dsc_t *dsc, lv_coord_t x, lv_coord_t y)
|
||||||
|
{
|
||||||
|
lv_color_t p_color = LV_COLOR_BLACK;
|
||||||
|
if(x >= dsc->header.w) {
|
||||||
|
x = dsc->header.w - 1;
|
||||||
|
LV_LOG_WARN("lv_canvas_get_px: x is too large (out of canvas)");
|
||||||
|
}
|
||||||
|
else if(x < 0) {
|
||||||
|
x = 0;
|
||||||
|
LV_LOG_WARN("lv_canvas_get_px: x is < 0 (out of canvas)");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(y >= dsc->header.h) {
|
||||||
|
y = dsc->header.h - 1;
|
||||||
|
LV_LOG_WARN("lv_canvas_get_px: y is too large (out of canvas)");
|
||||||
|
}
|
||||||
|
else if(y < 0) {
|
||||||
|
y = 0;
|
||||||
|
LV_LOG_WARN("lv_canvas_get_px: y is < 0 (out of canvas)");
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t * buf_u8 = (uint8_t *) dsc->data;
|
||||||
|
|
||||||
|
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR ||
|
||||||
|
dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
|
||||||
|
{
|
||||||
|
uint32_t px = dsc->header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
|
||||||
|
memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t));
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
|
||||||
|
buf_u8 += 4 * 2;
|
||||||
|
uint8_t bit = x & 0x7;
|
||||||
|
x = x >> 3;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 3) * y + x;
|
||||||
|
p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
|
||||||
|
buf_u8 += 4 * 4;
|
||||||
|
uint8_t bit = (x & 0x3) * 2;
|
||||||
|
x = x >> 2;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 2) * y + x;
|
||||||
|
p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
|
||||||
|
buf_u8 += 4 * 16;
|
||||||
|
uint8_t bit = (x & 0x1) * 4;
|
||||||
|
x = x >> 1;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 1) * y + x;
|
||||||
|
p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||||
|
buf_u8 += 4 * 256;
|
||||||
|
uint32_t px = dsc->header.w * y + x;
|
||||||
|
p_color.full = buf_u8[px];
|
||||||
|
}
|
||||||
|
return p_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color of a pixel on the canvas
|
||||||
|
* @param dsc image
|
||||||
|
* @param x x coordinate of the point to set
|
||||||
|
* @param y x coordinate of the point to set
|
||||||
|
* @param c color of the point
|
||||||
|
*/
|
||||||
|
void lv_img_buf_set_px(lv_img_dsc_t *dsc, lv_coord_t x, lv_coord_t y, lv_color_t c)
|
||||||
|
{
|
||||||
|
uint8_t * buf_u8 = (uint8_t *) dsc->data;
|
||||||
|
|
||||||
|
if(dsc->header.cf == LV_IMG_CF_TRUE_COLOR ||
|
||||||
|
dsc->header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
|
||||||
|
{
|
||||||
|
uint32_t px = dsc->header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
|
||||||
|
|
||||||
|
memcpy(&buf_u8[px], &c, sizeof(lv_color_t));
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_1BIT) {
|
||||||
|
buf_u8 += 4 * 2;
|
||||||
|
uint8_t bit = x & 0x7;
|
||||||
|
x = x >> 3;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 3) * y + x;
|
||||||
|
buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
|
||||||
|
buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_2BIT) {
|
||||||
|
buf_u8 += 4 * 4;
|
||||||
|
uint8_t bit = (x & 0x3) * 2;
|
||||||
|
x = x >> 2;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 2) * y + x;
|
||||||
|
|
||||||
|
buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
|
||||||
|
buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_4BIT) {
|
||||||
|
buf_u8 += 4 * 16;
|
||||||
|
uint8_t bit = (x & 0x1) * 4;
|
||||||
|
x = x >> 1;
|
||||||
|
|
||||||
|
uint32_t px = (dsc->header.w >> 1) * y + x;
|
||||||
|
|
||||||
|
buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
|
||||||
|
buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
|
||||||
|
}
|
||||||
|
else if(dsc->header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
||||||
|
buf_u8 += 4 * 256;
|
||||||
|
uint32_t px = dsc->header.w * y + x;
|
||||||
|
buf_u8[px] = c.full;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf)
|
uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf)
|
||||||
{
|
{
|
||||||
uint8_t px_size = 0;
|
uint8_t px_size = 0;
|
||||||
|
@ -153,7 +153,24 @@ uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf);
|
|||||||
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf);
|
bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf);
|
||||||
|
|
||||||
bool lv_img_color_format_has_alpha(lv_img_cf_t cf);
|
bool lv_img_color_format_has_alpha(lv_img_cf_t cf);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the color of a pixel on an image
|
||||||
|
* @param dsc image
|
||||||
|
* @param x x coordinate of the point to set
|
||||||
|
* @param y x coordinate of the point to set
|
||||||
|
* @param c color of the point
|
||||||
|
*/
|
||||||
|
void lv_img_buf_set_px(lv_img_dsc_t *dsc, lv_coord_t x, lv_coord_t y, lv_color_t c);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the color of a pixel on an image
|
||||||
|
* @param dsc image
|
||||||
|
* @param x x coordinate of the point to set
|
||||||
|
* @param y x coordinate of the point to set
|
||||||
|
* @return color of the point
|
||||||
|
*/
|
||||||
|
lv_color_t lv_img_buf_get_px(lv_img_dsc_t *dsc, lv_coord_t x, lv_coord_t y);
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* MACROS
|
* MACROS
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
*********************/
|
*********************/
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "lv_canvas.h"
|
#include "lv_canvas.h"
|
||||||
#include "../lv_misc/lv_math.h"
|
#include "../lv_misc/lv_math.h"
|
||||||
|
#include "../lv_draw/lv_draw_img.h"
|
||||||
#if LV_USE_CANVAS != 0
|
#if LV_USE_CANVAS != 0
|
||||||
|
|
||||||
/*********************
|
/*********************
|
||||||
@ -23,7 +24,6 @@
|
|||||||
* STATIC PROTOTYPES
|
* STATIC PROTOTYPES
|
||||||
**********************/
|
**********************/
|
||||||
static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param);
|
static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * param);
|
||||||
static void set_px_core(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c);
|
|
||||||
|
|
||||||
/**********************
|
/**********************
|
||||||
* STATIC VARIABLES
|
* STATIC VARIABLES
|
||||||
@ -130,8 +130,10 @@ void lv_canvas_set_buffer(lv_obj_t * canvas, void * buf, lv_coord_t w, lv_coord_
|
|||||||
* @param c color of the point
|
* @param c color of the point
|
||||||
*/
|
*/
|
||||||
void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c)
|
void lv_canvas_set_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c)
|
||||||
{
|
{
|
||||||
set_px_core(canvas, x, y, c);
|
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
|
||||||
|
|
||||||
|
lv_img_buf_set_px(&ext->dsc, x, y, c);
|
||||||
lv_obj_invalidate(canvas);
|
lv_obj_invalidate(canvas);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -164,65 +166,9 @@ void lv_canvas_set_style(lv_obj_t * canvas, lv_canvas_style_t type, lv_style_t *
|
|||||||
*/
|
*/
|
||||||
lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y)
|
lv_color_t lv_canvas_get_px(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y)
|
||||||
{
|
{
|
||||||
lv_color_t p_color = LV_COLOR_BLACK;
|
|
||||||
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
|
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
|
||||||
if(x >= ext->dsc.header.w) {
|
|
||||||
x = ext->dsc.header.w - 1;
|
return lv_img_buf_get_px(&ext->dsc, x, y);
|
||||||
LV_LOG_WARN("lv_canvas_get_px: x is too large (out of canvas)");
|
|
||||||
}
|
|
||||||
else if(x < 0) {
|
|
||||||
x = 0;
|
|
||||||
LV_LOG_WARN("lv_canvas_get_px: x is < 0 (out of canvas)");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if(y >= ext->dsc.header.h) {
|
|
||||||
y = ext->dsc.header.h - 1;
|
|
||||||
LV_LOG_WARN("lv_canvas_get_px: y is too large (out of canvas)");
|
|
||||||
}
|
|
||||||
else if(y < 0) {
|
|
||||||
y = 0;
|
|
||||||
LV_LOG_WARN("lv_canvas_get_px: y is < 0 (out of canvas)");
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t * buf_u8 = (uint8_t *) ext->dsc.data;
|
|
||||||
|
|
||||||
if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR ||
|
|
||||||
ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
|
|
||||||
{
|
|
||||||
uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
|
|
||||||
memcpy(&p_color, &buf_u8[px], sizeof(lv_color_t));
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) {
|
|
||||||
buf_u8 += 4 * 2;
|
|
||||||
uint8_t bit = x & 0x7;
|
|
||||||
x = x >> 3;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 3) * y + x;
|
|
||||||
p_color.full = (buf_u8[px] & (1 << (7 - bit))) >> (7 - bit);
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) {
|
|
||||||
buf_u8 += 4 * 4;
|
|
||||||
uint8_t bit = (x & 0x3) * 2;
|
|
||||||
x = x >> 2;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 2) * y + x;
|
|
||||||
p_color.full = (buf_u8[px] & (3 << (6 - bit))) >> (6 - bit);
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) {
|
|
||||||
buf_u8 += 4 * 16;
|
|
||||||
uint8_t bit = (x & 0x1) * 4;
|
|
||||||
x = x >> 1;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 1) * y + x;
|
|
||||||
p_color.full = (buf_u8[px] & (0xF << (4 - bit))) >> (4 - bit);
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
|
||||||
buf_u8 += 4 * 256;
|
|
||||||
uint32_t px = ext->dsc.header.w * y + x;
|
|
||||||
p_color.full = buf_u8[px];
|
|
||||||
}
|
|
||||||
return p_color;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -443,7 +389,7 @@ void lv_canvas_rotate(lv_obj_t * canvas_dest, lv_obj_t * canvas_src, int16_t ang
|
|||||||
// if (x + offset_x >= 0 && x + offset_x < dest_width && y + offset_y >= 0 && y + offset_y < dest_height)
|
// if (x + offset_x >= 0 && x + offset_x < dest_width && y + offset_y >= 0 && y + offset_y < dest_height)
|
||||||
{
|
{
|
||||||
/*The result color as the average of the x/y mixed colors*/
|
/*The result color as the average of the x/y mixed colors*/
|
||||||
set_px_core(canvas_dest, x + offset_x, y + offset_y, lv_color_mix(x_dest, y_dest, LV_OPA_50));
|
lv_img_buf_set_px(&ext_dst->dsc, x + offset_x, y + offset_y, lv_color_mix(x_dest, y_dest, LV_OPA_50));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,7 +476,7 @@ void lv_canvas_draw_line(lv_obj_t * canvas, lv_point_t point1, lv_point_t point2
|
|||||||
* @param color line color of the triangle
|
* @param color line color of the triangle
|
||||||
*/
|
*/
|
||||||
void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
|
void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
|
||||||
{
|
{
|
||||||
lv_canvas_draw_polygon(canvas, points, 3, color);
|
lv_canvas_draw_polygon(canvas, points, 3, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -541,7 +487,7 @@ void lv_canvas_draw_triangle(lv_obj_t * canvas, lv_point_t * points, lv_color_t
|
|||||||
* @param color line color of the rectangle
|
* @param color line color of the rectangle
|
||||||
*/
|
*/
|
||||||
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
|
void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t color)
|
||||||
{
|
{
|
||||||
lv_canvas_draw_polygon(canvas, points, 4, color);
|
lv_canvas_draw_polygon(canvas, points, 4, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -553,7 +499,7 @@ void lv_canvas_draw_rect(lv_obj_t * canvas, lv_point_t * points, lv_color_t colo
|
|||||||
* @param color line color of the polygon
|
* @param color line color of the polygon
|
||||||
*/
|
*/
|
||||||
void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color)
|
void lv_canvas_draw_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size, lv_color_t color)
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
|
||||||
for(i=0; i < (size - 1); i++) {
|
for(i=0; i < (size - 1); i++) {
|
||||||
@ -593,7 +539,7 @@ void lv_canvas_fill_polygon(lv_obj_t * canvas, lv_point_t * points, size_t size,
|
|||||||
* @param x x coordinate of the start position (seed)
|
* @param x x coordinate of the start position (seed)
|
||||||
* @param y y coordinate of the start position (seed)
|
* @param y y coordinate of the start position (seed)
|
||||||
* @param boundary_color edge/boundary color of the area
|
* @param boundary_color edge/boundary color of the area
|
||||||
* @param fill_color fill color of the area
|
* @param fill_color fill color of the area
|
||||||
*/
|
*/
|
||||||
void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color)
|
void lv_canvas_boundary_fill4(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t boundary_color, lv_color_t fill_color)
|
||||||
{
|
{
|
||||||
@ -671,61 +617,4 @@ static lv_res_t lv_canvas_signal(lv_obj_t * canvas, lv_signal_t sign, void * par
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Set a pixel of the canvas. Doesn't check for errors and doesn't invalidate the canvas
|
|
||||||
* @param canvas pointer to canvas object
|
|
||||||
* @param x x coordinate of the point to set
|
|
||||||
* @param y x coordinate of the point to set
|
|
||||||
* @param c color of the point
|
|
||||||
*/
|
|
||||||
static void set_px_core(lv_obj_t * canvas, lv_coord_t x, lv_coord_t y, lv_color_t c)
|
|
||||||
{
|
|
||||||
lv_canvas_ext_t * ext = lv_obj_get_ext_attr(canvas);
|
|
||||||
|
|
||||||
uint8_t * buf_u8 = (uint8_t *) ext->dsc.data;
|
|
||||||
|
|
||||||
if(ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR ||
|
|
||||||
ext->dsc.header.cf == LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED)
|
|
||||||
{
|
|
||||||
uint32_t px = ext->dsc.header.w * y * sizeof(lv_color_t) + x * sizeof(lv_color_t);
|
|
||||||
|
|
||||||
memcpy(&buf_u8[px], &c, sizeof(lv_color_t));
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_1BIT) {
|
|
||||||
buf_u8 += 4 * 2;
|
|
||||||
uint8_t bit = x & 0x7;
|
|
||||||
x = x >> 3;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 3) * y + x;
|
|
||||||
buf_u8[px] = buf_u8[px] & ~(1 << (7 - bit));
|
|
||||||
buf_u8[px] = buf_u8[px] | ((c.full & 0x1) << (7 - bit));
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_2BIT) {
|
|
||||||
buf_u8 += 4 * 4;
|
|
||||||
uint8_t bit = (x & 0x3) * 2;
|
|
||||||
x = x >> 2;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 2) * y + x;
|
|
||||||
|
|
||||||
buf_u8[px] = buf_u8[px] & ~(3 << (6 - bit));
|
|
||||||
buf_u8[px] = buf_u8[px] | ((c.full & 0x3) << (6 - bit));
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_4BIT) {
|
|
||||||
buf_u8 += 4 * 16;
|
|
||||||
uint8_t bit = (x & 0x1) * 4;
|
|
||||||
x = x >> 1;
|
|
||||||
|
|
||||||
uint32_t px = (ext->dsc.header.w >> 1) * y + x;
|
|
||||||
|
|
||||||
buf_u8[px] = buf_u8[px] & ~(0xF << (4 - bit));
|
|
||||||
buf_u8[px] = buf_u8[px] | ((c.full & 0xF) << (4 - bit));
|
|
||||||
}
|
|
||||||
else if(ext->dsc.header.cf == LV_IMG_CF_INDEXED_8BIT) {
|
|
||||||
buf_u8 += 4 * 256;
|
|
||||||
uint32_t px = ext->dsc.header.w * y + x;
|
|
||||||
buf_u8[px] = c.full;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user