画像回転(2)

int cos = Math::cos( rotate );
int sin = Math::sin( rotate );
int y,x;
int yy,xx;
for( y = 0 , yy = -h / 2 ; y < h ; y++ , yy++ ){
    for( x = 0 , xx = -w / 2 ; x < w ; x++ , xx++ ){
        if( src[ x ] != key ){
            int u = ((cos * xx + sin * yy) >> 15) + w;
            int v = ((-sin * xx + cos * yy) >> 15) + h;
            // 領域外への描画チェック
            if(
                (u >> 1) <  dcx  ||
                (u >> 1) >= dcx2 ||
                (v >> 1) <  dcy  ||
                (v >> 1) >= dcy2
            ){
                continue;
            }
            int d = ((v >> 1) * dstPitch) + (u >> 1);
            dst[ d ] = pal[ src[ x ] ];
            if( (u << 31) != 0 ){
                dst[ d + 1 ] = pal[ src[ x ] ];
            }
            if( (v << 31) != 0 ){
                dst[ d + dstPitch ] = pal[ src[ x ] ];
            }
            if( ((u << 31) != 0) && ((v << 31) != 0) ){
                dst[ d + dstPitch + 1 ] = pal[ src[ x ] ];
            }
        }
    }
    src += srcPitch;
}

追記:
↑描画元から描画先を直接求める回転ルーチン。
線形補間しようと思ったら、描画先から描画元を求めないといけないらしい。。