refactoring zoom code

This commit is contained in:
tTh 2022-10-28 05:59:49 +02:00
parent f70037a143
commit 2c4612411b
2 changed files with 115 additions and 21 deletions

View File

@ -26,35 +26,37 @@ long hit, mess;
#endif
#if DEBUG_LEVEL
fprintf(stderr, "%s : %p -> %p %f %f 0x%x\n", __func__,
fprintf(stderr, ">>> %s ( %p %p %f %f 0x%x )\n", __func__,
src, dst, kx, ky, flags);
#endif
/* initilaisation de variables de debug/comptage */
if (flags) {
fprintf(stderr, "in %s, flags muste be 0x0000\n", __func__);
return WRONG_FLAG;
}
/* initialisation de variables de debug/comptage */
#if DEBUG_LEVEL
hit = mess = 0L;
#endif
for (xd=0; xd<dst->width; xd++)
{
for (xd=0; xd<dst->width; xd++) {
dxs = (double)xd * kx;
for (yd=0; yd<dst->height; yd++)
{
for (yd=0; yd<dst->height; yd++) {
rd = gd = bd = 42;
dys = (double)yd * ky; /* kikoo lol */
xs = (int)dxs;
ys = (int)dys;
if ( Image_xy_inside(src, xs, ys) )
{
if ( Image_xy_inside(src, xs, ys) ) {
Image_getRGB(src, xs, ys, &rd, &gd, &bd);
#if DEBUG_LEVEL
hit++;
#endif
}
#if DEBUG_LEVEL
else mess++;
else { mess++; }
#endif
Image_plotRGB(dst, xd, yd, rd, gd, bd);
}
@ -67,25 +69,117 @@ fprintf(stderr, "%s -> hit=%ld mess=%ld\n", __func__, hit, mess);
return BAD_ZOOM;
}
/*::------------------------------------------------------------------::*/
int Image_zoom_000(Image_Desc *src, Image_Desc *dst, Image_Rect *rect)
/*
* Very old non-working code get an update on Thu 24 Sep 2022
*
* We have two versions:
* zoom_000 without interpolation
* zoom_001 with a pseudo bi-linear interpolation
* Public intercace:
* Image_zoom_extract(src, dst, rect, flags)
*/
/* this is a semi-private function */
int Image_zoom_000(Image_Desc *src, Image_Desc *dst, Image_Rect *rect,
float kx, float ky)
{
int xd, yd, r, g, b;
double fxd, fyd;
int xd, yd, xs, ys, r, g, b;
float ftmp;
#if DEBUG_LEVEL
fprintf(stderr, "%s ( %p %p %p )\n", __func__, src, dst, rect);
fprintf(stderr, ">>> %s ( %p %p %p )\n", __func__, src, dst, rect);
#endif
for (yd=0; yd<dst->height; yd++)
{
fyd = (double)yd;
for (xd=0; xd<dst->height; xd++)
{
fxd = (double)xd;
for (yd=0; yd<dst->height; yd++) {
ftmp = ((float)yd) / ky;
ys = (int) (ftmp);
ys += rect->y;
/*
fprintf(stderr, " yd %5d -> %8.3f ys %5d\n", yd, ftmp, ys);
*/
for (xd=0; xd<dst->width; xd++) {
xs = (int) ((float)xd / kx);
xs += rect->x;
if ( Image_xy_inside(src, xs, ys) )
{ Image_getRGB(src, xs, ys, &r, &g, &b); }
else
{ r = g = b = 127; }
Image_plotRGB(dst, xd, yd, r, g, b);
}
}
return FULL_NUCKED;
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* */
/* nouveau Fri 23 Sep 2022 02:27:00 PM CEST */
/* this is a semi-private function */
/* */
int Image_zoom_001(Image_Desc *src, Image_Desc *dst, Image_Rect *rect,
float kx, float ky)
{
int xd, yd, xs, ys, r, g, b;
double dxs, dys;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p %.3f %.3f)\n", __func__,
src, dst, rect, kx, ky);
#endif
for (yd=0; yd<dst->height; yd++) {
dys = (double)rect->y + (((double)yd) / ky);
ys = (int)dys;
for (xd=0; xd<dst->width; xd++) {
dxs = (double)rect->x + ((double)xd / kx);
xs = (int)dxs;
if ( Image_xy_inside(src, xs, ys) )
{
/* see 'scale.c' for this func */
Image_getpix_bilin(src, dxs, dys, &r, &g, &b);
}
else
{ r = g = b = 127; }
Image_plotRGB(dst, xd, yd, r, g, b);
}
}
return FUNC_IS_BETA;
}
/*::------------------------------------------------------------------::*/
/* */
/* nouveau Fri 23 Sep 2022 02:16:55 PM CEST */
/* */
int Image_zoom_extract(Image_Desc *src, Image_Desc *dst, Image_Rect *rect,
int flags)
{
int foo;
float kx, ky;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %p 0x%x)\n", __func__, src, dst, rect, flags);
#endif
kx = (float)dst->width / (float)rect->w;
ky = (float)dst->height / (float)rect->h;
#if DEBUG_LEVEL
fprintf(stderr, " kx %8.3f ky %8.3f\n", kx, ky);
#endif
/* this is ugly code ! */
if (flags)
{ foo = Image_zoom_001(src, dst, rect, kx, ky); }
else
{ foo = Image_zoom_000(src, dst, rect, kx, ky); }
if (foo) {
fprintf(stderr, "got %d in %s\n", foo, __func__);
return foo;
}
return FUNC_IS_ALPHA;
}
/*::------------------------------------------------------------------::*/

View File

@ -4,7 +4,7 @@
http:///la.buvette.org/devel/libimage/
*/
#ifndef IMAGE_VERSION_STRING
#define IMAGE_VERSION_STRING "0.4.51 pl 38"
#define IMAGE_VERSION_STRING "0.4.51 pl 39"
/*::------------------------------------------------------------------::*/
/*