diff --git a/src/conio/Common.gmake b/src/conio/Common.gmake index ad16f2bfe81eda7a409b2daec6194ed2dbeefe4e..b5e46e2056cbfb7735f1f267ba968f302f1a204f 100644 --- a/src/conio/Common.gmake +++ b/src/conio/Common.gmake @@ -66,6 +66,7 @@ else ifndef WITHOUT_GDI CIOLIB-MT_LIBS += -lgdi32 CIOLIB-MT_CFLAGS += -DWITH_GDI + NEED_BITMAP := 1 endif ifdef USE_SDL WITH_SDL := 1 @@ -102,6 +103,7 @@ ifdef USE_SDL endif ifdef WITH_SDL + NEED_BITMAP := 1 # Prefer local include over system includes. #CFLAGS += -I$(SRC_ROOT)/../include/sdl ifdef SDL_CONFIG @@ -155,6 +157,7 @@ ifdef WITH_SDL endif ifndef NO_X + NEED_BITMAP := 1 CIOLIB_CFLAGS += -DHAS_VSTAT CIOLIB-MT_CFLAGS += -DHAS_VSTAT else @@ -170,3 +173,7 @@ ifdef NO_X CIOLIB_CFLAGS += -DNO_FONTS endif endif + +ifdef NEED_BITMAP + CIOLIB_INTERPOLATE_OBJS = $(CIOLIB_SRC)$(DIRSEP)$(MTOBJODIR)$(DIRSEP)rgbmap$(OFILE) +endif diff --git a/src/conio/GNUmakefile b/src/conio/GNUmakefile index 48c17e91de210107cd42d3449e1d063bc6ef229c..ac069f691a152ca08de17ff7ed6e31ac2cd75f10 100644 --- a/src/conio/GNUmakefile +++ b/src/conio/GNUmakefile @@ -7,6 +7,7 @@ CFLAGS += $(XPDEV-MT_CFLAGS) $(HASH_CFLAGS) $(ENCODE_CFLAGS) $(CIOLIB-MT_CFLAGS) ifeq ($(os),win32) ifndef WITHOUT_GDI OBJS += $(MTOBJODIR)$(DIRSEP)win32gdi$(OFILE) + NEED_BITMAP := 1 endif OBJS += $(MTOBJODIR)$(DIRSEP)SDL_win32_main$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)win32cio$(OFILE) @@ -41,12 +42,13 @@ endif ifdef NEED_BITMAP OBJS += $(MTOBJODIR)$(DIRSEP)bitmap_con$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)scale$(OFILE) - OBJS += $(MTOBJODIR)$(DIRSEP)rgbmap$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)xbr$(OFILE) endif + + # CIOLIB Library Link Rule -$(CIOLIB-MT_BUILD): $(MTOBJODIR) $(OBJS) +$(CIOLIB-MT_BUILD): $(MTOBJODIR) $(OBJS) $(CIOLIB_INTERPOLATE_OBJS) @echo Creating $@ ... $(QUIET)$(AR) rc $@ $(OBJS) $(QUIET)$(RANLIB) $@ diff --git a/src/conio/ciolib.c b/src/conio/ciolib.c index 1ff8834e03f580469c090ea56501d1a728265d2b..8089fe57b2843f3b38b906495ac0b8522545822e 100644 --- a/src/conio/ciolib.c +++ b/src/conio/ciolib.c @@ -449,8 +449,6 @@ CIOLIBEXPORT int initciolib(int mode) return(0); } - memset(&cio_api,0,sizeof(cio_api)); - switch(mode) { case CIOLIB_MODE_AUTO: #ifndef NO_X diff --git a/src/conio/scale.c b/src/conio/scale.c index aa0421db4847b75a3f730cb1eccdc416253e49ee..c5fdf2c3bbb62c3f17d18a160745b6f0ab59d2bb 100644 --- a/src/conio/scale.c +++ b/src/conio/scale.c @@ -7,11 +7,8 @@ #include "scale.h" #include "xbr.h" -#if 0 -uint32_t r2y[1<<24]; -uint32_t y2r[1<<24]; -#endif -static int r2y_inited = true; +const uint32_t *r2yptr; +const uint32_t *y2rptr; static void pointy_scale3(uint32_t* src, uint32_t* dest, int width, int height); static void pointy_scale5(uint32_t* src, uint32_t* dest, int width, int height); @@ -40,8 +37,14 @@ aspect_fix_inside(int *x, int *y, int aspect_width, int aspect_height) if (aspect_width == 0 || aspect_height == 0) return; - bestx = lround((double)*y * aspect_width / aspect_height); - besty = lround((double)*x * aspect_height / aspect_width); + if (r2yptr != NULL && y2rptr != NULL) { + bestx = lround((double)*y * aspect_width / aspect_height); + besty = lround((double)*x * aspect_height / aspect_width); + } + else { + bestx = lround((double)*y * *x / *y); + besty = lround((double)*x * *y / *x); + } if (besty <= *y) *y = besty; @@ -63,8 +66,14 @@ aspect_fix(int *x, int *y, int aspect_width, int aspect_height) // Nothing we can do here... if (aspect_width == 0 || aspect_height == 0) return; - bestx = lround((double)*y * aspect_width / aspect_height); - besty = lround((double)*x * aspect_height / aspect_width); + if (r2yptr != NULL && y2rptr != NULL) { + bestx = lround((double)*y * aspect_width / aspect_height); + besty = lround((double)*x * aspect_height / aspect_width); + } + else { + bestx = lround((double)*y * *x / *y); + besty = lround((double)*x * *y / *x); + } if (bestx < *x && besty > 0) *y = besty; @@ -83,8 +92,13 @@ aspect_fix_low(int *x, int *y, int aspect_width, int aspect_height) // Nothing we can do here... if (aspect_width == 0 || aspect_height == 0) return; - bestx = lround((double)*y * aspect_width / aspect_height); - besty = lround((double)*x * aspect_height / aspect_width); + if (r2yptr != NULL && y2rptr != NULL) { + bestx = lround((double)*y * aspect_width / aspect_height); + besty = lround((double)*x * aspect_height / aspect_width); + } else { + bestx = lround((double)*y * *x / *y); + besty = lround((double)*x * *y / *x); + } if (bestx < *x && bestx > 0) *x = bestx; @@ -102,6 +116,8 @@ aspect_correct(int *x, int *y, int aspect_width, int aspect_height) int width = *x; int height; + if (r2yptr == NULL || y2rptr == NULL) + return; if (!aspect_height || !aspect_width) return; height = lround((double)(width * aspect_height) / aspect_width); @@ -130,6 +146,8 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width, int cheight; int cwidth; + if (r2yptr == NULL || y2rptr == NULL) + return; if (!aspect_height || !aspect_width) { width = scrnwidth * (*x / scrnwidth); if (width < scrnwidth) @@ -168,6 +186,7 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width, *y = height; } +#if 0 void init_r2y(void) { @@ -188,7 +207,7 @@ init_r2y(void) v = 128 + (112.439 * r - 94.154 * g - 18.285 * b + 128) / 256; CLAMP(v); - r2y[(r<<16) | (g<<8) | b] = (y<<16)|(u<<8)|v; + r2yptr[(r<<16) | (g<<8) | b] = (y<<16)|(u<<8)|v; } } } @@ -205,12 +224,13 @@ init_r2y(void) b = luma * c + col * 1.772 * d; CLAMP(b); - y2r[(y<<16) | (u<<8) | v] = (r<<16)|(g<<8)|b; + y2rptr[(y<<16) | (u<<8) | v] = (r<<16)|(g<<8)|b; } } } r2y_inited = true; } +#endif struct graphics_buffer * get_buffer(void) @@ -305,19 +325,21 @@ do_scale(struct rectlist* rect, int xscale, int yscale, int aspect_width, int as total_yscaling /= 3; yscale *= 3; } - while (total_xscaling > 1 && ((total_xscaling % 4) == 0) && ((total_yscaling % 4) == 0)) { - xbr4++; - total_xscaling /= 4; - xscale *= 4; - total_yscaling /= 4; - yscale *= 4; - } - while (total_xscaling > 1 && ((total_xscaling % 2) == 0) && ((total_yscaling % 2) == 0)) { - xbr2++; - total_xscaling /= 2; - xscale *= 2; - total_yscaling /= 2; - yscale *= 2; + if (r2yptr != NULL && y2rptr != NULL) { + while (total_xscaling > 1 && ((total_xscaling % 4) == 0) && ((total_yscaling % 4) == 0)) { + xbr4++; + total_xscaling /= 4; + xscale *= 4; + total_yscaling /= 4; + yscale *= 4; + } + while (total_xscaling > 1 && ((total_xscaling % 2) == 0) && ((total_yscaling % 2) == 0)) { + xbr2++; + total_xscaling /= 2; + xscale *= 2; + total_yscaling /= 2; + yscale *= 2; + } } } } @@ -462,26 +484,28 @@ csrc->w, csrc->h, pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc-> } // And finally, interpolate if needed - if (fheight != csrc->h) { - interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight); - ctarget->h = fheight; - ctarget->w = csrc->w; - csrc = ctarget; - if (ctarget == ret1) - ctarget = ret2; - else - ctarget = ret1; - } - - if (fwidth != csrc->w) { - interpolate_width(csrc->data, ctarget->data, csrc->w, csrc->h, fwidth); - ctarget->h = csrc->h; - ctarget->w = fwidth; - csrc = ctarget; - if (ctarget == ret1) - ctarget = ret2; - else - ctarget = ret1; + if (r2yptr != NULL && y2rptr != NULL) { + if (fheight != csrc->h) { + interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight); + ctarget->h = fheight; + ctarget->w = csrc->w; + csrc = ctarget; + if (ctarget == ret1) + ctarget = ret2; + else + ctarget = ret1; + } + + if (fwidth != csrc->w) { + interpolate_width(csrc->data, ctarget->data, csrc->w, csrc->h, fwidth); + ctarget->h = csrc->h; + ctarget->w = fwidth; + csrc = ctarget; + if (ctarget == ret1) + ctarget = ret2; + else + ctarget = ret1; + } } release_buffer(ctarget); @@ -793,8 +817,8 @@ blend(const uint32_t c1, const uint32_t c2, uint16_t weight) uint8_t yuv3[4]; const uint16_t iw = 65535 - weight; - *(uint32_t *)yuv1 = r2y[c1]; - *(uint32_t *)yuv2 = r2y[c2]; + *(uint32_t *)yuv1 = r2yptr[c1]; + *(uint32_t *)yuv2 = r2yptr[c2]; #ifdef __BIG_ENDIAN__ yuv3[0] = 0; yuv3[1] = (yuv1[1] * iw + yuv2[1] * weight) / 65535; @@ -807,7 +831,7 @@ blend(const uint32_t c1, const uint32_t c2, uint16_t weight) yuv3[0] = (yuv1[0] * iw + yuv2[0] * weight) / 65535; #endif - return y2r[*(uint32_t*)yuv3]; + return y2rptr[*(uint32_t*)yuv3]; } /* diff --git a/src/conio/scale.h b/src/conio/scale.h index 7092540f009687afda944aec8aa771a4372a4ef2..4ce37c55a0c8fc3279aed44b39e6869184cecd32 100644 --- a/src/conio/scale.h +++ b/src/conio/scale.h @@ -8,8 +8,8 @@ struct graphics_buffer { struct graphics_buffer *next; }; -extern uint32_t r2y[1<<24]; -extern uint32_t y2r[1<<24]; +extern const uint32_t *r2yptr; +extern const uint32_t *y2rptr; struct graphics_buffer * get_buffer(void); void release_buffer(struct graphics_buffer *); diff --git a/src/conio/xbr.c b/src/conio/xbr.c index a7f02ed6e36332dc04aee59226c883b407d537e4..8fd137b0b0b31224ebc206019ae4f7db7f8ae25b 100644 --- a/src/conio/xbr.c +++ b/src/conio/xbr.c @@ -47,9 +47,9 @@ static uint32_t pixel_diff(uint32_t x, uint32_t y) #define VMASK 0x0000ff #define ABSDIFF(a,b) (abs((int)(a)-(int)(b))) - uint32_t yuv1 = r2y[x & 0xffffff]; + uint32_t yuv1 = r2yptr[x & 0xffffff]; - uint32_t yuv2 = r2y[y & 0xffffff]; + uint32_t yuv2 = r2yptr[y & 0xffffff]; return (ABSDIFF(yuv1 & YMASK, yuv2 & YMASK) >> 16) + (ABSDIFF(yuv1 & UMASK, yuv2 & UMASK) >> 8) + diff --git a/src/syncterm/GNUmakefile b/src/syncterm/GNUmakefile index d3fd71445aff7d09ba32f31fd529ad736fc1f90a..d542ec0140b0abec16e10e6811b5472c8cb47e53 100644 --- a/src/syncterm/GNUmakefile +++ b/src/syncterm/GNUmakefile @@ -2,6 +2,10 @@ SRC_ROOT := .. include ${SRC_ROOT}/build/Common.gmake include extdeps.mk +ifdef NEED_BITMAP + OBJS += $(CIOLIB_INTERPOLATE_OBJS) +endif + ifdef WITHOUT_OOII CFLAGS += -DWITHOUT_OOII=1 else diff --git a/src/syncterm/syncterm.c b/src/syncterm/syncterm.c index 2275055b24b060dc07181ab86f43380f8577ba78..87f34485aa9ed508b59313a97e84d24f413b3092 100644 --- a/src/syncterm/syncterm.c +++ b/src/syncterm/syncterm.c @@ -46,6 +46,7 @@ static const KNOWNFOLDERID FOLDERID_ProgramData = { #include <xp_dl.h> /* xp_dlopen() and friends */ #endif /* ifdef _WIN32 */ +#include <rgbmap.h> #include <ciolib.h> #include <cterm.h> #include <dirwrap.h> @@ -1707,6 +1708,8 @@ main(int argc, char **argv) cio_api.options |= CONIO_OPT_BLOCKY_SCALING; else cio_api.options &= ~CONIO_OPT_BLOCKY_SCALING; + r2yptr = r2y; + y2rptr = y2r; if (initciolib(ciolib_mode)) return 1; if (settings.blocky)