Work in progress on major refactoring...
This commit is contained in:
parent
33224ba3bd
commit
ffc0ce9c55
@ -1,7 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -xe
|
||||
|
||||
gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -c -o xprite.o xprite.c
|
||||
|
||||
exit
|
@ -5,7 +5,5 @@ set -xe
|
||||
mkdir -p /usr/local/include/xolatile
|
||||
|
||||
cp xprite.h /usr/local/include/xolatile/xprite.h
|
||||
cp xprite.c /usr/local/include/xolatile/xprite.c
|
||||
cp xprite.o /usr/local/include/xolatile/xprite.o
|
||||
|
||||
exit
|
||||
|
2
xiewer.c
2
xiewer.c
@ -17,7 +17,7 @@ int main (int argc, char * * argv) {
|
||||
xprite_swap_channels (data, width, height);
|
||||
|
||||
while (xlesses_active == true) {
|
||||
xlesses_render_background_colour (0xffffffff);
|
||||
xlesses_render_background_colour (0xff00ffff);
|
||||
|
||||
xlesses_render_sprite (data, width, height, 0, 0);
|
||||
|
||||
|
21
xonverter.c
Normal file
21
xonverter.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <xolatile/xprite.c>
|
||||
|
||||
#include "stb_image.h"
|
||||
|
||||
int main (int argc, char * * argv) {
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int format = 0;
|
||||
|
||||
unsigned int * data = null;
|
||||
|
||||
fatal_failure (argc != 3, "xonverter input output");
|
||||
|
||||
data = stbi_load (argv [1], & width, & height, & format, 4);
|
||||
|
||||
data = xprite_export (argv [2], xprite_format_true, width, height, data);
|
||||
|
||||
data = deallocate (data);
|
||||
|
||||
return (log_success);
|
||||
}
|
115
xprite.c
115
xprite.c
@ -1,115 +0,0 @@
|
||||
#ifndef xprite_source
|
||||
#define xprite_source
|
||||
|
||||
#include <xolatile/xtandard.c>
|
||||
#include <xolatile/xprite.h>
|
||||
|
||||
unsigned int xprite_colour [128] = {
|
||||
0x00000000, 0xff222222, 0xff444444, 0xff666666, 0xff888888, 0xffaaaaaa, 0xffcccccc, 0xffeeeeee,
|
||||
0x11000000, 0xff000022, 0xff000044, 0xff000066, 0xff000088, 0xff0000aa, 0xff0000cc, 0xff0000ee,
|
||||
0x22000000, 0xff002200, 0xff004400, 0xff006600, 0xff008800, 0xff00aa00, 0xff00cc00, 0xff00ee00,
|
||||
0x33000000, 0xff220000, 0xff440000, 0xff660000, 0xff880000, 0xffaa0000, 0xffcc0000, 0xffee0000,
|
||||
0x44000000, 0xff002222, 0xff004444, 0xff006666, 0xff008888, 0xff00aaaa, 0xff00cccc, 0xff00eeee,
|
||||
0x55000000, 0xff222200, 0xff444400, 0xff666600, 0xff888800, 0xffaaaa00, 0xffcccc00, 0xffeeee00,
|
||||
0x66000000, 0xff220022, 0xff440044, 0xff660066, 0xff880088, 0xffaa00aa, 0xffcc00cc, 0xffee00ee,
|
||||
0x77000000, 0xff001122, 0xff002244, 0xff003366, 0xff004488, 0xff0055aa, 0xff0066cc, 0xff0077ee,
|
||||
0x88000000, 0xff110022, 0xff220044, 0xff330066, 0xff440088, 0xff5500aa, 0xff6600cc, 0xff7700ee,
|
||||
0x99000000, 0xff002211, 0xff004422, 0xff006633, 0xff008844, 0xff00aa55, 0xff00cc66, 0xff00ee77,
|
||||
0xaa000000, 0xff112200, 0xff224400, 0xff336600, 0xff448800, 0xff55aa00, 0xff66cc00, 0xff77ee00,
|
||||
0xbb000000, 0xff220011, 0xff440022, 0xff660033, 0xff880044, 0xffaa0055, 0xffcc0066, 0xffee0077,
|
||||
0xcc000000, 0xff221100, 0xff442200, 0xff663300, 0xff884400, 0xffaa5500, 0xffcc6600, 0xffee7700,
|
||||
0xdd000000, 0xff112222, 0xff224444, 0xff336666, 0xff448888, 0xff55aaaa, 0xff66cccc, 0xff77eeee,
|
||||
0xee000000, 0xff222211, 0xff444422, 0xff666633, 0xff888844, 0xffaaaa55, 0xffcccc66, 0xffeeee77,
|
||||
0xff000000, 0xff221122, 0xff442244, 0xff663366, 0xff884488, 0xffaa55aa, 0xffcc66cc, 0xffee77ee
|
||||
};
|
||||
|
||||
void * xprite_import (char * path, int * format, int * width, int * height) {
|
||||
int file, move;
|
||||
|
||||
unsigned int * data = null;
|
||||
|
||||
file = file_open (path, O_RDWR);
|
||||
|
||||
file_read (file, format, 1);
|
||||
file_read (file, width, 1);
|
||||
file_read (file, height, 1);
|
||||
|
||||
fatal_failure ((* format) >= xprite_format_count, "xprite_import: Invalid sprite format.");
|
||||
fatal_failure ((* width) == 0, "xprite_import: Invalid sprite width.");
|
||||
fatal_failure ((* height) == 0, "xprite_import: Invalid sprite height.");
|
||||
|
||||
data = allocate ((* width) * (* height) * (int) sizeof (* data));
|
||||
|
||||
for (move = 0; move < (* width) * (* height); ++move) {
|
||||
int colour = 0;
|
||||
int repeat = 0;
|
||||
|
||||
file_read (file, & colour, 1);
|
||||
|
||||
if ((colour & 0x80) == 0) {
|
||||
data [move] = xprite_colour [colour];
|
||||
} else {
|
||||
int offset;
|
||||
|
||||
file_read (file, & repeat, 1);
|
||||
|
||||
for (offset = 0; offset < repeat; ++offset) {
|
||||
data [move + offset] = xprite_colour [colour & 0x7f];
|
||||
}
|
||||
|
||||
move += offset - 1;
|
||||
}
|
||||
}
|
||||
|
||||
file = file_close (file);
|
||||
|
||||
return (data);
|
||||
}
|
||||
|
||||
void xprite_export (char * path, int format, int width, int height, unsigned int * data) {
|
||||
int file, move;
|
||||
|
||||
file = file_open (path, O_RDWR | O_TRUNC | O_CREAT);
|
||||
|
||||
fatal_failure (format >= xprite_format_count, "xprite_export: Invalid sprite format.");
|
||||
fatal_failure ((width <= 0) || (width >= 256), "xprite_export: Invalid sprite width.");
|
||||
fatal_failure ((height <= 0) || (height >= 256), "xprite_export: Invalid sprite height.");
|
||||
|
||||
file_write (file, & format, 1);
|
||||
file_write (file, & width, 1);
|
||||
file_write (file, & height, 1);
|
||||
|
||||
for (move = 0; move < width * height; ++move) {
|
||||
int colour, repeat;
|
||||
|
||||
for (repeat = 0; (data [move] == data [move + repeat + 1]) && (repeat < 256); ++repeat);
|
||||
for (colour = 0; (data [move] != xprite_colour [colour]) && (colour < 128); ++colour);
|
||||
|
||||
if (colour == 128) colour = 127;
|
||||
|
||||
++repeat;
|
||||
|
||||
if (repeat == 1) {
|
||||
file_write (file, & colour, 1);
|
||||
} else {
|
||||
colour |= 0x80;
|
||||
move += repeat - 1;
|
||||
|
||||
file_write (file, & colour, 1);
|
||||
file_write (file, & repeat, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
file = file_close (file);
|
||||
}
|
||||
|
||||
void xprite_swap_channels (unsigned int * data, int width, int height) {
|
||||
int move;
|
||||
|
||||
for (move = 0; move < width * height; ++move) {
|
||||
data [move] = (data [move] & 0xff00ff00) | ((data [move] & 0xff0000) >> 16) | ((data [move] & 0xff) << 16);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
111
xprite.h
111
xprite.h
@ -1,13 +1,118 @@
|
||||
#ifndef xprite_header
|
||||
#define xprite_header
|
||||
|
||||
#include <xolatile/xtandard.h>
|
||||
|
||||
enum {
|
||||
xprite_format_mono, xprite_format_grey, xprite_format_true, xprite_format_count
|
||||
};
|
||||
|
||||
extern unsigned int xprite_colour [128];
|
||||
static unsigned int xprite_colour [128] = {
|
||||
0x00000000, 0xff222222, 0xff444444, 0xff666666, 0xff888888, 0xffaaaaaa, 0xffcccccc, 0xffeeeeee,
|
||||
0x11000000, 0xff000022, 0xff000044, 0xff000066, 0xff000088, 0xff0000aa, 0xff0000cc, 0xff0000ee,
|
||||
0x22000000, 0xff002200, 0xff004400, 0xff006600, 0xff008800, 0xff00aa00, 0xff00cc00, 0xff00ee00,
|
||||
0x33000000, 0xff220000, 0xff440000, 0xff660000, 0xff880000, 0xffaa0000, 0xffcc0000, 0xffee0000,
|
||||
0x44000000, 0xff002222, 0xff004444, 0xff006666, 0xff008888, 0xff00aaaa, 0xff00cccc, 0xff00eeee,
|
||||
0x55000000, 0xff222200, 0xff444400, 0xff666600, 0xff888800, 0xffaaaa00, 0xffcccc00, 0xffeeee00,
|
||||
0x66000000, 0xff220022, 0xff440044, 0xff660066, 0xff880088, 0xffaa00aa, 0xffcc00cc, 0xffee00ee,
|
||||
0x77000000, 0xff001122, 0xff002244, 0xff003366, 0xff004488, 0xff0055aa, 0xff0066cc, 0xff0077ee,
|
||||
0x88000000, 0xff110022, 0xff220044, 0xff330066, 0xff440088, 0xff5500aa, 0xff6600cc, 0xff7700ee,
|
||||
0x99000000, 0xff002211, 0xff004422, 0xff006633, 0xff008844, 0xff00aa55, 0xff00cc66, 0xff00ee77,
|
||||
0xaa000000, 0xff112200, 0xff224400, 0xff336600, 0xff448800, 0xff55aa00, 0xff66cc00, 0xff77ee00,
|
||||
0xbb000000, 0xff220011, 0xff440022, 0xff660033, 0xff880044, 0xffaa0055, 0xffcc0066, 0xffee0077,
|
||||
0xcc000000, 0xff221100, 0xff442200, 0xff663300, 0xff884400, 0xffaa5500, 0xffcc6600, 0xffee7700,
|
||||
0xdd000000, 0xff112222, 0xff224444, 0xff336666, 0xff448888, 0xff55aaaa, 0xff66cccc, 0xff77eeee,
|
||||
0xee000000, 0xff222211, 0xff444422, 0xff666633, 0xff888844, 0xffaaaa55, 0xffcccc66, 0xffeeee77,
|
||||
0xff000000, 0xff221122, 0xff442244, 0xff663366, 0xff884488, 0xffaa55aa, 0xffcc66cc, 0xffee77ee
|
||||
};
|
||||
|
||||
extern void * xprite_import (char * path, int * format, int * width, int * height);
|
||||
extern void xprite_export (char * path, int format, int width, int height, unsigned int * data);
|
||||
static void * xprite_import (char * path, int * format, int * width, int * height) {
|
||||
int file, move;
|
||||
|
||||
unsigned int * data = null;
|
||||
|
||||
file = file_open (path, O_RDWR);
|
||||
|
||||
file_read (file, format, 1);
|
||||
file_read (file, width, 1);
|
||||
file_read (file, height, 1);
|
||||
|
||||
fatal_failure ((* format) >= xprite_format_count, "xprite_import: Invalid sprite format.");
|
||||
fatal_failure ((* width) == 0, "xprite_import: Invalid sprite width.");
|
||||
fatal_failure ((* height) == 0, "xprite_import: Invalid sprite height.");
|
||||
|
||||
data = allocate ((* width) * (* height) * (int) sizeof (* data));
|
||||
|
||||
for (move = 0; move < (* width) * (* height); ++move) {
|
||||
int colour = 0;
|
||||
int repeat = 0;
|
||||
|
||||
file_read (file, & colour, 1);
|
||||
|
||||
if ((colour & 0x80) == 0) {
|
||||
data [move] = xprite_colour [colour];
|
||||
} else {
|
||||
int offset;
|
||||
|
||||
file_read (file, & repeat, 1);
|
||||
|
||||
for (offset = 0; offset < repeat; ++offset) {
|
||||
data [move + offset] = xprite_colour [colour & 0x7f];
|
||||
}
|
||||
|
||||
move += offset - 1;
|
||||
}
|
||||
}
|
||||
|
||||
file = file_close (file);
|
||||
|
||||
return (data);
|
||||
}
|
||||
|
||||
static void xprite_export (const char * path, int format, int width, int height, unsigned int * data) {
|
||||
int file, move;
|
||||
|
||||
file = file_open (path, O_RDWR | O_TRUNC | O_CREAT);
|
||||
|
||||
fatal_failure (format >= xprite_format_count, "xprite_export: Invalid sprite format.");
|
||||
fatal_failure ((width <= 0) || (width >= 256), "xprite_export: Invalid sprite width.");
|
||||
fatal_failure ((height <= 0) || (height >= 256), "xprite_export: Invalid sprite height.");
|
||||
|
||||
file_write (file, & format, 1);
|
||||
file_write (file, & width, 1);
|
||||
file_write (file, & height, 1);
|
||||
|
||||
for (move = 0; move < width * height; ++move) {
|
||||
int colour, repeat;
|
||||
|
||||
for (repeat = 0; (data [move] == data [move + repeat + 1]) && (repeat < 256); ++repeat);
|
||||
for (colour = 0; (data [move] != xprite_colour [colour]) && (colour < 128); ++colour);
|
||||
|
||||
if (colour == 128) colour = 127;
|
||||
|
||||
++repeat;
|
||||
|
||||
if (repeat == 1) {
|
||||
file_write (file, & colour, 1);
|
||||
} else {
|
||||
colour |= 0x80;
|
||||
move += repeat - 1;
|
||||
|
||||
file_write (file, & colour, 1);
|
||||
file_write (file, & repeat, 1);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
file = file_close (file);
|
||||
}
|
||||
|
||||
static void xprite_swap_channels (unsigned int * data, int width, int height) {
|
||||
int move;
|
||||
|
||||
for (move = 0; move < width * height; ++move) {
|
||||
data [move] = (data [move] & 0xff00ff00) | ((data [move] & 0xff0000) >> 16) | ((data [move] & 0xff) << 16);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user