Skip to content
Snippets Groups Projects
Commit 22f3d102 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Don't link in RGB <-> YUV tables by default.

Instead, have the r2yptr and y2rptr pointers that need to be set
to those tables in order for interpolation to work.  Not setting one
locks ciolib into "LCD" modes (everything uses square pixels), and
XBR scaling is disabled.

The CIOLIB_INTERPOLATE_OBJS make variable contains the path to the
object file that contains those tables, so it's just a matter of
some code and an extra (128MB) object to link against.
parent fb7ba893
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4177 failed
...@@ -66,6 +66,7 @@ else ...@@ -66,6 +66,7 @@ else
ifndef WITHOUT_GDI ifndef WITHOUT_GDI
CIOLIB-MT_LIBS += -lgdi32 CIOLIB-MT_LIBS += -lgdi32
CIOLIB-MT_CFLAGS += -DWITH_GDI CIOLIB-MT_CFLAGS += -DWITH_GDI
NEED_BITMAP := 1
endif endif
ifdef USE_SDL ifdef USE_SDL
WITH_SDL := 1 WITH_SDL := 1
...@@ -102,6 +103,7 @@ ifdef USE_SDL ...@@ -102,6 +103,7 @@ ifdef USE_SDL
endif endif
ifdef WITH_SDL ifdef WITH_SDL
NEED_BITMAP := 1
# Prefer local include over system includes. # Prefer local include over system includes.
#CFLAGS += -I$(SRC_ROOT)/../include/sdl #CFLAGS += -I$(SRC_ROOT)/../include/sdl
ifdef SDL_CONFIG ifdef SDL_CONFIG
...@@ -155,6 +157,7 @@ ifdef WITH_SDL ...@@ -155,6 +157,7 @@ ifdef WITH_SDL
endif endif
ifndef NO_X ifndef NO_X
NEED_BITMAP := 1
CIOLIB_CFLAGS += -DHAS_VSTAT CIOLIB_CFLAGS += -DHAS_VSTAT
CIOLIB-MT_CFLAGS += -DHAS_VSTAT CIOLIB-MT_CFLAGS += -DHAS_VSTAT
else else
...@@ -170,3 +173,7 @@ ifdef NO_X ...@@ -170,3 +173,7 @@ ifdef NO_X
CIOLIB_CFLAGS += -DNO_FONTS CIOLIB_CFLAGS += -DNO_FONTS
endif endif
endif endif
ifdef NEED_BITMAP
CIOLIB_INTERPOLATE_OBJS = $(CIOLIB_SRC)$(DIRSEP)$(MTOBJODIR)$(DIRSEP)rgbmap$(OFILE)
endif
...@@ -7,6 +7,7 @@ CFLAGS += $(XPDEV-MT_CFLAGS) $(HASH_CFLAGS) $(ENCODE_CFLAGS) $(CIOLIB-MT_CFLAGS) ...@@ -7,6 +7,7 @@ CFLAGS += $(XPDEV-MT_CFLAGS) $(HASH_CFLAGS) $(ENCODE_CFLAGS) $(CIOLIB-MT_CFLAGS)
ifeq ($(os),win32) ifeq ($(os),win32)
ifndef WITHOUT_GDI ifndef WITHOUT_GDI
OBJS += $(MTOBJODIR)$(DIRSEP)win32gdi$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)win32gdi$(OFILE)
NEED_BITMAP := 1
endif endif
OBJS += $(MTOBJODIR)$(DIRSEP)SDL_win32_main$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)SDL_win32_main$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)win32cio$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)win32cio$(OFILE)
...@@ -41,12 +42,13 @@ endif ...@@ -41,12 +42,13 @@ endif
ifdef NEED_BITMAP ifdef NEED_BITMAP
OBJS += $(MTOBJODIR)$(DIRSEP)bitmap_con$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)bitmap_con$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)scale$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)scale$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)rgbmap$(OFILE)
OBJS += $(MTOBJODIR)$(DIRSEP)xbr$(OFILE) OBJS += $(MTOBJODIR)$(DIRSEP)xbr$(OFILE)
endif endif
# CIOLIB Library Link Rule # CIOLIB Library Link Rule
$(CIOLIB-MT_BUILD): $(MTOBJODIR) $(OBJS) $(CIOLIB-MT_BUILD): $(MTOBJODIR) $(OBJS) $(CIOLIB_INTERPOLATE_OBJS)
@echo Creating $@ ... @echo Creating $@ ...
$(QUIET)$(AR) rc $@ $(OBJS) $(QUIET)$(AR) rc $@ $(OBJS)
$(QUIET)$(RANLIB) $@ $(QUIET)$(RANLIB) $@
......
...@@ -449,8 +449,6 @@ CIOLIBEXPORT int initciolib(int mode) ...@@ -449,8 +449,6 @@ CIOLIBEXPORT int initciolib(int mode)
return(0); return(0);
} }
memset(&cio_api,0,sizeof(cio_api));
switch(mode) { switch(mode) {
case CIOLIB_MODE_AUTO: case CIOLIB_MODE_AUTO:
#ifndef NO_X #ifndef NO_X
......
...@@ -7,11 +7,8 @@ ...@@ -7,11 +7,8 @@
#include "scale.h" #include "scale.h"
#include "xbr.h" #include "xbr.h"
#if 0 const uint32_t *r2yptr;
uint32_t r2y[1<<24]; const uint32_t *y2rptr;
uint32_t y2r[1<<24];
#endif
static int r2y_inited = true;
static void pointy_scale3(uint32_t* src, uint32_t* dest, int width, int height); 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); 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) ...@@ -40,8 +37,14 @@ aspect_fix_inside(int *x, int *y, int aspect_width, int aspect_height)
if (aspect_width == 0 || aspect_height == 0) if (aspect_width == 0 || aspect_height == 0)
return; return;
if (r2yptr != NULL && y2rptr != NULL) {
bestx = lround((double)*y * aspect_width / aspect_height); bestx = lround((double)*y * aspect_width / aspect_height);
besty = lround((double)*x * aspect_height / aspect_width); besty = lround((double)*x * aspect_height / aspect_width);
}
else {
bestx = lround((double)*y * *x / *y);
besty = lround((double)*x * *y / *x);
}
if (besty <= *y) if (besty <= *y)
*y = besty; *y = besty;
...@@ -63,8 +66,14 @@ aspect_fix(int *x, int *y, int aspect_width, int aspect_height) ...@@ -63,8 +66,14 @@ aspect_fix(int *x, int *y, int aspect_width, int aspect_height)
// Nothing we can do here... // Nothing we can do here...
if (aspect_width == 0 || aspect_height == 0) if (aspect_width == 0 || aspect_height == 0)
return; return;
if (r2yptr != NULL && y2rptr != NULL) {
bestx = lround((double)*y * aspect_width / aspect_height); bestx = lround((double)*y * aspect_width / aspect_height);
besty = lround((double)*x * aspect_height / aspect_width); 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) if (bestx < *x && besty > 0)
*y = besty; *y = besty;
...@@ -83,8 +92,13 @@ aspect_fix_low(int *x, int *y, int aspect_width, int aspect_height) ...@@ -83,8 +92,13 @@ aspect_fix_low(int *x, int *y, int aspect_width, int aspect_height)
// Nothing we can do here... // Nothing we can do here...
if (aspect_width == 0 || aspect_height == 0) if (aspect_width == 0 || aspect_height == 0)
return; return;
if (r2yptr != NULL && y2rptr != NULL) {
bestx = lround((double)*y * aspect_width / aspect_height); bestx = lround((double)*y * aspect_width / aspect_height);
besty = lround((double)*x * aspect_height / aspect_width); 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) if (bestx < *x && bestx > 0)
*x = bestx; *x = bestx;
...@@ -102,6 +116,8 @@ aspect_correct(int *x, int *y, int aspect_width, int aspect_height) ...@@ -102,6 +116,8 @@ aspect_correct(int *x, int *y, int aspect_width, int aspect_height)
int width = *x; int width = *x;
int height; int height;
if (r2yptr == NULL || y2rptr == NULL)
return;
if (!aspect_height || !aspect_width) if (!aspect_height || !aspect_width)
return; return;
height = lround((double)(width * aspect_height) / aspect_width); 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, ...@@ -130,6 +146,8 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width,
int cheight; int cheight;
int cwidth; int cwidth;
if (r2yptr == NULL || y2rptr == NULL)
return;
if (!aspect_height || !aspect_width) { if (!aspect_height || !aspect_width) {
width = scrnwidth * (*x / scrnwidth); width = scrnwidth * (*x / scrnwidth);
if (width < scrnwidth) if (width < scrnwidth)
...@@ -168,6 +186,7 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width, ...@@ -168,6 +186,7 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width,
*y = height; *y = height;
} }
#if 0
void void
init_r2y(void) init_r2y(void)
{ {
...@@ -188,7 +207,7 @@ init_r2y(void) ...@@ -188,7 +207,7 @@ init_r2y(void)
v = 128 + (112.439 * r - 94.154 * g - 18.285 * b + 128) / 256; v = 128 + (112.439 * r - 94.154 * g - 18.285 * b + 128) / 256;
CLAMP(v); 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) ...@@ -205,12 +224,13 @@ init_r2y(void)
b = luma * c + col * 1.772 * d; b = luma * c + col * 1.772 * d;
CLAMP(b); 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; r2y_inited = true;
} }
#endif
struct graphics_buffer * struct graphics_buffer *
get_buffer(void) get_buffer(void)
...@@ -305,6 +325,7 @@ do_scale(struct rectlist* rect, int xscale, int yscale, int aspect_width, int as ...@@ -305,6 +325,7 @@ do_scale(struct rectlist* rect, int xscale, int yscale, int aspect_width, int as
total_yscaling /= 3; total_yscaling /= 3;
yscale *= 3; yscale *= 3;
} }
if (r2yptr != NULL && y2rptr != NULL) {
while (total_xscaling > 1 && ((total_xscaling % 4) == 0) && ((total_yscaling % 4) == 0)) { while (total_xscaling > 1 && ((total_xscaling % 4) == 0) && ((total_yscaling % 4) == 0)) {
xbr4++; xbr4++;
total_xscaling /= 4; total_xscaling /= 4;
...@@ -321,6 +342,7 @@ do_scale(struct rectlist* rect, int xscale, int yscale, int aspect_width, int as ...@@ -321,6 +342,7 @@ do_scale(struct rectlist* rect, int xscale, int yscale, int aspect_width, int as
} }
} }
} }
}
xmult = total_xscaling; xmult = total_xscaling;
xscale *= xmult; xscale *= xmult;
...@@ -462,6 +484,7 @@ csrc->w, csrc->h, pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc-> ...@@ -462,6 +484,7 @@ csrc->w, csrc->h, pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->
} }
// And finally, interpolate if needed // And finally, interpolate if needed
if (r2yptr != NULL && y2rptr != NULL) {
if (fheight != csrc->h) { if (fheight != csrc->h) {
interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight); interpolate_height(csrc->data, ctarget->data, csrc->w, csrc->h, fheight);
ctarget->h = fheight; ctarget->h = fheight;
...@@ -483,6 +506,7 @@ csrc->w, csrc->h, pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc-> ...@@ -483,6 +506,7 @@ csrc->w, csrc->h, pointymult, pointy5, pointy3, xbr4, xbr2, xmult, ymult, csrc->
else else
ctarget = ret1; ctarget = ret1;
} }
}
release_buffer(ctarget); release_buffer(ctarget);
return csrc; return csrc;
...@@ -793,8 +817,8 @@ blend(const uint32_t c1, const uint32_t c2, uint16_t weight) ...@@ -793,8 +817,8 @@ blend(const uint32_t c1, const uint32_t c2, uint16_t weight)
uint8_t yuv3[4]; uint8_t yuv3[4];
const uint16_t iw = 65535 - weight; const uint16_t iw = 65535 - weight;
*(uint32_t *)yuv1 = r2y[c1]; *(uint32_t *)yuv1 = r2yptr[c1];
*(uint32_t *)yuv2 = r2y[c2]; *(uint32_t *)yuv2 = r2yptr[c2];
#ifdef __BIG_ENDIAN__ #ifdef __BIG_ENDIAN__
yuv3[0] = 0; yuv3[0] = 0;
yuv3[1] = (yuv1[1] * iw + yuv2[1] * weight) / 65535; 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) ...@@ -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; yuv3[0] = (yuv1[0] * iw + yuv2[0] * weight) / 65535;
#endif #endif
return y2r[*(uint32_t*)yuv3]; return y2rptr[*(uint32_t*)yuv3];
} }
/* /*
......
...@@ -8,8 +8,8 @@ struct graphics_buffer { ...@@ -8,8 +8,8 @@ struct graphics_buffer {
struct graphics_buffer *next; struct graphics_buffer *next;
}; };
extern uint32_t r2y[1<<24]; extern const uint32_t *r2yptr;
extern uint32_t y2r[1<<24]; extern const uint32_t *y2rptr;
struct graphics_buffer * get_buffer(void); struct graphics_buffer * get_buffer(void);
void release_buffer(struct graphics_buffer *); void release_buffer(struct graphics_buffer *);
......
...@@ -47,9 +47,9 @@ static uint32_t pixel_diff(uint32_t x, uint32_t y) ...@@ -47,9 +47,9 @@ static uint32_t pixel_diff(uint32_t x, uint32_t y)
#define VMASK 0x0000ff #define VMASK 0x0000ff
#define ABSDIFF(a,b) (abs((int)(a)-(int)(b))) #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) + return (ABSDIFF(yuv1 & YMASK, yuv2 & YMASK) >> 16) +
(ABSDIFF(yuv1 & UMASK, yuv2 & UMASK) >> 8) + (ABSDIFF(yuv1 & UMASK, yuv2 & UMASK) >> 8) +
......
...@@ -2,6 +2,10 @@ SRC_ROOT := .. ...@@ -2,6 +2,10 @@ SRC_ROOT := ..
include ${SRC_ROOT}/build/Common.gmake include ${SRC_ROOT}/build/Common.gmake
include extdeps.mk include extdeps.mk
ifdef NEED_BITMAP
OBJS += $(CIOLIB_INTERPOLATE_OBJS)
endif
ifdef WITHOUT_OOII ifdef WITHOUT_OOII
CFLAGS += -DWITHOUT_OOII=1 CFLAGS += -DWITHOUT_OOII=1
else else
......
...@@ -46,6 +46,7 @@ static const KNOWNFOLDERID FOLDERID_ProgramData = { ...@@ -46,6 +46,7 @@ static const KNOWNFOLDERID FOLDERID_ProgramData = {
#include <xp_dl.h> /* xp_dlopen() and friends */ #include <xp_dl.h> /* xp_dlopen() and friends */
#endif /* ifdef _WIN32 */ #endif /* ifdef _WIN32 */
#include <rgbmap.h>
#include <ciolib.h> #include <ciolib.h>
#include <cterm.h> #include <cterm.h>
#include <dirwrap.h> #include <dirwrap.h>
...@@ -1707,6 +1708,8 @@ main(int argc, char **argv) ...@@ -1707,6 +1708,8 @@ main(int argc, char **argv)
cio_api.options |= CONIO_OPT_BLOCKY_SCALING; cio_api.options |= CONIO_OPT_BLOCKY_SCALING;
else else
cio_api.options &= ~CONIO_OPT_BLOCKY_SCALING; cio_api.options &= ~CONIO_OPT_BLOCKY_SCALING;
r2yptr = r2y;
y2rptr = y2r;
if (initciolib(ciolib_mode)) if (initciolib(ciolib_mode))
return 1; return 1;
if (settings.blocky) if (settings.blocky)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment