2

I am stuck on how to perform these transformations on a PPM image.

This is what I have so far, these are close to the solution but a few pixels are wrong for each of them, and I have no idea why?

void vertical_flip(PpmImage &ppm) {
  for (unsigned int r = 0; r < ppm.height/2; r++) {
    for (unsigned int c = 0; c < ppm.width; c++) {
      Pixel temp = ppm.pixels[r][c];
      ppm.pixels[r][c] = ppm.pixels[ppm.height-r-1][c];
      ppm.pixels[ppm.height-r-1][c] = temp;
    }
  }
}

void grey_scale(PpmImage &ppm) {
  for (unsigned int r = 0; r < ppm.height; r++) {
    for (unsigned int c = 0; c < ppm.width; c++) {
      Pixel p = ppm.pixels[r][c];
      p.r = p.g = p.b = p.r/3.0 + p.g/3.0 + p.b/3.0;
      ppm.pixels[r][c] = p;
    }
  }
}
DBoyer
  • 3,062
  • 4
  • 22
  • 32
  • 1
    If `Pixel::r` etc are integral, are you expecting the integer division `/3` chopping off fractions instead of rounding? Do you expect the sum or `r,g,b` to overflow? Do you want the simplified averaged grayscale instead of the more common weighted grayscale? – PeterT Feb 16 '16 at 21:37
  • 1
    and I guess is "r+g+r" what you want instead of "r+g+b" – PeterT Feb 16 '16 at 21:45
  • for `grey_scale` I agree with @PeterT, but what's wrong with `vertical_flip`? Which pixels are wrong flipped? – Bob__ Feb 16 '16 at 22:22
  • Looks like my vertical flip is correct, a separate problem was causing it to seem incorrect. I have update my code for grey_scale which still appears to not give the the right answer. – DBoyer Feb 18 '16 at 00:53

0 Answers0