Skip to content

Commit c3c3113

Browse files
committed
Add rgbgfx.
1 parent 330a395 commit c3c3113

File tree

10 files changed

+1039
-4
lines changed

10 files changed

+1039
-4
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ released under the following license:
1818
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
1919
under the ISC license; see the source file for the text of the license.
2020

21+
rgbgfx was written by stag019, and is released under the ISC license.
22+
2123
The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
2224
released under the MIT license. The remainder of charmap.c was written by
2325
stag019, and is released under the ISC license.

Makefile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
.POSIX:
2-
1+
PKG_CONFIG = pkg-config
32
WARNFLAGS = -Wall -Werror=implicit
4-
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
3+
PNGFLAGS != ${PKG_CONFIG} --cflags libpng
4+
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
55
-std=c99 -D_POSIX_C_SOURCE=200809L
66

77
# User-defined variables
88
PREFIX = /usr/local
99
BINPREFIX = ${PREFIX}/bin
1010
MANPREFIX = ${PREFIX}/man
1111
Q = @
12+
PKG_CONFIG = pkg-config
1213

1314
rgbasm_obj = \
1415
src/asm/asmy.o \
@@ -42,25 +43,34 @@ rgbfix_obj = \
4243
src/fix/main.o \
4344
src/extern/err.o
4445

45-
all: rgbasm rgblink rgbfix
46+
rgbgfx_obj = \
47+
src/gfx/gb.o \
48+
src/gfx/main.o \
49+
src/gfx/png.o \
50+
src/extern/err.o
51+
52+
all: rgbasm rgblink rgbfix rgbgfx
4653

4754
clean:
4855
$Qrm -rf rgbds.html
4956
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
5057
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
5158
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
59+
$Qrm -rf rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.html
5260
$Qrm -rf src/asm/asmy.c src/asm/asmy.h
5361

5462
install: all
5563
$Qmkdir -p ${BINPREFIX}
5664
$Qinstall -s -m 555 rgbasm ${BINPREFIX}/rgbasm
5765
$Qinstall -s -m 555 rgbfix ${BINPREFIX}/rgbfix
5866
$Qinstall -s -m 555 rgblink ${BINPREFIX}/rgblink
67+
$Qinstall -s -m 555 rgbgfx ${BINPREFIX}/rgbgfx
5968
$Qmkdir -p ${MANPREFIX}/man1 ${MANPREFIX}/man7
6069
$Qinstall -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7
6170
$Qinstall -m 444 src/asm/rgbasm.1 ${MANPREFIX}/man1/rgbasm.1
6271
$Qinstall -m 444 src/fix/rgbfix.1 ${MANPREFIX}/man1/rgbfix.1
6372
$Qinstall -m 444 src/link/rgblink.1 ${MANPREFIX}/man1/rgblink.1
73+
$Qinstall -m 444 src/gfx/rgbgfx.1 ${MANPREFIX}/man1/rgbgfx.1
6474

6575
rgbasm: ${rgbasm_obj}
6676
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
@@ -71,6 +81,9 @@ rgblink: ${rgblink_obj}
7181
rgbfix: ${rgbfix_obj}
7282
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}
7383

84+
rgbgfx: ${rgbgfx_obj}
85+
$Q${CC} `${PKG_CONFIG} --libs libpng` ${REALCFLAGS} -o $@ ${rgbgfx_obj}
86+
7487
.y.c:
7588
$Q${YACC} -d ${YFLAGS} -o $@ $<
7689

@@ -91,6 +104,7 @@ mingw:
91104
$Qmv rgbasm rgbasm.exe
92105
$Qmv rgblink rgblink.exe
93106
$Qmv rgbfix rgbfix.exe
107+
$Qmv rgbgfx rgbgfx.exe
94108

95109
# Below is a target for the project maintainer to easily create web manuals.
96110
# It relies on mandoc: http://mdocml.bsd.lv
@@ -105,3 +119,5 @@ wwwman:
105119
rgbfix.html
106120
$Qmandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > \
107121
rgblink.html
122+
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 | sed s/OpenBSD/General/ > \
123+
rgbgfx.html

README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ for the Game Boy and Game Boy Color. It consists of:
88
- rgbasm (assembler)
99
- rgblink (linker)
1010
- rgbfix (checksum/header fixer)
11+
- rgbgfx (PNG‐to‐Game Boy graphics converter)
1112

1213
rgbds-linux is a fork of the original RGBDS which aims to make the programs
1314
more like other UNIX tools.

include/gfx/gb.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright © 2013 stag019 <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef RGBDS_GFX_GB_H
18+
#define RGBDS_GFX_GB_H
19+
20+
#include <stdint.h>
21+
#include "gfx/main.h"
22+
23+
void png_to_gb(struct PNGImage png, struct GBImage *gb);
24+
void output_file(struct Options opts, struct GBImage gb);
25+
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size);
26+
void create_tilemap(struct Options opts, struct GBImage *gb, struct Tilemap *tilemap);
27+
void output_tilemap_file(struct Options opts, struct Tilemap tilemap);
28+
void output_palette_file(struct Options opts, struct PNGImage png);
29+
30+
#endif

include/gfx/main.h

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright © 2013 stag019 <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef RGBDS_GFX_MAIN_H
18+
#define RGBDS_GFX_MAIN_H
19+
20+
#include <png.h>
21+
#include <stdbool.h>
22+
#include <stdint.h>
23+
24+
#include "extern/err.h"
25+
26+
struct Options {
27+
bool debug;
28+
bool verbose;
29+
bool hardfix;
30+
bool fix;
31+
bool horizontal;
32+
bool unique;
33+
int trim;
34+
char *mapfile;
35+
bool mapout;
36+
char *palfile;
37+
bool palout;
38+
char *outfile;
39+
char *infile;
40+
};
41+
42+
struct PNGImage {
43+
png_struct *png;
44+
png_info *info;
45+
png_byte **data;
46+
int width;
47+
int height;
48+
png_byte depth;
49+
png_byte type;
50+
bool horizontal;
51+
int trim;
52+
char *mapfile;
53+
bool mapout;
54+
char *palfile;
55+
bool palout;
56+
};
57+
58+
struct GBImage {
59+
uint8_t *data;
60+
int size;
61+
bool horizontal;
62+
int trim;
63+
};
64+
65+
struct Tilemap {
66+
uint8_t *data;
67+
int size;
68+
};
69+
70+
int depth, colors;
71+
72+
#include "gfx/png.h"
73+
#include "gfx/gb.h"
74+
75+
#endif

include/gfx/png.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright © 2013 stag019 <[email protected]>
3+
*
4+
* Permission to use, copy, modify, and distribute this software for any
5+
* purpose with or without fee is hereby granted, provided that the above
6+
* copyright notice and this permission notice appear in all copies.
7+
*
8+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9+
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10+
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11+
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12+
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13+
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14+
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15+
*/
16+
17+
#ifndef RGBDS_GFX_PNG_H
18+
#define RGBDS_GFX_PNG_H
19+
20+
#include "gfx/main.h"
21+
22+
void input_png_file(struct Options opts, struct PNGImage *img);
23+
void get_text(struct PNGImage *png);
24+
void set_text(struct PNGImage *png);
25+
void output_png_file(struct Options opts, struct PNGImage *png);
26+
void free_png_data(struct PNGImage *png);
27+
28+
#endif

0 commit comments

Comments
 (0)