diff --git a/bin/xrick2png/Makefile b/bin/xrick2png/Makefile new file mode 100644 index 0000000..dfbddc6 --- /dev/null +++ b/bin/xrick2png/Makefile @@ -0,0 +1,160 @@ +#-------------------------------------------------------- +# $File: Makefile,v $ +# +# $Date: 2006/05/29 $ +# $Author: jandersen $ +# $Revision: #1 $ +#-------------------------------------------------------- +# +# xrick2png GCC-Gnu Makefile +# +# Latest update - Just link with system libpng +# You should keep this up2date anyways +# On Ubuntu, something like this to install +# sudo apt-get install libpng-dev +# +SHELL = /bin/sh +MKDIR = mkdir + +TARGET = xrick2png + +PROJROOT = . + +#SYSTEM = /usr +#SYSLIBDIR = $(SYSTEM)/lib +#SYSINCDIR = $(SYSTEM)/include + +INCCMD = -I$(SYSINCDIR) +INCCMD += -I$(PROJROOT)/source +INCCMD += -I$(PROJROOT)/include + +OBJDIR = $(PROJROOT)/obj +DEPDIR = $(PROJROOT)/dep +LSTDIR = $(PROJROOT)/lst + +# +# Special GnuMake Search Path Directive +# +VPATH = $(PROJROOT)/source + +# +# Dedicated Search Paths for Specific Types +# +# Can be used to speed up compile by using this feature +# for each filetype (reducing the amount of searching) +# +vpath %.o $(OBJDIR) +vpath %.d $(DEPDIR) + +LIBCMD +=-lm -lpng + +OBJS := xrick2png.o +#OBJS += dat_picsPC.o +OBJS += dat_picsST.o +#OBJS += dat_tilesPC.o +OBJS += dat_tilesST.o +#OBJS += dat_spritesPC.o +OBJS += dat_spritesST.o + +# change list of .o's into a list of .d's + +DEPS := $(OBJS:%.o=%.d) + +AS = gcc +CC = gcc +LD = gcc +RM = /bin/rm -rfv + +CFLAGS = -O2 -Wall -Werror -Wa,-al -fno-common +CXXFLAGS = -O2 -Wall -Werror -Wa,-al -fno-common +ASFLAGS = -c -xassembler-with-cpp -Wa,-al +LDFLAGS = -Wl,-Map,$(TARGET).map $(LIBCMD) + +# Clear Default Suffixes +.SUFFIXES: +# Set my Own Suffixes +.SUFFIXES: .c .s .cc .d .o + +all: $(TARGET) + +$(TARGET): $(DEPS) $(OBJS) $(LIBS) + $(LD) -o $@ $(addprefix $(OBJDIR)/,$(OBJS)) $(LIBS) $(LDFLAGS) + +# Object Rules + +.s.o: + $(AS) $(ASFLAGS) $(TMPFLAGS) $(INCCMD) -o $(OBJDIR)/$@ $< > $(LSTDIR)/$*.lst + +.c.o: + $(CC) $(CFLAGS) $(TMPFLAGS) $(INCCMD) -c $< -o $(OBJDIR)/$*.o > $(LSTDIR)/$*.lst + +.cc.o: + $(CC) $(CXXFLAGS) $(TMPFLAGS) $(INCCMD) -c $< -o $(OBJDIR)/$*.o > $(LSTDIR)/$*.lst + +# Dependencie Rules +# +# for now just touch, to create the file if its not defined +# +.s.d: + touch $(DEPDIR)/$*.d + +.c.d: + set -e; $(CC) -M $(CFLAGS) $(INCCMD) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $(DEPDIR)/$@; \ + [ -s $(DEPDIR)/$@ ] || rm -f $(DEPDIR)/$@ + +.cc.d: + set -e; $(CC) -M $(CXXFLAGS) $(INCCMD) $< \ + | sed 's/\($*\)\.o[ :]*/\1.o $@ : /g' > $(DEPDIR)/$@; \ + [ -s $(DEPDIR)/$@ ] || rm -f $(DEPDIR)/$@ + +.PHONY: install +install: $(TARGET) + cp $(TARGET).exe $(PROJROOT)/../bin + +.PHONY: clean +clean: + $(RM) $(OBJDIR) *.o $(DEPDIR) *.map $(LSTDIR) $(TARGET) $(TARGET).exe + + +######################################## +# +# HELPER TARGET RULES +# +######################################## + +# +# Target that forces all of the objects to be rebuilt if the makefile changes +# + +$(OBJS) : Makefile +$(DEPS) : Makefile +# +# Targets that create the output object directory if it doesn't already exist +# + +Makefile : $(OBJDIR) $(DEPDIR) $(LSTDIR) + +$(OBJDIR) : + $(MKDIR) $(OBJDIR) + +# +# Targets that create the output dependency directory if it doesn't already exist +# + +$(DEPDIR) : + $(MKDIR) $(DEPDIR) + +# +# Targets that create the output list directory if it doesn't already exist +# + +$(LSTDIR) : + $(MKDIR) $(LSTDIR) + +# +# Generated Dependencie Files +# +-include $(wildcard $(DEPDIR)/*.d) + + diff --git a/bin/xrick2png/source/bctypes.h b/bin/xrick2png/source/bctypes.h new file mode 100644 index 0000000..fab7f0d --- /dev/null +++ b/bin/xrick2png/source/bctypes.h @@ -0,0 +1,55 @@ +/* + bctypes.h + + Budcat Standard Types + + (c) 2001-2006 Budcat Creations, LLC. + +*/ + +#ifndef _bctypes_h +#define _bctypes_h + +#include "system.h" + +typedef signed char i8; +typedef unsigned char u8; +typedef signed short i16; +typedef unsigned short u16; +typedef signed long i32; +typedef unsigned long u32; + +#if !_MSVC +typedef signed long long i64; +typedef unsigned long long u64; + +//typedef int i128 __attribute__ ((__mode__(__TI__))); // 128 bit integer +//typedef int s128 __attribute__ ((__mode__(__TI__))); // 128 bit signed integer +//typedef unsigned int u128 __attribute__ ((__mode__(__TI__))); // 128 bit unsigned integer +#endif + +typedef i32 bool; + +typedef float f32; +typedef float r32; +typedef double f64; +typedef double r64; + + +#define false (0) +#define true (!false) + +#define null (0) + +// Odd Types +typedef union { +// u128 ul128; + u64 ul64[2]; + u32 ui32[4]; +} QWdata; + + +#endif // _bctypes_h + +// EOF - bctypes.h + diff --git a/bin/xrick2png/source/xrick2png.c b/bin/xrick2png/source/xrick2png.c new file mode 100644 index 0000000..c0a5eff --- /dev/null +++ b/bin/xrick2png/source/xrick2png.c @@ -0,0 +1,336 @@ +/* +#-------------------------------------------------------- +# $File: xrick2png.c,v $ +#-------------------------------------------------------- +*/ + + +#include +#include +#include +#include + +#include "bctypes.h" +#include "xrick2png.h" +#include "png.h" + +// For the 3 pics +#include "pics.h" + +#include "sprites.h" +#include "tiles.h" + +#include "img.h" +#include "img_icon.e" +#include "img_splash.e" + +static void _usage() +{ + printf("xrick2png v%s\n\n", VERSION); + printf("Usage: xrick2png\n" + "Written by Jason Andersen\n" + "Copyright (c) 2018 Jason Andersen.\n" + "Unauthorized use prohibited\n"); + + exit(1); + +} // usage + +// +// Save the RawBMP Pixel Data, as raw IIGS +// framebuffer data +// +void savePixelsGS(MYBMP *pBitmap, const char* pFilename) +{ + FILE* gsfile = fopen( pFilename, "wb" ); + + if (gsfile) + { + unsigned char* pPixels = pBitmap->map; + + for (int y = 0; y < pBitmap->height; ++y) + { + for (int x = 0; x < pBitmap->width; x+=2) + { + unsigned char* pPixel = pPixels + (y*pBitmap->width) + x; + + unsigned char GS_PIXEL = 0; + GS_PIXEL = (pPixel[0] << 4) | (pPixel[1] & 0xF); + putc(GS_PIXEL, gsfile); + } + } + + fclose(gsfile); + } + else + { + fprintf(stderr,"\nERROR Unable to create output file: %s\n", pFilename); + exit(1); + } +} + +// +// Save the RawBMP Data as a PNG +// +void savePng(MYBMP *pBitmap, const char* pFilename) +{ + png_structp png_ptr; + png_infop info_ptr; + + // PNG Stuff + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, NULL, NULL ); + + if (!png_ptr) + { + fprintf(stderr,"\nERROR unable to png_create_write_struct\n"); + exit(1); + } + + info_ptr = png_create_info_struct(png_ptr); + + if (!info_ptr) + { + png_destroy_write_struct(&png_ptr,(png_infopp)NULL); + fprintf(stderr,"\nERROR enable to png_create_info_struct\n"); + exit(1); + } + + // Save it as a PNG + FILE *pngfile = fopen( pFilename, "wb" ); + if (pngfile) + { + int idx; + png_bytep ptr = (png_bytep) pBitmap->map; + + png_bytep *row_pointers = png_malloc(png_ptr, pBitmap->height * sizeof(png_bytep)); + + png_init_io( png_ptr, pngfile ); + + png_set_filter( png_ptr, 0, PNG_FILTER_NONE ); + + png_set_compression_level( png_ptr, Z_BEST_COMPRESSION ); + + if (256 == pBitmap->num_colors) + { + png_set_IHDR( png_ptr, + info_ptr, + pBitmap->width, + pBitmap->height, + 8, /*bit depth*/ + PNG_COLOR_TYPE_PALETTE, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT ); + + png_set_PLTE( png_ptr, + info_ptr, + (png_color*)pBitmap->palette, // (palette) Array of png color + 256 ); // (num_palette) number of color entries in palette + + for (idx = 0; idx < pBitmap->height; idx++) + { + row_pointers[ idx ] = ptr; + ptr+= pBitmap->width; + } + + png_set_rows(png_ptr, info_ptr, row_pointers); + + png_write_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL); + } + + fclose(pngfile); + } + else + { + fprintf(stderr,"\nERROR Unable to create output file: %s\n", pFilename); + exit(1); + } +} + + +/* + * color tables + */ + +#ifdef GFXPC +static U8 RED[] = { 0x00, 0x50, 0xf0, 0xf0, 0x00, 0x50, 0xf0, 0xf0 }; +static U8 GREEN[] = { 0x00, 0xf8, 0x50, 0xf8, 0x00, 0xf8, 0x50, 0xf8 }; +static U8 BLUE[] = { 0x00, 0x50, 0x50, 0x50, 0x00, 0xf8, 0xf8, 0xf8 }; +#endif +#ifdef GFXST +static U8 RED[] = { 0x00, 0xd8, 0xb0, 0xf8, + 0x20, 0x00, 0x00, 0x20, + 0x48, 0x48, 0x90, 0xd8, + 0x48, 0x68, 0x90, 0xb0, + /* cheat colors */ + 0x50, 0xe0, 0xc8, 0xf8, + 0x68, 0x50, 0x50, 0x68, + 0x80, 0x80, 0xb0, 0xe0, + 0x80, 0x98, 0xb0, 0xc8 +}; +static U8 GREEN[] = { 0x00, 0x00, 0x6c, 0x90, + 0x24, 0x48, 0x6c, 0x48, + 0x6c, 0x24, 0x48, 0x6c, + 0x48, 0x6c, 0x90, 0xb4, + /* cheat colors */ + 0x54, 0x54, 0x9c, 0xb4, + 0x6c, 0x84, 0x9c, 0x84, + 0x9c, 0x6c, 0x84, 0x9c, + 0x84, 0x9c, 0xb4, 0xcc +}; +static U8 BLUE[] = { 0x00, 0x00, 0x68, 0x68, + 0x20, 0xb0, 0xd8, 0x00, + 0x20, 0x00, 0x00, 0x00, + 0x48, 0x68, 0x90, 0xb0, + /* cheat colors */ + 0x50, 0x50, 0x98, 0x98, + 0x68, 0xc8, 0xe0, 0x50, + 0x68, 0x50, 0x50, 0x50, + 0x80, 0x98, 0xb0, 0xc8}; +#endif + +// +// Load the Data into the BMP +// +MYBMP* loadPic(U32* pPicData, int width, int height) +{ + MYBMP *pBitmap = (MYBMP*)malloc(sizeof(MYBMP)); + memset(pBitmap, 0, sizeof(MYBMP)); + + pBitmap->width = width; + pBitmap->height = height; + +#ifdef GFXST + + pBitmap->map = (unsigned char*) malloc(width*height); + pBitmap->num_colors = 256; + pBitmap->palette = (unsigned char*) malloc(256*3); + + int x; int y; int k; + + unsigned char* pMap = pBitmap->map; + + for (y = 0; y < height; ++y) + { + unsigned char *pB = pMap; + for (x = 0; x < width; x+=8) + { + u32 v = *pPicData++; + for (k = 8; k--; v >>=4) + { + pB[k] = v & 0xF; + } + pB+=8; + } + pMap += width; + } + + // palette + memset(pBitmap->palette, 0, 256*3); + + int pIdx = 0; + for (int idx=0; idx < 32; ++idx) + { + pBitmap->palette[pIdx++] = RED[idx]; + pBitmap->palette[pIdx++] = GREEN[idx]; + pBitmap->palette[pIdx++] = BLUE[idx]; + } + +#endif + + return pBitmap; +} + +MYBMP* loadImage(img_t *pImage) +{ + MYBMP *pBitmap = (MYBMP*)malloc(sizeof(MYBMP)); + memset(pBitmap, 0, sizeof(MYBMP)); + + int width = pImage->w; + int height = pImage->h; + + pBitmap->width = width; + pBitmap->height = height; + + pBitmap->map = (unsigned char*) pImage->pixels; + pBitmap->num_colors = 256; + pBitmap->palette = (unsigned char*) malloc(256*3); + + // palette + memset(pBitmap->palette, 0, 256*3); + + U8* pPal = pBitmap->palette; + + for (int idx = 0; idx < pImage->ncolors; ++idx) + { + pPal[0] = pImage->colors[idx].r; + pPal[1] = pImage->colors[idx].g; + pPal[2] = pImage->colors[idx].b; + pPal+=3; + } + + return pBitmap; +} + + +// +// Parse command line options +// +int main(int argc, char **argv) +{ + MYBMP *pBitmap; + + // Check Arguments + while (--argc > 0 && (*++argv)[0] == '-') + { + *argv+=1; + + if (strcmp("v", *argv) == 0) + { + printf("xrick2png v%s\n", VERSION); + exit(0); + } + + *argv+= strlen(*argv); // skip rest of string + + } + // At this point only one or 2 arguments left + // unput filename, and output base name + + if (argc) _usage(); + + pBitmap = loadPic( pic_haf, 0x140, 0x20 ); + savePng(pBitmap, "haf.png"); + savePixelsGS(pBitmap, "haf.gs"); + + pBitmap = loadPic( pic_congrats, 0x140, 0x20 ); + savePng(pBitmap, "congrats.png"); + savePixelsGS(pBitmap, "congrats.gs"); + + pBitmap = loadPic( pic_splash, 320, 200 ); + savePng(pBitmap, "splash.png"); + + pBitmap = loadImage( IMG_SPLASH ); + savePng(pBitmap, "img_splash.png"); + + pBitmap = loadImage( IMG_ICON ); + savePng(pBitmap, "img_icon.png"); + + pBitmap = loadPic((U32*)&sprites_data[0][0], 32, 21 * 0xd6); + savePng(pBitmap, "sprites_data.png"); + savePixelsGS(pBitmap, "sprites_data.gs"); + + pBitmap = loadPic((U32*)&tiles_data[0][0], 8, 8 * 0x100); + savePng(pBitmap, "tiles_data.png"); + savePixelsGS(pBitmap, "tiles_data.gs"); + + + printf("\nxrick2png - Processing complete.\n"); + + exit(0); + +} // main + + +// eof - xrick2png.c + diff --git a/bin/xrick2png/source/xrick2png.h b/bin/xrick2png/source/xrick2png.h new file mode 100644 index 0000000..6e7bec5 --- /dev/null +++ b/bin/xrick2png/source/xrick2png.h @@ -0,0 +1,28 @@ +/* +#-------------------------------------------------------- +# $File: xrick2png.h,v $ +# $Author: jandersen $ +# $Revision: #1 $ +#-------------------------------------------------------- + +*/ + +#ifndef _xrick2png_h +#define _xrick2png_h + +//#define VERSION "1.00" + +// MYBMP Structure +typedef struct MYBMP { + signed int width; // width in pixels + signed int height; // height in pixels + int num_colors; + unsigned char *map; // pointer to pixel map + unsigned char *palette; // pointer to palette data +} MYBMP; + +#endif // _dg2png_h + +// EOF - xrick2png.h + +