I use the standard formula to rotate a solid (filled) rectangle/object with pivot point. The image is a on/off byte array.
const uint8_t *srcBuf;
color_t *dstBuf[];
double angle = 25.0;
double roCos = cos(angle);
double roSin = sin(angle);
int16_t src_val;
for(int y = 0; y < src_h; y++) {
for(int x = 0; x < src_w ; x++) {
src_val = srcBuf[y * src_w + x];
if (src_val == 0) { continue; }
deltaX = (double)(x - src_piv_x);
deltaY = (double)(y - src_piv_y);
xp = (int16_t)(deltaX * roCos - deltaY * roSin);
yp = (int16_t)(deltaX * roSin + deltaY * roCos);
xp += pivot_x;
yp += pivot_y;
if (xp >= 0 && xp < dst_w && yp >= 0 && yp <= dst_h) {
dstBuf[yp * dst_w + xp] = color ;
}
}
}
The image is rotated correctly. However, I get blank dots (regular pattern) inside the rotated rectangle/object. I presume these unfilled dots are because the equation does not produce map 1:1 on the destination due to rounding/precision.
Is there a recommendation to overcome this limitation?
Thanks