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, generate has been updated via 2fae7f19796fbac3a1e8a05891838595669c9407 (commit) from 6e824825b32a4d3ed3fc9b7e41dee600d010b093 (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/2fae7f19796fbac3a1e8a05891838595669c9...
commit 2fae7f19796fbac3a1e8a05891838595669c9407 Author: Cyril Hrubis metan@ucw.cz Date: Tue Sep 27 20:23:39 2011 +0200
First version of bicubic interpolation, only for rgb888 now.
diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_ScaleDown.c index 2cc379b..da5d9d3 100644 --- a/libs/filters/GP_ScaleDown.c +++ b/libs/filters/GP_ScaleDown.c @@ -52,3 +52,114 @@ GP_Context *GP_ScaleDown(GP_Context *src)
return dst; } + +#define A 0.5 + +float cubic(float x) +{ + if (x < 0) + x = -x; + + if (x < 1) + return (2 - A)*x*x*x + (A - 3)*x*x + 1; + + if (x < 2) + return -A*x*x*x + 5*A*x*x - 8*A*x + 4*A; + + return 0; +} + +GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h) +{ + GP_Context *dst; + float col_r[src->h], col_g[src->h], col_b[src->h]; + uint32_t i, j, k; + int idx; + + if (src->pixel_type != GP_PIXEL_RGB888) + return NULL; + + dst = GP_ContextAlloc(w, h, GP_PIXEL_RGB888); + + if (dst == NULL) + return NULL; + + for (i = 0; i < w; i++) { + float x = (1.00 * i / w) * src->w + 0.5; + + /* Generate interpolated column */ + for (j = 0; j < src->h; j++) { + uint8_t r[4], g[4], b[4]; + float c[4]; + + for (k = 0; k < 4; k++) { + GP_Pixel pix; + idx = x + k - 1; + + if (idx < 0) + idx = 0; + + if (idx > (int)src->w - 1) + idx = src->w - 1; + + pix = GP_GetPixel_Raw_24BPP(src, idx, j); + + r[k] = GP_Pixel_GET_R_RGB888(pix); + g[k] = GP_Pixel_GET_G_RGB888(pix); + b[k] = GP_Pixel_GET_B_RGB888(pix); + + c[k] = cubic(x - idx); + } + + col_r[j] = r[0] * c[0] + r[1] * c[1] + r[2] * c[2] + r[3] * c[3]; + col_g[j] = g[0] * c[0] + g[1] * c[1] + g[2] * c[2] + g[3] * c[3]; + col_b[j] = b[0] * c[0] + b[1] * c[1] + b[2] * c[2] + b[3] * c[3]; + + } + + /* now interpolate column for new image */ + for (j = 0; j < h; j++) { + float y = (1.00 * j / h) * src->h + 0.5; + float r = 0, g = 0, b = 0, c; + + for (k = 0; k < 4; k++) { + idx = y + k - 1; + + if (idx < 0) + idx = 0; + + if (idx > (int)src->h - 1) + idx = src->h - 1; + + c = cubic(y - idx); + + r += col_r[idx] * c; + g += col_g[idx] * c; + b += col_b[idx] * c; + } + + 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); + } + } + + return dst; +} diff --git a/tests/SDL/Makefile b/tests/SDL/Makefile index e5d9500..6d93313 100644 --- a/tests/SDL/Makefile +++ b/tests/SDL/Makefile @@ -6,7 +6,7 @@ INCLUDE=core gfx SDL backends LDLIBS+=-lGP -L$(TOPDIR)/build/ -lGP_SDL -lSDL -lpng
APPS=pixeltest fileview fonttest linetest randomshapetest shapetest sierpinsky- symbolstest textaligntest trianglefps input blittest subcontext ppm_test+ symbolstest textaligntest trianglefps input blittest subcontext scale_test showimage
include $(TOPDIR)/include.mk diff --git a/tests/SDL/ppm_test.c b/tests/SDL/scale_test.c similarity index 90% rename from tests/SDL/ppm_test.c rename to tests/SDL/scale_test.c index a0653b2..4bfc0e8 100644 --- a/tests/SDL/ppm_test.c +++ b/tests/SDL/scale_test.c @@ -30,13 +30,22 @@ int main(int argc, char *argv[]) GP_Context *bitmap; GP_SetDebugLevel(10); GP_RetCode ret; + GP_Size w, h;
- if ((ret = GP_LoadPPM(argv[1], &bitmap))) { + if (argc < 4) { + fprintf(stderr, "Usage: image w hn"); + return 1; + } + + if ((ret = GP_LoadImage(argv[1], &bitmap))) { fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret)); return 1; }
- bitmap = GP_ScaleDown(bitmap); + w = atoi(argv[2]); + h = atoi(argv[3]); + + bitmap = GP_Scale(bitmap, w, h);
if ((ret = GP_SavePPM("out.ppm", bitmap, "b"))) { fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
-----------------------------------------------------------------------
Summary of changes: libs/filters/GP_ScaleDown.c | 111 ++++++++++++++++++++++++++++++++ tests/SDL/Makefile | 2 +- tests/SDL/{ppm_test.c => scale_test.c} | 13 +++- 3 files changed, 123 insertions(+), 3 deletions(-) rename tests/SDL/{ppm_test.c => scale_test.c} (90%)
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.