My image is blown out. It is not dark its mostly light.
Chat GPT says everything is fine. I looked over the logic, its fine. Its not rounding its not a integer or double issue. Its not a calculation issue. I have no idea what the issue is. Maybe its that the values in in the image 2d array are different then the copied temp 2d array. I am really not sure.
RGBTRIPLE temp[height][width]; //(*temp)[width] = malloc(height * sizeof(RGBTRIPLE[width]));
/*
if (temp == NULL)
{
fprintf(stderr, "Not enough memory to store temp.n");
return;
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
temp[i][j] = image[i][j];
}
}
*/
int Gx[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, 1}};
int Gy[3][3] = {{-1, -2, 1}, {0, 0, 0}, {1, 2, 1}};
int GxBlue, GxRed, GxGreen;
int GyBlue, GyRed, GyGreen;
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
GxRed = 0;
GxBlue = 0;
GxGreen = 0;
GyRed = 0;
GyBlue = 0;
GyGreen = 0;
double GB;
double GR;
double Gg;
for (int k = -1; k < 2; k++)
{
for (int f = -1; f < 2; f++)
{
int newI = i + k;
int newJ = j + f;
if (newI > 0 && newI < height && newJ > 0 && newJ < width )
{
GxBlue += image[newI][newJ].rgbtBlue * Gx[k + 1][f + 1];
GxRed += image[newI][newJ].rgbtRed * Gx[k + 1][f + 1];
GxGreen += image[newI][newJ].rgbtGreen * Gx[k + 1][f + 1];
GyBlue += image[newI][newJ].rgbtBlue * Gy[k + 1][f + 1];
GyRed += image[newI][newJ].rgbtRed * Gy[k + 1][f + 1];
GyGreen += image[newI][newJ].rgbtGreen * Gy[k + 1][f + 1];
}
}
}
GB = fmin(round(sqrt((GxBlue * GxBlue) + (GyBlue * GyBlue))), 255);
GR = fmin(round(sqrt((GxRed * GxRed) + (GyRed * GyRed))), 255);
Gg = fmin(round(sqrt((GxGreen * GxGreen) + (GyGreen * GyGreen))), 255);
temp[i][j].rgbtBlue = GB;
temp[i][j].rgbtRed = GR;
temp[i][j].rgbtGreen = Gg;
}
}
for (int i = 0; i < height; i++)
{
for (int j = 0; j < width; j++)
{
image[i][j] = temp[i][j];
}
}
return;
}
New contributor
Roatleroy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.