diff --git a/graphics/spinda_spots/spot_0.bin b/graphics/spinda_spots/spot_0.bin deleted file mode 100644 index 938d1d592..000000000 Binary files a/graphics/spinda_spots/spot_0.bin and /dev/null differ diff --git a/graphics/spinda_spots/spot_0.png b/graphics/spinda_spots/spot_0.png new file mode 100644 index 000000000..e0a515d77 Binary files /dev/null and b/graphics/spinda_spots/spot_0.png differ diff --git a/graphics/spinda_spots/spot_1.bin b/graphics/spinda_spots/spot_1.bin deleted file mode 100644 index db46b5de4..000000000 Binary files a/graphics/spinda_spots/spot_1.bin and /dev/null differ diff --git a/graphics/spinda_spots/spot_1.png b/graphics/spinda_spots/spot_1.png new file mode 100644 index 000000000..0e7fbd399 Binary files /dev/null and b/graphics/spinda_spots/spot_1.png differ diff --git a/graphics/spinda_spots/spot_2.bin b/graphics/spinda_spots/spot_2.bin deleted file mode 100644 index 3b1bf7214..000000000 Binary files a/graphics/spinda_spots/spot_2.bin and /dev/null differ diff --git a/graphics/spinda_spots/spot_2.png b/graphics/spinda_spots/spot_2.png new file mode 100644 index 000000000..9bf72bd8c Binary files /dev/null and b/graphics/spinda_spots/spot_2.png differ diff --git a/graphics/spinda_spots/spot_3.bin b/graphics/spinda_spots/spot_3.bin deleted file mode 100644 index 10c73f9ba..000000000 Binary files a/graphics/spinda_spots/spot_3.bin and /dev/null differ diff --git a/graphics/spinda_spots/spot_3.png b/graphics/spinda_spots/spot_3.png new file mode 100644 index 000000000..cf4a96f7d Binary files /dev/null and b/graphics/spinda_spots/spot_3.png differ diff --git a/graphics_file_rules.mk b/graphics_file_rules.mk index 69fc398d8..97a7794b3 100644 --- a/graphics_file_rules.mk +++ b/graphics_file_rules.mk @@ -21,6 +21,7 @@ JPCONTESTGFXDIR := graphics/contest/japanese POKEDEXGFXDIR := graphics/pokedex STARTERGFXDIR := graphics/starter_choose NAMINGGFXDIR := graphics/naming_screen +SPINDAGFXDIR := graphics/spinda_spots types := normal fight flying poison ground rock bug ghost steel mystery fire water grass electric psychic ice dragon dark contest_types := cool beauty cute smart tough @@ -680,3 +681,15 @@ $(NAMINGGFXDIR)/cursor_squished.4bpp: %.4bpp: %.png $(NAMINGGFXDIR)/cursor_filled.4bpp: %.4bpp: %.png $(GFX) $< $@ -num_tiles 5 -Wnum_tiles + +$(SPINDAGFXDIR)/spot_0.1bpp: %.1bpp: %.png + $(GFX) $< $@ -plain -data_width 2 + +$(SPINDAGFXDIR)/spot_1.1bpp: %.1bpp: %.png + $(GFX) $< $@ -plain -data_width 2 + +$(SPINDAGFXDIR)/spot_2.1bpp: %.1bpp: %.png + $(GFX) $< $@ -plain -data_width 2 + +$(SPINDAGFXDIR)/spot_3.1bpp: %.1bpp: %.png + $(GFX) $< $@ -plain -data_width 2 diff --git a/src/pokemon.c b/src/pokemon.c index bebed465b..fa2eee42c 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -1346,10 +1346,10 @@ static const u16 sHoennToNationalOrder[NUM_SPECIES - 1] = const struct SpindaSpot gSpindaSpotGraphics[] = { - {.x = 16, .y = 7, .image = INCBIN_U16("graphics/spinda_spots/spot_0.bin")}, - {.x = 40, .y = 8, .image = INCBIN_U16("graphics/spinda_spots/spot_1.bin")}, - {.x = 22, .y = 25, .image = INCBIN_U16("graphics/spinda_spots/spot_2.bin")}, - {.x = 34, .y = 26, .image = INCBIN_U16("graphics/spinda_spots/spot_3.bin")} + {.x = 16, .y = 7, .image = INCBIN_U16("graphics/spinda_spots/spot_0.1bpp")}, + {.x = 40, .y = 8, .image = INCBIN_U16("graphics/spinda_spots/spot_1.1bpp")}, + {.x = 22, .y = 25, .image = INCBIN_U16("graphics/spinda_spots/spot_2.1bpp")}, + {.x = 34, .y = 26, .image = INCBIN_U16("graphics/spinda_spots/spot_3.1bpp")} }; #include "data/pokemon/item_effects.h" diff --git a/tools/gbagfx/convert_png.c b/tools/gbagfx/convert_png.c index a5fefbd8b..c9c240efb 100644 --- a/tools/gbagfx/convert_png.c +++ b/tools/gbagfx/convert_png.c @@ -130,7 +130,6 @@ void ReadPng(char *path, struct Image *image) FATAL_ERROR("Bit depth of image must be 1, 2, 4, or 8.\n"); image->pixels = ConvertBitDepth(image->pixels, bit_depth, image->bitDepth, image->width * image->height); free(src); - image->bitDepth = bit_depth; } } diff --git a/tools/gbagfx/gfx.c b/tools/gbagfx/gfx.c index 832e9bb39..1dfc38e2d 100644 --- a/tools/gbagfx/gfx.c +++ b/tools/gbagfx/gfx.c @@ -204,6 +204,18 @@ static void ConvertToTiles8Bpp(unsigned char *src, unsigned char *dest, int numT } } +// For untiled, plain images +static void CopyPlainPixels(unsigned char *src, unsigned char *dest, int size, int dataWidth, bool invertColors) +{ + if (dataWidth == 0) return; + for (int i = 0; i < size; i += dataWidth) { + for (int j = dataWidth; j > 0; j--) { + unsigned char pixels = src[i + j - 1]; + *dest++ = invertColors ? ~pixels : pixels; + } + } +} + static void DecodeAffineTilemap(unsigned char *input, unsigned char *output, unsigned char *tilemap, int tileSize, int numTiles) { for (int i = 0; i < numTiles; i++) @@ -345,9 +357,9 @@ static unsigned char *DecodeTilemap(unsigned char *tiles, struct Tilemap *tilema return decoded; } -void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors) +void ReadTileImage(char *path, int tilesWidth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors) { - int tileSize = bitDepth * 8; + int tileSize = image->bitDepth * 8; int fileSize; unsigned char *buffer = ReadWholeFile(path, &fileSize); @@ -355,26 +367,25 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int int numTiles = fileSize / tileSize; if (image->tilemap.data.affine != NULL) { - int outTileSize = (bitDepth == 4 && image->palette.numColors > 16) ? 64 : tileSize; - buffer = DecodeTilemap(buffer, &image->tilemap, &numTiles, image->isAffine, tileSize, outTileSize, bitDepth); + int outTileSize = (image->bitDepth == 4 && image->palette.numColors > 16) ? 64 : tileSize; + buffer = DecodeTilemap(buffer, &image->tilemap, &numTiles, image->isAffine, tileSize, outTileSize, image->bitDepth); if (outTileSize == 64) { tileSize = 64; - image->bitDepth = bitDepth = 8; + image->bitDepth = 8; } } int tilesHeight = (numTiles + tilesWidth - 1) / tilesWidth; if (tilesWidth % metatileWidth != 0) - FATAL_ERROR("The width in tiles (%d) isn't a multiple of the specified metatile width (%d)", tilesWidth, metatileWidth); + FATAL_ERROR("The width in tiles (%d) isn't a multiple of the specified metatile width (%d)\n", tilesWidth, metatileWidth); if (tilesHeight % metatileHeight != 0) - FATAL_ERROR("The height in tiles (%d) isn't a multiple of the specified metatile height (%d)", tilesHeight, metatileHeight); + FATAL_ERROR("The height in tiles (%d) isn't a multiple of the specified metatile height (%d)\n", tilesHeight, metatileHeight); image->width = tilesWidth * 8; image->height = tilesHeight * 8; - image->bitDepth = bitDepth; image->pixels = calloc(tilesWidth * tilesHeight, tileSize); if (image->pixels == NULL) @@ -382,7 +393,7 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int int metatilesWide = tilesWidth / metatileWidth; - switch (bitDepth) { + switch (image->bitDepth) { case 1: ConvertFromTiles1Bpp(buffer, image->pixels, numTiles, metatilesWide, metatileWidth, metatileHeight, invertColors); break; @@ -397,9 +408,9 @@ void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int free(buffer); } -void WriteImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors) +void WriteTileImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors) { - int tileSize = bitDepth * 8; + int tileSize = image->bitDepth * 8; if (image->width % 8 != 0) FATAL_ERROR("The width in pixels (%d) isn't a multiple of 8.\n", image->width); @@ -411,10 +422,10 @@ void WriteImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int bi int tilesHeight = image->height / 8; if (tilesWidth % metatileWidth != 0) - FATAL_ERROR("The width in tiles (%d) isn't a multiple of the specified metatile width (%d)", tilesWidth, metatileWidth); + FATAL_ERROR("The width in tiles (%d) isn't a multiple of the specified metatile width (%d)\n", tilesWidth, metatileWidth); if (tilesHeight % metatileHeight != 0) - FATAL_ERROR("The height in tiles (%d) isn't a multiple of the specified metatile height (%d)", tilesHeight, metatileHeight); + FATAL_ERROR("The height in tiles (%d) isn't a multiple of the specified metatile height (%d)\n", tilesHeight, metatileHeight); int maxNumTiles = tilesWidth * tilesHeight; @@ -432,7 +443,7 @@ void WriteImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int bi int metatilesWide = tilesWidth / metatileWidth; - switch (bitDepth) { + switch (image->bitDepth) { case 1: ConvertToTiles1Bpp(image->pixels, buffer, maxNumTiles, metatilesWide, metatileWidth, metatileHeight, invertColors); break; @@ -468,6 +479,57 @@ void WriteImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int bi free(buffer); } +void ReadPlainImage(char *path, int dataWidth, struct Image *image, bool invertColors) +{ + int fileSize; + unsigned char *buffer = ReadWholeFile(path, &fileSize); + + if (fileSize % dataWidth != 0) + FATAL_ERROR("The image data size (%d) isn't a multiple of the specified data width %d.\n", fileSize, dataWidth); + + // png scanlines have wasted bits if they do not align to byte boundaries. + // pngs misaligned in this way are not currently handled. + int pixelsPerByte = 8 / image->bitDepth; + if (image->width % pixelsPerByte != 0) + FATAL_ERROR("The width in pixels (%d) isn't a multiple of %d.\n", image->width, pixelsPerByte); + + int numPixels = fileSize * pixelsPerByte; + image->height = (numPixels + image->width - 1) / image->width; + image->pixels = calloc(image->width * image->height * image->bitDepth / 8, 1); + + if (image->pixels == NULL) + FATAL_ERROR("Failed to allocate memory for pixels.\n"); + + CopyPlainPixels(buffer, image->pixels, fileSize, dataWidth, invertColors); + + free(buffer); +} + +void WritePlainImage(char *path, int dataWidth, struct Image *image, bool invertColors) +{ + int bufferSize = image->width * image->height * image->bitDepth / 8; + + if (bufferSize % dataWidth != 0) + FATAL_ERROR("The image data size (%d) isn't a multiple of the specified data width %d.\n", bufferSize, dataWidth); + + // png scanlines have wasted bits if they do not align to byte boundaries. + // pngs misaligned in this way are not currently handled. + int pixelsPerByte = 8 / image->bitDepth; + if (image->width % pixelsPerByte != 0) + FATAL_ERROR("The width in pixels (%d) isn't a multiple of %d.\n", image->width, pixelsPerByte); + + unsigned char *buffer = malloc(bufferSize); + + if (buffer == NULL) + FATAL_ERROR("Failed to allocate memory for pixels.\n"); + + CopyPlainPixels(image->pixels, buffer, bufferSize, dataWidth, invertColors); + + WriteWholeFile(path, buffer, bufferSize); + + free(buffer); +} + void FreeImage(struct Image *image) { if (image->tilemap.data.affine != NULL) diff --git a/tools/gbagfx/gfx.h b/tools/gbagfx/gfx.h index f1dbfcf4f..1797d84df 100644 --- a/tools/gbagfx/gfx.h +++ b/tools/gbagfx/gfx.h @@ -50,8 +50,10 @@ enum NumTilesMode { NUM_TILES_ERROR, }; -void ReadImage(char *path, int tilesWidth, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); -void WriteImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int bitDepth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); +void ReadTileImage(char *path, int tilesWidth, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); +void WriteTileImage(char *path, enum NumTilesMode numTilesMode, int numTiles, int metatileWidth, int metatileHeight, struct Image *image, bool invertColors); +void ReadPlainImage(char *path, int dataWidth, struct Image *image, bool invertColors); +void WritePlainImage(char *path, int dataWidth, struct Image *image, bool invertColors); void FreeImage(struct Image *image); void ReadGbaPalette(char *path, struct Palette *palette); void WriteGbaPalette(char *path, struct Palette *palette); diff --git a/tools/gbagfx/main.c b/tools/gbagfx/main.c index 5d4faacab..98a1a1edf 100644 --- a/tools/gbagfx/main.c +++ b/tools/gbagfx/main.c @@ -25,6 +25,9 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * { struct Image image; + image.bitDepth = options->bitDepth; + image.tilemap.data.affine = NULL; + if (options->paletteFilePath != NULL) { char *paletteFileExtension = GetFileExtensionAfterDot(options->paletteFilePath); @@ -45,22 +48,25 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions * image.hasPalette = false; } - if (options->tilemapFilePath != NULL) + if (options->isTiled) { - int fileSize; - image.tilemap.data.affine = ReadWholeFile(options->tilemapFilePath, &fileSize); - if (options->isAffineMap && options->bitDepth != 8) - FATAL_ERROR("affine maps are necessarily 8bpp\n"); - image.isAffine = options->isAffineMap; - image.tilemap.size = fileSize; + if (options->tilemapFilePath != NULL) + { + int fileSize; + image.tilemap.data.affine = ReadWholeFile(options->tilemapFilePath, &fileSize); + if (options->isAffineMap && options->bitDepth != 8) + FATAL_ERROR("affine maps are necessarily 8bpp\n"); + image.isAffine = options->isAffineMap; + image.tilemap.size = fileSize; + } + ReadTileImage(inputPath, options->width, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); } else { - image.tilemap.data.affine = NULL; + image.width = options->width; + ReadPlainImage(inputPath, options->dataWidth, &image, !image.hasPalette); } - ReadImage(inputPath, options->width, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); - image.hasTransparency = options->hasTransparency; WritePng(outputPath, &image); @@ -77,7 +83,10 @@ void ConvertPngToGba(char *inputPath, char *outputPath, struct PngToGbaOptions * ReadPng(inputPath, &image); - WriteImage(outputPath, options->numTilesMode, options->numTiles, options->bitDepth, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); + if (options->isTiled) + WriteTileImage(outputPath, options->numTilesMode, options->numTiles, options->metatileWidth, options->metatileHeight, &image, !image.hasPalette); + else + WritePlainImage(outputPath, options->dataWidth, &image, !image.hasPalette); FreeImage(&image); } @@ -94,6 +103,8 @@ void HandleGbaToPngCommand(char *inputPath, char *outputPath, int argc, char **a options.metatileHeight = 1; options.tilemapFilePath = NULL; options.isAffineMap = false; + options.isTiled = true; + options.dataWidth = 1; for (int i = 3; i < argc; i++) { @@ -162,6 +173,22 @@ void HandleGbaToPngCommand(char *inputPath, char *outputPath, int argc, char **a { options.isAffineMap = true; } + else if (strcmp(option, "-plain") == 0) + { + options.isTiled = false; + } + else if (strcmp(option, "-data_width") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No data width value following \"-data_width\".\n"); + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.dataWidth)) + FATAL_ERROR("Failed to parse data width.\n"); + + if (options.dataWidth < 1) + FATAL_ERROR("Data width must be positive.\n"); + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -177,15 +204,16 @@ void HandleGbaToPngCommand(char *inputPath, char *outputPath, int argc, char **a void HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **argv) { char *outputFileExtension = GetFileExtensionAfterDot(outputPath); - int bitDepth = outputFileExtension[0] - '0'; struct PngToGbaOptions options; options.numTilesMode = NUM_TILES_IGNORE; options.numTiles = 0; - options.bitDepth = bitDepth; + options.bitDepth = outputFileExtension[0] - '0'; options.metatileWidth = 1; options.metatileHeight = 1; options.tilemapFilePath = NULL; options.isAffineMap = false; + options.isTiled = true; + options.dataWidth = 1; for (int i = 3; i < argc; i++) { @@ -236,6 +264,22 @@ void HandlePngToGbaCommand(char *inputPath, char *outputPath, int argc, char **a if (options.metatileHeight < 1) FATAL_ERROR("metatile height must be positive.\n"); } + else if (strcmp(option, "-plain") == 0) + { + options.isTiled = false; + } + else if (strcmp(option, "-data_width") == 0) + { + if (i + 1 >= argc) + FATAL_ERROR("No data width value following \"-data_width\".\n"); + i++; + + if (!ParseNumber(argv[i], NULL, 10, &options.dataWidth)) + FATAL_ERROR("Failed to parse data width.\n"); + + if (options.dataWidth < 1) + FATAL_ERROR("Data width must be positive.\n"); + } else { FATAL_ERROR("Unrecognized option \"%s\".\n", option); @@ -403,7 +447,7 @@ void HandleLZCompressCommand(char *inputPath, char *outputPath, int argc, char * else if (strcmp(option, "-search") == 0) { if (i + 1 >= argc) - FATAL_ERROR("No size following \"-overflow\".\n"); + FATAL_ERROR("No size following \"-search\".\n"); i++; diff --git a/tools/gbagfx/options.h b/tools/gbagfx/options.h index 250b72345..830158b52 100644 --- a/tools/gbagfx/options.h +++ b/tools/gbagfx/options.h @@ -15,6 +15,8 @@ struct GbaToPngOptions { int metatileHeight; char *tilemapFilePath; bool isAffineMap; + bool isTiled; + int dataWidth; }; struct PngToGbaOptions { @@ -25,6 +27,8 @@ struct PngToGbaOptions { int metatileHeight; char *tilemapFilePath; bool isAffineMap; + bool isTiled; + int dataWidth; }; #endif // OPTIONS_H