better SHR support

This commit is contained in:
Denis Molony 2019-11-19 15:25:10 +10:00
parent 457f1f753c
commit 735f90ca7c
3 changed files with 66 additions and 13 deletions

View File

@ -323,7 +323,7 @@ public abstract class HiResImage extends AbstractFile
int ptr = 0; int ptr = 0;
while (ptr < buffer.length) while (ptr < buffer.length)
{ {
int type = (buffer[ptr] & 0xC0) >> 6; // 0-3 int type = (buffer[ptr] & 0xC0) >>> 6; // 0-3
int count = (buffer[ptr++] & 0x3F) + 1; // 1-64 int count = (buffer[ptr++] & 0x3F) + 1; // 1-64
if (ptr >= buffer.length) // needed for NAGELxx if (ptr >= buffer.length) // needed for NAGELxx
@ -373,7 +373,7 @@ public abstract class HiResImage extends AbstractFile
int size = 0; int size = 0;
while (ptr < buffer.length) while (ptr < buffer.length)
{ {
int type = (buffer[ptr] & 0xC0) >> 6; // 0-3 int type = (buffer[ptr] & 0xC0) >>> 6; // 0-3
int count = (buffer[ptr++] & 0x3F) + 1; // 1-64 int count = (buffer[ptr++] & 0x3F) + 1; // 1-64
if (type == 0) if (type == 0)

View File

@ -7,15 +7,19 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class SHRPictureFile1 extends HiResImage public class SHRPictureFile1 extends HiResImage
// -----------------------------------------------------------------------------------//
{ {
private final List<Block> blocks = new ArrayList<Block> (); private final List<Block> blocks = new ArrayList<Block> ();
private Main mainBlock; private Main mainBlock;
private Multipal multipalBlock; private Multipal multipalBlock;
private final boolean debug = false; private final boolean debug = false;
// 0xC0/02 - Apple IIGS Super Hi-Res Picture File (APF) // PNT - 0xC0/02 - Apple IIGS Super Hi-Res Picture File (APF)
// ---------------------------------------------------------------------------------//
public SHRPictureFile1 (String name, byte[] buffer, int fileType, int auxType, int eof) public SHRPictureFile1 (String name, byte[] buffer, int fileType, int auxType, int eof)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer, fileType, auxType, eof); super (name, buffer, fileType, auxType, eof);
@ -71,8 +75,10 @@ public class SHRPictureFile1 extends HiResImage
createImage (); createImage ();
} }
// ---------------------------------------------------------------------------------//
@Override @Override
void createMonochromeImage () void createMonochromeImage ()
// ---------------------------------------------------------------------------------//
{ {
image = new BufferedImage (320, 200, BufferedImage.TYPE_BYTE_GRAY); image = new BufferedImage (320, 200, BufferedImage.TYPE_BYTE_GRAY);
DataBuffer db = image.getRaster ().getDataBuffer (); DataBuffer db = image.getRaster ().getDataBuffer ();
@ -93,10 +99,12 @@ public class SHRPictureFile1 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
void createColourImage () void createColourImage ()
// ---------------------------------------------------------------------------------//
{ {
int width = mainBlock.pixelsPerScanLine == 320 ? 640 : mainBlock.pixelsPerScanLine; int width = mainBlock.unpackedSize[0] * (mainBlock.scbMode == 0 ? 4 : 8);
image = image =
new BufferedImage (width, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB); new BufferedImage (width, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
@ -122,9 +130,12 @@ public class SHRPictureFile1 extends HiResImage
// System.out.println ("fillmode " + fillMode); // System.out.println ("fillmode " + fillMode);
// 320 mode // 320 mode
if (mainBlock.pixelsPerScanLine == 320) // if (mainBlock.pixelsPerScanLine == 320)
if (mainBlock.scbMode == 0)
{ {
for (int i = 0; i < 160; i++) // two pixels per col // int max = mainBlock.pixelsPerScanLine / 2;
int max = mainBlock.unpackedSize[line];
for (int i = 0; i < max; i++) // two pixels per col
{ {
int left = (buffer[ptr] & 0xF0) >> 4; int left = (buffer[ptr] & 0xF0) >> 4;
int right = buffer[ptr++] & 0x0F; int right = buffer[ptr++] & 0x0F;
@ -150,7 +161,8 @@ public class SHRPictureFile1 extends HiResImage
} }
else else
{ {
int max = mainBlock.pixelsPerScanLine / 4; // int max = mainBlock.pixelsPerScanLine / 4;
int max = mainBlock.unpackedSize[line];
for (int col = 0; col < max; col++) // four pixels per col for (int col = 0; col < max; col++) // four pixels per col
{ {
int p1 = (buffer[ptr] & 0xC0) >> 6; int p1 = (buffer[ptr] & 0xC0) >> 6;
@ -182,8 +194,10 @@ public class SHRPictureFile1 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (super.getText ()); StringBuilder text = new StringBuilder (super.getText ());
text.append ("\n\n"); text.append ("\n\n");
@ -203,7 +217,9 @@ public class SHRPictureFile1 extends HiResImage
return text.toString (); return text.toString ();
} }
// ---------------------------------------------------------------------------------//
private class Block private class Block
// ---------------------------------------------------------------------------------//
{ {
String kind; String kind;
byte[] data; byte[] data;
@ -226,7 +242,9 @@ public class SHRPictureFile1 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
private class Multipal extends Block private class Multipal extends Block
// ---------------------------------------------------------------------------------//
{ {
int numPalettes; int numPalettes;
ColorTable[] colorTables; ColorTable[] colorTables;
@ -251,7 +269,9 @@ public class SHRPictureFile1 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
private class Main extends Block private class Main extends Block
// ---------------------------------------------------------------------------------//
{ {
int masterMode; // 0 = Brooks, 0 = PNT 320 80 = PNT 640 int masterMode; // 0 = Brooks, 0 = PNT 320 80 = PNT 640
int pixelsPerScanLine; // 320 or 640 int pixelsPerScanLine; // 320 or 640
@ -261,18 +281,19 @@ public class SHRPictureFile1 extends HiResImage
DirEntry[] scanLineDirectory; // [numScanLines] DirEntry[] scanLineDirectory; // [numScanLines]
byte[][] packedScanLines; byte[][] packedScanLines;
int scbMode;
int unpackedSize[];
public Main (String kind, byte[] data) public Main (String kind, byte[] data)
{ {
super (kind, data); super (kind, data);
int ptr = 5 + kind.length (); int ptr = 5 + kind.length ();
masterMode = HexFormatter.unsignedShort (data, ptr); masterMode = HexFormatter.unsignedShort (data, ptr);
scbMode = masterMode & 0x80;
pixelsPerScanLine = HexFormatter.unsignedShort (data, ptr + 2); pixelsPerScanLine = HexFormatter.unsignedShort (data, ptr + 2);
numColorTables = HexFormatter.unsignedShort (data, ptr + 4); numColorTables = HexFormatter.unsignedShort (data, ptr + 4);
// System.out.printf ("mm %02X, pix %d%n", masterMode, pixelsPerScanLine);
// System.out.printf ("color tables: %d%n", numColorTables);
ptr += 6; ptr += 6;
colorTables = new ColorTable[numColorTables]; colorTables = new ColorTable[numColorTables];
for (int i = 0; i < numColorTables; i++) for (int i = 0; i < numColorTables; i++)
@ -285,6 +306,7 @@ public class SHRPictureFile1 extends HiResImage
ptr += 2; ptr += 2;
scanLineDirectory = new DirEntry[numScanLines]; scanLineDirectory = new DirEntry[numScanLines];
unpackedSize = new int[numScanLines];
packedScanLines = new byte[numScanLines][]; packedScanLines = new byte[numScanLines][];
for (int i = 0; i < numScanLines; i++) for (int i = 0; i < numScanLines; i++)
@ -299,13 +321,19 @@ public class SHRPictureFile1 extends HiResImage
{ {
int len = scanLineDirectory[i].numBytes; int len = scanLineDirectory[i].numBytes;
if (ptr + len > data.length) if (ptr + len > data.length)
{
System.out.println ("breaking early");
break; break;
}
System.arraycopy (data, ptr, packedScanLines[i], 0, len); System.arraycopy (data, ptr, packedScanLines[i], 0, len);
ptr += len; ptr += len;
} }
int width = pixelsPerScanLine == 320 ? 160 : pixelsPerScanLine / 4; // int width = pixelsPerScanLine == 320 ? 160 : (pixelsPerScanLine - 1) / 4 + 1;
// int width = pixelsPerScanLine == 320 ? 160 : pixelsPerScanLine / 4;
// int width = scbMode == 0 ? pixelsPerScanLine / 2 : pixelsPerScanLine / 4;
int width = 320;
byte[] unpackedBuffer = new byte[numScanLines * width]; byte[] unpackedBuffer = new byte[numScanLines * width];
ptr = 0; ptr = 0;
for (int line = 0; line < numScanLines; line++) for (int line = 0; line < numScanLines; line++)
@ -316,7 +344,10 @@ public class SHRPictureFile1 extends HiResImage
break; break;
} }
int oldPtr = ptr;
ptr = unpackLine (packedScanLines[line], unpackedBuffer, ptr); ptr = unpackLine (packedScanLines[line], unpackedBuffer, ptr);
// System.out.printf ("%3d %5d %5d %3d%n", line, oldPtr, ptr, ptr - oldPtr);
unpackedSize[line] = ptr - oldPtr;
// something strange happening here // something strange happening here
if (line == 102 && name.equals ("DRAGON.SHR")) if (line == 102 && name.equals ("DRAGON.SHR"))

View File

@ -6,14 +6,18 @@ import java.awt.image.DataBuffer;
import com.bytezone.diskbrowser.prodos.ProdosConstants; import com.bytezone.diskbrowser.prodos.ProdosConstants;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
// -----------------------------------------------------------------------------------//
public class SHRPictureFile2 extends HiResImage public class SHRPictureFile2 extends HiResImage
// -----------------------------------------------------------------------------------//
{ {
ColorTable[] colorTables; ColorTable[] colorTables;
byte[] controlBytes; byte[] controlBytes;
// see Graphics & Animation.2mg // see Graphics & Animation.2mg
// ---------------------------------------------------------------------------------//
public SHRPictureFile2 (String name, byte[] buffer, int fileType, int auxType, int eof) public SHRPictureFile2 (String name, byte[] buffer, int fileType, int auxType, int eof)
// ---------------------------------------------------------------------------------//
{ {
super (name, buffer, fileType, auxType, eof); super (name, buffer, fileType, auxType, eof);
@ -35,7 +39,9 @@ public class SHRPictureFile2 extends HiResImage
createImage (); createImage ();
} }
// ---------------------------------------------------------------------------------//
private void doPnt () private void doPnt ()
// ---------------------------------------------------------------------------------//
{ {
switch (auxType) switch (auxType)
{ {
@ -59,6 +65,7 @@ public class SHRPictureFile2 extends HiResImage
colorTables = new ColorTable[16]; colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++) for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32); colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32);
break; break;
case 2: // handled in SHRPictureFile1 case 2: // handled in SHRPictureFile1
@ -98,6 +105,7 @@ public class SHRPictureFile2 extends HiResImage
data = new byte[buffer.length - 6404]; // skip APP. and color tables data = new byte[buffer.length - 6404]; // skip APP. and color tables
System.arraycopy (buffer, 6404, data, 0, data.length); System.arraycopy (buffer, 6404, data, 0, data.length);
this.buffer = unpack (data); this.buffer = unpack (data);
break; break;
case 4096: // seems to be a PIC/$00 case 4096: // seems to be a PIC/$00
@ -107,6 +115,7 @@ public class SHRPictureFile2 extends HiResImage
colorTables = new ColorTable[16]; colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++) for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32);
break; break;
default: default:
@ -115,7 +124,9 @@ public class SHRPictureFile2 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
private void doPic () private void doPic ()
// ---------------------------------------------------------------------------------//
{ {
switch (auxType) switch (auxType)
{ {
@ -131,8 +142,12 @@ public class SHRPictureFile2 extends HiResImage
System.arraycopy (buffer, 32000, controlBytes, 0, controlBytes.length); System.arraycopy (buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16]; colorTables = new ColorTable[16];
int ptr = 32256;
for (int i = 0; i < colorTables.length; i++) for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32); {
colorTables[i] = new ColorTable (i, buffer, ptr);
ptr += 32;
}
break; break;
case 1: // unpacked version of PNT/$03 case 1: // unpacked version of PNT/$03
@ -150,11 +165,12 @@ public class SHRPictureFile2 extends HiResImage
return; return;
} }
colorTables = new ColorTable[200]; colorTables = new ColorTable[200];
ptr = 32000;
for (int i = 0; i < colorTables.length; i++) for (int i = 0; i < colorTables.length; i++)
{ {
int ptr = 32000 + i * 32;
colorTables[i] = new ColorTable (i, buffer, ptr); colorTables[i] = new ColorTable (i, buffer, ptr);
colorTables[i].reverse (); colorTables[i].reverse ();
ptr += 32;
} }
break; break;
@ -164,13 +180,17 @@ public class SHRPictureFile2 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
void createMonochromeImage () void createMonochromeImage ()
// ---------------------------------------------------------------------------------//
{ {
} }
// ---------------------------------------------------------------------------------//
@Override @Override
void createColourImage () void createColourImage ()
// ---------------------------------------------------------------------------------//
{ {
image = new BufferedImage (640, 400, BufferedImage.TYPE_INT_RGB); image = new BufferedImage (640, 400, BufferedImage.TYPE_INT_RGB);
DataBuffer dataBuffer = image.getRaster ().getDataBuffer (); DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
@ -255,8 +275,10 @@ public class SHRPictureFile2 extends HiResImage
} }
} }
// ---------------------------------------------------------------------------------//
@Override @Override
public String getText () public String getText ()
// ---------------------------------------------------------------------------------//
{ {
StringBuilder text = new StringBuilder (super.getText ()); StringBuilder text = new StringBuilder (super.getText ());
text.append ("\n"); text.append ("\n");