refactoring zoom code
This commit is contained in:
parent
f70037a143
commit
2c4612411b
134
Lib/zoom.c
134
Lib/zoom.c
@ -26,35 +26,37 @@ long hit, mess;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#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);
|
src, dst, kx, ky, flags);
|
||||||
#endif
|
#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
|
#if DEBUG_LEVEL
|
||||||
hit = mess = 0L;
|
hit = mess = 0L;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (xd=0; xd<dst->width; xd++)
|
for (xd=0; xd<dst->width; xd++) {
|
||||||
{
|
|
||||||
dxs = (double)xd * kx;
|
dxs = (double)xd * kx;
|
||||||
for (yd=0; yd<dst->height; yd++)
|
for (yd=0; yd<dst->height; yd++) {
|
||||||
{
|
|
||||||
rd = gd = bd = 42;
|
rd = gd = bd = 42;
|
||||||
|
|
||||||
dys = (double)yd * ky; /* kikoo lol */
|
dys = (double)yd * ky; /* kikoo lol */
|
||||||
xs = (int)dxs;
|
xs = (int)dxs;
|
||||||
ys = (int)dys;
|
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);
|
Image_getRGB(src, xs, ys, &rd, &gd, &bd);
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
hit++;
|
hit++;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#if DEBUG_LEVEL
|
#if DEBUG_LEVEL
|
||||||
else mess++;
|
else { mess++; }
|
||||||
#endif
|
#endif
|
||||||
Image_plotRGB(dst, xd, yd, rd, gd, bd);
|
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;
|
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;
|
int xd, yd, xs, ys, r, g, b;
|
||||||
double fxd, fyd;
|
float ftmp;
|
||||||
|
|
||||||
#if DEBUG_LEVEL
|
#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
|
#endif
|
||||||
|
|
||||||
for (yd=0; yd<dst->height; yd++)
|
for (yd=0; yd<dst->height; yd++) {
|
||||||
{
|
ftmp = ((float)yd) / ky;
|
||||||
fyd = (double)yd;
|
ys = (int) (ftmp);
|
||||||
for (xd=0; xd<dst->height; xd++)
|
ys += rect->y;
|
||||||
{
|
/*
|
||||||
fxd = (double)xd;
|
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;
|
||||||
}
|
}
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
http:///la.buvette.org/devel/libimage/
|
http:///la.buvette.org/devel/libimage/
|
||||||
*/
|
*/
|
||||||
#ifndef IMAGE_VERSION_STRING
|
#ifndef IMAGE_VERSION_STRING
|
||||||
#define IMAGE_VERSION_STRING "0.4.51 pl 38"
|
#define IMAGE_VERSION_STRING "0.4.51 pl 39"
|
||||||
|
|
||||||
/*::------------------------------------------------------------------::*/
|
/*::------------------------------------------------------------------::*/
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user