Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. stats::stats(PNG& im) {
  2. sumRed.resize(im.width(), vector<long>(im.height()));
  3. sumGreen.resize(im.width(), vector<long>(im.height()));
  4. sumBlue.resize(im.width(), vector<long>(im.height()));
  5.  
  6. sumsqRed.resize(im.width(), vector<long>(im.height()));
  7. sumsqGreen.resize(im.width(), vector<long>(im.height()));
  8. sumsqBlue.resize(im.width(), vector<long>(im.height()));
  9.  
  10. RGBAPixel* pixel = im.getPixel(0,0);
  11. sumRed[0][0] = pixel->r;
  12. sumGreen[0][0] = pixel->g;
  13. sumBlue[0][0] = pixel->b;
  14.  
  15. sumsqRed[0][0] = pixel->r * pixel->r;
  16. sumsqGreen[0][0] = pixel->g * pixel->g;
  17. sumsqBlue[0][0] = pixel->b * pixel->b;
  18.  
  19. for (unsigned int w = 1; w < im.width(); w++) {
  20. RGBAPixel* p = im.getPixel(w,0);
  21. sumRed[w][0] = p->r + sumRed[w-1][0];
  22. sumGreen[w][0] = p->g + sumGreen[w-1][0];
  23. sumBlue[w][0] = p->b + sumBlue[w-1][0];
  24. sumsqRed[w][0] = p->r * p->r + sumsqRed[w-1][0];
  25. sumsqGreen[w][0] = p->g * p->g + sumsqGreen[w-1][0];
  26. sumsqBlue[w][0] = p->b * p->b + sumsqBlue[w-1][0];
  27. }
  28.  
  29. for (unsigned int h = 1; h < im.height(); h++) {
  30. RGBAPixel* p = im.getPixel(0,h);
  31. sumRed[0][h] = p->r + sumRed[0][h-1];
  32. sumGreen[0][h] = p->g + sumGreen[0][h-1];
  33. sumBlue[0][h] = p->b + sumBlue[0][h-1];
  34. sumsqRed[0][h] = p->r * p->r + sumsqRed[0][h-1];
  35. sumsqGreen[0][h] = p->g * p->g + sumsqGreen[0][h-1];
  36. sumsqBlue[0][h] = p->b * p->b + sumsqBlue[0][h-1];
  37. }
  38.  
  39. for (unsigned int w = 1; w < im.width(); w++) {
  40. for (unsigned int h = 1; h < im.height(); h++) {
  41. RGBAPixel* p = im.getPixel(w, h);
  42. sumRed[w][h] = p->r + sumRed[w-1][h] + sumRed[w][h-1] - sumRed[w-1][h-1];
  43. sumGreen[w][h] = p->g + sumGreen[w-1][h] + sumGreen[w][h-1] - sumGreen[w-1][h-1];
  44. sumBlue[w][h] = p->b + sumBlue[w-1][h] + sumBlue[w][h-1] - sumBlue[w-1][h-1];
  45.  
  46. sumsqRed[w][h] = p->r * p->r + sumsqRed[w-1][h] + sumsqRed[w][h-1] - sumsqRed[w-1][h-1];
  47. sumsqGreen[w][h] = p->g * p->g + sumsqGreen[w-1][h] + sumsqGreen[w][h-1] - sumsqGreen[w-1][h-1];
  48. sumsqBlue[w][h] = p->b * p->b + sumsqBlue[w-1][h] + sumsqBlue[w][h-1] - sumsqBlue[w-1][h-1];
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement