mainly comments

This commit is contained in:
Denis Molony 2018-07-31 17:02:19 +10:00
parent 7366aa19c7
commit a0ffb8e530
4 changed files with 162 additions and 130 deletions

View File

@ -49,20 +49,21 @@ public abstract class HiResImage extends AbstractFile
// $C2 ANI Paintworks animation
// $C3 PAL Paintworks palette
protected static PaletteFactory paletteFactory = new PaletteFactory ();
static PaletteFactory paletteFactory = new PaletteFactory ();
private static final byte[] pngHeader =
static final byte[] pngHeader =
{ (byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
protected static boolean colourQuirks;
protected static boolean monochrome;
static boolean colourQuirks;
static boolean monochrome;
protected int fileType;
protected int auxType;
protected int eof;
int fileType;
int auxType;
int eof;
protected byte[] unpackedBuffer;
protected int paletteIndex;
byte[] unpackedBuffer;
int paletteIndex;
String failureReason = "";
public HiResImage (String name, byte[] buffer)
{
@ -194,7 +195,7 @@ public abstract class HiResImage extends AbstractFile
auxText = "Packed Super Hi-Res Image";
break;
case 2:
auxText = "Super Hi-Res Image (Apple Preferred)";
auxText = "Super Hi-Res Image (Apple Preferred Format)";
break;
case 3:
auxText = "Packed QuickDraw II PICT File";
@ -234,6 +235,8 @@ public abstract class HiResImage extends AbstractFile
text.append (String.format ("%nUnpacked : %,d%n%n", unpackedBuffer.length));
// text.append (HexFormatter.format (unpackedBuffer));
}
if (!failureReason.isEmpty ())
text.append (String.format ("%nFailure : %s", failureReason));
return text.toString ();
}
@ -264,9 +267,10 @@ public abstract class HiResImage extends AbstractFile
}
catch (ArrayIndexOutOfBoundsException e)
{
}
System.out.println ("unpackBytes()");
failureReason = "buffer too small";
return new byte[0];
}
@ -314,8 +318,8 @@ public abstract class HiResImage extends AbstractFile
}
}
// Super Hi-res IIGS
protected int unpackLine (byte[] buffer, byte[] newBuf, int newPtr)
// Super Hi-res IIGS (MAIN in $C0/02)
int unpackLine (byte[] buffer, byte[] newBuf, int newPtr)
{
byte[] fourBuf = new byte[4];
@ -332,14 +336,14 @@ public abstract class HiResImage extends AbstractFile
{
case 0:
while (count-- != 0)
if (newPtr < unpackedBuffer.length && ptr < buffer.length)
if (newPtr < newBuf.length && ptr < buffer.length)
newBuf[newPtr++] = buffer[ptr++];
break;
case 1:
byte b = buffer[ptr++];
while (count-- != 0)
if (newPtr < unpackedBuffer.length)
if (newPtr < newBuf.length)
newBuf[newPtr++] = b;
break;
@ -349,7 +353,7 @@ public abstract class HiResImage extends AbstractFile
fourBuf[i] = buffer[ptr++];
while (count-- != 0)
for (int i = 0; i < 4; i++)
if (newPtr < unpackedBuffer.length)
if (newPtr < newBuf.length)
newBuf[newPtr++] = fourBuf[i];
break;
@ -357,7 +361,7 @@ public abstract class HiResImage extends AbstractFile
b = buffer[ptr++];
count *= 4;
while (count-- != 0)
if (newPtr < unpackedBuffer.length)
if (newPtr < newBuf.length)
newBuf[newPtr++] = b;
break;
}
@ -484,6 +488,11 @@ public abstract class HiResImage extends AbstractFile
this.id = id;
for (int i = 0; i < 16; i++)
{
// if (offset >= data.length)
// {
// System.out.println ("oops");
// return;
// }
entries[i] = new ColorEntry (data, offset);
offset += 2;
}

View File

@ -13,7 +13,7 @@ public class SHRPictureFile1 extends HiResImage
private Main mainBlock;
private Multipal multipalBlock;
// 0xC0 aux = 2 - Apple IIGS Super Hi-Res Picture File
// 0xC0/02 - Apple IIGS Super Hi-Res Picture File (APF)
public SHRPictureFile1 (String name, byte[] buffer, int fileType, int auxType, int eof)
{
super (name, buffer, fileType, auxType, eof);
@ -42,31 +42,19 @@ public class SHRPictureFile1 extends HiResImage
break;
case "PALETTES":
System.out.println ("PALETTES not written");
blocks.add (new Block (kind, data));
break;
case "MASK":
System.out.println ("MASK not written");
blocks.add (new Block (kind, data));
break;
case "PATS":
System.out.println ("PATS not written");
blocks.add (new Block (kind, data));
break;
case "SCIB":
System.out.println ("SCIB not written");
System.out.println (kind + " not written");
blocks.add (new Block (kind, data));
break;
// case "SuperConvert":
// case "NOTE":
// case "EOA ": // DeluxePaint
// case "Platinum Paint":
// blocks.add (new Block (kind, data));
// break;
case "NOTE": // Convert 3200
case "SuperConvert":
case "EOA ": // DeluxePaint
case "Platinum Paint":
blocks.add (new Block (kind, data));
break;
default:
blocks.add (new Block (kind, data));
@ -109,20 +97,22 @@ public class SHRPictureFile1 extends HiResImage
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
if (mainBlock.pixelsPerScanLine != 320)
System.out.println ("Pixels per scanline: " + mainBlock.pixelsPerScanLine);
System.out.printf ("%s: Pixels per scanline: %d%n", name,
mainBlock.pixelsPerScanLine);
int element = 0;
int ptr = 0;
for (int row = 0; row < mainBlock.numScanLines; row++)
int element = 0; // index into dataBuffer
int ptr = 0; // index into unpackedBuffer
for (int line = 0; line < mainBlock.numScanLines; line++)
{
DirEntry dirEntry = mainBlock.scanLineDirectory[row];
DirEntry dirEntry = mainBlock.scanLineDirectory[line];
int hi = dirEntry.mode & 0xFF00; // always 0
int lo = dirEntry.mode & 0x00FF; // mode bit if hi == 0
if (hi != 0)
System.out.println ("hi not zero");
ColorTable colorTable = multipalBlock != null ? multipalBlock.colorTables[row]
ColorTable colorTable = multipalBlock != null ? multipalBlock.colorTables[line]
: mainBlock.colorTables[lo & 0x0F];
boolean fillMode = (lo & 0x20) != 0;
@ -130,7 +120,7 @@ public class SHRPictureFile1 extends HiResImage
System.out.println ("fillmode " + fillMode);
// 320 mode
for (int col = 0; col < 160; col++)
for (int i = 0; i < 160; i++)
{
int left = (unpackedBuffer[ptr] & 0xF0) >> 4;
int right = unpackedBuffer[ptr] & 0x0F;
@ -230,6 +220,8 @@ public class SHRPictureFile1 extends HiResImage
pixelsPerScanLine = HexFormatter.unsignedShort (data, ptr + 2);
numColorTables = HexFormatter.unsignedShort (data, ptr + 4);
System.out.printf ("mm %d, pix %d%n", masterMode, pixelsPerScanLine);
ptr += 6;
colorTables = new ColorTable[numColorTables];
for (int i = 0; i < numColorTables; i++)

View File

@ -19,95 +19,14 @@ public class SHRPictureFile2 extends HiResImage
switch (fileType)
{
case ProdosConstants.FILE_TYPE_PNT:
switch (auxType)
{
case 0:
System.out.printf (
"%s: PNT aux 0 (Paintworks Packed SHR Image) not written yet%n", name);
int background = HexFormatter.intValue (buffer[0x20], buffer[0x21]);
byte[] palette = new byte[32];
byte[] patterns = new byte[512];
byte[] data = new byte[buffer.length - 0x222];
System.arraycopy (buffer, 0x00, palette, 0, palette.length);
System.arraycopy (buffer, 0x22, patterns, 0, patterns.length);
System.arraycopy (buffer, 0x0222, data, 0, data.length);
this.buffer = unpackBytes (data);
break;
case 1: // packed version of PIC/$00
this.buffer = unpackBytes (buffer);
controlBytes = new byte[200];
System.arraycopy (this.buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32);
break;
case 2: // handled in SHRPictureFile1
break;
case 3: // packed version of PIC/$01
System.out.printf ("%s: PNT aux 3 (Packed IIGS SHR Image) not written yet%n",
name);
break;
case 4: // packed version of PIC/$02
System.out.printf ("%s: PNT aux 4 (Packed SHR Brooks Image) not tested yet%n",
name);
this.buffer = unpackBytes (buffer);
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
{
colorTables[i] = new ColorTable (i, this.buffer, 32000 + i * 32);
colorTables[i].reverse ();
}
break;
default:
System.out.printf ("%s: PNT unknown aux: %04X%n", name, auxType);
}
case ProdosConstants.FILE_TYPE_PNT: // packed images
doPnt (buffer);
break;
case ProdosConstants.FILE_TYPE_PIC:
if (auxType > 2)
{
System.out.printf ("%s: PIC changing aux from %04X to 0%n", name, auxType);
auxType = 0;
}
switch (auxType)
{
case 0: // unpacked version of PNT/$01
controlBytes = new byte[200];
System.arraycopy (buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32);
break;
case 1: // unpacked version of PNT/$03
System.out.printf ("%s: PIC aux 1 not written yet%n", name);
break;
case 2: // unpacked version of PNT/$04
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
{
colorTables[i] = new ColorTable (i, buffer, 32000 + i * 32);
colorTables[i].reverse ();
}
break;
default:
System.out.println ("PIC unknown aux " + auxType);
}
case ProdosConstants.FILE_TYPE_PIC: // unpacked images
doPic ();
break;
default:
System.out.println ("unknown filetype " + fileType);
}
@ -116,6 +35,116 @@ public class SHRPictureFile2 extends HiResImage
createImage ();
}
private void doPnt (byte[] buffer)
{
switch (auxType)
{
case 0:
System.out.printf (
"%s: PNT aux 0 (Paintworks Packed SHR Image) not written yet%n", name);
int background = HexFormatter.intValue (buffer[0x20], buffer[0x21]);
byte[] palette = new byte[32];
byte[] patterns = new byte[512];
byte[] data = new byte[buffer.length - 0x222];
System.arraycopy (buffer, 0x00, palette, 0, palette.length);
System.arraycopy (buffer, 0x22, patterns, 0, patterns.length);
System.arraycopy (buffer, 0x0222, data, 0, data.length);
failureReason = "not written yet";
this.buffer = unpackBytes (data);
break;
case 1: // packed version of PIC/$00
this.buffer = unpackBytes (buffer);
controlBytes = new byte[200];
System.arraycopy (this.buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, this.buffer, 32256 + i * 32);
break;
case 2: // handled in SHRPictureFile1
break;
case 3: // packed version of PIC/$01
System.out.printf ("%s: PNT aux 3 (Packed IIGS SHR Image) not written yet%n",
name);
// Apple IIGS Tech Note #46
// https://www.prepressure.com/library/file-formats/pict
this.buffer = unpackBytes (buffer);
int mode = HexFormatter.unsignedShort (this.buffer, 0);
int rect1 = HexFormatter.unsignedLong (this.buffer, 2);
int rect2 = HexFormatter.unsignedLong (this.buffer, 6);
int version = HexFormatter.unsignedShort (this.buffer, 10); // $8211
break;
case 4: // packed version of PIC/$02
System.out.printf ("%s: PNT aux 4 (Packed SHR Brooks Image) not tested yet%n",
name);
this.buffer = unpackBytes (buffer);
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
{
colorTables[i] = new ColorTable (i, this.buffer, 32000 + i * 32);
colorTables[i].reverse ();
}
break;
default:
System.out.printf ("%s: PNT unknown aux: %04X%n", name, auxType);
}
}
private void doPic ()
{
switch (auxType)
{
case 0: // unpacked version of PNT/$01
case 0x4100:
// 00000 - 31999 pixel data 32,000 bytes
// 32000 - 32199 200 control bytes (one per scan line)
// 32200 - 32255 empty
// 32256 - 32767 16 color tables of 32 bytes each
controlBytes = new byte[200];
System.arraycopy (buffer, 32000, controlBytes, 0, controlBytes.length);
colorTables = new ColorTable[16];
for (int i = 0; i < colorTables.length; i++)
colorTables[i] = new ColorTable (i, buffer, 32256 + i * 32);
break;
case 1: // unpacked version of PNT/$03
System.out.printf ("%s: PIC aux 1 not written yet%n", name);
break;
case 2: // unpacked version of PNT/$04, .3200
// 00000 - 31999 pixel data 32,000 bytes
// 32000 - 38399 200 color tables of 32 bytes each (one color table per scan line)
if (buffer.length < 38400)
{
failureReason = "Buffer should be 38,400 bytes";
return;
}
colorTables = new ColorTable[200];
for (int i = 0; i < colorTables.length; i++)
{
int ptr = 32000 + i * 32;
colorTables[i] = new ColorTable (i, buffer, ptr);
colorTables[i].reverse ();
}
break;
default:
System.out.println ("PIC unknown aux " + auxType);
}
}
@Override
void createMonochromeImage ()
{

View File

@ -278,6 +278,8 @@ class FileEntry extends CatalogEntry implements ProdosConstants
assert auxType == 0; // auxType > 0 handled above
if (name.endsWith (".S"))
file = new MerlinSource (name, exactBuffer, auxType, endOfFile);
else if (name.endsWith (".GIF") && HiResImage.isGif (exactBuffer))
file = new OriginalHiResImage (name, exactBuffer, auxType);
else
file = new TextFile (name, exactBuffer, auxType, endOfFile);
break;