This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project gfxprim.git.
The branch, master has been updated via 09241d96413a6376d399b4e81219fdf2d9fb1462 (commit) from 1d97b3f64cb80fea14245d253f6c7db64b8495b2 (commit)
Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below.
- Log ----------------------------------------------------------------- http://repo.or.cz/w/gfxprim.git/commit/09241d96413a6376d399b4e81219fdf2d9fb1...
commit 09241d96413a6376d399b4e81219fdf2d9fb1462 Author: Cyril Hrubis metan@ucw.cz Date: Sun Jan 22 18:09:25 2012 +0100
filters: BiCubic now the coordinate mapping is right.
diff --git a/libs/filters/GP_Linear.c b/libs/filters/GP_Linear.c index 7101472..447e805 100644 --- a/libs/filters/GP_Linear.c +++ b/libs/filters/GP_Linear.c @@ -16,7 +16,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
diff --git a/libs/filters/GP_Resize.c b/libs/filters/GP_Resize.c index 7b26eaa..a29ec0d 100644 --- a/libs/filters/GP_Resize.c +++ b/libs/filters/GP_Resize.c @@ -16,10 +16,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, * * Boston, MA 02110-1301 USA * * * - * Copyright (C) 2009-2011 Cyril Hrubis metan@ucw.cz * + * Copyright (C) 2009-2012 Cyril Hrubis metan@ucw.cz * * * *****************************************************************************/
+#include <math.h> + #include <GP_Context.h> #include <GP_GetPutPixel.h>
@@ -92,6 +94,13 @@ typedef union v4f {
#define SUM_V4SF(a) ((a).f[0] + (a).f[1] + (a).f[2] + (a).f[3])
+#define CLAMP(val) do { + if (val < 0) + val = 0; + if (val > 255) + val = 255; +} while (0) + int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst, GP_ProgressCallback *callback) { @@ -105,28 +114,36 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst, for (i = 0; i < dst->w; i++) { float x = (1.00 * i / dst->w) * src->w; v4f cvx; - int xi = x - 1; + int xi[4]; + + xi[0] = floor(x - 1); + xi[1] = x; + xi[2] = x + 1; + xi[3] = x + 2; + + cvx.f[0] = cubic(xi[0] - x); + cvx.f[1] = cubic(xi[1] - x); + cvx.f[2] = cubic(xi[2] - x); + cvx.f[3] = cubic(xi[3] - x); - if (xi < 0) - xi = 0; + if (xi[0] < 0) + xi[0] = 0;
- if (xi > (int)src->w - 4) - xi = src->w - 4; + if (xi[2] >= (int)src->w) + xi[2] = src->w - 1; - cvx.f[0] = cubic(xi - x); - cvx.f[1] = cubic(xi + 1 - x); - cvx.f[2] = cubic(xi + 2 - x); - cvx.f[3] = cubic(xi + 3 - x); + if (xi[3] >= (int)src->w) + xi[3] = src->w - 1; /* Generate interpolated column */ for (j = 0; j < src->h; j++) { v4f rv, gv, bv; GP_Pixel pix[4];
- pix[0] = GP_GetPixel_Raw_24BPP(src, xi, j); - pix[1] = GP_GetPixel_Raw_24BPP(src, xi + 1, j); - pix[2] = GP_GetPixel_Raw_24BPP(src, xi + 2, j); - pix[3] = GP_GetPixel_Raw_24BPP(src, xi + 3, j); + pix[0] = GP_GetPixel_Raw_24BPP(src, xi[0], j); + pix[1] = GP_GetPixel_Raw_24BPP(src, xi[1], j); + pix[2] = GP_GetPixel_Raw_24BPP(src, xi[2], j); + pix[3] = GP_GetPixel_Raw_24BPP(src, xi[3], j); rv.f[0] = GP_Pixel_GET_R_RGB888(pix[0]); rv.f[1] = GP_Pixel_GET_R_RGB888(pix[1]); @@ -157,33 +174,41 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst, float y = (1.00 * j / dst->h) * src->h; v4f cvy, rv, gv, bv; float r, g, b; - int yi = y - 1; - - if (yi < 0) - yi = 0; - - if (yi > (int)src->h - 4) - yi = src->h - 4; + int yi[4]; + + yi[0] = floor(y - 1); + yi[1] = y; + yi[2] = y + 1; + yi[3] = y + 2; + + cvy.f[0] = cubic(yi[0] - y); + cvy.f[1] = cubic(yi[1] - y); + cvy.f[2] = cubic(yi[2] - y); + cvy.f[3] = cubic(yi[3] - y); + + if (yi[0] < 0) + yi[0] = 0; + + if (yi[2] >= (int)src->h) + yi[2] = src->h - 1; + + if (yi[3] >= (int)src->h) + yi[3] = src->h - 1; - cvy.f[0] = cubic(yi - y); - cvy.f[1] = cubic(yi + 1 - y); - cvy.f[2] = cubic(yi + 2 - y); - cvy.f[3] = cubic(yi + 3 - y); - - rv.f[0] = col_r[yi]; - rv.f[1] = col_r[yi + 1]; - rv.f[2] = col_r[yi + 2]; - rv.f[3] = col_r[yi + 3]; + rv.f[0] = col_r[yi[0]]; + rv.f[1] = col_r[yi[1]]; + rv.f[2] = col_r[yi[2]]; + rv.f[3] = col_r[yi[3]]; - gv.f[0] = col_g[yi]; - gv.f[1] = col_g[yi + 1]; - gv.f[2] = col_g[yi + 2]; - gv.f[3] = col_g[yi + 3]; + gv.f[0] = col_g[yi[0]]; + gv.f[1] = col_g[yi[1]]; + gv.f[2] = col_g[yi[2]]; + gv.f[3] = col_g[yi[3]]; - bv.f[0] = col_b[yi]; - bv.f[1] = col_b[yi + 1]; - bv.f[2] = col_b[yi + 2]; - bv.f[3] = col_b[yi + 3]; + bv.f[0] = col_b[yi[0]]; + bv.f[1] = col_b[yi[1]]; + bv.f[2] = col_b[yi[2]]; + bv.f[3] = col_b[yi[3]]; rv = MUL_V4SF(rv, cvy); gv = MUL_V4SF(gv, cvy); @@ -193,24 +218,10 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst, g = SUM_V4SF(gv); b = SUM_V4SF(bv);
- if (r > 255) - r = 255; - - if (r < 0) - r = 0; - - if (g > 255) - g = 255; - - if (g < 0) - g = 0; - - if (b > 255) - b = 255; - - if (b < 0) - b = 0; - + CLAMP(r); + CLAMP(g); + CLAMP(b); + GP_Pixel pix = GP_Pixel_CREATE_RGB888((uint8_t)r, (uint8_t)g, (uint8_t)b); GP_PutPixel_Raw_24BPP(dst, i, j, pix); } @@ -238,137 +249,6 @@ int GP_FilterInterpolate_Cubic(const GP_Context *src, GP_Context *dst, int GP_FilterInterpolate_CubicInt(const GP_Context *src, GP_Context *dst, GP_ProgressCallback *callback) { - int32_t col_r[src->h], col_g[src->h], col_b[src->h]; - uint32_t i, j; - - GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f", - src->w, src->h, dst->w, dst->h, - 1.00 * dst->w / src->w, 1.00 * dst->h / src->h); - - for (i = 0; i < dst->w; i++) { - float x = (1.00 * i / dst->w) * src->w; - int32_t cvx[4]; - int xi = x - 1; - - if (xi < 0) - xi = 0; - - if (xi > (int)src->w - 4) - xi = src->w - 4; - - cvx[0] = cubic(xi - x) * MUL + 0.5; - cvx[1] = cubic(xi + 1 - x) * MUL + 0.5; - cvx[2] = cubic(xi + 2 - x) * MUL + 0.5; - cvx[3] = cubic(xi + 3 - x) * MUL + 0.5; - - /* Generate interpolated column */ - for (j = 0; j < src->h; j++) { - int32_t rv[4], gv[4], bv[4]; - GP_Pixel pix[4]; - - pix[0] = GP_GetPixel_Raw_24BPP(src, xi, j); - pix[1] = GP_GetPixel_Raw_24BPP(src, xi + 1, j); - pix[2] = GP_GetPixel_Raw_24BPP(src, xi + 2, j); - pix[3] = GP_GetPixel_Raw_24BPP(src, xi + 3, j); - - rv[0] = GP_Pixel_GET_R_RGB888(pix[0]); - rv[1] = GP_Pixel_GET_R_RGB888(pix[1]); - rv[2] = GP_Pixel_GET_R_RGB888(pix[2]); - rv[3] = GP_Pixel_GET_R_RGB888(pix[3]); - - gv[0] = GP_Pixel_GET_G_RGB888(pix[0]); - gv[1] = GP_Pixel_GET_G_RGB888(pix[1]); - gv[2] = GP_Pixel_GET_G_RGB888(pix[2]); - gv[3] = GP_Pixel_GET_G_RGB888(pix[3]); - - bv[0] = GP_Pixel_GET_B_RGB888(pix[0]); - bv[1] = GP_Pixel_GET_B_RGB888(pix[1]); - bv[2] = GP_Pixel_GET_B_RGB888(pix[2]); - bv[3] = GP_Pixel_GET_B_RGB888(pix[3]); - - MUL_I(rv, cvx); - MUL_I(gv, cvx); - MUL_I(bv, cvx); - - col_r[j] = SUM_I(rv); - col_g[j] = SUM_I(gv); - col_b[j] = SUM_I(bv); - } - - /* now interpolate column for new image */ - for (j = 0; j < dst->h; j++) { - float y = (1.00 * j / dst->h) * src->h; - int32_t cvy[4], rv[4], gv[4], bv[4]; - int32_t r, g, b; - int yi = y - 1; - - if (yi < 0) - yi = 0; - - if (yi > (int)src->h - 4) - yi = src->h - 4; - - cvy[0] = cubic(yi - y) * MUL + 0.5; - cvy[1] = cubic(yi + 1 - y) * MUL + 0.5; - cvy[2] = cubic(yi + 2 - y) * MUL + 0.5; - cvy[3] = cubic(yi + 3 - y) * MUL + 0.5; - - rv[0] = col_r[yi]; - rv[1] = col_r[yi + 1]; - rv[2] = col_r[yi + 2]; - rv[3] = col_r[yi + 3]; - - gv[0] = col_g[yi]; - gv[1] = col_g[yi + 1]; - gv[2] = col_g[yi + 2]; - gv[3] = col_g[yi + 3]; - - bv[0] = col_b[yi]; - bv[1] = col_b[yi + 1]; - bv[2] = col_b[yi + 2]; - bv[3] = col_b[yi + 3]; - - MUL_I(rv, cvy); - MUL_I(gv, cvy); - MUL_I(bv, cvy); - - r = (SUM_I(rv) + MUL*MUL/2) / MUL / MUL; - g = (SUM_I(gv) + MUL*MUL/2) / MUL / MUL; - b = (SUM_I(bv) + MUL*MUL/2) / MUL / MUL; - - if (r > 255) - r = 255; - - if (r < 0) - r = 0; - - if (g > 255) - g = 255; - - if (g < 0) - g = 0; - - if (b > 255) - b = 255; - - if (b < 0) - b = 0; - - GP_Pixel pix = GP_Pixel_CREATE_RGB888((uint8_t)r, (uint8_t)g, (uint8_t)b); - GP_PutPixel_Raw_24BPP(dst, i, j, pix); - } - - if (GP_ProgressCallbackReport(callback, i, dst->w, dst->h)) - return 1; - } - - GP_ProgressCallbackDone(callback); - return 0; -} - -int GP_FilterInterpolate_CubicInt2(const GP_Context *src, GP_Context *dst, - GP_ProgressCallback *callback) -{ int32_t col_r[src->w], col_g[src->w], col_b[src->w]; uint32_t i, j;
@@ -379,28 +259,36 @@ int GP_FilterInterpolate_CubicInt2(const GP_Context *src, GP_Context *dst, for (i = 0; i < dst->h; i++) { float y = (1.00 * i / dst->h) * src->h; int32_t cvy[4]; - int yi = y - 1; + int yi[4]; - if (yi < 0) - yi = 0; - - if (yi > (int)src->h - 4) - yi = src->h - 4; + yi[0] = floor(y - 1); + yi[1] = y; + yi[2] = y + 1; + yi[3] = y + 2; - cvy[0] = cubic(yi - y) * MUL + 0.5; - cvy[1] = cubic(yi + 1 - y) * MUL + 0.5; - cvy[2] = cubic(yi + 2 - y) * MUL + 0.5; - cvy[3] = cubic(yi + 3 - y) * MUL + 0.5; + cvy[0] = cubic(yi[0] - y) * MUL + 0.5; + cvy[1] = cubic(yi[1] - y) * MUL + 0.5; + cvy[2] = cubic(yi[2] - y) * MUL + 0.5; + cvy[3] = cubic(yi[3] - y) * MUL + 0.5; + if (yi[0] < 0) + yi[0] = 0; + + if (yi[2] >= (int)src->h) + yi[2] = src->h - 1; + + if (yi[3] >= (int)src->h) + yi[3] = src->h - 1; + /* Generate interpolated row */ for (j = 0; j < src->w; j++) { int32_t rv[4], gv[4], bv[4]; GP_Pixel pix[4];
- pix[0] = GP_GetPixel_Raw_24BPP(src, j, yi); - pix[1] = GP_GetPixel_Raw_24BPP(src, j, yi + 1); - pix[2] = GP_GetPixel_Raw_24BPP(src, j, yi + 2); - pix[3] = GP_GetPixel_Raw_24BPP(src, j, yi + 3); + pix[0] = GP_GetPixel_Raw_24BPP(src, j, yi[0]); + pix[1] = GP_GetPixel_Raw_24BPP(src, j, yi[1]); + pix[2] = GP_GetPixel_Raw_24BPP(src, j, yi[2]); + pix[3] = GP_GetPixel_Raw_24BPP(src, j, yi[3]); rv[0] = GP_Pixel_GET_R_RGB888(pix[0]); rv[1] = GP_Pixel_GET_R_RGB888(pix[1]); @@ -416,7 +304,7 @@ int GP_FilterInterpolate_CubicInt2(const GP_Context *src, GP_Context *dst, bv[1] = GP_Pixel_GET_B_RGB888(pix[1]); bv[2] = GP_Pixel_GET_B_RGB888(pix[2]); bv[3] = GP_Pixel_GET_B_RGB888(pix[3]); - + MUL_I(rv, cvy); MUL_I(gv, cvy); MUL_I(bv, cvy); @@ -431,33 +319,41 @@ int GP_FilterInterpolate_CubicInt2(const GP_Context *src, GP_Context *dst, float x = (1.00 * j / dst->w) * src->w; int32_t cvx[4], rv[4], gv[4], bv[4]; int32_t r, g, b; - int xi = x - 1; + int xi[4]; + + xi[0] = floor(x - 1); + xi[1] = x; + xi[2] = x + 1; + xi[3] = x + 2; - if (xi < 0) - xi = 0; - - if (xi > (int)src->w - 4) - xi = src->w - 4; + cvx[0] = cubic(xi[0] - x) * MUL + 0.5; + cvx[1] = cubic(xi[1] - x) * MUL + 0.5; + cvx[2] = cubic(xi[2] - x) * MUL + 0.5; + cvx[3] = cubic(xi[3] - x) * MUL + 0.5; - cvx[0] = cubic(xi - x) * MUL + 0.5; - cvx[1] = cubic(xi + 1 - x) * MUL + 0.5; - cvx[2] = cubic(xi + 2 - x) * MUL + 0.5; - cvx[3] = cubic(xi + 3 - x) * MUL + 0.5; + if (xi[0] < 0) + xi[0] = 0; + + if (xi[2] >= (int)src->w) + xi[2] = src->w - 1; - rv[0] = col_r[xi]; - rv[1] = col_r[xi + 1]; - rv[2] = col_r[xi + 2]; - rv[3] = col_r[xi + 3]; + if (xi[3] >= (int)src->w) + xi[3] = src->w - 1; + + rv[0] = col_r[xi[0]]; + rv[1] = col_r[xi[1]]; + rv[2] = col_r[xi[2]]; + rv[3] = col_r[xi[3]]; - gv[0] = col_g[xi]; - gv[1] = col_g[xi + 1]; - gv[2] = col_g[xi + 2]; - gv[3] = col_g[xi + 3]; + gv[0] = col_g[xi[0]]; + gv[1] = col_g[xi[1]]; + gv[2] = col_g[xi[2]]; + gv[3] = col_g[xi[3]]; - bv[0] = col_b[xi]; - bv[1] = col_b[xi + 1]; - bv[2] = col_b[xi + 2]; - bv[3] = col_b[xi + 3]; + bv[0] = col_b[xi[0]]; + bv[1] = col_b[xi[1]]; + bv[2] = col_b[xi[2]]; + bv[3] = col_b[xi[3]]; MUL_I(rv, cvx); MUL_I(gv, cvx); @@ -467,23 +363,9 @@ int GP_FilterInterpolate_CubicInt2(const GP_Context *src, GP_Context *dst, g = (SUM_I(gv) + MUL*MUL/2) / MUL / MUL; b = (SUM_I(bv) + MUL*MUL/2) / MUL / MUL;
- if (r > 255) - r = 255; - - if (r < 0) - r = 0; - - if (g > 255) - g = 255; - - if (g < 0) - g = 0; - - if (b > 255) - b = 255; - - if (b < 0) - b = 0; + CLAMP(r); + CLAMP(g); + CLAMP(b); GP_Pixel pix = GP_Pixel_CREATE_RGB888((uint8_t)r, (uint8_t)g, (uint8_t)b); GP_PutPixel_Raw_24BPP(dst, j, i, pix); @@ -507,7 +389,7 @@ int GP_FilterResize_Raw(const GP_Context *src, GP_Context *dst, case GP_INTERP_CUBIC: return GP_FilterInterpolate_Cubic(src, dst, callback); case GP_INTERP_CUBIC_INT: - return GP_FilterInterpolate_CubicInt2(src, dst, callback); + return GP_FilterInterpolate_CubicInt(src, dst, callback); }
return 1;
-----------------------------------------------------------------------
Summary of changes: libs/filters/GP_Linear.c | 2 +- libs/filters/GP_Resize.c | 366 ++++++++++++++++------------------------------ 2 files changed, 125 insertions(+), 243 deletions(-)
repo.or.cz automatic notification. Contact project admin jiri.bluebear.dluhos@gmail.com if you want to unsubscribe, or site admin admin@repo.or.cz if you receive no reply.