Optimization of ImageDrawRectangleRec() (#3185)
A significant performance increase can be had by copying the first row to all other rows.
This commit is contained in:
parent
5635e4214c
commit
1310617a92
1 changed files with 16 additions and 14 deletions
|
@ -3135,18 +3135,14 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color)
|
|||
if (rec.height < 0) rec.height = 0;
|
||||
|
||||
int sy = (int)rec.y;
|
||||
int ey = sy + (int)rec.height;
|
||||
|
||||
int sx = (int)rec.x;
|
||||
|
||||
int bytesPerPixel = GetPixelDataSize(1, 1, dst->format);
|
||||
|
||||
for (int y = sy; y < ey; y++)
|
||||
{
|
||||
// Fill in the first pixel of the row based on image format
|
||||
ImageDrawPixel(dst, sx, y, color);
|
||||
// Fill in the first pixel of the first row based on image format
|
||||
ImageDrawPixel(dst, sx, sy, color);
|
||||
|
||||
int bytesOffset = ((y*dst->width) + sx)*bytesPerPixel;
|
||||
int bytesOffset = ((sy*dst->width) + sx)*bytesPerPixel;
|
||||
unsigned char *pSrcPixel = (unsigned char *)dst->data + bytesOffset;
|
||||
|
||||
// Repeat the first pixel data throughout the row
|
||||
|
@ -3154,6 +3150,12 @@ void ImageDrawRectangleRec(Image *dst, Rectangle rec, Color color)
|
|||
{
|
||||
memcpy(pSrcPixel + x*bytesPerPixel, pSrcPixel, bytesPerPixel);
|
||||
}
|
||||
|
||||
// Repeat the first row data for all other rows
|
||||
int bytesPerRow = bytesPerPixel * (int)rec.width;
|
||||
for (int y = 1; y < (int)rec.height; y++)
|
||||
{
|
||||
memcpy(pSrcPixel + (y*dst->width)*bytesPerPixel, pSrcPixel, bytesPerRow);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue