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

Remove rgbmap.c and rgbmap.h

Instead, generate these as part of the build and use the .incbin
macro on GNU-compatible assemblers to build the .o file quickly.

No good solution for Win32, but genmap could write the C file again
and take forever building it if/when we need to build rgbmap.obj
on Win32.
parent aa4c5de9
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
Pipeline #4221 failed
......@@ -452,6 +452,11 @@ endif
-include $(SRC_ROOT)/build/rules.mk
-include objects.mk # defines $(OBJS)
# Implicit ASM Compile Rule
$(OBJODIR)/%$(OFILE) : %.s $(BUILD_DEPENDS) | $(OBJODIR)
@echo $(COMPILE_MSG) $<
$(QUIET)$(AS) $(ASFLAGS) -o $@ $<
# Implicit C Compile Rule
$(OBJODIR)/%$(OFILE) : %.c $(BUILD_DEPENDS) | $(OBJODIR)
@echo $(COMPILE_MSG) $<
......@@ -462,6 +467,11 @@ $(OBJODIR)/%$(OFILE) : %.cpp $(BUILD_DEPENDS) | $(OBJODIR)
@echo $(COMPILE_MSG) $<
$(QUIET)$(CXX) -std=c++11 $(CFLAGS) $(CXXFLAGS) -o $@ -c $<
# Implicit MT ASM Compile Rule
$(MTOBJODIR)/%$(OFILE) : %.s $(BUILD_DEPENDS) | $(OBJODIR)
@echo $(COMPILE_MSG) $<
$(QUIET)$(AS) $(ASFLAGS) -o $@ $<
# Implicit MT C Compile Rule
$(MTOBJODIR)/%$(OFILE) : %.c $(BUILD_DEPENDS) | $(MTOBJODIR)
@echo $(COMPILE_MSG) $<
......
......@@ -67,7 +67,16 @@ $(MTOBJODIR)$(DIRSEP)ciolib_res${OFILE}: ciolib.rc syncicon64.ico
$(QUIET)${WINDRES} $(WINDRESFLAGS) -O coff -i ciolib.rc -o $@
endif
genamp: $(EXEODIR) $(MTOBJODIR) $(EXEODIR)$(DIRSEP)genmap$(EXEFILE)
$(EXEODIR)$(DIRSEP)genmap$(EXEFILE): $(EXEODIR)
rgbmap.s: $(EXEODIR)$(DIRSEP)genmap$(EXEFILE)
@echo Creating $@...
$(QUIET)$(EXEODIR)$(DIRSEP)genmap$(EXEFILE)
rgbmap.h: rgbmap.s
$(MTOBJODIR)$(DIRSEP)rgbmap$(OFILE): rgbmap.s rgbmap.h
$(EXEODIR)$(DIRSEP)genmap$(EXEFILE): $(OBJODIR)$(DIRSEP)genmap$(OFILE)
$(CC) $(LDFLAGS) $(OBJODIR)$(DIRSEP)genmap$(OFILE) -o $@
$(EXEODIR)$(DIRSEP)genmap$(EXEFILE): $(MTOBJODIR)$(DIRSEP)genmap$(OFILE) $(MTOBJODIR)$(DIRSEP)scale$(OFILE) $(MTOBJODIR)$(DIRSEP)xbr$(OFILE)
$(CC) $(LDFLAGS) $(MT_LDFLAGS) $(MTOBJODIR)$(DIRSEP)genmap$(OFILE) $(MTOBJODIR)$(DIRSEP)scale$(OFILE) $(MTOBJODIR)$(DIRSEP)xbr$(OFILE) -o $@ -lm
#include <stdio.h>
#include "scale.h"
#include "ciolib.h"
cioapi_t cio_api;
#include <inttypes.h>
uint32_t r2y[16777216];
uint32_t y2r[16777216];
int main(int argc, char **argv)
#define CLAMP(x) do { \
if (x < 0) \
x = 0; \
else if (x > 255) \
x = 255; \
} while(0)
void
init_r2y(void)
{
uint32_t i;
FILE *c = fopen("rgbmap.c", "wb");
FILE *h = fopen("rgbmap.h", "wb");
init_r2y();
int r, g, b;
int y, u, v;
const double luma = 255.0 / 219;
const double col = 255.0 / 224;
for (r = 0; r < 256; r++) {
for (g = 0; g < 256; g++) {
for (b = 0; b < 256; b++) {
y = 16 + ( 65.738 * r + 129.057 * g + 25.064 * b + 128) / 256;
CLAMP(y);
u = 128 + (-37.945 * r - 74.494 * g + 112.439 * b + 128) / 256;
CLAMP(u);
v = 128 + (112.439 * r - 94.154 * g - 18.285 * b + 128) / 256;
CLAMP(v);
fprintf(c, "#include <inttypes.h>\n\n"
"const uint32_t r2y[%u] = {\n", 1 << 24);
fprintf(h, "#ifndef RGBMAP_H\n"
"#define RGBMAP_H\n\n"
"#include <inttypes.h>\n\n"
"extern const uint32_t r2y[%u];\n"
"extern const uint32_t y2r[%u];\n\n"
"#endif\n", 1 << 24, 1 << 24);
for (i = 0; i < (1<<24); i++) {
if (i % 8 == 0)
fputs("\t", c);
fprintf(c, "0x%08x,", r2y[i]);
if (i % 8 == 7)
fputs("\n", c);
else
fputs(" ", c);
r2y[(r<<16) | (g<<8) | b] = (y<<16)|(u<<8)|v;
}
}
}
fprintf(c, "};\n\n"
"const uint32_t y2r[%u] = {\n", 1 << 24);
for (i = 0; i < (1<<24); i++) {
if (i % 8 == 0)
fputs("\t", c);
fprintf(c, "0x%08x,", y2r[i]);
if (i % 8 == 7)
fputs("\n", c);
else
fputs(" ", c);
for (y = 0; y < 256; y++) {
for (u = 0; u < 256; u++) {
for (v = 0; v < 256; v++) {
const int c = y - 16;
const int d = u - 128;
const int e = v - 128;
r = luma * c + col * 1.402 * e;
CLAMP(r);
g = luma * c - col * 1.772 * (0.114 / 0.587) * d - col * 1.402 * (0.299 / 0.587) * e;
CLAMP(g);
b = luma * c + col * 1.772 * d;
CLAMP(b);
y2r[(y<<16) | (u<<8) | v] = (r<<16)|(g<<8)|b;
}
}
}
fputs("};\n", c);
}
int
main(int argc, char **argv)
{
FILE *s = fopen("rgbmap.s", "w");
FILE *h = fopen("rgbmap.h", "w");
FILE *r = fopen("r2y.bin", "wb");
FILE *y = fopen("y2r.bin", "wb");
init_r2y();
fprintf(s,
".section .rodata\n"
".global r2y\n"
".type r2y, @object\n"
".align 4\n"
"r2y:\n"
" .incbin \"r2y.bin\"\n"
".global y2r\n"
".type y2r, @object\n"
".align 4\n"
"y2r:\n"
" .incbin \"y2r.bin\"\n");
fprintf(h,
"#ifndef RGBMAP_H\n"
"#define RGBMAP_H\n"
"\n"
"#include <inttypes.h>\n"
"\n"
"extern const uint32_t r2y[16777216];\n"
"extern const uint32_t y2r[16777216];\n"
"\n"
"#endif\n");
fwrite(r2y, 4, 1 << 24, r);
fwrite(y2r, 4, 1 << 24, y);
fclose(s);
fclose(h);
fclose(r);
fclose(y);
return 0;
}
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
#ifndef RGBMAP_H
#define RGBMAP_H
#include <inttypes.h>
extern const uint32_t r2y[16777216];
extern const uint32_t y2r[16777216];
#endif
......@@ -16,13 +16,6 @@ static void multiply_scale(uint32_t* src, uint32_t* dst, int width, int height,
static struct graphics_buffer *free_list;
#define CLAMP(x) do { \
if (x < 0) \
x = 0; \
else if (x > 255) \
x = 255; \
} while(0)
/*
* Corrects width/height to have the specified aspect ratio
* any fit inside the specified rectangle
......@@ -182,52 +175,6 @@ aspect_reverse(int *x, int *y, int scrnwidth, int scrnheight, int aspect_width,
*y = height;
}
#if 0
void
init_r2y(void)
{
int r, g, b;
int y, u, v;
const double luma = 255.0 / 219;
const double col = 255.0 / 224;
if (r2y_inited)
return;
for (r = 0; r < 256; r++) {
for (g = 0; g < 256; g++) {
for (b = 0; b < 256; b++) {
y = 16 + ( 65.738 * r + 129.057 * g + 25.064 * b + 128) / 256;
CLAMP(y);
u = 128 + (-37.945 * r - 74.494 * g + 112.439 * b + 128) / 256;
CLAMP(u);
v = 128 + (112.439 * r - 94.154 * g - 18.285 * b + 128) / 256;
CLAMP(v);
ciolib_r2yptr[(r<<16) | (g<<8) | b] = (y<<16)|(u<<8)|v;
}
}
}
for (y = 0; y < 256; y++) {
for (u = 0; u < 256; u++) {
for (v = 0; v < 256; v++) {
const int c = y - 16;
const int d = u - 128;
const int e = v - 128;
r = luma * c + col * 1.402 * e;
CLAMP(r);
g = luma * c - col * 1.772 * (0.114 / 0.587) * d - col * 1.402 * (0.299 / 0.587) * e;
CLAMP(g);
b = luma * c + col * 1.772 * d;
CLAMP(b);
ciolib_y2rptr[(y<<16) | (u<<8) | v] = (r<<16)|(g<<8)|b;
}
}
}
r2y_inited = true;
}
#endif
struct graphics_buffer *
get_buffer(void)
{
......
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