Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void glue(struct Png *image, struct Png *image2, int width_pixel) {
- png_byte *new_row, img2_row, img2_ptr;
- int new_height;
- int new_width = image->width + image2->width;
- if (image->height > image2->height)
- new_height = image->height;
- else
- new_height = image2->height;
- 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++) {
- new_row = new_mas[y];
- for (int x = 0; x < new_width; x++) {
- png_byte *new_ptr = &(new_row[x * width_pixel]);
- new_ptr[0] = 255;
- new_ptr[1] = 255;
- new_ptr[2] = 255;
- }
- }
- for (int y = 0; y < new_height; y++) {
- new_row = new_mas[y];
- for (int x = 0; x < new_width; x++) {
- png_byte *new_ptr = &(new_row[x * width_pixel]);
- if ((x - image->width) < 0 && y < image->height) {
- png_byte *img1_row = image->row_pointers[y];
- png_byte *img1_ptr = &(img1_row[x * width_pixel]);
- new_ptr[0] = img1_ptr[0];
- new_ptr[1] = img1_ptr[1];
- new_ptr[2] = img1_ptr[2];
- } else if ((x - image->width) >= 0 && y < image2->height) {
- png_byte *img2_row = image2->row_pointers[y];
- png_byte *img2_ptr = &(img2_row[(x - image->width) * width_pixel]);
- new_ptr[0] = img2_ptr[0];
- new_ptr[1] = img2_ptr[1];
- new_ptr[2] = img2_ptr[2];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement