gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit e3671c05a71d72a62f96c64fe98b9c44b79bed54 parent af5bcd03b8a39e3703e1f662825eefd0b666e4e4 Author: Zal0 <cebolleto@gmail.com> Date: Fri, 29 Jan 2021 09:44:33 +0100 compiling with gcc, added makefile Diffstat:
| A | gbdk-support/png2mtspr/Makefile | 30 | ++++++++++++++++++++++++++++++ |
| M | gbdk-support/png2mtspr/picopng.cpp | 8 | +++++--- |
| M | gbdk-support/png2mtspr/png2mtspr.cpp | 17 | +++++++++-------- |
3 files changed, 44 insertions(+), 11 deletions(-)
diff --git a/gbdk-support/png2mtspr/Makefile b/gbdk-support/png2mtspr/Makefile @@ -0,0 +1,29 @@ +# ***************************************************** +# Variables to control Makefile operation + +CXX = g++ +CXXFLAGS = -Wall -g +LFLAGS = -g -static -std=c++11 + +# **************************************************** +# Targets needed to bring the executable up to date + +TARGET = png2mtspr + +SRCS := picopng.cpp png2mtspr.cpp +OBJS := $(SRCS:%.cpp=%.o) + +$(TARGET): $(OBJS) + $(CXX) $(LFLAGS) -o $(TARGET) $(OBJS) + +# The main.o target can be written more simply + +%.cpp.o: %.cpp + @echo compiling $< + $(CXX) $(CXXFLAGS) -c $< -o $@ + + clean: + @echo cleaning $(TARGET) + rm -f *.o + rm -f *.exe + rm -f TARGET + diff --git a/gbdk-support/png2mtspr/picopng.cpp b/gbdk-support/png2mtspr/picopng.cpp @@ -1,5 +1,8 @@ #include <vector> +#include <cstddef> +using namespace std; + /* decodePNG: The picoPNG function, decodes a PNG file buffer in memory, into a raw pixel buffer. out_image: output parameter, this will contain the raw pixels after decoding. @@ -260,7 +263,7 @@ int decodePNG(std::vector<unsigned char>& out_image, unsigned long& image_width, readPngHeader(&in[0], size); if(error) return; size_t pos = 33; //first byte of the first chunk after the header std::vector<unsigned char> idat; //the data from idat chunks - bool IEND = false, known_type = true; + bool IEND = false/*, known_type = true*/; info.key_defined = false; while(!IEND) //loop through the chunks, ignoring unknown chunks and stopping at IEND chunk. IDAT data is put at the start of the in buffer { @@ -312,7 +315,7 @@ int decodePNG(std::vector<unsigned char>& out_image, unsigned long& image_width, { if(!(in[pos + 0] & 32)) { error = 69; return; } //error: unknown critical chunk (5th bit of first byte of chunk type is 0) pos += (chunkLength + 4); //skip 4 letters and uninterpreted data of unimplemented chunk - known_type = false; + //known_type = false; } pos += 4; //step over CRC (which is ignored) } @@ -577,7 +580,6 @@ void loadFile(std::vector<unsigned char>& buffer, const std::string& filename) / if(image.size() > 4) std::cout << "width: " << w << " height: " << h << " first pixel: " << std::hex << int(image[0]) << int(image[1]) << int(image[2]) << int(image[3]) << std::endl; } -/* //this is test code, it displays the pixels of a 1 bit PNG. To use it, set the flag convert_to_rgba32 to false and load a 1-bit PNG image with a small size (so that its ASCII representation can fit in a console window) for(int y = 0; y < h; y++) { diff --git a/gbdk-support/png2mtspr/png2mtspr.cpp b/gbdk-support/png2mtspr/png2mtspr.cpp @@ -3,6 +3,7 @@ #include <fstream> #include <string> #include <algorithm> +#include <cstring> using namespace std; @@ -184,12 +185,12 @@ int main(int argc, char *argv[]) if(argc < 2) { printf("usage: png2mtspr <file>.png [options]\n"); - printf("-c ouput file (default: <png file>.c)\n"); - printf("-sw <width> metasprites width size (default: png width)\n"); + printf("-c ouput file (default: <png file>.c)\n"); + printf("-sw <width> metasprites width size (default: png width)\n"); printf("-sh <height> metasprites height size (default: png height)\n"); - printf("-spr8x8 use SPRITES_8x8 (default: SPRITES_8x16)\n"); - printf("-spr8x16 use SPRITES_8x16 (default: SPRITES_8x16)\n"); - printf("-b <bank> bank (default 0)\n"); + printf("-spr8x8 use SPRITES_8x8 (default: SPRITES_8x16)\n"); + printf("-spr8x16 use SPRITES_8x16 (default: SPRITES_8x16)\n"); + printf("-b <bank> bank (default 0)\n"); return 0; } @@ -230,10 +231,10 @@ int main(int argc, char *argv[]) } } - int slash_pos = output_filename.find_last_of('/'); + int slash_pos = output_filename.rfind('/'); if(slash_pos == -1) - slash_pos = output_filename.find_last_of('\\'); - int dot_pos = output_filename.find_last_of('.'); + slash_pos = output_filename.rfind('\\'); + int dot_pos = output_filename.rfind('.'); if(slash_pos == -1) slash_pos = 0; if(dot_pos == -1) dot_pos = 0;
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.