Skip to content

Commit

Permalink
Add default palette capability.
Browse files Browse the repository at this point in the history
Rename openPalette to loadPalette.
Initialize empty palette values with grey stripes instead.
  • Loading branch information
bbbradsmith committed Oct 11, 2024
1 parent 61a162f commit eaa4457
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
36 changes: 28 additions & 8 deletions BinxelviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ string parseOption(string optline)
valu.EndsWith(".TIF");
bool vga =
valu.EndsWith(".VGA");
if (!openPalette(val,image,vga)) return "Could not load palette file: "+val+"\n"+palette_error;
if (!loadPalette(val,image,vga)) return "Could not load palette file: "+val+"\n"+palette_error;
return "";
}
if (opt == "AUTOPAL")
Expand Down Expand Up @@ -1043,9 +1043,19 @@ void reloadPresets()
}
}

bool openPalette(string path, bool image, bool sixbit_vga)
void initCustomPalette()
{
// initialize palette to grey stripes
for (int i=0; i<(PALETTE_DIM*PALETTE_DIM); ++i)
{
int v = ((i&1)==1) ? 0x84 : 0x74;
setPalette(i,v,v,v);
}
palette_mode = PaletteMode.PALETTE_CUSTOM;
}

bool loadPalette(string path, bool image, bool sixbit_vga)
{

if (image)
{
Expand All @@ -1066,6 +1076,8 @@ bool openPalette(string path, bool image, bool sixbit_vga)
palette_error = "Image does not contain a palette.";
return false;
}

initCustomPalette();
for (int i=0; (i<(PALETTE_DIM*PALETTE_DIM)) && (i<cols.Length); ++i)
{
Color c = cols[i];
Expand All @@ -1085,6 +1097,7 @@ bool openPalette(string path, bool image, bool sixbit_vga)
return false;
}

initCustomPalette();
for (int i=0; (i<(PALETTE_DIM*PALETTE_DIM)) && (((i*3)+2)<read_data.Length); ++i)
{
int r = read_data[(i * 3) + 0];
Expand Down Expand Up @@ -1320,7 +1333,17 @@ private void BinxelviewForm_Load(object sender, EventArgs e)
reloadPresets(); // loads "Default" preset if it exists
preset = default_preset.copy();

// open file from the command line
// load default palette if it exists
DirectoryInfo dir_cwd = new DirectoryInfo(".");
DirectoryInfo dir_app = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory);
string pal_cwd = Path.Combine(dir_cwd.ToString(),"default.pal");
string pal_app = Path.Combine(dir_app.ToString(),"default.pal");
bool success = true;
if (File.Exists(pal_cwd)) { success = loadPalette(pal_cwd,false,false); }
else if (File.Exists(pal_app)) { success = loadPalette(pal_app,false,false); }
if (!success) MessageBox.Show("Error opening default palette:\n" + palette_error,"Binxelview");

// parse the command line options
string[] args = Environment.GetCommandLineArgs();
string arg_err = "";
for (int i=1; i<args.Length; ++i)
Expand All @@ -1339,10 +1362,7 @@ private void BinxelviewForm_Load(object sender, EventArgs e)
arg_err += opt_err;
}
}
if (arg_err.Length > 0)
{
MessageBox.Show("Command line error:\n" + arg_err,"Binxelview");
}
if (arg_err.Length > 0) MessageBox.Show("Command line error:\n" + arg_err,"Binxelview");

scrollRange();
redrawPreset();
Expand Down Expand Up @@ -1664,7 +1684,7 @@ private void buttonLoadPal_Click(object sender, EventArgs e)
"All files, RGB24 (*.*)|*.*";
if (d.ShowDialog() == DialogResult.OK)
{
if (openPalette(d.FileName,d.FilterIndex==2,d.FilterIndex==3))
if (loadPalette(d.FileName,d.FilterIndex==2,d.FilterIndex==3))
{
refreshPalette();
redrawPixels();
Expand Down
5 changes: 5 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ otherwise an automatic RGB or Greyscale palette can be applied.
Custom palettes are 24-bit RGB triples (8 bits for each component).
Click on a colour in the palette box to edit it.

You can create a default palette named "default.pal" to be loaded automatically at startup.
As with presets, it will check the current working directory for "default.pal" first,
before also checking the directory of the executable.

If you are able to view a block of palette data in a file, you can quickly copy it to the palette.
Right click on the first pixel of the block, and the palette will be generated with the colour of
each pixel starting with that one. Note that this assumes contiguous pixel data, and will not account
Expand Down Expand Up @@ -235,6 +239,7 @@ Changes
- VGA Palette preset.
- Indicate hexadecimal position with bold font.
- Command line arguments for options.
- Default palette ability.

1.5.0.0 (2020-07-31)
- Twiddle option for inspecting textures stored with morton ordering of pixels.
Expand Down

0 comments on commit eaa4457

Please sign in to comment.