C ++中的PPM图像转换

时间:2016-02-16 21:22:36

标签: c++ matrix transpose ppm

我坚持如何在PPM图像上执行这些转换。

这是我到目前为止,这些都接近解决方案,但每个像素都有一些错误,我不明白为什么?

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;
    }
  }
}

0 个答案:

没有答案