Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. int height = i->GetWidth(); //width and height swapped for 90 degree rotation
  2.  
  3. int width = i->GetHeight();
  4. int bpp = i->GetBPP();
  5. int pitch1 = i->GetPitch();
  6.  
  7. int hwidth = width / 2;
  8. int hheight = height / 2;
  9.  
  10. double sinma = sin(1.57079633f); //90 degree rotation
  11. double cosma = cos(1.57079633f);
  12.  
  13. CImage *dest = new CImage();
  14. dest->Create(width, height, bpp);
  15. int pitch2 = dest->GetPitch();
  16.  
  17. for (int x = 0; x < width; x++)
  18. {
  19. for (int y = 0; y < height; y++)
  20. {
  21. int yt = x - hwidth;
  22. int xt = y - hheight;
  23.  
  24. int ys = (int)round((cosma * xt - sinma * yt) + hwidth); //get rotated pixel
  25. int xs = (int)round((sinma * xt + cosma * yt) + hheight);
  26.  
  27. if (xs >= 0 && xs < height && ys >= 0 && ys < width) {
  28. // set target pixel (x,y) to color at (xs,ys)
  29. dest->SetPixel(x, y, i->GetPixel(xs, ys));
  30. }
  31. else {
  32. // set target pixel (x,y) to some default background
  33. COLORREF pixel = RGB(0, 0, 0);
  34. dest->SetPixel(x, y, pixel);
  35. }
  36. }
  37. }
  38.  
  39. for (int x = 0; x < width; x++)
  40. {
  41. for (int y = 0; y < height; y++)
  42. {
  43.  
  44. int yt = x - hwidth;
  45. int xt = y - hheight;
  46.  
  47. int ys = (int)round((cosma * xt - sinma * yt) + hwidth);
  48. int xs = (int)round((sinma * xt + cosma * yt) + hheight);
  49.  
  50. if (xs >= 0 && xs < height && ys >= 0 && ys < width) {
  51. // set target pixel (x,y) to color at (xs,ys)
  52. //dest->SetPixel(x, y, i->GetPixel(xs, ys));
  53.  
  54. lAdrs2 = x * pitch2 + y * 3; // set target pixel (x,y)
  55. lAdrs1 = ys * pitch1 + xs * 3; // to color at (xs,ys)
  56.  
  57. bRed = *(pInImage + lAdrs1);
  58. bGreen = *(pInImage + lAdrs1 + 1);
  59. bBlue = *(pInImage + lAdrs1 + 2);
  60.  
  61. *(pOutImage + lAdrs2) = static_cast<BYTE>(bRed);
  62. *(pOutImage + lAdrs2 + 1) = static_cast<BYTE>(bGreen);
  63. *(pOutImage + lAdrs2 + 2) = static_cast<BYTE>(bBlue);
  64. }
  65.  
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement