0

I don't understand the error message, and i've been trying to modify the code to fix the error but it still appears.

// Blur image
void blur(int height, int width, RGBTRIPLE image[height][width])
{
RGBTRIPLE (*copy_image)[width] = calloc(height, width * sizeof(RGBTRIPLE)), avg_image[height][width];

for (int i = 0; i < height; i ++)
{
    for (int j = 0; j < width; j ++)
    {
        copy_image[i][j] = image[i][j];
        avg_image[i][j] = image[i][j];
        int boxes;
        int newline_i;
        int newline_j;
        float sum_red = 0, sum_green = 0, sum_blue = 0;
        //line[3] = {-1, 0, 1};

         //corner pixels
        if ((i == 0 || i == height - 1) && (j == 0 || j == width - 1))
        {
            boxes = 4;
        }

        //vertical edge pixels
        else if ((i == 0 || i == height - 1) && (j != 0 || j != width - 1))
        {
            boxes = 6;
        }

        //horizontal edge pixels
        else if ((j == 0 || j == width - 1) && (i != 0 || i != height - 1))
        {
            boxes = 6;
        }

        //center pixel
        else
        {
            boxes = 9;
        }


        pixels(height, width, copy_image[height][width], sum_red, sum_green, sum_blue);
        average(height, width, avg_image[height][width], boxes, sum_red, sum_green, sum_blue);
    }
}

//loop to allocate the new values to the old image
for (int i = 0; i < height; i ++)
{
    for (int j = 0; j < width; j ++)
    {
        image[i][j] = copy_image[i][j];
    }
}

free(copy_image);

return;
}


void pixels(int height, int width, RGBTRIPLE copy_image[height][width], float sum_red, float sum_green, float sum_blue)
{
for (int i = 0; i < height; i ++)
{
    for (int j = 0; j < width; j ++)
    {
        //middle pixel
        if (i >= 0 && j >= 0)
        {
            for (int a = i - 1; a < i + 2; a ++)
            {
                for (int b = j - 1; b < j + 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }
        //CORNER PIXELS

        //left bottom corner pixel
        else if (i == height - 1 && j == 0)
        {
            //loop through surrounding 4 pixels
        for (int a = i; a < 2; a ++)
            {
                for (int b = j; b < 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //left top corner pixel
        else if (i == 0 && j == 0)
        {
            //loop through surrounding 4 pixels
            for (int a = i - 1; a < 2; a ++)
            {
                for (int b = j; b < 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //right top corner pixel
        else if (i == 0 && j == width - 1)
        {
            //loop through the four pixels
            for (int a = i - 1; a < 2; a ++)
            {
                for (int b = j - 1; b < 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //right bottom corner pixel
        else if (i == height - 1 && j == width - 1)
        {
            //loop through the four pixels
            for (int a = i; a < 2; a ++)
            {
                for (int b = j - 1; b < 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //EDGES

        //top edge
        else if ((i == 0) && (j >= 1 && j <= width - 2))
        {
            for (int a = i; a < 2; a ++)
            {
                for (int b = j - 1; b < j + 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //left edge
        else if ((i >= 1 && i <= height - 2) && (j == 0))
        {
            for (int a = i - 1; a < i + 2; a ++)
            {
                for (int b = j; b < 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //bottom edge
        else if ((i == height - 1) && (j <= width - 2 && j >= 1))
        {
            for (int a = i - 1; a < 2; a ++)
            {
                for (int b = j - 1; b < j + 2; b ++)
                {
                    sum_red += copy_image[a][b].rgbtRed;
                    sum_green += copy_image[a][b].rgbtGreen;
                    sum_blue += copy_image[a][b].rgbtBlue;
                }
            }
        }

        //right edge
        else if ((i >= 1 && i <= height - 2) && (j == width - 1))
        {
            for (int a = i - 1; a < i + 2; a ++)
            {
                for (int b = j - 1; b < 2; b ++)
                {
                    sum_red +=  copy_image[a][b].rgbtRed;
                    sum_green +=  copy_image[a][b].rgbtGreen;
                    sum_blue +=  copy_image[a][b].rgbtBlue;
                }
            }
        }
    }
}

return;
}

void average(int height, int width, RGBTRIPLE avg_image[height][width], int boxes, float sum_red, float sum_green, float sum_blue)
{
for (int i = 0; i < height; i ++)
{
    for (int j = 0; j < width; j ++)
    {
        avg_image[i][j].rgbtRed = round(sum_red / boxes);
        avg_image[i][j].rgbtGreen = round(sum_green / boxes);
        avg_image[i][j].rgbtBlue = round(sum_blue / boxes);
    }
}
return;
}

this is the error message:

clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -Qunused-arguments -std=c11 
-Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o filter 
filter.c helpers.c
helpers.c:110:35: error: passing 'RGBTRIPLE' to parameter of incompatible type 'RGBTRIPLE (*)[*]'
            pixels(height, width, copy_image[height][width], sum_red, sum_green, sum_blue);
                              ^~~~~~~~~~~~~~~~~~~~~~~~~
./helpers.h:15:47: note: passing argument to parameter 'copy_image' here
void pixels( int height, int width, RGBTRIPLE copy_image[height][width], float sum_red, float 
sum_green, float sum_blue);
                                          ^
helpers.c:111:36: error: passing 'RGBTRIPLE' to parameter of incompatible type 'RGBTRIPLE (*)[*]'
            average(height, width, avg_image[height][width], boxes, sum_red, sum_green, sum_blue);
                               ^~~~~~~~~~~~~~~~~~~~~~~~
./helpers.h:17:47: note: passing argument to parameter 'avg_image' here
void average(int height, int width, RGBTRIPLE avg_image[height][width], int boxes, float sum_red, 
float sum_green, float sum_blue);
                                          ^
0

The errors are the same issue. The 3rd parameter that the pixels() function takes is an array of RGBTRIPLEs. The problem is that the array that the code is trying to pass is declared as an array of POINTERS to RGBTRIPLEs. The code can't pass an array of pointers when an array of RGBTRIPLES is expected.

Look at the declaration:

RGBTRIPLE (*copy_image)[width] = calloc(height, width * sizeof(RGBTRIPLE)), avg_image[height][width];

That first asterisk makes it an array of POINTERS. Remove the asterisk and it becomes a declaration of an array of RGBTRIPLEs. That also means that a calloc is not needed. The memory will automatically be allocated.

Next, wouldn't this need to be a 2 dimensional array?

There will be additional cleanup needed in the code. Any errors that you see when compiling will guide you on what to do.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .