Advertisement
LilChicha174

Untitled

Jun 5th, 2022
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. void bridge(struct Png *image, int x1, int y1, int x3, int y3, int width_pixel) {
  2.     int x2 = x1, y2 = y3;
  3.     int x4 = x3, y4 = y1;
  4.     int new_width = sqrt((x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1));
  5.     int new_height = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
  6.     png_byte **new_mas = (png_byte **) malloc(sizeof(png_byte * ) * new_height);
  7.     for (int y = 0; y < new_height; y++)
  8.         new_mas[y] = (png_byte *) malloc(sizeof(png_byte) * new_width * width_pixel);
  9.     for (int y = y1; y < y2; y++) {
  10.         png_byte *row = image->row_pointers[y];
  11.         png_byte *new_row = new_mas[y - y1];
  12.         for (int x = x1; x < x4; x++) {
  13.             png_byte *ptr = &(row[x * width_pixel]);
  14.             png_byte *new_ptr = &(new_row[(x - x1) * width_pixel]);
  15.             new_ptr[0] = ptr[0];
  16.             new_ptr[1] = ptr[1];
  17.             new_ptr[2] = ptr[2];
  18.         }
  19.     }
  20.     for (int y = 0; y < image->height; y++) {
  21.         png_byte *row = image->row_pointers[y];
  22.         png_byte *new_row = new_mas[y%new_height];
  23.         for (int x = 0; x < image->width; x++) {
  24.             png_byte *ptr = &(row[x * width_pixel]);
  25.             png_byte *new_ptr = &(new_row[(x % new_width) * width_pixel]);
  26.             ptr[0] = new_ptr[0];
  27.             ptr[1] = new_ptr[1];
  28.             ptr[2] = new_ptr[2];
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement