Skip to content

Commit

Permalink
[MSXimg] Added option to provide input the color palette to be used f…
Browse files Browse the repository at this point in the history
…or image conversion.
  • Loading branch information
aoineko-fr committed May 25, 2024
1 parent b5039cf commit 7aa4002
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 13 deletions.
Binary file modified tools/MSXtk/bin/MSXbin.exe
Binary file not shown.
Binary file modified tools/MSXtk/bin/MSXcrypt.exe
Binary file not shown.
Binary file modified tools/MSXtk/bin/MSXhex.exe
Binary file not shown.
Binary file modified tools/MSXtk/bin/MSXimg.exe
Binary file not shown.
1 change: 1 addition & 0 deletions tools/MSXtk/bin/MSXimg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Options:
-pal Palette to use for 16 colors mode
msx1 Use default MSX1 palette
custom Generate a custom palette and add it to the output file
input n [c1 c2 ...] Use the following colors for conversion
--palcount n Number of color in the custom palette to create (default: 15)
--paloff n Index offset of the palette (default: 1)
--pal24 Use 24-bits palette (for v9990; default: false)
Expand Down
Binary file modified tools/MSXtk/bin/MSXmath.exe
Binary file not shown.
Binary file modified tools/MSXtk/bin/MSXzip.exe
Binary file not shown.
15 changes: 14 additions & 1 deletion tools/MSXtk/src/MSXimg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void PrintHelp()
printf(" -pal Palette to use for 16 colors mode\n");
printf(" msx1 Use default MSX1 palette\n");
printf(" custom Generate a custom palette and add it to the output file\n");
printf(" input n [c1 c2 ...] Use the following colors for conversion\n");
printf(" --palcount n Number of color in the custom palette to create (default: 15)\n");
printf(" --paloff n Index offset of the palette (default: 1)\n");
printf(" --pal24 Use 24-bits palette (for v9990; default: false)\n");
Expand Down Expand Up @@ -231,7 +232,7 @@ int main(int argc, const char* argv[])

//-------------------------------------------------------------------------
// Parse parameters
for(i=2; i<argc; i++)
for(i = 2; i < argc; i++)
{
if (MSX::StrEqual(argv[i], "-help")) // Display help
{
Expand Down Expand Up @@ -301,6 +302,18 @@ int main(int argc, const char* argv[])
param.palType = PALETTE_MSX1;
else if (MSX::StrEqual(argv[i], "custom"))
param.palType = PALETTE_Custom;
else if (MSX::StrEqual(argv[i], "input"))
{
param.palType = PALETTE_Input;
param.palCount = atoi(argv[++i]);
param.palInput.clear();
for (i32 j = 0; j < param.palCount; j++)
{
u32 c24;
sscanf(argv[++i], "%i", &c24);
param.palInput.push_back(c24);
}
}
}
else if (MSX::StrEqual(argv[i], "--palcount") || MSX::StrEqual(argv[i], "-palcount")) // Palette count
{
Expand Down
1 change: 1 addition & 0 deletions tools/MSXtk/src/color.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ enum PaletteType
PALETTE_MSX1,
PALETTE_MSX2,
PALETTE_Custom, // Generate a custom palette
PALETTE_Input, // Use input palette
};

enum DitheringMethod
Expand Down
1 change: 1 addition & 0 deletions tools/MSXtk/src/exporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ struct ExportParameters
i32 palCount; ///< Number of colors in the palette
i32 palOffset; ///< Index offset of the palette
bool pal24; ///< Use 24-bits palette (v9990)
std::vector<u32> palInput; ///< Use 24-bits palette (v9990)
MSX::Compressor comp; ///< Compressor to use (@see MSX::Compressor)
MSX::DataFormat format; ///< Data format to use for text export (@see MSX::DataFormat)
MSX::AsmSyntax syntax; ///< Assember syntax (@see MSX::AsmSyntax)
Expand Down
24 changes: 12 additions & 12 deletions tools/MSXtk/src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,21 +202,21 @@ bool ExportBitmap(ExportParameters * param, ExporterInterface * exp)

// Get custom palette for 16 colors mode
u32 customPalette[16];
/*RGBQUAD defaultPal[3] = {
{ 0x00, 0x00, 0x00, 0 },
{ 0x80, 0x80, 0x80, 0 },
{ 0xFF, 0xFF, 0xFF, 0 },
};*/
if ((param->bpc == 4) && (param->palType == PALETTE_Custom))
if (param->palType == PALETTE_Input)
{
for (i32 i = 0; i < param->palCount; i++)
customPalette[i] = param->palInput[i];
}
else if ((param->bpc == 4) && (param->palType == PALETTE_Custom))
{
if (param->bUseTrans)
{
u32 black = 0;
i32 res = FreeImage_ApplyColorMapping(dib32, (RGBQUAD*)&transRGB, (RGBQUAD*)&black, 1, true, false); // @warning: must be call AFTER retreving raw data!
}
FIBITMAP* dib4 = FreeImage_ColorQuantizeEx(dib32, FIQ_LFPQUANT, param->palCount, 0, NULL /*3, defaultPal*/); // Try Lossless Fast Pseudo-Quantization algorithm (if there are 15 colors or less)
FIBITMAP* dib4 = FreeImage_ColorQuantizeEx(dib32, FIQ_LFPQUANT, param->palCount, 0, NULL); // Try Lossless Fast Pseudo-Quantization algorithm (if there are 15 colors or less)
if(dib4 == NULL)
dib4 = FreeImage_ColorQuantizeEx(dib32, FIQ_WUQUANT, param->palCount, 0, NULL /*3, defaultPal*/); // Else, use Efficient Statistical Computations for Optimal Color Quantization
dib4 = FreeImage_ColorQuantizeEx(dib32, FIQ_WUQUANT, param->palCount, 0, NULL); // Else, use Efficient Statistical Computations for Optimal Color Quantization
RGBQUAD* pal = FreeImage_GetPalette(dib4);

for (i32 c = 0; c < param->palOffset; c++)
Expand All @@ -232,9 +232,9 @@ bool ExportBitmap(ExportParameters * param, ExporterInterface * exp)
u32 black = 0;
i32 res = FreeImage_ApplyColorMapping(dib32, (RGBQUAD*)&transRGB, (RGBQUAD*)&black, 1, true, false); // @warning: must be call AFTER retreving raw data!
}
FIBITMAP* dib2 = FreeImage_ColorQuantizeEx(dib32, FIQ_LFPQUANT, param->palCount, 0, NULL /*3, defaultPal*/); // Try Lossless Fast Pseudo-Quantization algorithm (if there are 3 colors or less)
FIBITMAP* dib2 = FreeImage_ColorQuantizeEx(dib32, FIQ_LFPQUANT, param->palCount, 0, NULL); // Try Lossless Fast Pseudo-Quantization algorithm (if there are 3 colors or less)
if (dib2 == NULL)
dib2 = FreeImage_ColorQuantizeEx(dib32, FIQ_WUQUANT, param->palCount, 0, NULL /*3, defaultPal*/); // Else, use Efficient Statistical Computations for Optimal Color Quantization
dib2 = FreeImage_ColorQuantizeEx(dib32, FIQ_WUQUANT, param->palCount, 0, NULL); // Else, use Efficient Statistical Computations for Optimal Color Quantization
RGBQUAD* pal = FreeImage_GetPalette(dib2);
for (i32 c = 0; c < param->palOffset; c++)
customPalette[c] = 0;
Expand All @@ -243,7 +243,7 @@ bool ExportBitmap(ExportParameters * param, ExporterInterface * exp)
FreeImage_Unload(dib2);
}
// Apply dithering for 2 color mode
else if ((param->bpc == 1) && (param->dither != DITHER_None))
if ((param->bpc == 1) && (param->dither != DITHER_None))
{
FIBITMAP* dib1 = FreeImage_Dither(dib32, (FREE_IMAGE_DITHER)param->dither);
FreeImage_ConvertToRawBits(bits, dib1, scanWidth, 32, FI_RGBA_RED_MASK, FI_RGBA_GREEN_MASK, FI_RGBA_BLUE_MASK, TRUE);
Expand Down Expand Up @@ -753,7 +753,7 @@ bool ExportBitmap(ExportParameters * param, ExporterInterface * exp)
//-------------------------------------------------------------------------
// PALETTE TABLE

if (((param->bpc == 2) || (param->bpc == 4)) && (param->palType == PALETTE_Custom))
if (((param->bpc == 2) || (param->bpc == 4)) && ((param->palType == PALETTE_Custom) || (param->palType == PALETTE_Input)))
{
sprintf(strData, "%s_palette", param->tabName.c_str());
if (param->pal24)
Expand Down

0 comments on commit 7aa4002

Please sign in to comment.