Commit 2f1f386f authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Rework maketables to not need ColourTrans loaded at build time

During generation of the 32k colour lookup tables, the tool already has to hand the 5:5:5 RGB value and 8:8:8 RGB palette, so can do the colour lookup itself. This removes the need to build a platform agnostic ColourTrans module, it's just C code.
* Replace make_32k_table() with brute force colour matcher
* Use <stdio.h> functions to write out the output, change to use <stdint.h>
* Simplify top level makefile
* Header.s: minor warning squashed
Binary output compared with Colours-1_83.

Version 1.85. Tagged as 'Colours-1_85'
parent 26d10f2e
......@@ -32,10 +32,8 @@ HEADER1 = ColourTran
RESOURCEEXTRA = resources-colourtrans
include StdTools
include AAsmModule
include AppLibs
#
# Binary build environment
......@@ -56,39 +54,20 @@ clean::
${XWIPE} Palettes.* ${WFLAGS}
${RM} MkTables.maketables
${RM} MkTables.module
@echo ${COMPONENT}: cleaned
resources-colourtrans: Palettes.8desktop
resources-colourtrans: MkTables.maketables
${RUN}MkTables.maketables @
${SQUASH} Tables.4greys
${SQUASH} Tables.8greys
${SQUASH} Tables.4desktop
${MKDIR} ${RESFSDIR}
${CP} Palettes ${RESFSDIR}.* ${CPFLAGS}
${CP} Tables ${RESFSDIR}.* ${CPFLAGS}
@echo ${COMPONENT}: extra resource files copied
MkTables.maketables: MkTables.c.maketables
MkTables.maketables: MkTables.c.maketables
${CD} MkTables
${MAKE} -f maketables/mk COMPONENT=maketables THROWBACK=${THROWBACK}
${CD} ^
MkTables.module: MkTables.o.module
${LD} -rmf -o $@ MkTables.o.module
# Manually build a version which should be safe to softload on the host
# (assuming the host is running RISC OS!)
# This is all very nasty
MkTables.o.module: MkTables.o._dirs
set OldMachine <Machine>
set Machine 32
%objasm -APCS 3/32bit -cpu 3 -Stamp -quit -depend !Depend -ihdr -i<Hdr$Dir>.Global -i<Hdr$Dir>.Interface -i<Hdr$Dir>.Interface2 -pd "APCS SETS \"APCS-32\"" -pd "Machine SETS \"32\"" -o $@ ${ROM_SOURCE} -PD "standalone SETL {TRUE}"
set Machine <OldMachine>
Palettes.8desktop: MkTables.maketables MkTables.module
rmload MkTables.module
${RUN}MkTables.maketables @
${SQUASH} Tables.4greys
${SQUASH} Tables.8greys
${SQUASH} Tables.4desktop
MkTables.o._dirs:
${MKDIR} MkTables.o
# Dynamic dependencies:
......@@ -14,64 +14,75 @@
*/
/* maketables.c - makes the colourtrans ROM tables */
#include <stdint.h>
#include <stdio.h>
#include "swis.h"
#include <stdlib.h>
#include <string.h>
static unsigned int palette4[16] =
static const uint32_t palette4[16] =
{ 0xffffff00, 0xdddddd00, 0xbbbbbb00, 0x99999900,
0x77777700, 0x55555500, 0x33333300, 0x00000000,
0x99440000, 0x00eeee00, 0x00cc0000, 0x0000dd00,
0xbbeeee00, 0x00885500, 0x00bbff00, 0xffbb0000 };
static unsigned int palette4g[16] =
static const uint32_t palette4g[16] =
{ 0xffffff00, 0xdddddd00, 0xbbbbbb00, 0x99999900,
0x77777700, 0x55555500, 0x33333300, 0x00000000,
0x11111100, 0xcccccc00, 0x66666600, 0x22222200,
0xeeeeee00, 0x44444400, 0xaaaaaa00, 0x88888800 };
static char *make_32ktable(int *palette, int mode, char *table)
static uint8_t *make_32ktable(const uint32_t *palette, uint8_t *table, size_t palsize)
{
int element;
for (element=0;element<32768;element++)
{
int palette_entry;
int colour;
int r,g,b;
// palette_entry = ((element & 0x7c00) << 17) | ((element & 0x3e0) << 14) | ((element & 0x1f) << 11);
r = (element >> 10) * 255/31;
g = ((element >> 5) & 0x1f) * 255/31;
b = (element & 0x1f) * 255/31;
//printf("rgb = (%d,%d,%d)\n", r, g, b);
palette_entry = (r << 24) | (g << 16) | (b << 8);
_swi(ColourTrans_ReturnColourNumberForMode, _IN(0) | _IN(1) | _IN(2) | _OUT(0),
palette_entry, mode, palette, &colour);
//printf("pal %x = (%d)\n", palette_entry, colour);
table[element] = (unsigned char)(colour & 0xff);
}
return(table);
uint32_t element;
for (element = 0; element < 32768; element++)
{
uint32_t shortest, euclid;
size_t best = 0, colour;
uint32_t r,g,b;
uint32_t rp,gp,bp;
b = ((element >> 10) & 0x1f) * 255/31;
g = ((element >> 5) & 0x1f) * 255/31;
r = ((element >> 0) & 0x1f) * 255/31;
shortest = UINT32_MAX;
for (colour = 0; colour < palsize; colour++)
{
rp = (uint8_t)(palette[colour] >> 8);
gp = (uint8_t)(palette[colour] >> 16);
bp = (uint8_t)(palette[colour] >> 24);
/* Weight the distances per PRM 3-339 */
euclid = (2 * (rp - r) * (rp - r)) +
(4 * (gp - g) * (gp - g)) +
(1 * (bp - b) * (bp - b));
if (euclid < shortest)
{
shortest = euclid;
best = colour;
}
}
table[element] = (uint8_t)best;
}
return table;
}
int main(int argc, char *argv[])
{
int *palette;
char *table;
unsigned int loop,
r,g,b;
char outfile[256];
static int modeselector8bpp[10] = {1, 800, 600, 3, -1, 0, 128, 3, 255, -1}; /* 800x600 8bpp new format mode with
full colour palette */
static int modeselector4bpp[6] = {1, 800, 600, 2, -1, -1}; /* 800x600 4bpp new format mode */
palette = (int *)malloc(256*sizeof(int));
table = (char *)malloc(32*32*32*sizeof(char));
uint32_t *palette;
uint8_t *table;
FILE *file;
size_t loop;
uint32_t r, g, b;
char outfile[256];
palette = (uint32_t *)malloc(256 * sizeof(uint32_t));
table = (uint8_t *)malloc(32 * 32 * 32 * sizeof(uint8_t));
(void)argc; /* Unused */
/* 8bpp desktop */
/* 8bpp desktop */
printf("Constructing 8bpp desktop tables\n");
for (loop=0;loop<256;loop++)
for (loop = 0; loop < 256; loop++)
{
r = g = b = 0;
if (loop & 0x80) b |= 0x88; /* top bit blue */
......@@ -87,54 +98,73 @@ int main(int argc, char *argv[])
palette[loop] = (b<<24) | (g<<16) | (r<<8);
}
sprintf(outfile,"%s.Palettes.8desktop",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, palette, palette+256);
file = fopen(outfile, "wb");
fwrite(palette, sizeof(uint32_t), 256, file);
fclose(file);
printf(" - written palette.\n");
memset(table,0,32*32*32);
table = make_32ktable(palette, (int)modeselector8bpp, table);
table = make_32ktable(palette, table, 256);
sprintf(outfile,"%s.Tables.8desktop",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, table, table+32*32*32);
file = fopen(outfile, "wb");
fwrite(table, sizeof(uint8_t), 32 * 32 * 32, file);
fclose(file);
printf(" - written table.\n");
/* 8bpp grey */
/* 8bpp grey */
printf("Constructing 8bpp grey tables\n");
for (loop=0;loop<256;loop++)
for (loop = 0; loop < 256; loop++)
{
palette[loop] = (loop<<24) | (loop<<16) | (loop<<8);
}
sprintf(outfile,"%s.Palettes.8greys",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, palette, palette+256);
file = fopen(outfile, "wb");
fwrite(palette, sizeof(uint32_t), 256, file);
fclose(file);
printf(" - written palette.\n");
memset(table,0,32*32*32);
table = make_32ktable(palette, (int)modeselector8bpp, table);
table = make_32ktable(palette, table, 256);
sprintf(outfile,"%s.Tables.8greys",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, table, table+32*32*32);
file = fopen(outfile, "wb");
fwrite(table, sizeof(uint8_t), 32 * 32 * 32, file);
fclose(file);
printf(" - written table.\n");
/* 4bpp desktop */
/* 4bpp desktop */
printf("Constructing 4bpp desktop tables\n");
sprintf(outfile,"%s.Palettes.4desktop",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, palette4, palette4+16);
file = fopen(outfile, "wb");
fwrite(palette4, sizeof(uint32_t), 16, file);
fclose(file);
printf(" - written palette.\n");
memset(table,0,32*32*32);
table = make_32ktable((int *)palette4, (int)modeselector4bpp, table);
table = make_32ktable(palette4, table, 16);
sprintf(outfile,"%s.Tables.4desktop",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, table, table+32*32*32);
file = fopen(outfile, "wb");
fwrite(table, sizeof(uint8_t), 32 * 32 * 32, file);
fclose(file);
printf(" - written table.\n");
/* 4bpp grey */
/* 4bpp grey */
printf("Constructing 4bpp grey tables\n");
sprintf(outfile,"%s.Palettes.4greys",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, palette4g, palette4g+16);
file = fopen(outfile, "wb");
fwrite(palette4g, sizeof(uint32_t), 16, file);
fclose(file);
printf(" - written palette.\n");
memset(table,0,32*32*32);
table = make_32ktable((int *)palette4g, (int)modeselector4bpp, table);
table = make_32ktable(palette4g, table, 16);
sprintf(outfile,"%s.Tables.4greys",argv[1]);
_swi(OS_File, _IN(0) | _IN(1) | _IN(2) | _IN(4) | _IN(5), 10, outfile, 0xffd, table, table+32*32*32);
file = fopen(outfile, "wb");
fwrite(table, sizeof(uint8_t), 32 * 32 * 32, file);
fclose(file);
printf(" - written table.\n");
free(palette);
free(table);
return(0);
return 0;
}
......@@ -15,7 +15,6 @@
# Makefile for maketables
include HostTools
#include StdRules
include AppLibs
include CApp
......
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "1.84"
Module_Version SETA 184
Module_MajorVersion SETS "1.85"
Module_Version SETA 185
Module_MinorVersion SETS ""
Module_Date SETS "09 Feb 2013"
Module_ApplicationDate SETS "09-Feb-13"
Module_Date SETS "11 Feb 2013"
Module_ApplicationDate SETS "11-Feb-13"
Module_ComponentName SETS "Colours"
Module_ComponentPath SETS "castle/RiscOS/Sources/Video/Render/Colours"
Module_FullVersion SETS "1.84"
Module_HelpVersion SETS "1.84 (09 Feb 2013)"
Module_FullVersion SETS "1.85"
Module_HelpVersion SETS "1.85 (11 Feb 2013)"
END
/* (1.84)
/* (1.85)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 1.84
#define Module_MajorVersion_CMHG 1.85
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Feb 2013
#define Module_Date_CMHG 11 Feb 2013
#define Module_MajorVersion "1.84"
#define Module_Version 184
#define Module_MajorVersion "1.85"
#define Module_Version 185
#define Module_MinorVersion ""
#define Module_Date "09 Feb 2013"
#define Module_Date "11 Feb 2013"
#define Module_ApplicationDate "09-Feb-13"
#define Module_ApplicationDate "11-Feb-13"
#define Module_ComponentName "Colours"
#define Module_ComponentPath "castle/RiscOS/Sources/Video/Render/Colours"
#define Module_FullVersion "1.84"
#define Module_HelpVersion "1.84 (09 Feb 2013)"
#define Module_LibraryVersionInfo "1:84"
#define Module_FullVersion "1.85"
#define Module_HelpVersion "1.85 (11 Feb 2013)"
#define Module_LibraryVersionInfo "1:85"
......@@ -798,7 +798,7 @@ Die ROUT
LDR R2,[R1,#persist]
TEQ R2,#0
MOVNE WP,R1
LDMNEFD R13!,{LR}
Pull "LR",NE
BNE cannotdie
]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment