This commit is contained in:
Denis Molony 2017-01-25 08:53:34 +11:00
parent f5ed58d922
commit 1d144492ce
5 changed files with 116 additions and 32 deletions

View File

@ -52,21 +52,6 @@ public abstract class HiResImage extends AbstractFile
this.fileType = fileType; this.fileType = fileType;
this.auxType = auxType; this.auxType = auxType;
if (fileType == ProdosConstants.FILE_TYPE_PNT)
{
if (auxType == 1)
{
unpackedBuffer = unpackBytes (buffer);
makeScreen (unpackedBuffer);
System.out.println ("aux 1 - " + name);
}
// if (auxType == 2)
// {
// System.out.println ("aux 2 - " + name);
// }
}
} }
protected void createImage () protected void createImage ()
@ -159,11 +144,7 @@ public abstract class HiResImage extends AbstractFile
case ProdosConstants.FILE_TYPE_PNT: case ProdosConstants.FILE_TYPE_PNT:
if (auxType == 1) if (auxType == 1)
{
if (unpackedBuffer == null)
unpackedBuffer = unpackBytes (buffer);
auxText = "Packed Super Hi-Res Image"; auxText = "Packed Super Hi-Res Image";
}
else if (auxType == 2) else if (auxType == 2)
auxText = "Super Hi-Res Image"; auxText = "Super Hi-Res Image";
else if (auxType == 3) else if (auxType == 3)

View File

@ -0,0 +1,21 @@
package com.bytezone.diskbrowser.applefile;
public class PackedSHR extends HiResImage
{
public PackedSHR (String name, byte[] buffer, int fileType, int auxType)
{
super (name, buffer, fileType, auxType);
}
@Override
protected void createMonochromeImage ()
{
}
@Override
protected void createColourImage ()
{
}
}

View File

@ -5,11 +5,11 @@ import java.util.List;
import com.bytezone.diskbrowser.utilities.HexFormatter; import com.bytezone.diskbrowser.utilities.HexFormatter;
public class PaintFile extends HiResImage public class SHRPictureFile extends HiResImage
{ {
List<Block> blocks = new ArrayList<Block> (); List<Block> blocks = new ArrayList<Block> ();
public PaintFile (String name, byte[] buffer, int fileType, int auxType) public SHRPictureFile (String name, byte[] buffer, int fileType, int auxType)
{ {
super (name, buffer, fileType, auxType); super (name, buffer, fileType, auxType);
@ -131,6 +131,76 @@ public class PaintFile extends HiResImage
System.arraycopy (data, ptr, packedScanLines[i], 0, len); System.arraycopy (data, ptr, packedScanLines[i], 0, len);
ptr += len; ptr += len;
} }
if (true)
{
byte[] newBuf = new byte[32768];
ptr = 0;
for (int line = 0; line < numScanLines; line++)
{
byte[] lineBuffer = packedScanLines[line];
if (lineBuffer.length % 2 == 1 && isEmpty (lineBuffer))
{
System.out.println ("Odd number of bytes in empty buffer in " + name);
break;
}
ptr = unpackLine (lineBuffer, newBuf, ptr);
}
makeScreen (newBuf);
}
}
// Super Hi-res IIGS
protected int unpackLine (byte[] buffer, byte[] newBuf, int newPtr)
{
byte[] fourBuf = new byte[4];
int ptr = 0;
while (ptr < buffer.length)
{
int type = (buffer[ptr] & 0xC0) >> 6; // 0-3
int count = (buffer[ptr++] & 0x3F) + 1; // 1-64
switch (type)
{
case 0:
while (count-- != 0)
// if (ptr < buffer.length) // fixes a bug in some images
newBuf[newPtr++] = buffer[ptr++];
break;
case 1:
byte b = buffer[ptr++];
while (count-- != 0)
newBuf[newPtr++] = b;
break;
case 2:
for (int i = 0; i < 4; i++)
fourBuf[i] = buffer[ptr++];
while (count-- != 0)
for (int i = 0; i < 4; i++)
newBuf[newPtr++] = fourBuf[i];
break;
case 3:
b = buffer[ptr++];
count *= 4;
while (count-- != 0)
newBuf[newPtr++] = b;
break;
}
}
return newPtr;
}
private boolean isEmpty (byte[] buffer)
{
for (byte b : buffer)
if (b != 0)
return false;
return true;
} }
@Override @Override
@ -166,15 +236,26 @@ public class PaintFile extends HiResImage
text.append ("\nScan Lines\n"); text.append ("\nScan Lines\n");
text.append ("----------\n\n"); text.append ("----------\n\n");
text.append (" # Mode Packed Data\n"); text.append (" # Mode Len Packed Data\n");
text.append ("--- ---- ---------------------------------------------"); text.append ("--- ---- --- ---------------------------------------");
text.append ("------------------------------------------\n"); text.append ("------------------------------------------\n");
int lineSize = 24;
for (int i = 0; i < scanLineDirectory.length; i++) for (int i = 0; i < scanLineDirectory.length; i++)
{ {
DirEntry dirEntry = scanLineDirectory[i]; DirEntry dirEntry = scanLineDirectory[i];
byte[] packedScanLine = packedScanLines[i]; byte[] packedScanLine = packedScanLines[i];
text.append (String.format ("%3d %2d ", i, dirEntry.mode)); text.append (String.format ("%3d %2d %3d ", i, dirEntry.mode,
text.append (HexFormatter.getHexString (packedScanLine)); packedScanLine.length));
int ptr = 0;
while (true)
{
text.append (HexFormatter.getHexString (packedScanLine, ptr, lineSize));
ptr += lineSize;
if (ptr >= packedScanLine.length)
break;
text.append ("\n ");
}
text.append ("\n"); text.append ("\n");
} }

View File

@ -354,8 +354,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants
file = new IconFile (name, exactBuffer); file = new IconFile (name, exactBuffer);
break; break;
case FILE_TYPE_PNT: case FILE_TYPE_PNT:
if (auxType == 1)
file = new PackedSHR (name, exactBuffer, fileType, auxType);
if (auxType == 2) if (auxType == 2)
file = new PaintFile (name, exactBuffer, fileType, auxType); file = new SHRPictureFile (name, exactBuffer, fileType, auxType);
else else
file = new OriginalHiResImage (name, exactBuffer, fileType, auxType); file = new OriginalHiResImage (name, exactBuffer, fileType, auxType);
break; break;
@ -387,10 +389,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
private byte[] getExactBuffer (byte[] buffer) private byte[] getExactBuffer (byte[] buffer)
{ {
if (buffer.length < endOfFile) if (buffer.length < endOfFile)
{ System.out.printf ("Buffer (%,d) shorter than EOF (%,d) in %s%n", buffer.length,
System.out.println ("Buffer shorter than EOF in " + name); endOfFile, name);
System.out.printf (" buffer %,d, eof %,d%n", buffer.length, endOfFile);
}
byte[] exactBuffer; byte[] exactBuffer;
if (buffer.length < endOfFile) if (buffer.length < endOfFile)

View File

@ -205,9 +205,10 @@ public class HexFormatter
public static String getHexString (byte[] buffer, int offset, int length, boolean space) public static String getHexString (byte[] buffer, int offset, int length, boolean space)
{ {
StringBuilder hex = new StringBuilder (); StringBuilder hex = new StringBuilder ();
for (int i = 0; i < length; i++) int max = Math.min (offset + length, buffer.length);
for (int i = offset; i < max; i++)
{ {
hex.append (String.format ("%02X", buffer[offset + i])); hex.append (String.format ("%02X", buffer[i]));
if (space) if (space)
hex.append (' '); hex.append (' ');
} }