Advertisement
LilChicha174

Untitled

Jun 6th, 2022
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.63 KB | None | 0 0
  1. void cut(struct Png *image, int x1, int y1, int x2, int y2) {
  2.     int y, x;
  3.     for (y = 0; y <= y2 - y1; y++) {
  4.         png_byte *cut_row1 = image->row_pointers[y + y1];
  5.         for (x = 0; x <= x2 - x1; x++) {
  6.             png_byte *row = image->row_pointers[y];
  7.             png_byte *ptr = &(row[x * 3]);
  8.             png_byte *cut_ptr1 = &(cut_row1[(x + x1) * 3]);
  9.             ptr[0] = cut_ptr1[0];
  10.             ptr[1] = cut_ptr1[1];
  11.             ptr[2] = cut_ptr1[2];
  12.         }
  13.     }
  14.     for (y = y2 - y1 + 1; y < image->height; y++)
  15.         free(image->row_pointers[y]);
  16.     image->height = y2 - y1;
  17.     image->width = x2 - x1;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement