Advertisement
LilChicha174

Untitled

Jun 5th, 2022
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.50 KB | None | 0 0
  1. void glue2(struct Png *image, struct Png *image2, int width_pixel) {
  2.     png_byte *new_row, img2_row, img2_ptr;
  3.     int new_height, new_width;
  4. //    int new_width = image->width + image2->width;
  5.     if (image->height > image2->height)
  6.         new_height = image2->height;
  7.     else
  8.         new_height = image->height;
  9.  
  10.     if (image->width > image2->width)
  11.         new_width = image2->width;
  12.     else
  13.         new_width = image->width;
  14.  
  15.     png_byte **new_mas = (png_byte **) malloc(sizeof(png_byte * ) * new_height);
  16.     for (int y = 0; y < new_height; y++)
  17.         new_mas[y] = (png_byte *) malloc(sizeof(png_byte) * new_width * width_pixel);
  18.  
  19.     for (int x = 0; x < new_width; x++) {
  20.         for (int y = 0; y < new_height; y++) {
  21.             new_row = new_mas[y];
  22.             png_byte *new_ptr = &(new_row[x * width_pixel]);
  23.             png_byte *img1_row = image->row_pointers[y];
  24.             png_byte *img1_ptr = &(img1_row[x * width_pixel]);
  25.             png_byte *img2_row = image2->row_pointers[y];
  26.             png_byte *img2_ptr = &(img2_row[x * width_pixel]);
  27.             if (x % 2 == 0) {
  28.                 new_ptr[0] = img1_ptr[0];
  29.                 new_ptr[1] = img1_ptr[1];
  30.                 new_ptr[2] = img1_ptr[2];
  31.             } else {
  32.                 new_ptr[0] = img2_ptr[0];
  33.                 new_ptr[1] = img2_ptr[1];
  34.                 new_ptr[2] = img2_ptr[2];
  35.             }
  36.         }
  37.     }
  38.     image->row_pointers = new_mas;
  39.     image->width = new_width;
  40.     image->height = new_height;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement