Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // перенос пикселя при создании коллажа
- void replace(png_byte *new_pixel, png_byte *old_pixel, int width_pixel) {
- for (int i = 0; i < width_pixel; i++) {
- new_pixel[i] = old_pixel[i];
- }
- }
- void make_collage(struct Png *image, int width_pixel, int x_photos, int y_photos) {
- int new_width = image->width * x_photos;
- int new_height = image->height * y_photos;
- png_byte **new_mas = (png_byte **) malloc(sizeof(png_byte * ) * new_height);
- for (int y = 0; y < new_height; y++)
- new_mas[y] = (png_byte *) malloc(sizeof(png_byte) * new_width * width_pixel);
- for (int y = 0; y < new_height; y++) {
- int old_y = y % image->height;
- png_byte *old_row = image->row_pointers[old_y];
- png_byte *new_row = new_mas[y];
- for (int x = 0; x < new_width; x++) {
- int old_x = x % image->width;
- png_byte *old_pixel = &(old_row[old_x * width_pixel]);
- png_byte *new_pixel = &(new_row[x * width_pixel]);
- replace(new_pixel, old_pixel, width_pixel);
- }
- }
- for (int x = 0; x < image->height; x++) {
- free(image->row_pointers[x]);
- }
- free(image->row_pointers);
- image->row_pointers = new_mas;
- image->width = new_width;
- image->height = new_height;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement