The function invertPixel(pixel) is supposed to invert the color values of a pixel. However, there is an issue in the code. Instead of inverting the color values, it is subtracting the color value from 255. To fix this, we need to subtract the color value from 255 and assign the result to the color value. Here is the corrected code:
function invertPixel(pixel) {
pixel[RED] = MAX_COLOR_VALUE - pixel[RED];
pixel[GREEN] = MAX_COLOR_VALUE - pixel[GREEN];
pixel[BLUE] = MAX_COLOR_VALUE - pixel[BLUE];
return pixel;
}
Also, the invert() function should modify the color values using the corrected invertPixel() function, like this:
function invert(image) {
for (var x = 0; x < image.getWidth(); x++) {
for (var y = 0; y < image.getHeight(); y++) {
// Get the current pixel
var pixel = image.getPixel(x, y);
// Modify the current pixel
pixel = invertPixel(pixel);
// Update the image with the modified pixel
image.setRed(x, y, pixel[RED]);
image.setGreen(x, y, pixel[GREEN]);
image.setBlue(x, y, pixel[BLUE]);
}
}
}