Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stats::stats(PNG& im) {
- sumRed.resize(im.width(), vector<long>(im.height()));
- sumGreen.resize(im.width(), vector<long>(im.height()));
- sumBlue.resize(im.width(), vector<long>(im.height()));
- sumsqRed.resize(im.width(), vector<long>(im.height()));
- sumsqGreen.resize(im.width(), vector<long>(im.height()));
- sumsqBlue.resize(im.width(), vector<long>(im.height()));
- RGBAPixel* pixel = im.getPixel(0,0);
- sumRed[0][0] = pixel->r;
- sumGreen[0][0] = pixel->g;
- sumBlue[0][0] = pixel->b;
- sumsqRed[0][0] = pixel->r * pixel->r;
- sumsqGreen[0][0] = pixel->g * pixel->g;
- sumsqBlue[0][0] = pixel->b * pixel->b;
- for (unsigned int w = 1; w < im.width(); w++) {
- RGBAPixel* p = im.getPixel(w,0);
- sumRed[w][0] = p->r + sumRed[w-1][0];
- sumGreen[w][0] = p->g + sumGreen[w-1][0];
- sumBlue[w][0] = p->b + sumBlue[w-1][0];
- sumsqRed[w][0] = p->r * p->r + sumsqRed[w-1][0];
- sumsqGreen[w][0] = p->g * p->g + sumsqGreen[w-1][0];
- sumsqBlue[w][0] = p->b * p->b + sumsqBlue[w-1][0];
- }
- for (unsigned int h = 1; h < im.height(); h++) {
- RGBAPixel* p = im.getPixel(0,h);
- sumRed[0][h] = p->r + sumRed[0][h-1];
- sumGreen[0][h] = p->g + sumGreen[0][h-1];
- sumBlue[0][h] = p->b + sumBlue[0][h-1];
- sumsqRed[0][h] = p->r * p->r + sumsqRed[0][h-1];
- sumsqGreen[0][h] = p->g * p->g + sumsqGreen[0][h-1];
- sumsqBlue[0][h] = p->b * p->b + sumsqBlue[0][h-1];
- }
- for (unsigned int w = 1; w < im.width(); w++) {
- for (unsigned int h = 1; h < im.height(); h++) {
- RGBAPixel* p = im.getPixel(w, h);
- sumRed[w][h] = p->r + sumRed[w-1][h] + sumRed[w][h-1] - sumRed[w-1][h-1];
- sumGreen[w][h] = p->g + sumGreen[w-1][h] + sumGreen[w][h-1] - sumGreen[w-1][h-1];
- sumBlue[w][h] = p->b + sumBlue[w-1][h] + sumBlue[w][h-1] - sumBlue[w-1][h-1];
- sumsqRed[w][h] = p->r * p->r + sumsqRed[w-1][h] + sumsqRed[w][h-1] - sumsqRed[w-1][h-1];
- sumsqGreen[w][h] = p->g * p->g + sumsqGreen[w-1][h] + sumsqGreen[w][h-1] - sumsqGreen[w-1][h-1];
- sumsqBlue[w][h] = p->b * p->b + sumsqBlue[w-1][h] + sumsqBlue[w][h-1] - sumsqBlue[w-1][h-1];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement