libui: Add an interface to fill a Canvas with an array of pixels

This commit is contained in:
apio 2023-08-04 21:14:43 +02:00
parent 49d5930912
commit 747c720159
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 25 additions and 0 deletions

View File

@ -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);
};
};

View File

@ -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);
}
}
}