Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void bridge(struct Png *image, int x1, int y1, int x3, int y3, int width_pixel) {
- int x2 = x1, y2 = y3;
- int x4 = x3, y4 = y1;
- int new_width = sqrt((x4 - x1) * (x4 - x1) + (y4 - y1) * (y4 - y1));
- int new_height = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
- 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 = y1; y < y2; y++) {
- png_byte *row = image->row_pointers[y];
- png_byte *new_row = new_mas[y - y1];
- for (int x = x1; x < x4; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- png_byte *new_ptr = &(new_row[(x - x1) * width_pixel]);
- new_ptr[0] = ptr[0];
- new_ptr[1] = ptr[1];
- new_ptr[2] = ptr[2];
- }
- }
- for (int y = 0; y < image->height; y++) {
- png_byte *row = image->row_pointers[y];
- png_byte *new_row = new_mas[y%new_height];
- for (int x = 0; x < image->width; x++) {
- png_byte *ptr = &(row[x * width_pixel]);
- png_byte *new_ptr = &(new_row[(x % new_width) * width_pixel]);
- ptr[0] = new_ptr[0];
- ptr[1] = new_ptr[1];
- ptr[2] = new_ptr[2];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement