Skip to content

Commit

Permalink
ImageBlend fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RevengeRL1 committed Nov 20, 2023
1 parent 636d8ae commit 1c07300
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions image8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -576,28 +576,23 @@ void ImageBlend(Image img1, int x, int y, Image img2, double alpha) { ///
assert (ImageValidRect(img1, x, y, img2->width, img2->height));
// Insert your code here!
int img1Width = img1->width;
int img1Height = img1->height;
int img2Width = img2->width;
int img2Height = img2->height;

for (int i = 0; i < img2Height; ++i) {
for (int j = 0; j < img2Width; ++j) {
int new_x = x + j;
int new_y = y + i;

if (new_x >= 0 && new_x < img1Width && new_y >= 0 && new_y < img1Height) {
uint8 pixel1 = ImageGetPixel(img1, new_x, new_y);
uint8 pixel2 = ImageGetPixel(img2, j, i);


uint8 blended_pixel = (uint8)(alpha * pixel2 + (1 - alpha) * pixel1);


ImageSetPixel(img1, new_x, new_y, blended_pixel);
}
}
int img1Height = img1->height;
int img2Width = img2->width;
int img2Height = img2->height;

for (int i = 0; i < img2Height; ++i) {
for (int j = 0; j < img2Width; ++j) {
int new_x = x + j;
int new_y = y + i;

if (new_x >= 0 && new_x < img1Width && new_y >= 0 && new_y < img1Height) {
uint8 pixel1 = ImageGetPixel(img1, new_x, new_y);
uint8 pixel2 = ImageGetPixel(img2, j, i);
uint8 blended_pixel = (uint8)(alpha * pixel2 + (1 - alpha) * pixel1);
ImageSetPixel(img1, new_x, new_y, blended_pixel);
}
}

}
}

/// Compare an image to a subimage of a larger image.
Expand Down

0 comments on commit 1c07300

Please sign in to comment.