mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-26 23:51:57 +00:00
Cycle palettes
This commit is contained in:
parent
152ac38ac8
commit
d3a328405e
@ -125,7 +125,7 @@ public class DoubleHiResImage extends HiResImage
|
||||
private final byte[] auxBuffer;
|
||||
private DoubleScrunch doubleScrunch;
|
||||
byte[] packedBuffer;
|
||||
private final int paletteIndex = 2;
|
||||
// private final int paletteIndex = 2;
|
||||
|
||||
public DoubleHiResImage (String name, byte[] buffer, byte[] auxBuffer)
|
||||
{
|
||||
@ -198,6 +198,8 @@ public class DoubleHiResImage extends HiResImage
|
||||
@Override
|
||||
protected void createColourImage ()
|
||||
{
|
||||
int paletteNdx = paletteIndex % palette2.length;
|
||||
|
||||
// image will be doubled horizontally
|
||||
image = new BufferedImage (140 * 2, 192, BufferedImage.TYPE_INT_RGB);
|
||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||
@ -217,8 +219,8 @@ public class DoubleHiResImage extends HiResImage
|
||||
for (int px = 0; px < 28; px += 4)
|
||||
{
|
||||
int val = (value >> px) & 0x0F;
|
||||
dataBuffer.setElem (ndx++, palette2[paletteIndex][val]);
|
||||
dataBuffer.setElem (ndx++, palette2[paletteIndex][val]); // repeat pixel
|
||||
dataBuffer.setElem (ndx++, palette2[paletteNdx][val]);
|
||||
dataBuffer.setElem (ndx++, palette2[paletteNdx][val]); // repeat pixel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public abstract class HiResImage extends AbstractFile
|
||||
|
||||
protected static boolean colourQuirks;
|
||||
protected static boolean monochrome;
|
||||
protected static int paletteIndex;
|
||||
|
||||
protected int fileType;
|
||||
protected int auxType;
|
||||
@ -79,6 +80,13 @@ public abstract class HiResImage extends AbstractFile
|
||||
|
||||
protected abstract void createColourImage ();
|
||||
|
||||
public void cyclePalette ()
|
||||
{
|
||||
++paletteIndex;
|
||||
if (!monochrome)
|
||||
createImage ();
|
||||
}
|
||||
|
||||
public void setColourQuirks (boolean value)
|
||||
{
|
||||
if (colourQuirks == value)
|
||||
|
@ -130,6 +130,17 @@ class DataPanel extends JTabbedPane
|
||||
mh.colourQuirksItem.setAction (new ColourQuirksAction (this));
|
||||
mh.monochromeItem.setAction (new MonochromeAction (this));
|
||||
mh.debuggingItem.setAction (new DebuggingAction (this));
|
||||
mh.paletteItem.setAction (new PaletteAction (this));
|
||||
}
|
||||
|
||||
public void cyclePalette ()
|
||||
{
|
||||
if (currentDataSource instanceof HiResImage)
|
||||
{
|
||||
HiResImage image = (HiResImage) currentDataSource;
|
||||
image.cyclePalette ();
|
||||
imagePanel.setImage (image.getImage ());
|
||||
}
|
||||
}
|
||||
|
||||
public void setColourQuirks (boolean value)
|
||||
|
@ -60,6 +60,7 @@ public class MenuHandler
|
||||
JMenuItem colourQuirksItem = new JCheckBoxMenuItem ("Colour quirks");
|
||||
JMenuItem monochromeItem = new JCheckBoxMenuItem ("Monochrome");
|
||||
JMenuItem debuggingItem = new JCheckBoxMenuItem ("Debugging");
|
||||
JMenuItem paletteItem = new JMenuItem ("Cycle Palette");
|
||||
|
||||
public MenuHandler (Preferences prefs)
|
||||
{
|
||||
@ -109,6 +110,7 @@ public class MenuHandler
|
||||
formatMenu.add (colourQuirksItem);
|
||||
formatMenu.add (monochromeItem);
|
||||
formatMenu.add (debuggingItem);
|
||||
formatMenu.add (paletteItem);
|
||||
|
||||
helpMenu.add (new JMenuItem (new EnvironmentAction ()));
|
||||
|
||||
|
28
src/com/bytezone/diskbrowser/gui/PaletteAction.java
Normal file
28
src/com/bytezone/diskbrowser/gui/PaletteAction.java
Normal file
@ -0,0 +1,28 @@
|
||||
package com.bytezone.diskbrowser.gui;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
import javax.swing.AbstractAction;
|
||||
import javax.swing.Action;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
public class PaletteAction extends AbstractAction
|
||||
{
|
||||
private final DataPanel owner;
|
||||
|
||||
public PaletteAction (DataPanel owner)
|
||||
{
|
||||
super ("Cycle Palette");
|
||||
putValue (Action.SHORT_DESCRIPTION, "Select next color palette");
|
||||
putValue (Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke ("alt P"));
|
||||
putValue (Action.MNEMONIC_KEY, KeyEvent.VK_P);
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed (ActionEvent e)
|
||||
{
|
||||
owner.cyclePalette ();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user