I have this function semi-working, but it seems that the image that comes out is overly-blurred. this is because it is processing already blurred portions, I imagine?
I was told I need to write it to a new image, but I can't figure out how to create that. When I was using the Image tempImage constructor, I was getting errors of segmentation fault and could not determine why. Prior to this function, there is a function scaleUp
that makes the image larger and save it to newImage.pixelData
, created by the constructor Image newImage(width*numTimes, height*numTimes, colorMode);
void Image::simpleBlur(int numPixels)
{
int middlePixX, middlePixY, redSum, greenSum, blueSum, denominator = 0;
//Image tempImage(width, height, colorMode);
//tempImage.createImage(width, height);
for (int middlePixX = 0; middlePixX < width; middlePixX++)
{
for (int middlePixY = 0; middlePixY < height; middlePixY++)
{
for (int x_subgrid = -1*numPixels; x_subgrid <= numPixels; x_subgrid++) //for (int x_subgrid = 0; x_subgrid < DIM_SQUARE; x_subgrid++)
{
for (int y_subgrid = -1*numPixels; y_subgrid <= numPixels; y_subgrid++) //for (int y_subgrid = 0; y_subgrid < DIM_SQUARE; y_subgrid++)
{
int xPos = x_subgrid + middlePixX;
int yPos = y_subgrid + middlePixY;
if( xPos >= 0 && xPos < width && yPos >= 0 && yPos < height )
{
redSum = redSum + pixelData[xPos][yPos].getRed();
greenSum = greenSum + pixelData[xPos][yPos].getGreen();
blueSum = blueSum + pixelData[xPos][yPos].getBlue();
denominator++;
}
}
}
redSum = redSum / denominator;
greenSum = greenSum / denominator;
blueSum = blueSum / denominator;
pixelData[middlePixX][middlePixY].setRed(redSum);
pixelData[middlePixX][middlePixY].setGreen(greenSum);
pixelData[middlePixX][middlePixY].setBlue(blueSum);
redSum, greenSum, blueSum = 0; denominator = 0;
}
}
}