Hello CS50 community,
my question is about the reflection filter (less comfortable):
- I have compiled a code that is reflecting (YEAH!) but there seems to be the following errors when checking:
*:) reflect correctly filters 1x2 image
:( reflect correctly filters 1x3 image expected "0 0 255\n0 255...", not "255 0 0\n0 255..."
:) reflect correctly filters image that is its own mirror image*
:( reflect correctly filters 3x3 image expected "70 80 90\n40 5...", not "10 20 30\n40 5..."
:) reflect correctly filters 4x4 image*
- Why does it work even if i do not use pointers?
Thank you for pointing me in the right direction, and happy new year!
void reflect(int height, int width, RGBTRIPLE image[height][width]) { if (width%2 == 0) { for (int i=0 ; i < height; i++) { for (int j=0 ; j < width/2; j++) { int blue = image[i][j].rgbtBlue; int green = image[i][j].rgbtGreen; int red = image[i][j].rgbtRed; int Bluereflect = image[i][width - 1 - j].rgbtBlue; int Greenreflect = image[i][width - 1 - j].rgbtGreen; int Redreflect = image[i][width - 1 - j].rgbtRed; int tmpB = image[i][j].rgbtBlue; image[i][j].rgbtBlue = image[i][width - 1 - j].rgbtBlue; image[i][width - 1 - j].rgbtBlue = tmpB; int tmpG = image[i][j].rgbtGreen; image[i][j].rgbtGreen = image[i][width - 1 - j].rgbtGreen; image[i][width - 1 - j].rgbtGreen = tmpG; int tmpR = image[i][j].rgbtRed; image[i][j].rgbtRed = image[i][width - 1 - j].rgbtRed; image[i][width - 1 - j].rgbtRed = tmpR; } } } return; if (width%2!=0) { for (int i=0 ; i < height; i++) { for (int j=0 ; j < round((width-1)/2); j++) { int blue = image[i][j].rgbtBlue; int green = image[i][j].rgbtGreen; int red = image[i][j].rgbtRed; int Bluereflect = image[i][width - 1 - j].rgbtBlue; int Greenreflect = image[i][width - 1 - j].rgbtGreen; int Redreflect = image[i][width - 1 - j].rgbtRed; int tmp_B = image[i][j].rgbtBlue; image[i][j].rgbtBlue = image[i][width - 1 - j].rgbtBlue; image[i][width - 1 - j].rgbtBlue = tmp_B; int tmp_G = image[i][j].rgbtGreen; image[i][j].rgbtGreen = image[i][width - 1 - j].rgbtGreen; image[i][width - 1 - j].rgbtGreen = tmp_G; int tmp_R = image[i][j].rgbtRed; image[i][j].rgbtRed = image[i][width - 1 - j].rgbtRed; image[i][width - 1 - j].rgbtRed = tmp_R; } } } return; }