Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
(R * 77 + G * 150 + B * 28) >> 8) & 255
// buffer = source buffer RGB565[320x200]
// scn = target buffer RGB565[320x200]
void FastRotate(float scale, //the scaling factor
float ang) //the rotation angle
{
long xscale=sin(ang)*65536L/scale;
long yscale=cos(ang)*65536L/scale;
long xc=(screen_dx/2)*65536L - ((screen_dx/2)*yscale+(screen_dy/2)*xscale);
long yc=(screen_dy/2)*65536L - ((screen_dy/2)*yscale-(screen_dx/2)*xscale);
WORD far *scn=shadow_buffer;
for (int y=0;y<screen_dy;y++) //normally from 0 to 199
{
long xlong=xc,ylong=yc; //init x/ylong to topleft of square
for (int x=0;x<screen_dx;) //normally from 0 to 319
{
register int tempx=xlong>>16;
register int tempy=ylong>>16;
if( (tempx<0) || (tempx>=screen_dx) || (tempy<0) || (tempy>=screen_dy) )
scn[x++]=0;
else
scn[x++]= buffer[tempx+y320[tempy]];
xlong+=yscale;ylong-=xscale;
}
scn+=screen_dx; // WARNING
xc+=xscale;yc+=yscale;
}
}
Попутно отметим, что алгоритм поворота, реализованный в Photoshop, не претерпел за 10 лет каких-либо ощутимых изменений.
при этом создаёт «ореолы» искажённого цвета
Прецизионный поворот растрового изображения на произвольный угол