Skip to content

Commit

Permalink
Add rgbgfx.
Browse files Browse the repository at this point in the history
  • Loading branch information
bentley committed Sep 5, 2016
1 parent 330a395 commit c3c3113
Show file tree
Hide file tree
Showing 10 changed files with 1,039 additions and 4 deletions.
2 changes: 2 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ released under the following license:
rgbfix was rewritten from scratch by Anthony J. Bentley, and is released
under the ISC license; see the source file for the text of the license.

rgbgfx was written by stag019, and is released under the ISC license.

The UTF-8 decoder in src/asm/charmap.c was written by Björn Höhrmann and is
released under the MIT license. The remainder of charmap.c was written by
stag019, and is released under the ISC license.
Expand Down
24 changes: 20 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
.POSIX:

PKG_CONFIG = pkg-config
WARNFLAGS = -Wall -Werror=implicit
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} -Iinclude -g \
PNGFLAGS != ${PKG_CONFIG} --cflags libpng
REALCFLAGS = ${CFLAGS} ${WARNFLAGS} ${PNGFLAGS} -Iinclude -g \
-std=c99 -D_POSIX_C_SOURCE=200809L

# User-defined variables
PREFIX = /usr/local
BINPREFIX = ${PREFIX}/bin
MANPREFIX = ${PREFIX}/man
Q = @
PKG_CONFIG = pkg-config

rgbasm_obj = \
src/asm/asmy.o \
Expand Down Expand Up @@ -42,25 +43,34 @@ rgbfix_obj = \
src/fix/main.o \
src/extern/err.o

all: rgbasm rgblink rgbfix
rgbgfx_obj = \
src/gfx/gb.o \
src/gfx/main.o \
src/gfx/png.o \
src/extern/err.o

all: rgbasm rgblink rgbfix rgbgfx

clean:
$Qrm -rf rgbds.html
$Qrm -rf rgbasm rgbasm.exe ${rgbasm_obj} rgbasm.html
$Qrm -rf rgblink rgblink.exe ${rgblink_obj} rgblink.html
$Qrm -rf rgbfix rgbfix.exe ${rgbfix_obj} rgbfix.html
$Qrm -rf rgbgfx rgbgfx.exe ${rgbgfx_obj} rgbgfx.html
$Qrm -rf src/asm/asmy.c src/asm/asmy.h

install: all
$Qmkdir -p ${BINPREFIX}
$Qinstall -s -m 555 rgbasm ${BINPREFIX}/rgbasm
$Qinstall -s -m 555 rgbfix ${BINPREFIX}/rgbfix
$Qinstall -s -m 555 rgblink ${BINPREFIX}/rgblink
$Qinstall -s -m 555 rgbgfx ${BINPREFIX}/rgbgfx
$Qmkdir -p ${MANPREFIX}/man1 ${MANPREFIX}/man7
$Qinstall -m 444 src/rgbds.7 ${MANPREFIX}/man7/rgbds.7
$Qinstall -m 444 src/asm/rgbasm.1 ${MANPREFIX}/man1/rgbasm.1
$Qinstall -m 444 src/fix/rgbfix.1 ${MANPREFIX}/man1/rgbfix.1
$Qinstall -m 444 src/link/rgblink.1 ${MANPREFIX}/man1/rgblink.1
$Qinstall -m 444 src/gfx/rgbgfx.1 ${MANPREFIX}/man1/rgbgfx.1

rgbasm: ${rgbasm_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbasm_obj} -lm
Expand All @@ -71,6 +81,9 @@ rgblink: ${rgblink_obj}
rgbfix: ${rgbfix_obj}
$Q${CC} ${REALCFLAGS} -o $@ ${rgbfix_obj}

rgbgfx: ${rgbgfx_obj}
$Q${CC} `${PKG_CONFIG} --libs libpng` ${REALCFLAGS} -o $@ ${rgbgfx_obj}

.y.c:
$Q${YACC} -d ${YFLAGS} -o $@ $<

Expand All @@ -91,6 +104,7 @@ mingw:
$Qmv rgbasm rgbasm.exe
$Qmv rgblink rgblink.exe
$Qmv rgbfix rgbfix.exe
$Qmv rgbgfx rgbgfx.exe

# Below is a target for the project maintainer to easily create web manuals.
# It relies on mandoc: http://mdocml.bsd.lv
Expand All @@ -105,3 +119,5 @@ wwwman:
rgbfix.html
$Qmandoc ${MANDOC} src/link/rgblink.1 | sed s/OpenBSD/General/ > \
rgblink.html
$Qmandoc ${MANDOC} src/gfx/rgbgfx.1 | sed s/OpenBSD/General/ > \
rgbgfx.html
1 change: 1 addition & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ for the Game Boy and Game Boy Color. It consists of:
- rgbasm (assembler)
- rgblink (linker)
- rgbfix (checksum/header fixer)
- rgbgfx (PNG‐to‐Game Boy graphics converter)

rgbds-linux is a fork of the original RGBDS which aims to make the programs
more like other UNIX tools.
Expand Down
30 changes: 30 additions & 0 deletions include/gfx/gb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef RGBDS_GFX_GB_H
#define RGBDS_GFX_GB_H

#include <stdint.h>
#include "gfx/main.h"

void png_to_gb(struct PNGImage png, struct GBImage *gb);
void output_file(struct Options opts, struct GBImage gb);
int get_tile_index(uint8_t *tile, uint8_t **tiles, int num_tiles, int tile_size);
void create_tilemap(struct Options opts, struct GBImage *gb, struct Tilemap *tilemap);
void output_tilemap_file(struct Options opts, struct Tilemap tilemap);
void output_palette_file(struct Options opts, struct PNGImage png);

#endif
75 changes: 75 additions & 0 deletions include/gfx/main.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef RGBDS_GFX_MAIN_H
#define RGBDS_GFX_MAIN_H

#include <png.h>
#include <stdbool.h>
#include <stdint.h>

#include "extern/err.h"

struct Options {
bool debug;
bool verbose;
bool hardfix;
bool fix;
bool horizontal;
bool unique;
int trim;
char *mapfile;
bool mapout;
char *palfile;
bool palout;
char *outfile;
char *infile;
};

struct PNGImage {
png_struct *png;
png_info *info;
png_byte **data;
int width;
int height;
png_byte depth;
png_byte type;
bool horizontal;
int trim;
char *mapfile;
bool mapout;
char *palfile;
bool palout;
};

struct GBImage {
uint8_t *data;
int size;
bool horizontal;
int trim;
};

struct Tilemap {
uint8_t *data;
int size;
};

int depth, colors;

#include "gfx/png.h"
#include "gfx/gb.h"

#endif
28 changes: 28 additions & 0 deletions include/gfx/png.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright © 2013 stag019 <stag019@gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef RGBDS_GFX_PNG_H
#define RGBDS_GFX_PNG_H

#include "gfx/main.h"

void input_png_file(struct Options opts, struct PNGImage *img);
void get_text(struct PNGImage *png);
void set_text(struct PNGImage *png);
void output_png_file(struct Options opts, struct PNGImage *png);
void free_png_data(struct PNGImage *png);

#endif
Loading

0 comments on commit c3c3113

Please sign in to comment.