mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-25 19:24:16 +01:00
Support plain pixel conversion, convert spinda spots to .png
This commit is contained in:
parent
41ac28b210
commit
6fdf75bd8c
Binary file not shown.
BIN
graphics/spinda_spots/spot_0.png
Normal file
BIN
graphics/spinda_spots/spot_0.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 111 B |
Binary file not shown.
BIN
graphics/spinda_spots/spot_1.png
Normal file
BIN
graphics/spinda_spots/spot_1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 112 B |
Binary file not shown.
BIN
graphics/spinda_spots/spot_2.png
Normal file
BIN
graphics/spinda_spots/spot_2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 B |
Binary file not shown.
BIN
graphics/spinda_spots/spot_3.png
Normal file
BIN
graphics/spinda_spots/spot_3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 99 B |
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
@ -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,6 +48,8 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions *
|
||||
image.hasPalette = false;
|
||||
}
|
||||
|
||||
if (options->isTiled)
|
||||
{
|
||||
if (options->tilemapFilePath != NULL)
|
||||
{
|
||||
int fileSize;
|
||||
@ -54,13 +59,14 @@ void ConvertGbaToPng(char *inputPath, char *outputPath, struct GbaToPngOptions *
|
||||
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++;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user