From e56d1eff13bf8b6863cd213db157b9544cb9e3a7 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 21 Jul 2015 18:46:24 +0000
Subject: [PATCH] Switch to fast resize

---
 src/image.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 48 insertions(+), 9 deletions(-)

diff --git a/src/image.c b/src/image.c
index 2e5d756..ae8ca0a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -59,6 +59,14 @@
     }
 }
 
+void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b)
+{
+    int i;
+    for(i = 0; i < w; ++i){
+        draw_box(a, x1+i, y1+i, x2-i, y2-i, r, g, b);
+    }
+}
+
 void flip_image(image a)
 {
     int i,j,k;
@@ -179,6 +187,7 @@
 {
     int x,y,k;
     image copy = copy_image(p);
+    constrain_image(copy);
     rgbgr_image(copy);
     //normalize_image(copy);
 
@@ -199,7 +208,8 @@
         }
     }
     free_image(copy);
-    if(disp->height < 448 || disp->width < 448 || disp->height > 1000){
+    if(0){
+    //if(disp->height < 448 || disp->width < 448 || disp->height > 1000){
         int w = 448;
         int h = w*p.h/p.w;
         if(h > 1000){
@@ -322,7 +332,7 @@
             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);
             }
         }
@@ -539,7 +549,7 @@
    }
  */
 
-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);
@@ -554,23 +564,47 @@
     return val;
 }
 
-// #wikipedia
 image resize_image(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);
     float h_scale = (float)(im.h - 1) / (h - 1);
     for(k = 0; k < im.c; ++k){
-        for(r = 0; r < h; ++r){
+        for(r = 0; r < im.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);
+                float val = 0;
+                if(c == w-1){
+                    val = get_pixel(im, im.w-1, r, k);
+                } else {
+                    float sx = c*w_scale;
+                    int ix = (int) sx;
+                    float dx = sx - ix;
+                    val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k);
+                }
+                set_pixel(part, c, r, k, val);
             }
         }
     }
+    for(k = 0; k < im.c; ++k){
+        for(r = 0; r < h; ++r){
+            float sy = r*h_scale;
+            int iy = (int) sy;
+            float dy = sy - iy;
+            for(c = 0; c < w; ++c){
+                float val = (1-dy) * get_pixel(part, c, iy, k);
+                set_pixel(resized, c, r, k, val);
+            }
+            if(r == h-1) continue;
+            for(c = 0; c < w; ++c){
+                float val = dy * get_pixel(part, c, iy+1, k);
+                add_pixel(resized, c, r, k, val);
+            }
+        }
+    }
+
+    free_image(part);
     return resized;
 }
 
@@ -718,6 +752,11 @@
     assert(x < m.w && y < m.h && c < m.c);
     m.data[c*m.h*m.w + y*m.w + x] = val;
 }
+void add_pixel(image m, int x, int y, int c, float val)
+{
+    assert(x < m.w && y < m.h && c < m.c);
+    m.data[c*m.h*m.w + y*m.w + x] += val;
+}
 
 void print_image(image m)
 {

--
Gitblit v1.10.0