Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int height = i->GetWidth(); //width and height swapped for 90 degree rotation
- int width = i->GetHeight();
- int bpp = i->GetBPP();
- int pitch1 = i->GetPitch();
- int hwidth = width / 2;
- int hheight = height / 2;
- double sinma = sin(1.57079633f); //90 degree rotation
- double cosma = cos(1.57079633f);
- CImage *dest = new CImage();
- dest->Create(width, height, bpp);
- int pitch2 = dest->GetPitch();
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- int yt = x - hwidth;
- int xt = y - hheight;
- int ys = (int)round((cosma * xt - sinma * yt) + hwidth); //get rotated pixel
- int xs = (int)round((sinma * xt + cosma * yt) + hheight);
- if (xs >= 0 && xs < height && ys >= 0 && ys < width) {
- // set target pixel (x,y) to color at (xs,ys)
- dest->SetPixel(x, y, i->GetPixel(xs, ys));
- }
- else {
- // set target pixel (x,y) to some default background
- COLORREF pixel = RGB(0, 0, 0);
- dest->SetPixel(x, y, pixel);
- }
- }
- }
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- int yt = x - hwidth;
- int xt = y - hheight;
- int ys = (int)round((cosma * xt - sinma * yt) + hwidth);
- int xs = (int)round((sinma * xt + cosma * yt) + hheight);
- if (xs >= 0 && xs < height && ys >= 0 && ys < width) {
- // set target pixel (x,y) to color at (xs,ys)
- //dest->SetPixel(x, y, i->GetPixel(xs, ys));
- lAdrs2 = x * pitch2 + y * 3; // set target pixel (x,y)
- lAdrs1 = ys * pitch1 + xs * 3; // to color at (xs,ys)
- bRed = *(pInImage + lAdrs1);
- bGreen = *(pInImage + lAdrs1 + 1);
- bBlue = *(pInImage + lAdrs1 + 2);
- *(pOutImage + lAdrs2) = static_cast<BYTE>(bRed);
- *(pOutImage + lAdrs2 + 1) = static_cast<BYTE>(bGreen);
- *(pOutImage + lAdrs2 + 2) = static_cast<BYTE>(bBlue);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement