mirror of
https://github.com/dmolony/DiskBrowser.git
synced 2024-11-25 16:34:00 +00:00
refactoring
This commit is contained in:
parent
96c733a7c6
commit
6e36bae590
@ -255,6 +255,50 @@ public abstract class HiResImage extends AbstractFile
|
|||||||
return text.toString ();
|
return text.toString ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
int mode320Line (int ptr, int element, int max, ColorTable colorTable,
|
||||||
|
DataBuffer dataBuffer, int imageWidth)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
int left = (buffer[ptr] & 0xF0) >> 4;
|
||||||
|
int right = buffer[ptr++] & 0x0F;
|
||||||
|
|
||||||
|
// get left/right colors
|
||||||
|
int rgbLeft = colorTable.entries[left].color.getRGB ();
|
||||||
|
int rgbRight = colorTable.entries[right].color.getRGB ();
|
||||||
|
|
||||||
|
draw (dataBuffer, element + imageWidth, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
||||||
|
element = draw (dataBuffer, element, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
int mode640Line (int ptr, int element, int max, ColorTable colorTable,
|
||||||
|
DataBuffer dataBuffer, int imageWidth)
|
||||||
|
// ---------------------------------------------------------------------------------//
|
||||||
|
{
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
int p1 = (buffer[ptr] & 0xC0) >> 6;
|
||||||
|
int p2 = (buffer[ptr] & 0x30) >> 4;
|
||||||
|
int p3 = (buffer[ptr] & 0x0C) >> 2;
|
||||||
|
int p4 = (buffer[ptr++] & 0x03);
|
||||||
|
|
||||||
|
// get pixel colors
|
||||||
|
int rgb1 = colorTable.entries[p1 + 8].color.getRGB ();
|
||||||
|
int rgb2 = colorTable.entries[p2 + 12].color.getRGB ();
|
||||||
|
int rgb3 = colorTable.entries[p3].color.getRGB ();
|
||||||
|
int rgb4 = colorTable.entries[p4 + 4].color.getRGB ();
|
||||||
|
|
||||||
|
draw (dataBuffer, element + imageWidth, rgb1, rgb2, rgb3, rgb4);
|
||||||
|
element = draw (dataBuffer, element, rgb1, rgb2, rgb3, rgb4);
|
||||||
|
}
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
int draw (DataBuffer dataBuffer, int element, int... rgb1)
|
int draw (DataBuffer dataBuffer, int element, int... rgb1)
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
|
@ -27,8 +27,11 @@ public class SHRPictureFile1 extends HiResImage
|
|||||||
while (ptr < buffer.length)
|
while (ptr < buffer.length)
|
||||||
{
|
{
|
||||||
int len = HexFormatter.unsignedLong (buffer, ptr);
|
int len = HexFormatter.unsignedLong (buffer, ptr);
|
||||||
if (len == 0)
|
if (len == 0 || len > buffer.length)
|
||||||
|
{
|
||||||
|
System.out.printf ("Block length: %d%n", len);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
String kind = HexFormatter.getPascalString (buffer, ptr + 4);
|
String kind = HexFormatter.getPascalString (buffer, ptr + 4);
|
||||||
byte[] data = new byte[Math.min (len, buffer.length - ptr)];
|
byte[] data = new byte[Math.min (len, buffer.length - ptr)];
|
||||||
@ -104,14 +107,16 @@ public class SHRPictureFile1 extends HiResImage
|
|||||||
void createColourImage ()
|
void createColourImage ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
int width = mainBlock.masterMode == 0x80 ? 640 : mainBlock.unpackedSize[0] * 4;
|
if (mainBlock == null)
|
||||||
image =
|
return;
|
||||||
new BufferedImage (width, mainBlock.numScanLines * 2, BufferedImage.TYPE_INT_RGB);
|
|
||||||
|
int imageWidth = mainBlock.masterMode == 0x80 ? 640 : mainBlock.unpackedSize[0] * 4;
|
||||||
|
image = new BufferedImage (imageWidth, mainBlock.numScanLines * 2,
|
||||||
|
BufferedImage.TYPE_INT_RGB);
|
||||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||||
|
|
||||||
int element1 = 0; // first line
|
int element = 0;
|
||||||
int element2 = width; // second line
|
int ptr = 0;
|
||||||
int ptr = 0; // index into buffer
|
|
||||||
|
|
||||||
for (int line = 0; line < mainBlock.numScanLines; line++)
|
for (int line = 0; line < mainBlock.numScanLines; line++)
|
||||||
{
|
{
|
||||||
@ -125,48 +130,15 @@ public class SHRPictureFile1 extends HiResImage
|
|||||||
ColorTable colorTable = multipalBlock != null ? multipalBlock.colorTables[line]
|
ColorTable colorTable = multipalBlock != null ? multipalBlock.colorTables[line]
|
||||||
: mainBlock.colorTables[lo & 0x0F];
|
: mainBlock.colorTables[lo & 0x0F];
|
||||||
|
|
||||||
// boolean fillMode = (lo & 0x20) != 0;
|
|
||||||
// if (fillMode)
|
|
||||||
// System.out.println ("fillmode " + fillMode);
|
|
||||||
boolean mode320 = (mainBlock.masterMode & 0x80) == 0;
|
boolean mode320 = (mainBlock.masterMode & 0x80) == 0;
|
||||||
int max = mainBlock.unpackedSize[line];
|
int max = mainBlock.unpackedSize[line];
|
||||||
|
|
||||||
if (mode320) // two pixels per col
|
if (mode320) // two pixels per col
|
||||||
{
|
ptr = mode320Line (ptr, element, max, colorTable, dataBuffer, imageWidth);
|
||||||
for (int i = 0; i < max; i++)
|
|
||||||
{
|
|
||||||
int left = (buffer[ptr] & 0xF0) >> 4;
|
|
||||||
int right = buffer[ptr++] & 0x0F;
|
|
||||||
|
|
||||||
// get left/right colors
|
|
||||||
int rgbLeft = colorTable.entries[left].color.getRGB ();
|
|
||||||
int rgbRight = colorTable.entries[right].color.getRGB ();
|
|
||||||
|
|
||||||
element1 = draw (dataBuffer, element1, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
|
||||||
element2 = draw (dataBuffer, element2, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // four pixels per col
|
else // four pixels per col
|
||||||
{
|
ptr = mode640Line (ptr, element, max, colorTable, dataBuffer, imageWidth);
|
||||||
for (int i = 0; i < max; i++)
|
|
||||||
{
|
|
||||||
int p1 = (buffer[ptr] & 0xC0) >> 6;
|
|
||||||
int p2 = (buffer[ptr] & 0x30) >> 4;
|
|
||||||
int p3 = (buffer[ptr] & 0x0C) >> 2;
|
|
||||||
int p4 = (buffer[ptr++] & 0x03);
|
|
||||||
|
|
||||||
// get pixel colors
|
element += imageWidth * 2;
|
||||||
int rgb1 = colorTable.entries[p1 + 8].color.getRGB ();
|
|
||||||
int rgb2 = colorTable.entries[p2 + 12].color.getRGB ();
|
|
||||||
int rgb3 = colorTable.entries[p3].color.getRGB ();
|
|
||||||
int rgb4 = colorTable.entries[p4 + 4].color.getRGB ();
|
|
||||||
|
|
||||||
element1 = draw (dataBuffer, element1, rgb1, rgb2, rgb3, rgb4);
|
|
||||||
element2 = draw (dataBuffer, element2, rgb1, rgb2, rgb3, rgb4);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
element1 += width; // skip line already drawn
|
|
||||||
element2 += width; // one line ahead
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,16 +194,17 @@ public class SHRPictureFile2 extends HiResImage
|
|||||||
void createColourImage ()
|
void createColourImage ()
|
||||||
// ---------------------------------------------------------------------------------//
|
// ---------------------------------------------------------------------------------//
|
||||||
{
|
{
|
||||||
image = new BufferedImage (640, rows * 2, BufferedImage.TYPE_INT_RGB);
|
int imageWidth = 640;
|
||||||
|
image = new BufferedImage (imageWidth, rows * 2, BufferedImage.TYPE_INT_RGB);
|
||||||
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
DataBuffer dataBuffer = image.getRaster ().getDataBuffer ();
|
||||||
|
|
||||||
int element1 = 0; // first line
|
int element = 0;
|
||||||
int element2 = 640; // second line
|
|
||||||
int ptr = 0;
|
int ptr = 0;
|
||||||
|
|
||||||
boolean mode320 = true;
|
boolean mode320 = true;
|
||||||
boolean fillMode = false;
|
boolean fillMode = false;
|
||||||
ColorTable colorTable = null;
|
ColorTable colorTable = null;
|
||||||
|
int max = 160;
|
||||||
|
|
||||||
for (int line = 0; line < rows; line++)
|
for (int line = 0; line < rows; line++)
|
||||||
{
|
{
|
||||||
@ -220,7 +221,7 @@ public class SHRPictureFile2 extends HiResImage
|
|||||||
|
|
||||||
if (mode320) // two pixels per col
|
if (mode320) // two pixels per col
|
||||||
{
|
{
|
||||||
for (int col = 0; col < 160; col++)
|
for (int i = 0; i < max; i++)
|
||||||
{
|
{
|
||||||
int left = (buffer[ptr] & 0xF0) >> 4;
|
int left = (buffer[ptr] & 0xF0) >> 4;
|
||||||
int right = buffer[ptr++] & 0x0F;
|
int right = buffer[ptr++] & 0x0F;
|
||||||
@ -229,13 +230,13 @@ public class SHRPictureFile2 extends HiResImage
|
|||||||
int rgbLeft = colorTable.entries[left].color.getRGB ();
|
int rgbLeft = colorTable.entries[left].color.getRGB ();
|
||||||
int rgbRight = colorTable.entries[right].color.getRGB ();
|
int rgbRight = colorTable.entries[right].color.getRGB ();
|
||||||
|
|
||||||
element1 = draw (dataBuffer, element1, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
draw (dataBuffer, element + imageWidth, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
||||||
element2 = draw (dataBuffer, element2, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
element = draw (dataBuffer, element, rgbLeft, rgbLeft, rgbRight, rgbRight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else // four pixels per col
|
else // four pixels per col
|
||||||
{
|
{
|
||||||
for (int col = 0; col < 160; col++)
|
for (int i = 0; i < max; i++)
|
||||||
{
|
{
|
||||||
int p1 = (buffer[ptr] & 0xC0) >> 6;
|
int p1 = (buffer[ptr] & 0xC0) >> 6;
|
||||||
int p2 = (buffer[ptr] & 0x30) >> 4;
|
int p2 = (buffer[ptr] & 0x30) >> 4;
|
||||||
@ -248,12 +249,11 @@ public class SHRPictureFile2 extends HiResImage
|
|||||||
int rgb3 = colorTable.entries[p3].color.getRGB ();
|
int rgb3 = colorTable.entries[p3].color.getRGB ();
|
||||||
int rgb4 = colorTable.entries[p4 + 4].color.getRGB ();
|
int rgb4 = colorTable.entries[p4 + 4].color.getRGB ();
|
||||||
|
|
||||||
element1 = draw (dataBuffer, element1, rgb1, rgb2, rgb3, rgb4);
|
draw (dataBuffer, element + imageWidth, rgb1, rgb2, rgb3, rgb4);
|
||||||
element2 = draw (dataBuffer, element2, rgb1, rgb2, rgb3, rgb4);
|
element = draw (dataBuffer, element, rgb1, rgb2, rgb3, rgb4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
element1 += 640; // skip line already drawn
|
element += imageWidth; // skip line already drawn
|
||||||
element2 += 640; // one line ahead
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user