com.webcodepro.applecommander.storage.filters
Class GraphicsFileFilter

java.lang.Object
  extended by com.webcodepro.applecommander.storage.filters.GraphicsFileFilter
All Implemented Interfaces:
FileFilter

public class GraphicsFileFilter
extends java.lang.Object
implements FileFilter

Filter the given file as if it were a graphics image.

Address for Apple2 HGR/DHR address is calculated from an observation of a pattern:
line number bits: 87654321
87 are multipled by 0x0028
65 are multipled by 0x0100
4 is multiplied by 0x0080
321 are multipled by 0x0400

HGR bit values ignore the high bit, as that switches the "palette", and for B&W mode, the bit does nothing. The other 7 bits simply toggle the pixel on or off. Double hires does not follow this - it uses a real 4 bit value, but the high bit is still ignored for graphics (hence, the 560 instead of 640 resolution).

SHR has been implemented in "16 color" mode as well as 3200 color mode. Note that 16 color mode is really 16 pallettes of 16 colors while 3200 color mode is 200 pallettes of 16 colors (one pallette per line).

NOTE: The design is feeling kludgy. There are 6 distinct variations - possibly a subclass is needed to interpret the various graphic image or some such redesign.

Date created: Nov 3, 2002 12:06:36 PM

Author:
Rob Greene

Field Summary
static int MODE_DHR_BLACK_AND_WHITE
           
static int MODE_DHR_COLOR
           
static int MODE_HGR_BLACK_AND_WHITE
           
static int MODE_HGR_COLOR
           
static int MODE_QUICKDRAW2_ICON
           
static int MODE_SHR_16
           
static int MODE_SHR_3200
           
 
Constructor Summary
GraphicsFileFilter()
          Constructor for GraphicsFileFilter.
 
Method Summary
protected  AppleImage[] buildQuickDraw2IconAndMask(byte[] filedata, int offset)
          Each icon is composed of two images - one an icon and the other is the mask.
protected  AppleImage buildQuickDraw2IconOrMask(byte[] filedata, boolean isColor, int height, int width, int offset)
          Build an image of an individual icon or its mask.
 AppleImage[] buildQuickDraw2Icons(FileEntry fileEntry)
          Construct a series of icons based on the QuickDraw II Icon file format.
 void copyImage(AppleImage destImage, AppleImage srcImage, int xStart, int yStart)
          Copy an image from the source image to the destination image.
 byte[] filter(FileEntry fileEntry)
          Filter the file data and produce an image.
 java.lang.String getExtension()
          Get the format name.
static java.lang.String[] getFileExtensions()
          Give file extensions.
 java.lang.String getSuggestedFileName(FileEntry fileEntry)
          Give suggested file name.
static boolean isCodecAvailable()
          Indicate if a codec is available (assist with interface requirements).
 boolean isDoubleHiresBlackAndWhiteMode()
          Indicates if this is configured for double hires black & white mode.
 boolean isDoubleHiresColorMode()
          Indicates if this is configured for double hires color mode.
 boolean isDoubleHiresMode()
          Indicates if this is a double hires mode.
 boolean isHiresBlackAndWhiteMode()
          Indicates if this is configured for hires black & white mode.
 boolean isHiresColorMode()
          Indicates if this is configured for hires color mode.
 boolean isHiresMode()
          Indicates if this is a hires mode.
 boolean isQuickDraw2Icon()
          Indicates if this is a QuickDraw II Icon.
 boolean isSuperHires16Mode()
          Indicates if this is configured for super hires 16 color mode.
 boolean isSuperHires3200Mode()
          Indicates if this is configured for super hires 3200 color mode.
 boolean isSuperHiresMode()
          Indicates if this is a super-hires mode.
protected  void processDoubleHiresBlackAndWhiteLine(byte[] lineData1, byte[] lineData2, AppleImage image, int y)
          Given a specific line in the image, process it in double hires black and white mode.
protected  void processDoubleHiresColorLine(byte[] lineData1, byte[] lineData2, AppleImage image, int y)
          Given a specific line in the image, process it in double hires color mode.
protected  void processHiresBlackAndWhiteLine(byte[] lineData, AppleImage image, int y)
          Given a specific line in the image, process it in hires black and white mode.
protected  void processHiresColorLine(byte[] lineData, AppleImage image, int y)
          Given a specific line in the image, process it in hires color mode.
protected  void processSuperHiresLine(byte[] lineData, AppleImage image, int y, byte scb, byte[] pallettes)
          Given a specific line in the image, process it in super hires color mode.
 void setExtension(java.lang.String extension)
          Set the format name.
 void setMode(int mode)
          Set the color mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MODE_HGR_BLACK_AND_WHITE

public static final int MODE_HGR_BLACK_AND_WHITE
See Also:
Constant Field Values

MODE_HGR_COLOR

public static final int MODE_HGR_COLOR
See Also:
Constant Field Values

MODE_DHR_BLACK_AND_WHITE

public static final int MODE_DHR_BLACK_AND_WHITE
See Also:
Constant Field Values

MODE_DHR_COLOR

public static final int MODE_DHR_COLOR
See Also:
Constant Field Values

MODE_SHR_16

public static final int MODE_SHR_16
See Also:
Constant Field Values

MODE_SHR_3200

public static final int MODE_SHR_3200
See Also:
Constant Field Values

MODE_QUICKDRAW2_ICON

public static final int MODE_QUICKDRAW2_ICON
See Also:
Constant Field Values
Constructor Detail

GraphicsFileFilter

public GraphicsFileFilter()
Constructor for GraphicsFileFilter.

Method Detail

isCodecAvailable

public static boolean isCodecAvailable()
Indicate if a codec is available (assist with interface requirements).


filter

public byte[] filter(FileEntry fileEntry)
Filter the file data and produce an image.

Specified by:
filter in interface FileFilter
See Also:
FileFilter.filter(FileEntry)

processHiresBlackAndWhiteLine

protected void processHiresBlackAndWhiteLine(byte[] lineData,
                                             AppleImage image,
                                             int y)
Given a specific line in the image, process it in hires black and white mode.


processHiresColorLine

protected void processHiresColorLine(byte[] lineData,
                                     AppleImage image,
                                     int y)
Given a specific line in the image, process it in hires color mode. HGR color is two bits to determine color - essentially resolution is 140 horizontally, but it indicates the color for two pixels.

The names of pixles is a bit confusion - pixel0 is really the left-most pixel (not the low-value bit). To alleviate my bad naming, here is a color table to assist:

 Color   Bits      RGB
 ======= ==== ========
 Black1   000 0x000000
 Green    001 0x00ff00
 Violet   010 0xff00ff
 White1   011 0xffffff
 Black2   100 0x000000
 Orange   101 0xff8000
 Blue     110 0x0000ff
 White2   111 0xffffff
 
Remember: bits are listed as "highbit", "pixel0", "pixel1"!


processDoubleHiresBlackAndWhiteLine

protected void processDoubleHiresBlackAndWhiteLine(byte[] lineData1,
                                                   byte[] lineData2,
                                                   AppleImage image,
                                                   int y)
Given a specific line in the image, process it in double hires black and white mode.


processDoubleHiresColorLine

protected void processDoubleHiresColorLine(byte[] lineData1,
                                           byte[] lineData2,
                                           AppleImage image,
                                           int y)
Given a specific line in the image, process it in double hires color mode. Treat image as 140x192 mode.

From the Apple2 technical note:

                                          Repeated
Binary
Color aux1 main1 aux2 main2 Pattern
Black 00 00 00 00 0000
Magenta 08 11 22 44 0001
Brown 44 08 11 22 0010
Orange 4C 19 33 66 0011
Dark Green 22 44 08 11 0100
Grey1 2A 55 2A 55 0101
Green 66 4C 19 33 0110
Yellow 6E 5D 3B 77 0111
Dark Blue 11 22 44 08 1000
Violet 19 33 66 4C 1001
Grey2 55 2A 55 2A 1010
Pink 5D 3B 77 6E 1011
Medium Blue 33 66 4C 19 1100
Light Blue 3B 77 6E 5D 1101
Aqua 77 6E 5D 3B 1110
White 7F 7F 7F 7F 1111


processSuperHiresLine

protected void processSuperHiresLine(byte[] lineData,
                                     AppleImage image,
                                     int y,
                                     byte scb,
                                     byte[] pallettes)
Given a specific line in the image, process it in super hires color mode.

The color map varies depending upon the SCB value(s) and the pallettes stored with the image. The SCB does not apple to 3200 SHR mode!


buildQuickDraw2Icons

public AppleImage[] buildQuickDraw2Icons(FileEntry fileEntry)
Construct a series of icons based on the QuickDraw II Icon file format. In ProDOS, this is the ICN ($Ca) file format.

See Also:
File Types

buildQuickDraw2IconAndMask

protected AppleImage[] buildQuickDraw2IconAndMask(byte[] filedata,
                                                  int offset)
Each icon is composed of two images - one an icon and the other is the mask.


buildQuickDraw2IconOrMask

protected AppleImage buildQuickDraw2IconOrMask(byte[] filedata,
                                               boolean isColor,
                                               int height,
                                               int width,
                                               int offset)
Build an image of an individual icon or its mask.


copyImage

public void copyImage(AppleImage destImage,
                      AppleImage srcImage,
                      int xStart,
                      int yStart)
Copy an image from the source image to the destination image. This isn't optimal, nor can it be - we're hiding the actual image implementation, after all. Initially written to handle Apple IIGS Toolbox Icon files.


getFileExtensions

public static java.lang.String[] getFileExtensions()
Give file extensions.


getSuggestedFileName

public java.lang.String getSuggestedFileName(FileEntry fileEntry)
Give suggested file name.

Specified by:
getSuggestedFileName in interface FileFilter

setExtension

public void setExtension(java.lang.String extension)
Set the format name.


getExtension

public java.lang.String getExtension()
Get the format name.


setMode

public void setMode(int mode)
Set the color mode.


isHiresBlackAndWhiteMode

public boolean isHiresBlackAndWhiteMode()
Indicates if this is configured for hires black & white mode.


isHiresColorMode

public boolean isHiresColorMode()
Indicates if this is configured for hires color mode.


isDoubleHiresBlackAndWhiteMode

public boolean isDoubleHiresBlackAndWhiteMode()
Indicates if this is configured for double hires black & white mode.


isDoubleHiresColorMode

public boolean isDoubleHiresColorMode()
Indicates if this is configured for double hires color mode.


isSuperHires16Mode

public boolean isSuperHires16Mode()
Indicates if this is configured for super hires 16 color mode.


isSuperHires3200Mode

public boolean isSuperHires3200Mode()
Indicates if this is configured for super hires 3200 color mode.


isHiresMode

public boolean isHiresMode()
Indicates if this is a hires mode.


isDoubleHiresMode

public boolean isDoubleHiresMode()
Indicates if this is a double hires mode.


isSuperHiresMode

public boolean isSuperHiresMode()
Indicates if this is a super-hires mode.


isQuickDraw2Icon

public boolean isQuickDraw2Icon()
Indicates if this is a QuickDraw II Icon.