mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2025-02-07 11:30:39 +00:00
Added rudimentary FND file
This commit is contained in:
parent
4f2a954add
commit
b1c5092329
47
src/com/bytezone/diskbrowser/applefile/FinderData.java
Normal file
47
src/com/bytezone/diskbrowser/applefile/FinderData.java
Normal file
@ -0,0 +1,47 @@
|
||||
package com.bytezone.diskbrowser.applefile;
|
||||
|
||||
import com.bytezone.diskbrowser.utilities.HexFormatter;
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
public class FinderData extends AbstractFile
|
||||
// -----------------------------------------------------------------------------------//
|
||||
{
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
public FinderData (String name, byte[] buffer)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
super (name, buffer);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@Override
|
||||
public String getText ()
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
StringBuilder text = new StringBuilder ();
|
||||
|
||||
text.append ("Name : " + name + "\n\n");
|
||||
|
||||
text.append (HexFormatter.format (buffer, 0, 41));
|
||||
text.append ("\n\n");
|
||||
|
||||
int ptr = 41;
|
||||
while (ptr < buffer.length - 1)
|
||||
{
|
||||
String line = HexFormatter.getHexString (buffer, ptr, 9);
|
||||
text.append (line + " ");
|
||||
|
||||
ptr += 9;
|
||||
String name = HexFormatter.getPascalString (buffer, ptr);
|
||||
text.append (name + "\n");
|
||||
|
||||
ptr += name.length () + 1;
|
||||
}
|
||||
|
||||
if (text.length () > 0)
|
||||
text.deleteCharAt (text.length () - 1);
|
||||
|
||||
return text.toString ();
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ import java.awt.Color;
|
||||
import java.awt.image.DataBuffer;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
@ -402,66 +401,8 @@ public abstract class HiResImage extends AbstractFile
|
||||
return element;
|
||||
}
|
||||
|
||||
// only called by SHRPictureFile2
|
||||
// ---------------------------------------------------------------------------------//
|
||||
byte[] unpack (byte[] buffer) throws ArrayIndexOutOfBoundsException
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
// this should be pixelsPerLine * (2 or 4) * screenLines
|
||||
byte[] newBuf = new byte[calculateBufferSize (buffer)];
|
||||
if (true)
|
||||
{
|
||||
unpackLine2 (buffer, 0, buffer.length, newBuf, 0);
|
||||
return newBuf;
|
||||
}
|
||||
|
||||
int ptr = 0, newPtr = 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: // copy next 1-64 bytes as is
|
||||
count = Math.min (count, buffer.length - ptr);
|
||||
System.arraycopy (buffer, ptr, newBuf, newPtr, count);
|
||||
newPtr += count;
|
||||
ptr += count;
|
||||
break;
|
||||
|
||||
case 1: // repeat next byte 3/5/6/7 times
|
||||
Arrays.fill (newBuf, newPtr, newPtr + count, buffer[ptr++]);
|
||||
newPtr += count;
|
||||
break;
|
||||
|
||||
case 2: // repeat next 4 bytes (count) times
|
||||
fourBuf[0] = buffer[ptr++];
|
||||
fourBuf[1] = buffer[ptr++];
|
||||
fourBuf[2] = buffer[ptr++];
|
||||
fourBuf[3] = buffer[ptr++];
|
||||
while (count-- != 0)
|
||||
{
|
||||
newBuf[newPtr++] = fourBuf[0];
|
||||
newBuf[newPtr++] = fourBuf[1];
|
||||
newBuf[newPtr++] = fourBuf[2];
|
||||
newBuf[newPtr++] = fourBuf[3];
|
||||
}
|
||||
break;
|
||||
|
||||
case 3: // repeat next byte (4*count) times
|
||||
count *= 4;
|
||||
Arrays.fill (newBuf, newPtr, newPtr + count, buffer[ptr++]);
|
||||
newPtr += count;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return newBuf;
|
||||
}
|
||||
|
||||
// Super Hi-res IIGS (MAIN in $C0/02)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
int unpackLine2 (byte[] buffer, int ptr, int max, byte[] newBuf, int newPtr)
|
||||
int unpack (byte[] buffer, int ptr, int max, byte[] newBuf, int newPtr)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int savePtr = newPtr;
|
||||
@ -506,52 +447,6 @@ public abstract class HiResImage extends AbstractFile
|
||||
return newPtr - savePtr; // bytes unpacked
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private int unpackLineX (byte[] buffer, int ptr, byte[] newBuf, int newPtr)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int savePtr = newPtr;
|
||||
|
||||
while (ptr < buffer.length - 1) // minimum 2 bytes needed
|
||||
{
|
||||
int type = (buffer[ptr] & 0xC0) >>> 6; // 0-3
|
||||
int count = (buffer[ptr++] & 0x3F) + 1; // 1-64
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case 0: // 2-65 bytes
|
||||
while (count-- != 0 && newPtr < newBuf.length && ptr < buffer.length)
|
||||
newBuf[newPtr++] = buffer[ptr++];
|
||||
break;
|
||||
|
||||
case 1: // 2 bytes
|
||||
byte b = buffer[ptr++];
|
||||
while (count-- != 0 && newPtr < newBuf.length)
|
||||
newBuf[newPtr++] = b;
|
||||
break;
|
||||
|
||||
case 2: // 5 bytes
|
||||
for (int i = 0; i < 4; i++)
|
||||
fourBuf[i] = ptr < buffer.length ? buffer[ptr++] : 0;
|
||||
|
||||
while (count-- != 0)
|
||||
for (int i = 0; i < 4; i++)
|
||||
if (newPtr < newBuf.length)
|
||||
newBuf[newPtr++] = fourBuf[i];
|
||||
break;
|
||||
|
||||
case 3: // 2 bytes
|
||||
b = buffer[ptr++];
|
||||
count *= 4;
|
||||
while (count-- != 0 && newPtr < newBuf.length)
|
||||
newBuf[newPtr++] = b;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return newPtr - savePtr; // bytes unpacked
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private void debug (byte[] buffer, int ptr, int length)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
@ -596,10 +491,10 @@ public abstract class HiResImage extends AbstractFile
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------//
|
||||
private int calculateBufferSize (byte[] buffer)
|
||||
int calculateBufferSize (byte[] buffer, int ptr)
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int ptr = 0;
|
||||
// int ptr = 0;
|
||||
int size = 0;
|
||||
while (ptr < buffer.length)
|
||||
{
|
||||
|
@ -272,10 +272,10 @@ public class SHRPictureFile1 extends HiResImage
|
||||
// ---------------------------------------------------------------------------------//
|
||||
{
|
||||
int masterMode; // 0 = Brooks, 0 = PNT 320 80 = PNT 640
|
||||
int pixelsPerScanLine; // 320 or 640 (but not always)
|
||||
int pixelsPerScanLine; // image width in pixels
|
||||
int numColorTables; // 1 = Brooks, 16 = Other (may be zero)
|
||||
ColorTable[] colorTables; // [numColorTables]
|
||||
int numScanLines; // >0
|
||||
int numScanLines; // image height in pixels
|
||||
DirEntry[] scanLineDirectory; // [numScanLines]
|
||||
byte[][] packedScanLines;
|
||||
boolean mode640;
|
||||
@ -289,7 +289,6 @@ public class SHRPictureFile1 extends HiResImage
|
||||
masterMode = HexFormatter.unsignedShort (data, ptr);
|
||||
pixelsPerScanLine = HexFormatter.unsignedShort (data, ptr + 2);
|
||||
numColorTables = HexFormatter.unsignedShort (data, ptr + 4);
|
||||
assert numColorTables > 0;
|
||||
mode640 = (masterMode & 0x80) != 0;
|
||||
|
||||
ptr += 6;
|
||||
@ -333,16 +332,16 @@ public class SHRPictureFile1 extends HiResImage
|
||||
ptr = 0;
|
||||
for (int line = 0; line < numScanLines; line++)
|
||||
{
|
||||
if (isOddAndEmpty (packedScanLines[line]))
|
||||
{
|
||||
System.out.println ("Odd number of bytes in empty buffer in " + name);
|
||||
break;
|
||||
}
|
||||
// if (isOddAndEmpty (packedScanLines[line]))
|
||||
// {
|
||||
// System.out.println ("Odd number of bytes in empty buffer in " + name);
|
||||
// break;
|
||||
// }
|
||||
|
||||
int bytesUnpacked = unpackLine2 (packedScanLines[line], 0,
|
||||
int bytesUnpacked = unpack (packedScanLines[line], 0,
|
||||
packedScanLines[line].length, unpackedBuffer, ptr);
|
||||
|
||||
if (bytesUnpacked != dataWidth)
|
||||
if (bytesUnpacked != dataWidth && false)
|
||||
System.out.printf ("Unexpected line width %3d %5d %3d %3d%n", line, ptr,
|
||||
bytesUnpacked, dataWidth);
|
||||
|
||||
@ -353,16 +352,16 @@ public class SHRPictureFile1 extends HiResImage
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
private boolean isOddAndEmpty (byte[] buffer)
|
||||
// -------------------------------------------------------------------------------//
|
||||
{
|
||||
if (buffer.length % 2 == 0)
|
||||
return false;
|
||||
for (byte b : buffer)
|
||||
if (b != 0)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// private boolean isOddAndEmpty (byte[] buffer)
|
||||
// // -------------------------------------------------------------------------------//
|
||||
// {
|
||||
// if (buffer.length % 2 == 0)
|
||||
// return false;
|
||||
// for (byte b : buffer)
|
||||
// if (b != 0)
|
||||
// return false;
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// -------------------------------------------------------------------------------//
|
||||
@Override
|
||||
|
@ -51,16 +51,35 @@ public class SHRPictureFile2 extends HiResImage
|
||||
colorTables = new ColorTable[1];
|
||||
colorTables[0] = new ColorTable (0, this.buffer, 0);
|
||||
|
||||
byte[] data = new byte[buffer.length - 0x222];
|
||||
System.arraycopy (buffer, 0x0222, data, 0, data.length);
|
||||
buffer = unpack (data);
|
||||
// if (false)
|
||||
// {
|
||||
// byte[] data = new byte[buffer.length - 0x222];
|
||||
// System.arraycopy (buffer, 0x0222, data, 0, data.length);
|
||||
// buffer = unpack (data);
|
||||
// System.out.println ("paintworks");
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
byte[] newBuffer = new byte[calculateBufferSize (buffer, 0x222)];
|
||||
unpack (buffer, 0x222, buffer.length, newBuffer, 0);
|
||||
buffer = newBuffer;
|
||||
// }
|
||||
rows = buffer.length / 160;
|
||||
controlBytes = new byte[rows]; // all pointing to 0th color table
|
||||
|
||||
break;
|
||||
|
||||
case 1: // packed version of PIC/$00
|
||||
buffer = unpack (buffer);
|
||||
// if (false)
|
||||
// {
|
||||
// buffer = unpack (buffer);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
newBuffer = new byte[calculateBufferSize (buffer, 0)];
|
||||
unpack (buffer, 0, buffer.length, newBuffer, 0);
|
||||
buffer = newBuffer;
|
||||
// }
|
||||
controlBytes = new byte[rows];
|
||||
System.arraycopy (this.buffer, 32000, controlBytes, 0, controlBytes.length);
|
||||
|
||||
@ -79,7 +98,14 @@ public class SHRPictureFile2 extends HiResImage
|
||||
|
||||
// Apple IIGS Tech Note #46
|
||||
// https://www.prepressure.com/library/file-formats/pict
|
||||
this.buffer = unpack (buffer);
|
||||
// if (false)
|
||||
// buffer = unpack (buffer);
|
||||
// else
|
||||
// {
|
||||
newBuffer = new byte[calculateBufferSize (buffer, 0)];
|
||||
unpack (buffer, 0, buffer.length, newBuffer, 0);
|
||||
buffer = newBuffer;
|
||||
// }
|
||||
int mode = HexFormatter.unsignedShort (this.buffer, 0);
|
||||
int rect1 = HexFormatter.unsignedLong (this.buffer, 2);
|
||||
int rect2 = HexFormatter.unsignedLong (this.buffer, 6);
|
||||
@ -104,9 +130,18 @@ public class SHRPictureFile2 extends HiResImage
|
||||
colorTables[i].reverse ();
|
||||
}
|
||||
|
||||
data = new byte[buffer.length - 6404]; // skip APP. and color tables
|
||||
System.arraycopy (buffer, 6404, data, 0, data.length);
|
||||
this.buffer = unpack (data);
|
||||
// if (false)
|
||||
// {
|
||||
// byte[] data = new byte[buffer.length - 6404]; // skip APP. and color tables
|
||||
// System.arraycopy (buffer, 6404, data, 0, data.length);
|
||||
// this.buffer = unpack (data);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
newBuffer = new byte[calculateBufferSize (buffer, 6404)];
|
||||
unpack (buffer, 6404, buffer.length, newBuffer, 0);
|
||||
buffer = newBuffer;
|
||||
// }
|
||||
|
||||
break;
|
||||
|
||||
|
@ -15,6 +15,7 @@ import com.bytezone.diskbrowser.applefile.ErrorMessageFile;
|
||||
import com.bytezone.diskbrowser.applefile.FaddenHiResImage;
|
||||
import com.bytezone.diskbrowser.applefile.FileSystemTranslator;
|
||||
import com.bytezone.diskbrowser.applefile.FileTypeDescriptorTable;
|
||||
import com.bytezone.diskbrowser.applefile.FinderData;
|
||||
import com.bytezone.diskbrowser.applefile.FontFile;
|
||||
import com.bytezone.diskbrowser.applefile.HiResImage;
|
||||
import com.bytezone.diskbrowser.applefile.IconFile;
|
||||
@ -443,7 +444,6 @@ class FileEntry extends CatalogEntry implements ProdosConstants
|
||||
file = new FileSystemTranslator (name, exactBuffer);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_FINDER:
|
||||
case FILE_TYPE_PASCAL_VOLUME:
|
||||
case FILE_TYPE_GEO:
|
||||
case FILE_TYPE_LDF:
|
||||
@ -460,6 +460,10 @@ class FileEntry extends CatalogEntry implements ProdosConstants
|
||||
file = new DefaultAppleFile (name, exactBuffer);
|
||||
break;
|
||||
|
||||
case FILE_TYPE_FINDER:
|
||||
file = new FinderData (name, exactBuffer);
|
||||
break;
|
||||
|
||||
default:
|
||||
// System.out.format ("%02X %s %s - Unknown Prodos file type%n",
|
||||
// fileType, fileTypes[fileType], name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user