libui: Add an interface to fill a Canvas with an array of pixels
This commit is contained in:
parent
f6ef79e759
commit
916b19825d
@ -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);
|
||||
};
|
||||
};
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user