Skip to content

Commit

Permalink
ImagePaste done
Browse files Browse the repository at this point in the history
  • Loading branch information
RevengeRL1 committed Nov 20, 2023
1 parent 08c03de commit 939be86
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions image8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,22 @@ void ImagePaste(Image img1, int x, int y, Image img2) { ///
assert (img2 != NULL);
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 pixel = ImageGetPixel(img2, j, i);
ImageSetPixel(img1, new_x, new_y, pixel);
}
}
}
}

/// Blend an image into a larger image.
Expand Down

0 comments on commit 939be86

Please sign in to comment.