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 8bed60585798f64bb79328f012a738f44746cc81 (commit) from 688e786f9814c87a37a3dbb6d2d7e94b8d392674 (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/8bed60585798f64bb79328f012a738f44746c...
commit 8bed60585798f64bb79328f012a738f44746cc81 Author: Cyril Hrubis metan@ucw.cz Date: Wed Sep 28 18:55:44 2011 +0200
Some more cleanup and moving things back and forth.
diff --git a/include/filters/GP_Filters.h b/include/filters/GP_Filters.h index 4575497..bbeb3eb 100644 --- a/include/filters/GP_Filters.h +++ b/include/filters/GP_Filters.h @@ -32,8 +32,12 @@ #ifndef GP_FILTERS_H #define GP_FILTERS_H
-#include "GP_Rotate.h" -#include "GP_Linear.h" -#include "GP_Resize.h" +/* Image rotations (90 180 270 grads) and mirroring */ +#include "filters/GP_Rotate.h" + +#include "filters/GP_Linear.h" + +/* Image down and up scaling */ +#include "filters/GP_Scale.h"
#endif /* GP_FILTERS_H */ diff --git a/include/filters/GP_Resize.h b/include/filters/GP_Scale.h similarity index 75% rename from include/filters/GP_Resize.h rename to include/filters/GP_Scale.h index c475645..06414c2 100644 --- a/include/filters/GP_Resize.h +++ b/include/filters/GP_Scale.h @@ -26,13 +26,27 @@
*/
-#ifndef GP_RESIZE_H -#define GP_RESIZE_H +#ifndef GP_SCALE_H +#define GP_SCALE_H
#include "core/GP_Context.h"
-GP_Context *GP_ScaleDown(GP_Context *src); +/* + * Nearest neighbour + * + * Faster than others, but produces pixelated images. Works however well for + * images with sharp edges mostly consisting of big once color parts (eg + * doesn't blurr the result on upscaling). + */ +GP_Context *GP_Scale_NN(GP_Context *src, GP_Size w, GP_Size h); + +/* + * Bicubic Scaling + * + * Works well for upscaling. Not so good for downscaling big images to small + * ones (looses too much information). + */ +GP_Context *GP_Scale_BiCubic(GP_Context *src, GP_Size w, GP_Size h);
-GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h);
-#endif /* GP_RESIZE_H */ +#endif /* GP_SCALE_H */ diff --git a/libs/filters/GP_ScaleDown.c b/libs/filters/GP_Scale.c similarity index 88% rename from libs/filters/GP_ScaleDown.c rename to libs/filters/GP_Scale.c index 35210cc..e0ff64b 100644 --- a/libs/filters/GP_ScaleDown.c +++ b/libs/filters/GP_Scale.c @@ -25,27 +25,33 @@
#include <GP_Debug.h>
-#include <GP_Resize.h> +#include <GP_Scale.h>
-GP_Context *GP_ScaleDown(GP_Context *src) + +GP_Context *GP_Scale_NN(GP_Context *src, GP_Size w, GP_Size h) { - uint32_t w, h, x, y; GP_Context *dst;
if (src->pixel_type != GP_PIXEL_RGB888) return NULL;
- w = src->w/2; - h = src->h/2; - dst = GP_ContextAlloc(w, h, GP_PIXEL_RGB888);
if (dst == NULL) return NULL;
- for (y = 0; y < h; y++) - for (x = 0; x < w; x++) { - GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, 2*x, 2*y); + GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f", + src->w, src->h, w, h, + 1.00 * w / src->w, 1.00 * h / src->h); + + GP_Coord x, y; + + for (y = 0; y < (int)h; y++) + for (x = 0; x < (int)w; x++) { + GP_Coord xi = (1.00 * x / w) * src->w; + GP_Coord yi = (1.00 * y / h) * src->h; + + GP_Pixel pix = GP_GetPixel_Raw_24BPP(src, xi, yi);
GP_PutPixel_Raw_24BPP(dst, x, y, pix); } @@ -79,7 +85,7 @@ typedef union v4f { #define MUL_V4SF(a, b) ((union v4f)((a).v * (b).v)) #define SUM_V4SF(a) ((a).f[0] + (a).f[1] + (a).f[2] + (a).f[3])
-GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h) +GP_Context *GP_Scale_BiCubic(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]; @@ -93,6 +99,10 @@ GP_Context *GP_Scale(GP_Context *src, GP_Size w, GP_Size h) if (dst == NULL) return NULL;
+ GP_DEBUG(1, "Scaling image %ux%u -> %ux%u %2.2f %2.2f", + src->w, src->h, w, h, + 1.00 * w / src->w, 1.00 * h / src->h); + for (i = 0; i < w; i++) { float x = (1.00 * i / w) * src->w + 0.5; v4f cvx; diff --git a/libs/loaders/GP_PPM.c b/libs/loaders/GP_PPM.c index de6877e..106e78d 100644 --- a/libs/loaders/GP_PPM.c +++ b/libs/loaders/GP_PPM.c @@ -144,6 +144,8 @@ GP_RetCode GP_SavePPM(const char *res_path, GP_Context *src, char *fmt) /* binary */ case 'b': hfmt = '6'; + GP_DEBUG(1, "Writing binary PPM %ux%u '%s'", + src->w, src->h, res_path); break; default: return GP_ENOIMPL; diff --git a/tests/SDL/scale_test.c b/tests/SDL/scale_test.c index 4bfc0e8..aa026b9 100644 --- a/tests/SDL/scale_test.c +++ b/tests/SDL/scale_test.c @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) w = atoi(argv[2]); h = atoi(argv[3]);
- bitmap = GP_Scale(bitmap, w, h); + bitmap = GP_Scale_BiCubic(bitmap, w, h);
if ((ret = GP_SavePPM("out.ppm", bitmap, "b"))) { fprintf(stderr, "Failed to load bitmap: %sn", GP_RetCodeName(ret));
-----------------------------------------------------------------------
Summary of changes: include/filters/GP_Filters.h | 10 ++++++-- include/filters/{GP_Resize.h => GP_Scale.h} | 24 +++++++++++++++++---- libs/filters/{GP_ScaleDown.c => GP_Scale.c} | 30 ++++++++++++++++++--------- libs/loaders/GP_PPM.c | 2 + tests/SDL/scale_test.c | 2 +- 5 files changed, 49 insertions(+), 19 deletions(-) rename include/filters/{GP_Resize.h => GP_Scale.h} (75%) rename libs/filters/{GP_ScaleDown.c => GP_Scale.c} (88%)
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.