From 61a162ff3680284bd72d059635744d434670752d Mon Sep 17 00:00:00 2001 From: bbbradsmith Date: Fri, 11 Oct 2024 06:03:17 -0400 Subject: [PATCH] Command line options --- BinxelviewForm.cs | 184 +++++++++++++++++++++++++++++++++++++++------- readme.txt | 53 ++++++++++++- 2 files changed, 211 insertions(+), 26 deletions(-) diff --git a/BinxelviewForm.cs b/BinxelviewForm.cs index a187a9b..70b78a4 100644 --- a/BinxelviewForm.cs +++ b/BinxelviewForm.cs @@ -288,6 +288,130 @@ public bool loadFile(string path) } }; + // + // Options + // + + string parseOption(string optline) + { + int eqpos = optline.IndexOf("="); + if (eqpos < 0) return "No = in option: "+optline; + string opt = optline.Substring(0,eqpos).ToUpperInvariant(); + string val = optline.Substring(eqpos+1); + string valu = val.ToUpperInvariant(); + + if (opt == "PRESETFILE") // load preset file to replace default + { + Preset p = new Preset(); + if (!p.loadFile(val)) return "Could not load preset file: "+val+"\n"+Preset.last_error; + default_preset = p; + preset = default_preset.copy(); + return ""; + } + if (opt == "PRESET") // select named preset from the library + { + foreach (Preset p in presets) + { + if (val == p.name) + { + preset = p.copy(); + return ""; + } + } + return "Preset not found in loaded presets: "+val; + } + if (opt == "PAL") // load palette file + { + bool image = + valu.EndsWith(".BMP") || + valu.EndsWith(".GIF") || + valu.EndsWith(".PNG") || + valu.EndsWith(".TIF"); + bool vga = + valu.EndsWith(".VGA"); + if (!openPalette(val,image,vga)) return "Could not load palette file: "+val+"\n"+palette_error; + return ""; + } + if (opt == "AUTOPAL") + { + if (valu == "RGB" ) { palette_mode = PaletteMode.PALETTE_RGB; } + else if (valu == "RANDOM" ) { palette_mode = PaletteMode.PALETTE_RANDOM; } + else if (valu == "GREYSCALE") { palette_mode = PaletteMode.PALETTE_GREY; } + else if (valu == "CUBEHELIX") { palette_mode = PaletteMode.PALETTE_CUBEHELIX; } + else return "Unknown autopal value: "+val; + comboBoxPalette.SelectedIndex = (int)palette_mode - 1; + return ""; + } + if (opt == "BACKGROUND") + { + int v; + if (!int.TryParse(val,System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.CurrentCulture, out v)) + return "Could not parse hex color for background: "+val; + background_raw = (v & 0x00FFFFFF) | unchecked((int)0xFF000000); + background = Color.FromArgb(background_raw); + return ""; + } + if (opt == "ZOOM") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for zoom: "+val; + if (v < 1) return "Zoom must be 1 or greater: "+val; + zoom = v; + numericZoom.Value = v; + return ""; + } + if (opt == "GRID") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for grid: "+val; + if (v != 0 && v != 1) return "Grid value must be 0 or 1: "+val; + hidegrid = (v == 0); + gridToolStripMenuItem.Checked = !hidegrid; + return ""; + } + if (opt == "HEXPOS") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for hexpos: "+val; + if (v != 0 && v != 1) return "Hexpos value must be 0 or 1: "+val; + decimal_position = (v == 0); + decimalPositionToolStripMenuItem.Checked = decimal_position; + hexadecimalPositionToolStripMenuItem.Checked = !decimal_position; + numericPosByte.Font = decimal_position ? posfont_regular : posfont_bold; + return ""; + } + if (opt == "SNAPSCROLL") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for snapscroll: "+val; + if (v != 0 && v != 1) return "Snapscroll value must be 0 or 1: "+val; + snap_scroll = (v != 0); + snapScrollToNextStrideToolStripMenuItem.Checked = snap_scroll; + return ""; + } + if (opt == "HORIZONTAL") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for horizontal: "+val; + if (v != 0 && v != 1) return "Horizontal value must be 0 or 1: "+val; + horizontal_layout = (v != 0); + verticalLayoutToolStripMenuItem.Checked = !horizontal_layout; + horizontalLayoutToolStripMenuItem.Checked = horizontal_layout; + return ""; + } + if (opt == "TWIDDLE") + { + int v; + if (!int.TryParse(val,out v)) return "Could not parse integer for twiddle: "+val; + if (v < 0 || v > 2) return "Twiddle value must be 0, 1 or 2: "+val; + twiddle = v; + twiddleZToolStripMenuItem.Checked = twiddle == 1; + twiddleNToolStripMenuItem.Checked = twiddle == 2; + return ""; + } + return "Invalid option: "+optline; + } + // // Pixel building // @@ -744,11 +868,7 @@ Color getPalette(long x) { if (preset.bpp <= PALETTE_BITS) return palette[x]; int p = autoPaletteRaw(x); - int b = (p >> 0) & 0xFF; - int g = (p >> 8) & 0xFF; - int r = (p >> 16) & 0xFF; - int a = (p >> 24) & 0xFF; - return Color.FromArgb(a,r,g,b); + return Color.FromArgb(p); } void randomPalette() @@ -850,7 +970,7 @@ bool openFile(string path) } catch (Exception ex) { - MessageBox.Show("Unable to open file:\n" + path + "\n\n" + ex.ToString(), "File open error!"); + MessageBox.Show("Unable to open file:\n" + path + "\n\n" + ex.ToString(), "Binxelview"); return false; } data = read_data; @@ -925,11 +1045,6 @@ void reloadPresets() bool openPalette(string path, bool image, bool sixbit_vga) { - if (preset.bpp > PALETTE_BITS) - { - palette_error = String.Format("Custom palettes are limited to {0} BPP.",PALETTE_BITS); - return false; - } palette_mode = PaletteMode.PALETTE_CUSTOM; if (image) @@ -951,7 +1066,7 @@ bool openPalette(string path, bool image, bool sixbit_vga) palette_error = "Image does not contain a palette."; return false; } - for (int i=0; (i<(1< 1) + string arg_err = ""; + for (int i=1; i 0 && arg_err.Length > 0) arg_err += "\n"; + arg_err += opt_err; + } + } + if (arg_err.Length > 0) { - openFile(args[1]); + MessageBox.Show("Command line error:\n" + arg_err,"Binxelview"); } - default_preset.empty(); - reloadPresets(); // loads "Default" preset if it exists - preset = default_preset.copy(); scrollRange(); redrawPreset(); autoPalette(); @@ -1288,7 +1422,7 @@ private void buttonLoadPreset_Click(object sender, EventArgs e) } else { - MessageBox.Show("Unable to load preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Preset load error!"); + MessageBox.Show("Unable to load preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); } } } @@ -1303,7 +1437,7 @@ private void buttonSavePreset_Click(object sender, EventArgs e) { if (!preset.saveFile(d.FileName)) { - MessageBox.Show("Unable to save preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Preset save error!"); + MessageBox.Show("Unable to save preset:\n" + d.FileName + "\n\n" + Preset.last_error, "Binxelview"); } else { @@ -1537,7 +1671,7 @@ private void buttonLoadPal_Click(object sender, EventArgs e) } else { - MessageBox.Show("Unable to load palette:\n" + d.FileName + "\n\n" + palette_error, "Palette load error!"); + MessageBox.Show("Unable to load palette:\n" + d.FileName + "\n\n" + palette_error, "Binxelview"); } } } @@ -1554,7 +1688,7 @@ private void buttonSavePal_Click(object sender, EventArgs e) { if (!savePalette(d.FileName)) { - MessageBox.Show("Unable to save palette:\n" + d.FileName + "\n\n" + palette_error, "Palette save error!"); + MessageBox.Show("Unable to save palette:\n" + d.FileName + "\n\n" + palette_error, "Binxelview"); } } } @@ -1607,7 +1741,7 @@ private void saveImageContextItem_Click(object sender, EventArgs e) if (selected_tile < 0) // shouldn't happen, but giving an error just in case { - MessageBox.Show("No image selected?", "Image save error!"); + MessageBox.Show("No image selected?", "Binxelview"); return; } @@ -1642,7 +1776,7 @@ private void saveImageContextItem_Click(object sender, EventArgs e) } catch (Exception ex) { - MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Image save error!"); + MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); } redrawPixels(); @@ -1686,7 +1820,7 @@ private void saveAllVisibleToolStripMenuItem_Click(object sender, EventArgs e) } catch (Exception ex) { - MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Image save error!"); + MessageBox.Show("Unable to save image:\n" + d.FileName + "\n\n" + ex.ToString(), "Binxelview"); } redrawPixels(); diff --git a/readme.txt b/readme.txt index e396095..6ac925e 100644 --- a/readme.txt +++ b/readme.txt @@ -160,6 +160,56 @@ Morton (Z/N) ordering, commonly seen in square textures "twiddled" or "swizzled" GPU cache coherence. +Command Line Options +-------------------- + +To open a file, just add that file's path to the command line. + +Options can be set with a command line argument beginning with '-', +followed by the option name, an '=' separator, and the value for the option. +If a space is required in the value, you should enclose the entire argument in quotes. + + "-presetfile=C:\mypreset.bxp" + Replaces the default preset with one from a file. + + "-preset=Atari ST 4BPP" + Chooses a named preset from your preset library instead of the default. + + "-pal=C:\red.pal" + Loads a palette file. + If the extension is .BMP .GIF .PNG or .TIF it will load it as an palette from an image. + If the extension is .VGA it will load it as 6-bit RGB18 format. + Otherwise it will load it as RGB24. + + -autopal=Greyscale + Chooses an automatic palette, one of: + RGB - RGB with the current preset BPP, bits evenly divided with G >= R >= B, red as the highest bits. + Random - Every colour is randomized. + Greyscale - Gradient from black to white. + Cubehelix - Smooth gradient with rotating hue, created by Dave Green. See: https://people.phy.cam.ac.uk/dag9/CUBEHELIX/ + + -background=FF0088 + Set the Background grid colour, uses a 6 digit hexadecimal RRGGBB value. + + -zoom=3 + Set the Zoom value. + + -grid=1 + Set the Grid Padding option (1 on, 0 off). + + -hexpos=1 + Set the Position byte display to use hexadecimal (1 hexadecimal, 0 decimal). + + -snapscroll=1 + Set the "Snap scroll to next stride" option (1 on, 0 off). + + -horizontal=1 + Set the layout option (1 horizontal, 0 vertical). + + -twiddle=1 + Set the twiddle option (0 off, 1 twiddle Z, 2 twiddle N). + + Changes ------- @@ -178,12 +228,13 @@ Changes - Right click context menu option to move position to the selected pixel. - File menu reload option. - Added global Ctrl hotkeys. -- Added Cubehelix automatic palette option: https://people.phy.cam.ac.uk/dag9/CUBEHELIX/ +- Added Cubehelix automatic palette option. - Automatic palette modes are now a dropdown list. - Right click context menu option to copy to the palette starting from the selected pixel. - PS1 15BPP and 4BPP presets. (Contributor: HeyItsLollie) - VGA Palette preset. - Indicate hexadecimal position with bold font. +- Command line arguments for options. 1.5.0.0 (2020-07-31) - Twiddle option for inspecting textures stored with morton ordering of pixels.