| | |
| | | int x,y,k; |
| | | image copy = copy_image(p); |
| | | constrain_image(copy); |
| | | rgbgr_image(copy); |
| | | if(p.c == 3) rgbgr_image(copy); |
| | | //normalize_image(copy); |
| | | |
| | | char buff[256]; |
| | |
| | | } |
| | | } |
| | | int success = stbi_write_png(buff, im.w, im.h, im.c, data, im.w*im.c); |
| | | free(data); |
| | | if(!success) fprintf(stderr, "Failed to write image %s\n", buff); |
| | | } |
| | | |
| | |
| | | for(x = 0; x < im.w; ++x){ |
| | | float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx; |
| | | float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy; |
| | | float val = billinear_interpolate(im, rx, ry, c); |
| | | float val = bilinear_interpolate(im, rx, ry, c); |
| | | set_pixel(rot, x, y, c, val); |
| | | } |
| | | } |
| | |
| | | } |
| | | */ |
| | | |
| | | float billinear_interpolate(image im, float x, float y, int c) |
| | | float bilinear_interpolate(image im, float x, float y, int c) |
| | | { |
| | | int ix = (int) floorf(x); |
| | | int iy = (int) floorf(y); |
| | |
| | | return val; |
| | | } |
| | | |
| | | // #wikipedia |
| | | image resize_image(image im, int w, int h) |
| | | { |
| | | image resized = make_image(w, h, im.c); |
| | | int r, c, k; |
| | | float w_scale = (float)(im.w - 1) / (w - 1); |
| | | float h_scale = (float)(im.h - 1) / (h - 1); |
| | | for(k = 0; k < im.c; ++k){ |
| | | for(r = 0; r < h; ++r){ |
| | | for(c = 0; c < w; ++c){ |
| | | float sx = c*w_scale; |
| | | float sy = r*h_scale; |
| | | float val = billinear_interpolate(im, sx, sy, k); |
| | | set_pixel(resized, c, r, k, val); |
| | | } |
| | | } |
| | | } |
| | | return resized; |
| | | } |
| | | |
| | | image resize_image2(image im, int w, int h) |
| | | { |
| | | image resized = make_image(w, h, im.c); |
| | | image part = make_image(w, im.h, im.c); |
| | | int r, c, k; |
| | | float w_scale = (float)(im.w - 1) / (w - 1); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | for(k = 0; k < im.c; ++k){ |
| | | for(r = 0; r < h; ++r){ |
| | | float sy = r*h_scale; |
| | |
| | | void show_images(image *ims, int n, char *window) |
| | | { |
| | | image m = collapse_images_vert(ims, n); |
| | | save_image(m, window); |
| | | show_image(m, window); |
| | | int w = 448; |
| | | int h = ((float)m.h/m.w) * 448; |
| | | if(h > 896){ |
| | | h = 896; |
| | | w = ((float)m.w/m.h) * 896; |
| | | } |
| | | image sized = resize_image(m, w, h); |
| | | save_image(sized, window); |
| | | show_image(sized, window); |
| | | free_image(sized); |
| | | free_image(m); |
| | | } |
| | | |