Advertisement
LilChicha174

Untitled

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