Skip to content

Commit

Permalink
Correção da função ImageCrop
Browse files Browse the repository at this point in the history
  • Loading branch information
TiagoA04 committed Nov 20, 2023
1 parent 5e68c1c commit 645e5cf
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions image8bit.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,21 +527,17 @@ Image ImageCrop(Image img, int x, int y, int w, int h) { ///
assert (img != NULL);
assert (ImageValidRect(img, x, y, w, h));
// Insert your code here!
Image newImg = ImageCreate(h, w, img->maxval);
Image newImg = ImageCreate(w, h, img->maxval);
if (newImg == NULL) {
return NULL;
}
int coordX = x;
int coordY = y;
for(int index = 0; index < w * h; index++){
uint8 level = ImageGetPixel(img, coordX, coordY);
if(coordX >= w){
coordX = x;
coordY++;
for(coordY = y; coordY < y + h; coordY++){
for(coordX = x; coordX < x + w; coordX++){
uint8 level = ImageGetPixel(img, coordX, coordY);
ImageSetPixel(newImg, coordX - x, coordY - y, level);
}
else
coordX++;
ImageSetPixel(newImg, coordX, coordY, level);
}
return newImg;
}
Expand Down

0 comments on commit 645e5cf

Please sign in to comment.