Skip to content

Commit

Permalink
tentativa blur
Browse files Browse the repository at this point in the history
  • Loading branch information
RevengeRL1 committed Nov 22, 2023
1 parent 62f9b28 commit 139fa20
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions image8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,5 +650,46 @@ int ImageLocateSubImage(Image img1, int* px, int* py, Image img2) { ///
/// The image is changed in-place.
void ImageBlur(Image img, int dx, int dy) { ///
// Insert your code here!
assert(img != NULL);
assert(dx >= 0 && dy >= 0);

int width = img->width;
int height = img->height;

Image tempImg = ImageCreate(width, height, img->maxval);
if (tempImg == NULL) {
return;
}

for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
int sum = 0;
int count = 0;

for (int i = -dy; i <= dy; i++) {
for (int j = -dx; j <= dx; j++) {
int new_x = x + j;
int new_y = y + i;

if (new_x >= 0 && new_x < width && new_y >= 0 && new_y < height) {
sum += ImageGetPixel(img, new_x, new_y);
count++;
}
}
}

if (count > 0) {
uint8 meanValue = (uint8)(sum / count + 0.5);
ImageSetPixel(tempImg, x, y, meanValue);
}
}
}
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
uint8 blurredValue = (uint8)(ImageGetPixel(tempImg, x, y) + 0.5);
ImageSetPixel(img, x, y, blurredValue);
}
}
ImageDestroy(&tempImg);
}

0 comments on commit 139fa20

Please sign in to comment.