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
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
......@@ -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) $@
......
......@@ -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
......
......@@ -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];
}
/*
......
......@@ -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 *);
......
......@@ -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) +
......
......@@ -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
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment