Advertisement
LilChicha174

Untitled

May 22nd, 2022
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. // перенос пикселя при создании коллажа
  2. void replace(png_byte *new_pixel, png_byte *old_pixel, int width_pixel) {
  3.     for (int i = 0; i < width_pixel; i++) {
  4.         new_pixel[i] = old_pixel[i];
  5.     }
  6. }
  7.  
  8. void make_collage(struct Png *image, int width_pixel, int x_photos, int y_photos) {
  9.     int new_width = image->width * x_photos;
  10.     int new_height = image->height * y_photos;
  11.  
  12.     png_byte **new_mas = (png_byte **) malloc(sizeof(png_byte * ) * new_height);
  13.     for (int y = 0; y < new_height; y++)
  14.         new_mas[y] = (png_byte *) malloc(sizeof(png_byte) * new_width * width_pixel);
  15.     for (int y = 0; y < new_height; y++) {
  16.         int old_y = y % image->height;
  17.         png_byte *old_row = image->row_pointers[old_y];
  18.         png_byte *new_row = new_mas[y];
  19.         for (int x = 0; x < new_width; x++) {
  20.             int old_x = x % image->width;
  21.             png_byte *old_pixel = &(old_row[old_x * width_pixel]);
  22.             png_byte *new_pixel = &(new_row[x * width_pixel]);
  23.             replace(new_pixel, old_pixel, width_pixel);
  24.         }
  25.     }
  26.     for (int x = 0; x < image->height; x++) {
  27.         free(image->row_pointers[x]);
  28.     }
  29.     free(image->row_pointers);
  30.  
  31.     image->row_pointers = new_mas;
  32.     image->width = new_width;
  33.     image->height = new_height;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement