diff --git a/libui/include/ui/Canvas.h b/libui/include/ui/Canvas.h index 02a662ba..74a34217 100644 --- a/libui/include/ui/Canvas.h +++ b/libui/include/ui/Canvas.h @@ -52,5 +52,13 @@ namespace ui * @param color The color to use. */ void fill(Color color); + + /** + * @brief Fill the canvas with pixels. + * + * @param pixels The array of pixels (must be at least width*height). + * @param stride The number of pixels to skip to go to the next line. + */ + void fill(u32* pixels, int stride); }; }; diff --git a/libui/src/Canvas.cpp b/libui/src/Canvas.cpp index a0c1c647..d14bc768 100644 --- a/libui/src/Canvas.cpp +++ b/libui/src/Canvas.cpp @@ -33,4 +33,21 @@ namespace ui p += stride * sizeof(Color); } } + + void Canvas::fill(u32* pixels, int _stride) + { + u8* p = ptr; + for (int i = 0; i < height; i++) + { + u32* colorp = (u32*)p; + for (int j = 0; j < width; j++) + { + u32 pix = pixels[j]; + if (Color::from_u32(pix).alpha() == 0xff) *colorp = pix; + colorp++; + } + pixels += _stride; + p += stride * sizeof(Color); + } + } }