commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r995859 [18/30] - in /commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan: ./ color/ common/ common/byteSources/ common/mylzw/ formats/bmp/ formats/bmp/pixelparsers/ formats/bmp/writers/ formats/gif/ formats/ico/ formats/jpeg/ f...
Date Fri, 10 Sep 2010 16:33:42 GMT
Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDConstants.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDConstants.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDConstants.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDConstants.java Fri Sep 10 16:33:35 2010
@@ -20,185 +20,185 @@ import org.apache.sanselan.util.Debug;
 
 public class PSDConstants
 {
-	public static final ImageResourceType fImageResourceTypes[];
+    public static final ImageResourceType fImageResourceTypes[];
 
-	public String getDescription(int id)
-	{
-		for (int i = 0; i < fImageResourceTypes.length; i++)
-		{
-			if (fImageResourceTypes[i].ID == id)
-				return fImageResourceTypes[i].Description;
-		}
-		return "Unknown";
-	}
+    public String getDescription(int id)
+    {
+        for (int i = 0; i < fImageResourceTypes.length; i++)
+        {
+            if (fImageResourceTypes[i].ID == id)
+                return fImageResourceTypes[i].Description;
+        }
+        return "Unknown";
+    }
 
-	static
-	{
-		ImageResourceType temp[] = null;
+    static
+    {
+        ImageResourceType temp[] = null;
 
-		try
-		{
-			temp = new ImageResourceType[]{
-					new ImageResourceType(
-							0x03E8,
-							1000,
-							" Contains five 2 byte values: number of channels, rows, columns, depth, and mode."),
-					new ImageResourceType(0x03E9, 1001,
-							"Optional. Macintosh print manager print info record."),
-					new ImageResourceType(0x03EB, 1003,
-							" Contains the indexed color table."),
-					new ImageResourceType(0x03ED, 1005,
-							"ResolutionInfo structure. See Appendix A in Photoshop SDK Guide.pdf."),
-					new ImageResourceType(0x03EE, 1006,
-							"Names of the alpha channels as a series of Pascal strings."),
-					new ImageResourceType(0x03EF, 1007,
-							"DisplayInfo structure. See Appendix A in Photoshop SDK Guide.pdf ."),
-					new ImageResourceType(0x03F0, 1008,
-							"Optional. The caption as a Pascal string."),
-					new ImageResourceType(
-							0x03F1,
-							1009,
-							"Border information. Contains a fixed-number for the border width, and 2 bytes for border units (1=inches, 2=cm, 3=points, 4=picas, 5=columns)."),
-					new ImageResourceType(0x03F2, 1010,
-							"Background color. See the Colors additional file information."),
-					new ImageResourceType(
-							0x03F3,
-							1011,
-							"Print flags. A series of one byte boolean values (see Page Setup dialog): labels, crop marks, color bars, registration marks, negative, flip, interpolate, caption."),
-					new ImageResourceType(0x03F4, 1012,
-							"Grayscale and multichannel halftoning information."),
-					new ImageResourceType(0x03F5, 1013,
-							"Color halftoning information."),
-					new ImageResourceType(0x03F6, 1014,
-							"Duotone halftoning information."),
-					new ImageResourceType(0x03F7, 1015,
-							"Grayscale and multichannel transfer function."),
-					new ImageResourceType(0x03F8, 1016,
-							"Color transfer functions."),
-					new ImageResourceType(0x03F9, 1017,
-							"Duotone transfer functions."),
-					new ImageResourceType(0x03FA, 1018,
-							"Duotone image information."),
-					new ImageResourceType(0x03FB, 1019,
-							"Two bytes for the effective black and white values for the dot range."),
-					new ImageResourceType(0x03FC, 1020, "Obsolete."),
-					new ImageResourceType(0x03FD, 1021, "EPS options."),
-					new ImageResourceType(
-							0x03FE,
-							1022,
-							"Quick Mask information. 2 bytes containing Quick Mask channel ID, 1 byte boolean indicating whether the mask was initially empty."),
-					new ImageResourceType(0x03FF, 1023, "Obsolete."),
-					new ImageResourceType(
-							0x0400,
-							1024,
-							"Layer state information. 2 bytes containing the index of target layer. 0=bottom layer."),
-					new ImageResourceType(0x0401, 1025,
-							"Working path (not saved). See path resource format later in this chapter."),
-					new ImageResourceType(
-							0x0402,
-							1026,
-							"Layers group information. 2 bytes per layer containing a group ID for the dragging groups. Layers in a group have the same group ID."),
-					new ImageResourceType(0x0403, 1027, "Obsolete."),
-					new ImageResourceType(
-							0x0404,
-							1028,
-							"IPTC-NAA record. This contains the File Info... information. See the IIMV4.pdf document."),
-					new ImageResourceType(0x0405, 1029,
-							"Image mode for raw format files."),
-					new ImageResourceType(0x0406, 1030,
-							"JPEG quality. Private."),
-					new ImageResourceType(
-							0x0408,
-							1032,
-							"Grid and guides information. See grid and guides resource format later in this chapter."),
-					new ImageResourceType(0x0409, 1033,
-							"Thumbnail resource. See thumbnail resource format later in this chapter."),
-					new ImageResourceType(
-							0x040A,
-							1034,
-							"Copyright flag. Boolean indicating whether image is copyrighted. Can be set via Property suite or by user in File Info..."),
-					new ImageResourceType(
-							0x040B,
-							1035,
-							"URL. Handle of a text string with uniform resource locator. Can be set via Property suite or by user in File Info..."),
-					new ImageResourceType(0x040C, 1036,
-							"Thumbnail resource. See thumbnail resource format later in this chapter."),
-					new ImageResourceType(
-							0x040D,
-							1037,
-							"Global Angle. 4 bytes that contain an integer between 0..359 which is the global lighting angle for effects layer. If not present assumes 30."),
-					new ImageResourceType(
-							0x040E,
-							1038,
-							"Color samplers resource. See color samplers resource format later in this chapter."),
-					new ImageResourceType(
-							0x040F,
-							1039,
-							"ICC Profile. The raw bytes of an ICC format profile, see the ICC34.pdf and ICC34.h files from the Internation Color Consortium located in the documentation section."),
-					new ImageResourceType(0x0410, 1040,
-							"One byte for Watermark."),
-					new ImageResourceType(
-							0x0411,
-							1041,
-							"ICC Untagged. 1 byte that disables any assumed profile handling when opening the file. 1 = intentionally untagged."),
-					new ImageResourceType(
-							0x0412,
-							1042,
-							"Effects visible. 1 byte global flag to show/hide all the effects layer. Only present when they are hidden."),
-					new ImageResourceType(
-							0x0413,
-							1043,
-							"Spot Halftone. 4 bytes for version, 4 bytes for length, and the variable length data."),
-					new ImageResourceType(
-							0x0414,
-							1044,
-							"Document specific IDs, layer IDs will be generated starting at this base value or a greater value if we find existing IDs to already exceed it. It’s purpose is to avoid the case where we add layers, flatten, save, open, and then add more layers that end up with the same IDs as the first set. 4 bytes."),
-					new ImageResourceType(0x0415, 1045,
-							"Unicode Alpha Names. 4 bytes for length and the string as a unicode string."),
-					new ImageResourceType(
-							0x0416,
-							1046,
-							"Indexed Color Table Count. 2 bytes for the number of colors in table that are actually defined"),
-					new ImageResourceType(0x0417, 1047,
-							"Tansparent Index. 2 bytes for the index of transparent color, if any."),
-					new ImageResourceType(0x0419, 1049,
-							"Global Altitude. 4 byte entry for altitude"),
-					new ImageResourceType(0x041A, 1050,
-							"Slices. See description later in this chapter"),
-					new ImageResourceType(0x041B, 1051,
-							"Workflow URL. Unicode string, 4 bytes of length followed by unicode string."),
-					new ImageResourceType(
-							0x041C,
-							1052,
-							"Jump To XPEP. 2 bytes major version, 2 bytes minor version, 4 bytes count. Following is repeated for count: 4 bytes block size, 4 bytes key, if key = 'jtDd' then next is a Boolean for the dirty flag otherwise it’s a 4 byte entry for the mod date."),
-					new ImageResourceType(
-							0x041D,
-							1053,
-							"Alpha Identifiers. 4 bytes of length, followed by 4 bytes each for every alpha identifier."),
-					new ImageResourceType(
-							0x041E,
-							1054,
-							"URL List. 4 byte count of URLs, followed by 4 byte long, 4 byte ID, and unicode string for each count."),
-					new ImageResourceType(
-							0x0421,
-							1057,
-							"Version Info. 4 byte version, 1 byte HasRealMergedData, unicode string of writer name, unicode string of reader name, 4 bytes of file version."),
-					new ImageResourceType(
-							0x07D0 - 0x0BB6,
-							2000 - 2998,
-							"Path Information (saved paths). See path resource format later in this chapter."),
-					new ImageResourceType(0x0BB7, 2999,
-							"Name of clipping path. See path resource format later in this chapter."),
-					new ImageResourceType(
-							0x2710,
-							10000,
-							"Print flags information. 2 bytes version (=1), 1 byte center crop marks, 1 byte (=0), 4 bytes bleed width value, 2 bytes bleed width scale."),
-			};
-		}
-		catch (Exception e)
-		{
-			Debug.debug(PSDConstants.class, e);
-		}
-		fImageResourceTypes = temp;
-	}
+        try
+        {
+            temp = new ImageResourceType[]{
+                    new ImageResourceType(
+                            0x03E8,
+                            1000,
+                            " Contains five 2 byte values: number of channels, rows, columns, depth, and mode."),
+                    new ImageResourceType(0x03E9, 1001,
+                            "Optional. Macintosh print manager print info record."),
+                    new ImageResourceType(0x03EB, 1003,
+                            " Contains the indexed color table."),
+                    new ImageResourceType(0x03ED, 1005,
+                            "ResolutionInfo structure. See Appendix A in Photoshop SDK Guide.pdf."),
+                    new ImageResourceType(0x03EE, 1006,
+                            "Names of the alpha channels as a series of Pascal strings."),
+                    new ImageResourceType(0x03EF, 1007,
+                            "DisplayInfo structure. See Appendix A in Photoshop SDK Guide.pdf ."),
+                    new ImageResourceType(0x03F0, 1008,
+                            "Optional. The caption as a Pascal string."),
+                    new ImageResourceType(
+                            0x03F1,
+                            1009,
+                            "Border information. Contains a fixed-number for the border width, and 2 bytes for border units (1=inches, 2=cm, 3=points, 4=picas, 5=columns)."),
+                    new ImageResourceType(0x03F2, 1010,
+                            "Background color. See the Colors additional file information."),
+                    new ImageResourceType(
+                            0x03F3,
+                            1011,
+                            "Print flags. A series of one byte boolean values (see Page Setup dialog): labels, crop marks, color bars, registration marks, negative, flip, interpolate, caption."),
+                    new ImageResourceType(0x03F4, 1012,
+                            "Grayscale and multichannel halftoning information."),
+                    new ImageResourceType(0x03F5, 1013,
+                            "Color halftoning information."),
+                    new ImageResourceType(0x03F6, 1014,
+                            "Duotone halftoning information."),
+                    new ImageResourceType(0x03F7, 1015,
+                            "Grayscale and multichannel transfer function."),
+                    new ImageResourceType(0x03F8, 1016,
+                            "Color transfer functions."),
+                    new ImageResourceType(0x03F9, 1017,
+                            "Duotone transfer functions."),
+                    new ImageResourceType(0x03FA, 1018,
+                            "Duotone image information."),
+                    new ImageResourceType(0x03FB, 1019,
+                            "Two bytes for the effective black and white values for the dot range."),
+                    new ImageResourceType(0x03FC, 1020, "Obsolete."),
+                    new ImageResourceType(0x03FD, 1021, "EPS options."),
+                    new ImageResourceType(
+                            0x03FE,
+                            1022,
+                            "Quick Mask information. 2 bytes containing Quick Mask channel ID, 1 byte boolean indicating whether the mask was initially empty."),
+                    new ImageResourceType(0x03FF, 1023, "Obsolete."),
+                    new ImageResourceType(
+                            0x0400,
+                            1024,
+                            "Layer state information. 2 bytes containing the index of target layer. 0=bottom layer."),
+                    new ImageResourceType(0x0401, 1025,
+                            "Working path (not saved). See path resource format later in this chapter."),
+                    new ImageResourceType(
+                            0x0402,
+                            1026,
+                            "Layers group information. 2 bytes per layer containing a group ID for the dragging groups. Layers in a group have the same group ID."),
+                    new ImageResourceType(0x0403, 1027, "Obsolete."),
+                    new ImageResourceType(
+                            0x0404,
+                            1028,
+                            "IPTC-NAA record. This contains the File Info... information. See the IIMV4.pdf document."),
+                    new ImageResourceType(0x0405, 1029,
+                            "Image mode for raw format files."),
+                    new ImageResourceType(0x0406, 1030,
+                            "JPEG quality. Private."),
+                    new ImageResourceType(
+                            0x0408,
+                            1032,
+                            "Grid and guides information. See grid and guides resource format later in this chapter."),
+                    new ImageResourceType(0x0409, 1033,
+                            "Thumbnail resource. See thumbnail resource format later in this chapter."),
+                    new ImageResourceType(
+                            0x040A,
+                            1034,
+                            "Copyright flag. Boolean indicating whether image is copyrighted. Can be set via Property suite or by user in File Info..."),
+                    new ImageResourceType(
+                            0x040B,
+                            1035,
+                            "URL. Handle of a text string with uniform resource locator. Can be set via Property suite or by user in File Info..."),
+                    new ImageResourceType(0x040C, 1036,
+                            "Thumbnail resource. See thumbnail resource format later in this chapter."),
+                    new ImageResourceType(
+                            0x040D,
+                            1037,
+                            "Global Angle. 4 bytes that contain an integer between 0..359 which is the global lighting angle for effects layer. If not present assumes 30."),
+                    new ImageResourceType(
+                            0x040E,
+                            1038,
+                            "Color samplers resource. See color samplers resource format later in this chapter."),
+                    new ImageResourceType(
+                            0x040F,
+                            1039,
+                            "ICC Profile. The raw bytes of an ICC format profile, see the ICC34.pdf and ICC34.h files from the Internation Color Consortium located in the documentation section."),
+                    new ImageResourceType(0x0410, 1040,
+                            "One byte for Watermark."),
+                    new ImageResourceType(
+                            0x0411,
+                            1041,
+                            "ICC Untagged. 1 byte that disables any assumed profile handling when opening the file. 1 = intentionally untagged."),
+                    new ImageResourceType(
+                            0x0412,
+                            1042,
+                            "Effects visible. 1 byte global flag to show/hide all the effects layer. Only present when they are hidden."),
+                    new ImageResourceType(
+                            0x0413,
+                            1043,
+                            "Spot Halftone. 4 bytes for version, 4 bytes for length, and the variable length data."),
+                    new ImageResourceType(
+                            0x0414,
+                            1044,
+                            "Document specific IDs, layer IDs will be generated starting at this base value or a greater value if we find existing IDs to already exceed it. It’s purpose is to avoid the case where we add layers, flatten, save, open, and then add more layers that end up with the same IDs as the first set. 4 bytes."),
+                    new ImageResourceType(0x0415, 1045,
+                            "Unicode Alpha Names. 4 bytes for length and the string as a unicode string."),
+                    new ImageResourceType(
+                            0x0416,
+                            1046,
+                            "Indexed Color Table Count. 2 bytes for the number of colors in table that are actually defined"),
+                    new ImageResourceType(0x0417, 1047,
+                            "Tansparent Index. 2 bytes for the index of transparent color, if any."),
+                    new ImageResourceType(0x0419, 1049,
+                            "Global Altitude. 4 byte entry for altitude"),
+                    new ImageResourceType(0x041A, 1050,
+                            "Slices. See description later in this chapter"),
+                    new ImageResourceType(0x041B, 1051,
+                            "Workflow URL. Unicode string, 4 bytes of length followed by unicode string."),
+                    new ImageResourceType(
+                            0x041C,
+                            1052,
+                            "Jump To XPEP. 2 bytes major version, 2 bytes minor version, 4 bytes count. Following is repeated for count: 4 bytes block size, 4 bytes key, if key = 'jtDd' then next is a Boolean for the dirty flag otherwise it’s a 4 byte entry for the mod date."),
+                    new ImageResourceType(
+                            0x041D,
+                            1053,
+                            "Alpha Identifiers. 4 bytes of length, followed by 4 bytes each for every alpha identifier."),
+                    new ImageResourceType(
+                            0x041E,
+                            1054,
+                            "URL List. 4 byte count of URLs, followed by 4 byte long, 4 byte ID, and unicode string for each count."),
+                    new ImageResourceType(
+                            0x0421,
+                            1057,
+                            "Version Info. 4 byte version, 1 byte HasRealMergedData, unicode string of writer name, unicode string of reader name, 4 bytes of file version."),
+                    new ImageResourceType(
+                            0x07D0 - 0x0BB6,
+                            2000 - 2998,
+                            "Path Information (saved paths). See path resource format later in this chapter."),
+                    new ImageResourceType(0x0BB7, 2999,
+                            "Name of clipping path. See path resource format later in this chapter."),
+                    new ImageResourceType(
+                            0x2710,
+                            10000,
+                            "Print flags information. 2 bytes version (=1), 1 byte center crop marks, 1 byte (=0), 4 bytes bleed width value, 2 bytes bleed width scale."),
+            };
+        }
+        catch (Exception e)
+        {
+            Debug.debug(PSDConstants.class, e);
+        }
+        fImageResourceTypes = temp;
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDHeaderInfo.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDHeaderInfo.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDHeaderInfo.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PSDHeaderInfo.java Fri Sep 10 16:33:35 2010
@@ -20,51 +20,51 @@ import java.io.PrintWriter;
 
 public class PSDHeaderInfo
 {
-	public final int Version;
-	public final byte Reserved[];
-	public final int Channels;
-	public final int Rows;
-	public final int Columns;
-	public final int Depth;
-	public final int Mode;
-
-	public PSDHeaderInfo(int Version, byte Reserved[], int Channels, int Rows,
-			int Columns, int Depth, int Mode)
-	{
-		this.Version = Version;
-		this.Reserved = Reserved;
-		this.Channels = Channels;
-		this.Rows = Rows;
-		this.Columns = Columns;
-		this.Depth = Depth;
-		this.Mode = Mode;
-
-	}
-
-	public void dump()
-	{
-		PrintWriter pw = new PrintWriter(System.out);
-		dump(pw);
-		pw.flush();
-	}
-
-	public void dump(PrintWriter pw)
-	{
-		pw.println("");
-		pw.println("Header");
-		pw.println("Version: " + Version + " (" + Integer.toHexString(Version)
-				+ ")");
-		pw.println("Channels: " + Channels + " ("
-				+ Integer.toHexString(Channels) + ")");
-		pw.println("Rows: " + Rows + " (" + Integer.toHexString(Rows) + ")");
-		pw.println("Columns: " + Columns + " (" + Integer.toHexString(Columns)
-				+ ")");
-		pw.println("Depth: " + Depth + " (" + Integer.toHexString(Depth) + ")");
-		pw.println("Mode: " + Mode + " (" + Integer.toHexString(Mode) + ")");
-		pw.println("Reserved: " + Reserved.length);
-		pw.println("");
-		pw.flush();
+    public final int Version;
+    public final byte Reserved[];
+    public final int Channels;
+    public final int Rows;
+    public final int Columns;
+    public final int Depth;
+    public final int Mode;
+
+    public PSDHeaderInfo(int Version, byte Reserved[], int Channels, int Rows,
+            int Columns, int Depth, int Mode)
+    {
+        this.Version = Version;
+        this.Reserved = Reserved;
+        this.Channels = Channels;
+        this.Rows = Rows;
+        this.Columns = Columns;
+        this.Depth = Depth;
+        this.Mode = Mode;
+
+    }
+
+    public void dump()
+    {
+        PrintWriter pw = new PrintWriter(System.out);
+        dump(pw);
+        pw.flush();
+    }
+
+    public void dump(PrintWriter pw)
+    {
+        pw.println("");
+        pw.println("Header");
+        pw.println("Version: " + Version + " (" + Integer.toHexString(Version)
+                + ")");
+        pw.println("Channels: " + Channels + " ("
+                + Integer.toHexString(Channels) + ")");
+        pw.println("Rows: " + Rows + " (" + Integer.toHexString(Rows) + ")");
+        pw.println("Columns: " + Columns + " (" + Integer.toHexString(Columns)
+                + ")");
+        pw.println("Depth: " + Depth + " (" + Integer.toHexString(Depth) + ")");
+        pw.println("Mode: " + Mode + " (" + Integer.toHexString(Mode) + ")");
+        pw.println("Reserved: " + Reserved.length);
+        pw.println("");
+        pw.flush();
 
-	}
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PsdImageParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PsdImageParser.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PsdImageParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/PsdImageParser.java Fri Sep 10 16:33:35 2010
@@ -49,802 +49,802 @@ import org.apache.sanselan.util.Debug;
 public class PsdImageParser extends ImageParser
 {
 
-	public PsdImageParser()
-	{
-		super.setByteOrder(BYTE_ORDER_MSB);
-		// setDebug(true);
-	}
-
-	public String getName()
-	{
-		return "PSD-Custom";
-	}
-
-	public String getDefaultExtension()
-	{
-		return DEFAULT_EXTENSION;
-	}
-
-	private static final String DEFAULT_EXTENSION = ".psd";
-
-	private static final String ACCEPTED_EXTENSIONS[] = { DEFAULT_EXTENSION, };
-
-	protected String[] getAcceptedExtensions()
-	{
-		return ACCEPTED_EXTENSIONS;
-	}
-
-	protected ImageFormat[] getAcceptedTypes()
-	{
-		return new ImageFormat[] { ImageFormat.IMAGE_FORMAT_PSD, //
-		};
-	}
-
-	private PSDHeaderInfo readHeader(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
-		InputStream is = null;
-
-		try
-		{
-			is = byteSource.getInputStream();
-
-			return readHeader(is);
-		} finally
-		{
-			try
-			{
-			    if (is != null) {
-			        is.close();
-			    }
-			} catch (Exception e)
-			{
-				Debug.debug(e);
-			}
-
-		}
-	}
-
-	private PSDHeaderInfo readHeader(InputStream is) throws ImageReadException,
-			IOException
-	{
-		readAndVerifyBytes(is, new byte[] { 56, 66, 80, 83 },
-				"Not a Valid PSD File");
-
-		int Version = read2Bytes("Version", is, "Not a Valid PSD File");
-
-		byte Reserved[] = readByteArray("Reserved", 6, is,
-				"Not a Valid PSD File");
-
-		int Channels = read2Bytes("Channels", is, "Not a Valid PSD File");
-		int Rows = read4Bytes("Rows", is, "Not a Valid PSD File");
-		int Columns = read4Bytes("Columns", is, "Not a Valid PSD File");
-		int Depth = read2Bytes("Depth", is, "Not a Valid PSD File");
-		int Mode = read2Bytes("Mode", is, "Not a Valid PSD File");
-
-		PSDHeaderInfo result = new PSDHeaderInfo(Version, Reserved, Channels,
-				Rows, Columns, Depth, Mode);
-
-		return result;
-	}
-
-	private ImageContents readImageContents(InputStream is)
-			throws ImageReadException, IOException
-	{
-		PSDHeaderInfo header = readHeader(is);
-
-		int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
-				"Not a Valid PSD File");
-		skipBytes(is, ColorModeDataLength);
-		// is.skip(ColorModeDataLength);
-		// byte ColorModeData[] = readByteArray("ColorModeData",
-		// ColorModeDataLength, is, "Not a Valid PSD File");
-
-		int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
-				"Not a Valid PSD File");
-		skipBytes(is, ImageResourcesLength);
-		// long skipped = is.skip(ImageResourcesLength);
-		// byte ImageResources[] = readByteArray("ImageResources",
-		// ImageResourcesLength, is, "Not a Valid PSD File");
-
-		int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength", is,
-				"Not a Valid PSD File");
-		skipBytes(is, LayerAndMaskDataLength);
-		// is.skip(LayerAndMaskDataLength);
-		// byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
-		// LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-		int Compression = read2Bytes("Compression", is, "Not a Valid PSD File");
-
-		// skip_bytes(is, LayerAndMaskDataLength);
-		// byte ImageData[] = readByteArray("ImageData", LayerAndMaskDataLength,
-		// is, "Not a Valid PSD File");
-
-		// System.out.println("Compression: " + Compression);
-
-		ImageContents result = new ImageContents(header, ColorModeDataLength,
-		// ColorModeData,
-				ImageResourcesLength,
-				// ImageResources,
-				LayerAndMaskDataLength,
-				// LayerAndMaskData,
-				Compression);
-
-		return result;
-	}
-
-	private ArrayList readImageResourceBlocks(byte bytes[],
-			int imageResourceIDs[], int maxBlocksToRead)
-			throws ImageReadException, IOException
-	{
-		return readImageResourceBlocks(new ByteArrayInputStream(bytes),
-				imageResourceIDs, maxBlocksToRead, bytes.length);
-	}
-
-	private boolean keepImageResourceBlock(int ID, int imageResourceIDs[])
-	{
-		if (imageResourceIDs == null)
-			return true;
-
-		for (int i = 0; i < imageResourceIDs.length; i++)
-			if (ID == imageResourceIDs[i])
-				return true;
-
-		return false;
-	}
-
-	private ArrayList readImageResourceBlocks(InputStream is,
-			int imageResourceIDs[], int maxBlocksToRead, int available)
-			throws ImageReadException, IOException
-	{
-		ArrayList result = new ArrayList();
-
-		while (available > 0)
-		{
-			readAndVerifyBytes(is, new byte[] { 56, 66, 73, 77 },
-					"Not a Valid PSD File");
-			available -= 4;
-
-			int id = read2Bytes("ID", is, "Not a Valid PSD File");
-			available -= 2;
-
-			int nameLength = readByte("NameLength", is, "Not a Valid PSD File");
-
-			available -= 1;
-			byte nameBytes[] = readByteArray("NameData", nameLength, is,
-					"Not a Valid PSD File");
-			available -= nameLength;
-			if (((nameLength + 1) % 2) != 0)
-			{
-				int NameDiscard = readByte("NameDiscard", is,
-						"Not a Valid PSD File");
-				available -= 1;
-			}
-			// String Name = readPString("Name", 6, is, "Not a Valid PSD File");
-			int DataSize = read4Bytes("Size", is, "Not a Valid PSD File");
-			available -= 4;
-			// int ActualDataSize = ((DataSize % 2) == 0)
-			// ? DataSize
-			// : DataSize + 1; // pad to make even
-
-			byte Data[] = readByteArray("Data", DataSize, is,
-					"Not a Valid PSD File");
-			available -= DataSize;
-
-			if ((DataSize % 2) != 0)
-			{
-				int DataDiscard = readByte("DataDiscard", is,
-						"Not a Valid PSD File");
-				available -= 1;
-			}
-
-			if (keepImageResourceBlock(id, imageResourceIDs))
-			{
-				result.add(new ImageResourceBlock(id, nameBytes, Data));
-
-				if ((maxBlocksToRead >= 0)
-						&& (result.size() >= maxBlocksToRead))
-					return result;
-			}
-			// debugNumber("ID", ID, 2);
-
-		}
-
-		return result;
-	}
-
-	private ArrayList readImageResourceBlocks(ByteSource byteSource,
-			int imageResourceIDs[], int maxBlocksToRead)
-			throws ImageReadException, IOException
-	{
-		InputStream is = null;
-
-		try
-		{
-			is = byteSource.getInputStream();
-
-			ImageContents imageContents = readImageContents(is);
-
-			is.close();
-
-			is = this.getInputStream(byteSource, PSD_SECTION_IMAGE_RESOURCES);
-			byte ImageResources[] = readByteArray("ImageResources",
-					imageContents.ImageResourcesLength, is,
-					"Not a Valid PSD File");
-
-			return readImageResourceBlocks(ImageResources, imageResourceIDs,
-					maxBlocksToRead);
-		} finally
-		{
-			try
-			{
-			    if (is != null) {
-			        is.close();
-			    }
-			} catch (Exception e)
-			{
-				Debug.debug(e);
-			}
-
-		}
-	}
-
-	private static final int PSD_SECTION_HEADER = 0;
-	private static final int PSD_SECTION_COLOR_MODE = 1;
-	private static final int PSD_SECTION_IMAGE_RESOURCES = 2;
-	private static final int PSD_SECTION_LAYER_AND_MASK_DATA = 3;
-	private static final int PSD_SECTION_IMAGE_DATA = 4;
-
-	private static final int PSD_HEADER_LENGTH = 26;
-
-	private InputStream getInputStream(ByteSource byteSource, int section)
-			throws ImageReadException, IOException
-	{
-		InputStream is = byteSource.getInputStream();
-
-		if (section == PSD_SECTION_HEADER)
-			return is;
-
-		skipBytes(is, PSD_HEADER_LENGTH);
-		// is.skip(kHeaderLength);
-
-		int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
-				"Not a Valid PSD File");
-
-		if (section == PSD_SECTION_COLOR_MODE)
-			return is;
-
-		skipBytes(is, ColorModeDataLength);
-		// byte ColorModeData[] = readByteArray("ColorModeData",
-		// ColorModeDataLength, is, "Not a Valid PSD File");
-
-		int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
-				"Not a Valid PSD File");
-
-		if (section == PSD_SECTION_IMAGE_RESOURCES)
-			return is;
-
-		skipBytes(is, ImageResourcesLength);
-		// byte ImageResources[] = readByteArray("ImageResources",
-		// ImageResourcesLength, is, "Not a Valid PSD File");
-
-		int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength", is,
-				"Not a Valid PSD File");
-
-		if (section == PSD_SECTION_LAYER_AND_MASK_DATA)
-			return is;
-
-		skipBytes(is, LayerAndMaskDataLength);
-		// byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
-		// LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-		int Compression = read2Bytes("Compression", is, "Not a Valid PSD File");
-
-		// byte ImageData[] = readByteArray("ImageData",
-		// LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-		if (section == PSD_SECTION_IMAGE_DATA)
-			return is;
-
-		throw new ImageReadException("getInputStream: Unknown Section: "
-				+ section);
-	}
-
-	private byte[] getData(ByteSource byteSource, int section)
-			throws ImageReadException, IOException
-	{
-		InputStream is = null;
-
-		try
-		{
-			is = byteSource.getInputStream();
-
-			// PSDHeaderInfo header = readHeader(is);
-			if (section == PSD_SECTION_HEADER)
-				return readByteArray("Header", PSD_HEADER_LENGTH, is,
-						"Not a Valid PSD File");
-			skipBytes(is, PSD_HEADER_LENGTH);
-
-			int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
-					"Not a Valid PSD File");
-
-			if (section == PSD_SECTION_COLOR_MODE)
-				return readByteArray("ColorModeData", ColorModeDataLength, is,
-						"Not a Valid PSD File");
-
-			skipBytes(is, ColorModeDataLength);
-			// byte ColorModeData[] = readByteArray("ColorModeData",
-			// ColorModeDataLength, is, "Not a Valid PSD File");
-
-			int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
-					"Not a Valid PSD File");
-
-			if (section == PSD_SECTION_IMAGE_RESOURCES)
-				return readByteArray("ImageResources", ImageResourcesLength,
-						is, "Not a Valid PSD File");
-
-			skipBytes(is, ImageResourcesLength);
-			// byte ImageResources[] = readByteArray("ImageResources",
-			// ImageResourcesLength, is, "Not a Valid PSD File");
-
-			int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength",
-					is, "Not a Valid PSD File");
-
-			if (section == PSD_SECTION_LAYER_AND_MASK_DATA)
-				return readByteArray("LayerAndMaskData",
-						LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-			skipBytes(is, LayerAndMaskDataLength);
-			// byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
-			// LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-			int Compression = read2Bytes("Compression", is,
-					"Not a Valid PSD File");
-
-			// byte ImageData[] = readByteArray("ImageData",
-			// LayerAndMaskDataLength, is, "Not a Valid PSD File");
-
-			// if (section == kPSD_SECTION_IMAGE_DATA)
-			// return readByteArray("LayerAndMaskData", LayerAndMaskDataLength,
-			// is,
-			// "Not a Valid PSD File");
-
-		} finally
-		{
-			try
-			{
-			    if (is != null) {
-			        is.close();
-			    }
-			} catch (Exception e)
-			{
-				Debug.debug(e);
-			}
-
-		}
-		throw new ImageReadException("getInputStream: Unknown Section: "
-				+ section);
-	}
-
-	private ImageContents readImageContents(ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
-		InputStream is = null;
-
-		try
-		{
-			is = byteSource.getInputStream();
-
-			ImageContents imageContents = readImageContents(is);
-			return imageContents;
-		} finally
-		{
-			try
-			{
-			    if (is != null) {
-			        is.close();
-			    }
-			} catch (Exception e)
-			{
-				Debug.debug(e);
-			}
-
-		}
-
-	}
-
-	public final static int IMAGE_RESOURCE_ID_ICC_PROFILE = 0x040F;
-
-	public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-		ArrayList blocks = readImageResourceBlocks(byteSource,
-				new int[] { IMAGE_RESOURCE_ID_ICC_PROFILE, }, 1);
-
-		if ((blocks == null) || (blocks.size() < 1))
-			return null;
-
-		ImageResourceBlock irb = (ImageResourceBlock) blocks.get(0);
-		byte bytes[] = irb.data;
-		if ((bytes == null) || (bytes.length < 1))
-			return null;
-		return bytes;
-	}
-
-	public Dimension getImageSize(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-		PSDHeaderInfo bhi = readHeader(byteSource);
-		if (bhi == null)
-			throw new ImageReadException("PSD: couldn't read header");
-
-		return new Dimension(bhi.Columns, bhi.Rows);
-
-	}
-
-	public byte[] embedICCProfile(byte image[], byte profile[])
-	{
-		return null;
-	}
-
-	public boolean embedICCProfile(File src, File dst, byte profile[])
-	{
-		return false;
-	}
-
-	public IImageMetadata getMetadata(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-		return null;
-	}
-
-	private int getChannelsPerMode(int mode)
-	{
-		switch (mode)
-		{
-		case 0: // Bitmap
-			return 1;
-		case 1: // Grayscale
-			return 1;
-		case 2: // Indexed
-			return -1;
-		case 3: // RGB
-			return 3;
-		case 4: // CMYK
-			return 4;
-		case 7: // Multichannel
-			return -1;
-		case 8: // Duotone
-			return -1;
-		case 9: // Lab
-			return 4;
-		default:
-			return -1;
-
-		}
-	}
-
-	public ImageInfo getImageInfo(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-		ImageContents imageContents = readImageContents(byteSource);
-		// ImageContents imageContents = readImage(byteSource, false);
-
-		if (imageContents == null)
-			throw new ImageReadException("PSD: Couldn't read blocks");
-
-		PSDHeaderInfo header = imageContents.header;
-		if (header == null)
-			throw new ImageReadException("PSD: Couldn't read Header");
-
-		int Width = header.Columns;
-		int Height = header.Rows;
-
-		ArrayList Comments = new ArrayList();
-		// TODO: comments...
-
-		int BitsPerPixel = header.Depth * getChannelsPerMode(header.Mode);
-		// System.out.println("header.Depth: " + header.Depth);
-		// System.out.println("header.Mode: " + header.Mode);
-		// System.out.println("getChannelsPerMode(header.Mode): " +
-		// getChannelsPerMode(header.Mode));
-		if (BitsPerPixel < 0)
-			BitsPerPixel = 0;
-		ImageFormat Format = ImageFormat.IMAGE_FORMAT_PSD;
-		String FormatName = "Photoshop";
-		String MimeType = "image/x-photoshop";
-		// we ought to count images, but don't yet.
-		int NumberOfImages = -1;
-		// not accurate ... only reflects first
-		boolean isProgressive = false;
-
-		int PhysicalWidthDpi = 72;
-		float PhysicalWidthInch = (float) ((double) Width / (double) PhysicalWidthDpi);
-		int PhysicalHeightDpi = 72;
-		float PhysicalHeightInch = (float) ((double) Height / (double) PhysicalHeightDpi);
-
-		String FormatDetails = "Psd";
-
-		boolean isTransparent = false; // TODO: inaccurate.
-		boolean usesPalette = header.Mode == COLOR_MODE_INDEXED;
-		int ColorType = ImageInfo.COLOR_TYPE_UNKNOWN;
-
-		String compressionAlgorithm;
-		switch (imageContents.Compression)
-		{
-		case 0:
-			compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_NONE;
-			break;
-		case 1:
-			compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_PSD;
-			break;
-		default:
-			compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_UNKNOWN;
-		}
-
-		ImageInfo result = new ImageInfo(FormatDetails, BitsPerPixel, Comments,
-				Format, FormatName, Height, MimeType, NumberOfImages,
-				PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
-				PhysicalWidthInch, Width, isProgressive, isTransparent,
-				usesPalette, ColorType, compressionAlgorithm);
-
-		return result;
-	}
-
-	// TODO not used
-	private ImageResourceBlock findImageResourceBlock(ArrayList blocks, int ID)
-	{
-		for (int i = 0; i < blocks.size(); i++)
-		{
-			ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
-
-			if (block.id == ID)
-				return block;
-		}
-		return null;
-	}
-
-	public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
-			throws ImageReadException, IOException
-	{
-		pw.println("gif.dumpImageFile");
-
-		{
-			ImageInfo fImageData = getImageInfo(byteSource);
-			if (fImageData == null)
-				return false;
-
-			fImageData.toString(pw, "");
-		}
-		{
-			ImageContents imageContents = readImageContents(byteSource);
-
-			imageContents.dump(pw);
-			imageContents.header.dump(pw);
-
-			ArrayList blocks = readImageResourceBlocks(byteSource,
-			// fImageContents.ImageResources,
-					null, -1);
-
-			pw.println("blocks.size(): " + blocks.size());
-
-			// System.out.println("gif.blocks: " + blocks.blocks.size());
-			for (int i = 0; i < blocks.size(); i++)
-			{
-				ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
-				pw.println("\t" + i + " (" + Integer.toHexString(block.id)
-						+ ", " + "'"
-						+ new String(block.nameData)
-						+ "' ("
-						+ block.nameData.length
-						+ "), "
-						// + block.getClass().getName()
-						// + ", "
-						+ " data: " + block.data.length + " type: '"
-						+ new PSDConstants().getDescription(block.id) + "' "
-						+ ")");
-
-			}
-
-		}
-
-		pw.println("");
-
-		return true;
-	}
-
-	private static final int COLOR_MODE_INDEXED = 2;
-
-	public BufferedImage getBufferedImage(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-		ImageContents imageContents = readImageContents(byteSource);
-		// ImageContents imageContents = readImage(byteSource, false);
-
-		if (imageContents == null)
-			throw new ImageReadException("PSD: Couldn't read blocks");
-
-		PSDHeaderInfo header = imageContents.header;
-		if (header == null)
-			throw new ImageReadException("PSD: Couldn't read Header");
-
-		// ImageDescriptor id = (ImageDescriptor)
-		// findBlock(fImageContents.blocks,
-		// kImageSeperator);
-		// if (id == null)
-		// throw new ImageReadException("PSD: Couldn't read Image Descriptor");
-		// GraphicControlExtension gce = (GraphicControlExtension) findBlock(
-		// fImageContents.blocks, kGraphicControlExtension);
-
-		ArrayList blocks = readImageResourceBlocks(byteSource,
-		// fImageContents.ImageResources,
-				null, -1);
-
-		int width = header.Columns;
-		int height = header.Rows;
-		// int height = header.Columns;
-
-		// int transfer_type;
-
-		// transfer_type = DataBuffer.TYPE_BYTE;
-
-		boolean hasAlpha = false;
-		BufferedImage result = getBufferedImageFactory(params)
-				.getColorBufferedImage(width, height, hasAlpha);
-
-		DataParser dataParser;
-		switch (imageContents.header.Mode)
-		{
-		case 0: // bitmap
-			dataParser = new DataParserBitmap();
-			break;
-		case 1:
-		case 8: // Duotone=8;
-			dataParser = new DataParserGrayscale();
-			break;
-		case 3:
-			dataParser = new DataParserRGB();
-			break;
-		case 4:
-			dataParser = new DataParserCMYK();
-			break;
-		case 9:
-			dataParser = new DataParserLab();
-			break;
-		case COLOR_MODE_INDEXED:
-			// case 2 : // Indexed=2;
-		{
-
-			byte ColorModeData[] = getData(byteSource, PSD_SECTION_COLOR_MODE);
-
-			// ImageResourceBlock block = findImageResourceBlock(blocks,
-			// 0x03EB);
-			// if (block == null)
-			// throw new ImageReadException(
-			// "Missing: Indexed Color Image Resource Block");
-
-			dataParser = new DataParserIndexed(ColorModeData);
-			break;
-		}
-		case 7: // Multichannel=7;
-			// fDataParser = new DataParserStub();
-			// break;
-
-			// case 1 :
-			// fDataReader = new CompressedDataReader();
-			// break;
-		default:
-			throw new ImageReadException("Unknown Mode: "
-					+ imageContents.header.Mode);
-		}
-		DataReader fDataReader;
-		switch (imageContents.Compression)
-		{
-		case 0:
-			fDataReader = new UncompressedDataReader(dataParser);
-			break;
-		case 1:
-			fDataReader = new CompressedDataReader(dataParser);
-			break;
-		default:
-			throw new ImageReadException("Unknown Compression: "
-					+ imageContents.Compression);
-		}
-		{
-			InputStream is = null;
-
-			try
-			{
-				is = getInputStream(byteSource, PSD_SECTION_IMAGE_DATA);
-				fDataReader.readData(is, result, imageContents, this);
-
-				fDataReader.dump();
-				// is.
-				// ImageContents imageContents = readImageContents(is);
-				// return imageContents;
-			} finally
-			{
-				try
-				{
-					if (is != null)
-						is.close();
-				} catch (Exception e)
-				{
-					Debug.debug(e);
-				}
-
-			}
-
-		}
-
-		return result;
-
-	}
-
-	public final static int IMAGE_RESOURCE_ID_XMP = 0x0424;
-
-	public final static String BLOCK_NAME_XMP = "XMP";
-
-	/**
-	 * Extracts embedded XML metadata as XML string.
-	 * <p>
-	 * 
-	 * @param byteSource
-	 *            File containing image data.
-	 * @param params
-	 *            Map of optional parameters, defined in SanselanConstants.
-	 * @return Xmp Xml as String, if present. Otherwise, returns null.
-	 */
-	public String getXmpXml(ByteSource byteSource, Map params)
-			throws ImageReadException, IOException
-	{
-
-		ImageContents imageContents = readImageContents(byteSource);
-
-		if (imageContents == null)
-			throw new ImageReadException("PSD: Couldn't read blocks");
-
-		PSDHeaderInfo header = imageContents.header;
-		if (header == null)
-			throw new ImageReadException("PSD: Couldn't read Header");
-
-		ArrayList blocks = readImageResourceBlocks(byteSource,
-				new int[] { IMAGE_RESOURCE_ID_XMP, }, -1);
-
-		if ((blocks == null) || (blocks.size() < 1))
-			return null;
-
-		List xmpBlocks = new ArrayList();
-		if (false)
-		{
-			// TODO: for PSD 7 and later, verify "XMP" name.
-			for (int i = 0; i < blocks.size(); i++)
-			{
-				ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
-				if (!block.getName().equals(BLOCK_NAME_XMP))
-					continue;
-				xmpBlocks.add(block);
-			}
-		} else
-			xmpBlocks.addAll(blocks);
-
-		if (xmpBlocks.size() < 1)
-			return null;
-		if (xmpBlocks.size() > 1)
-			throw new ImageReadException(
-					"PSD contains more than one XMP block.");
-
-		ImageResourceBlock block = (ImageResourceBlock) xmpBlocks.get(0);
-
-		try
-		{
-			// segment data is UTF-8 encoded xml.
-			String xml = new String(block.data, 0, block.data.length, "utf-8");
-			return xml;
-		} catch (UnsupportedEncodingException e)
-		{
-			throw new ImageReadException("Invalid JPEG XMP Segment.");
-		}
-	}
+    public PsdImageParser()
+    {
+        super.setByteOrder(BYTE_ORDER_MSB);
+        // setDebug(true);
+    }
+
+    public String getName()
+    {
+        return "PSD-Custom";
+    }
+
+    public String getDefaultExtension()
+    {
+        return DEFAULT_EXTENSION;
+    }
+
+    private static final String DEFAULT_EXTENSION = ".psd";
+
+    private static final String ACCEPTED_EXTENSIONS[] = { DEFAULT_EXTENSION, };
+
+    protected String[] getAcceptedExtensions()
+    {
+        return ACCEPTED_EXTENSIONS;
+    }
+
+    protected ImageFormat[] getAcceptedTypes()
+    {
+        return new ImageFormat[] { ImageFormat.IMAGE_FORMAT_PSD, //
+        };
+    }
+
+    private PSDHeaderInfo readHeader(ByteSource byteSource)
+            throws ImageReadException, IOException
+    {
+        InputStream is = null;
+
+        try
+        {
+            is = byteSource.getInputStream();
+
+            return readHeader(is);
+        } finally
+        {
+            try
+            {
+                if (is != null) {
+                    is.close();
+                }
+            } catch (Exception e)
+            {
+                Debug.debug(e);
+            }
+
+        }
+    }
+
+    private PSDHeaderInfo readHeader(InputStream is) throws ImageReadException,
+            IOException
+    {
+        readAndVerifyBytes(is, new byte[] { 56, 66, 80, 83 },
+                "Not a Valid PSD File");
+
+        int Version = read2Bytes("Version", is, "Not a Valid PSD File");
+
+        byte Reserved[] = readByteArray("Reserved", 6, is,
+                "Not a Valid PSD File");
+
+        int Channels = read2Bytes("Channels", is, "Not a Valid PSD File");
+        int Rows = read4Bytes("Rows", is, "Not a Valid PSD File");
+        int Columns = read4Bytes("Columns", is, "Not a Valid PSD File");
+        int Depth = read2Bytes("Depth", is, "Not a Valid PSD File");
+        int Mode = read2Bytes("Mode", is, "Not a Valid PSD File");
+
+        PSDHeaderInfo result = new PSDHeaderInfo(Version, Reserved, Channels,
+                Rows, Columns, Depth, Mode);
+
+        return result;
+    }
+
+    private ImageContents readImageContents(InputStream is)
+            throws ImageReadException, IOException
+    {
+        PSDHeaderInfo header = readHeader(is);
+
+        int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
+                "Not a Valid PSD File");
+        skipBytes(is, ColorModeDataLength);
+        // is.skip(ColorModeDataLength);
+        // byte ColorModeData[] = readByteArray("ColorModeData",
+        // ColorModeDataLength, is, "Not a Valid PSD File");
+
+        int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
+                "Not a Valid PSD File");
+        skipBytes(is, ImageResourcesLength);
+        // long skipped = is.skip(ImageResourcesLength);
+        // byte ImageResources[] = readByteArray("ImageResources",
+        // ImageResourcesLength, is, "Not a Valid PSD File");
+
+        int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength", is,
+                "Not a Valid PSD File");
+        skipBytes(is, LayerAndMaskDataLength);
+        // is.skip(LayerAndMaskDataLength);
+        // byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
+        // LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+        int Compression = read2Bytes("Compression", is, "Not a Valid PSD File");
+
+        // skip_bytes(is, LayerAndMaskDataLength);
+        // byte ImageData[] = readByteArray("ImageData", LayerAndMaskDataLength,
+        // is, "Not a Valid PSD File");
+
+        // System.out.println("Compression: " + Compression);
+
+        ImageContents result = new ImageContents(header, ColorModeDataLength,
+        // ColorModeData,
+                ImageResourcesLength,
+                // ImageResources,
+                LayerAndMaskDataLength,
+                // LayerAndMaskData,
+                Compression);
+
+        return result;
+    }
+
+    private ArrayList readImageResourceBlocks(byte bytes[],
+            int imageResourceIDs[], int maxBlocksToRead)
+            throws ImageReadException, IOException
+    {
+        return readImageResourceBlocks(new ByteArrayInputStream(bytes),
+                imageResourceIDs, maxBlocksToRead, bytes.length);
+    }
+
+    private boolean keepImageResourceBlock(int ID, int imageResourceIDs[])
+    {
+        if (imageResourceIDs == null)
+            return true;
+
+        for (int i = 0; i < imageResourceIDs.length; i++)
+            if (ID == imageResourceIDs[i])
+                return true;
+
+        return false;
+    }
+
+    private ArrayList readImageResourceBlocks(InputStream is,
+            int imageResourceIDs[], int maxBlocksToRead, int available)
+            throws ImageReadException, IOException
+    {
+        ArrayList result = new ArrayList();
+
+        while (available > 0)
+        {
+            readAndVerifyBytes(is, new byte[] { 56, 66, 73, 77 },
+                    "Not a Valid PSD File");
+            available -= 4;
+
+            int id = read2Bytes("ID", is, "Not a Valid PSD File");
+            available -= 2;
+
+            int nameLength = readByte("NameLength", is, "Not a Valid PSD File");
+
+            available -= 1;
+            byte nameBytes[] = readByteArray("NameData", nameLength, is,
+                    "Not a Valid PSD File");
+            available -= nameLength;
+            if (((nameLength + 1) % 2) != 0)
+            {
+                int NameDiscard = readByte("NameDiscard", is,
+                        "Not a Valid PSD File");
+                available -= 1;
+            }
+            // String Name = readPString("Name", 6, is, "Not a Valid PSD File");
+            int DataSize = read4Bytes("Size", is, "Not a Valid PSD File");
+            available -= 4;
+            // int ActualDataSize = ((DataSize % 2) == 0)
+            // ? DataSize
+            // : DataSize + 1; // pad to make even
+
+            byte Data[] = readByteArray("Data", DataSize, is,
+                    "Not a Valid PSD File");
+            available -= DataSize;
+
+            if ((DataSize % 2) != 0)
+            {
+                int DataDiscard = readByte("DataDiscard", is,
+                        "Not a Valid PSD File");
+                available -= 1;
+            }
+
+            if (keepImageResourceBlock(id, imageResourceIDs))
+            {
+                result.add(new ImageResourceBlock(id, nameBytes, Data));
+
+                if ((maxBlocksToRead >= 0)
+                        && (result.size() >= maxBlocksToRead))
+                    return result;
+            }
+            // debugNumber("ID", ID, 2);
+
+        }
+
+        return result;
+    }
+
+    private ArrayList readImageResourceBlocks(ByteSource byteSource,
+            int imageResourceIDs[], int maxBlocksToRead)
+            throws ImageReadException, IOException
+    {
+        InputStream is = null;
+
+        try
+        {
+            is = byteSource.getInputStream();
+
+            ImageContents imageContents = readImageContents(is);
+
+            is.close();
+
+            is = this.getInputStream(byteSource, PSD_SECTION_IMAGE_RESOURCES);
+            byte ImageResources[] = readByteArray("ImageResources",
+                    imageContents.ImageResourcesLength, is,
+                    "Not a Valid PSD File");
+
+            return readImageResourceBlocks(ImageResources, imageResourceIDs,
+                    maxBlocksToRead);
+        } finally
+        {
+            try
+            {
+                if (is != null) {
+                    is.close();
+                }
+            } catch (Exception e)
+            {
+                Debug.debug(e);
+            }
+
+        }
+    }
+
+    private static final int PSD_SECTION_HEADER = 0;
+    private static final int PSD_SECTION_COLOR_MODE = 1;
+    private static final int PSD_SECTION_IMAGE_RESOURCES = 2;
+    private static final int PSD_SECTION_LAYER_AND_MASK_DATA = 3;
+    private static final int PSD_SECTION_IMAGE_DATA = 4;
+
+    private static final int PSD_HEADER_LENGTH = 26;
+
+    private InputStream getInputStream(ByteSource byteSource, int section)
+            throws ImageReadException, IOException
+    {
+        InputStream is = byteSource.getInputStream();
+
+        if (section == PSD_SECTION_HEADER)
+            return is;
+
+        skipBytes(is, PSD_HEADER_LENGTH);
+        // is.skip(kHeaderLength);
+
+        int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
+                "Not a Valid PSD File");
+
+        if (section == PSD_SECTION_COLOR_MODE)
+            return is;
+
+        skipBytes(is, ColorModeDataLength);
+        // byte ColorModeData[] = readByteArray("ColorModeData",
+        // ColorModeDataLength, is, "Not a Valid PSD File");
+
+        int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
+                "Not a Valid PSD File");
+
+        if (section == PSD_SECTION_IMAGE_RESOURCES)
+            return is;
+
+        skipBytes(is, ImageResourcesLength);
+        // byte ImageResources[] = readByteArray("ImageResources",
+        // ImageResourcesLength, is, "Not a Valid PSD File");
+
+        int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength", is,
+                "Not a Valid PSD File");
+
+        if (section == PSD_SECTION_LAYER_AND_MASK_DATA)
+            return is;
+
+        skipBytes(is, LayerAndMaskDataLength);
+        // byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
+        // LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+        int Compression = read2Bytes("Compression", is, "Not a Valid PSD File");
+
+        // byte ImageData[] = readByteArray("ImageData",
+        // LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+        if (section == PSD_SECTION_IMAGE_DATA)
+            return is;
+
+        throw new ImageReadException("getInputStream: Unknown Section: "
+                + section);
+    }
+
+    private byte[] getData(ByteSource byteSource, int section)
+            throws ImageReadException, IOException
+    {
+        InputStream is = null;
+
+        try
+        {
+            is = byteSource.getInputStream();
+
+            // PSDHeaderInfo header = readHeader(is);
+            if (section == PSD_SECTION_HEADER)
+                return readByteArray("Header", PSD_HEADER_LENGTH, is,
+                        "Not a Valid PSD File");
+            skipBytes(is, PSD_HEADER_LENGTH);
+
+            int ColorModeDataLength = read4Bytes("ColorModeDataLength", is,
+                    "Not a Valid PSD File");
+
+            if (section == PSD_SECTION_COLOR_MODE)
+                return readByteArray("ColorModeData", ColorModeDataLength, is,
+                        "Not a Valid PSD File");
+
+            skipBytes(is, ColorModeDataLength);
+            // byte ColorModeData[] = readByteArray("ColorModeData",
+            // ColorModeDataLength, is, "Not a Valid PSD File");
+
+            int ImageResourcesLength = read4Bytes("ImageResourcesLength", is,
+                    "Not a Valid PSD File");
+
+            if (section == PSD_SECTION_IMAGE_RESOURCES)
+                return readByteArray("ImageResources", ImageResourcesLength,
+                        is, "Not a Valid PSD File");
+
+            skipBytes(is, ImageResourcesLength);
+            // byte ImageResources[] = readByteArray("ImageResources",
+            // ImageResourcesLength, is, "Not a Valid PSD File");
+
+            int LayerAndMaskDataLength = read4Bytes("LayerAndMaskDataLength",
+                    is, "Not a Valid PSD File");
+
+            if (section == PSD_SECTION_LAYER_AND_MASK_DATA)
+                return readByteArray("LayerAndMaskData",
+                        LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+            skipBytes(is, LayerAndMaskDataLength);
+            // byte LayerAndMaskData[] = readByteArray("LayerAndMaskData",
+            // LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+            int Compression = read2Bytes("Compression", is,
+                    "Not a Valid PSD File");
+
+            // byte ImageData[] = readByteArray("ImageData",
+            // LayerAndMaskDataLength, is, "Not a Valid PSD File");
+
+            // if (section == kPSD_SECTION_IMAGE_DATA)
+            // return readByteArray("LayerAndMaskData", LayerAndMaskDataLength,
+            // is,
+            // "Not a Valid PSD File");
+
+        } finally
+        {
+            try
+            {
+                if (is != null) {
+                    is.close();
+                }
+            } catch (Exception e)
+            {
+                Debug.debug(e);
+            }
+
+        }
+        throw new ImageReadException("getInputStream: Unknown Section: "
+                + section);
+    }
+
+    private ImageContents readImageContents(ByteSource byteSource)
+            throws ImageReadException, IOException
+    {
+        InputStream is = null;
+
+        try
+        {
+            is = byteSource.getInputStream();
+
+            ImageContents imageContents = readImageContents(is);
+            return imageContents;
+        } finally
+        {
+            try
+            {
+                if (is != null) {
+                    is.close();
+                }
+            } catch (Exception e)
+            {
+                Debug.debug(e);
+            }
+
+        }
+
+    }
+
+    public final static int IMAGE_RESOURCE_ID_ICC_PROFILE = 0x040F;
+
+    public byte[] getICCProfileBytes(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+        ArrayList blocks = readImageResourceBlocks(byteSource,
+                new int[] { IMAGE_RESOURCE_ID_ICC_PROFILE, }, 1);
+
+        if ((blocks == null) || (blocks.size() < 1))
+            return null;
+
+        ImageResourceBlock irb = (ImageResourceBlock) blocks.get(0);
+        byte bytes[] = irb.data;
+        if ((bytes == null) || (bytes.length < 1))
+            return null;
+        return bytes;
+    }
+
+    public Dimension getImageSize(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+        PSDHeaderInfo bhi = readHeader(byteSource);
+        if (bhi == null)
+            throw new ImageReadException("PSD: couldn't read header");
+
+        return new Dimension(bhi.Columns, bhi.Rows);
+
+    }
+
+    public byte[] embedICCProfile(byte image[], byte profile[])
+    {
+        return null;
+    }
+
+    public boolean embedICCProfile(File src, File dst, byte profile[])
+    {
+        return false;
+    }
+
+    public IImageMetadata getMetadata(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+        return null;
+    }
+
+    private int getChannelsPerMode(int mode)
+    {
+        switch (mode)
+        {
+        case 0: // Bitmap
+            return 1;
+        case 1: // Grayscale
+            return 1;
+        case 2: // Indexed
+            return -1;
+        case 3: // RGB
+            return 3;
+        case 4: // CMYK
+            return 4;
+        case 7: // Multichannel
+            return -1;
+        case 8: // Duotone
+            return -1;
+        case 9: // Lab
+            return 4;
+        default:
+            return -1;
+
+        }
+    }
+
+    public ImageInfo getImageInfo(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+        ImageContents imageContents = readImageContents(byteSource);
+        // ImageContents imageContents = readImage(byteSource, false);
+
+        if (imageContents == null)
+            throw new ImageReadException("PSD: Couldn't read blocks");
+
+        PSDHeaderInfo header = imageContents.header;
+        if (header == null)
+            throw new ImageReadException("PSD: Couldn't read Header");
+
+        int Width = header.Columns;
+        int Height = header.Rows;
+
+        ArrayList Comments = new ArrayList();
+        // TODO: comments...
+
+        int BitsPerPixel = header.Depth * getChannelsPerMode(header.Mode);
+        // System.out.println("header.Depth: " + header.Depth);
+        // System.out.println("header.Mode: " + header.Mode);
+        // System.out.println("getChannelsPerMode(header.Mode): " +
+        // getChannelsPerMode(header.Mode));
+        if (BitsPerPixel < 0)
+            BitsPerPixel = 0;
+        ImageFormat Format = ImageFormat.IMAGE_FORMAT_PSD;
+        String FormatName = "Photoshop";
+        String MimeType = "image/x-photoshop";
+        // we ought to count images, but don't yet.
+        int NumberOfImages = -1;
+        // not accurate ... only reflects first
+        boolean isProgressive = false;
+
+        int PhysicalWidthDpi = 72;
+        float PhysicalWidthInch = (float) ((double) Width / (double) PhysicalWidthDpi);
+        int PhysicalHeightDpi = 72;
+        float PhysicalHeightInch = (float) ((double) Height / (double) PhysicalHeightDpi);
+
+        String FormatDetails = "Psd";
+
+        boolean isTransparent = false; // TODO: inaccurate.
+        boolean usesPalette = header.Mode == COLOR_MODE_INDEXED;
+        int ColorType = ImageInfo.COLOR_TYPE_UNKNOWN;
+
+        String compressionAlgorithm;
+        switch (imageContents.Compression)
+        {
+        case 0:
+            compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_NONE;
+            break;
+        case 1:
+            compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_PSD;
+            break;
+        default:
+            compressionAlgorithm = ImageInfo.COMPRESSION_ALGORITHM_UNKNOWN;
+        }
+
+        ImageInfo result = new ImageInfo(FormatDetails, BitsPerPixel, Comments,
+                Format, FormatName, Height, MimeType, NumberOfImages,
+                PhysicalHeightDpi, PhysicalHeightInch, PhysicalWidthDpi,
+                PhysicalWidthInch, Width, isProgressive, isTransparent,
+                usesPalette, ColorType, compressionAlgorithm);
+
+        return result;
+    }
+
+    // TODO not used
+    private ImageResourceBlock findImageResourceBlock(ArrayList blocks, int ID)
+    {
+        for (int i = 0; i < blocks.size(); i++)
+        {
+            ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
+
+            if (block.id == ID)
+                return block;
+        }
+        return null;
+    }
+
+    public boolean dumpImageFile(PrintWriter pw, ByteSource byteSource)
+            throws ImageReadException, IOException
+    {
+        pw.println("gif.dumpImageFile");
+
+        {
+            ImageInfo fImageData = getImageInfo(byteSource);
+            if (fImageData == null)
+                return false;
+
+            fImageData.toString(pw, "");
+        }
+        {
+            ImageContents imageContents = readImageContents(byteSource);
+
+            imageContents.dump(pw);
+            imageContents.header.dump(pw);
+
+            ArrayList blocks = readImageResourceBlocks(byteSource,
+            // fImageContents.ImageResources,
+                    null, -1);
+
+            pw.println("blocks.size(): " + blocks.size());
+
+            // System.out.println("gif.blocks: " + blocks.blocks.size());
+            for (int i = 0; i < blocks.size(); i++)
+            {
+                ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
+                pw.println("\t" + i + " (" + Integer.toHexString(block.id)
+                        + ", " + "'"
+                        + new String(block.nameData)
+                        + "' ("
+                        + block.nameData.length
+                        + "), "
+                        // + block.getClass().getName()
+                        // + ", "
+                        + " data: " + block.data.length + " type: '"
+                        + new PSDConstants().getDescription(block.id) + "' "
+                        + ")");
+
+            }
+
+        }
+
+        pw.println("");
+
+        return true;
+    }
+
+    private static final int COLOR_MODE_INDEXED = 2;
+
+    public BufferedImage getBufferedImage(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+        ImageContents imageContents = readImageContents(byteSource);
+        // ImageContents imageContents = readImage(byteSource, false);
+
+        if (imageContents == null)
+            throw new ImageReadException("PSD: Couldn't read blocks");
+
+        PSDHeaderInfo header = imageContents.header;
+        if (header == null)
+            throw new ImageReadException("PSD: Couldn't read Header");
+
+        // ImageDescriptor id = (ImageDescriptor)
+        // findBlock(fImageContents.blocks,
+        // kImageSeperator);
+        // if (id == null)
+        // throw new ImageReadException("PSD: Couldn't read Image Descriptor");
+        // GraphicControlExtension gce = (GraphicControlExtension) findBlock(
+        // fImageContents.blocks, kGraphicControlExtension);
+
+        ArrayList blocks = readImageResourceBlocks(byteSource,
+        // fImageContents.ImageResources,
+                null, -1);
+
+        int width = header.Columns;
+        int height = header.Rows;
+        // int height = header.Columns;
+
+        // int transfer_type;
+
+        // transfer_type = DataBuffer.TYPE_BYTE;
+
+        boolean hasAlpha = false;
+        BufferedImage result = getBufferedImageFactory(params)
+                .getColorBufferedImage(width, height, hasAlpha);
+
+        DataParser dataParser;
+        switch (imageContents.header.Mode)
+        {
+        case 0: // bitmap
+            dataParser = new DataParserBitmap();
+            break;
+        case 1:
+        case 8: // Duotone=8;
+            dataParser = new DataParserGrayscale();
+            break;
+        case 3:
+            dataParser = new DataParserRGB();
+            break;
+        case 4:
+            dataParser = new DataParserCMYK();
+            break;
+        case 9:
+            dataParser = new DataParserLab();
+            break;
+        case COLOR_MODE_INDEXED:
+            // case 2 : // Indexed=2;
+        {
+
+            byte ColorModeData[] = getData(byteSource, PSD_SECTION_COLOR_MODE);
+
+            // ImageResourceBlock block = findImageResourceBlock(blocks,
+            // 0x03EB);
+            // if (block == null)
+            // throw new ImageReadException(
+            // "Missing: Indexed Color Image Resource Block");
+
+            dataParser = new DataParserIndexed(ColorModeData);
+            break;
+        }
+        case 7: // Multichannel=7;
+            // fDataParser = new DataParserStub();
+            // break;
+
+            // case 1 :
+            // fDataReader = new CompressedDataReader();
+            // break;
+        default:
+            throw new ImageReadException("Unknown Mode: "
+                    + imageContents.header.Mode);
+        }
+        DataReader fDataReader;
+        switch (imageContents.Compression)
+        {
+        case 0:
+            fDataReader = new UncompressedDataReader(dataParser);
+            break;
+        case 1:
+            fDataReader = new CompressedDataReader(dataParser);
+            break;
+        default:
+            throw new ImageReadException("Unknown Compression: "
+                    + imageContents.Compression);
+        }
+        {
+            InputStream is = null;
+
+            try
+            {
+                is = getInputStream(byteSource, PSD_SECTION_IMAGE_DATA);
+                fDataReader.readData(is, result, imageContents, this);
+
+                fDataReader.dump();
+                // is.
+                // ImageContents imageContents = readImageContents(is);
+                // return imageContents;
+            } finally
+            {
+                try
+                {
+                    if (is != null)
+                        is.close();
+                } catch (Exception e)
+                {
+                    Debug.debug(e);
+                }
+
+            }
+
+        }
+
+        return result;
+
+    }
+
+    public final static int IMAGE_RESOURCE_ID_XMP = 0x0424;
+
+    public final static String BLOCK_NAME_XMP = "XMP";
+
+    /**
+     * Extracts embedded XML metadata as XML string.
+     * <p>
+     *
+     * @param byteSource
+     *            File containing image data.
+     * @param params
+     *            Map of optional parameters, defined in SanselanConstants.
+     * @return Xmp Xml as String, if present. Otherwise, returns null.
+     */
+    public String getXmpXml(ByteSource byteSource, Map params)
+            throws ImageReadException, IOException
+    {
+
+        ImageContents imageContents = readImageContents(byteSource);
+
+        if (imageContents == null)
+            throw new ImageReadException("PSD: Couldn't read blocks");
+
+        PSDHeaderInfo header = imageContents.header;
+        if (header == null)
+            throw new ImageReadException("PSD: Couldn't read Header");
+
+        ArrayList blocks = readImageResourceBlocks(byteSource,
+                new int[] { IMAGE_RESOURCE_ID_XMP, }, -1);
+
+        if ((blocks == null) || (blocks.size() < 1))
+            return null;
+
+        List xmpBlocks = new ArrayList();
+        if (false)
+        {
+            // TODO: for PSD 7 and later, verify "XMP" name.
+            for (int i = 0; i < blocks.size(); i++)
+            {
+                ImageResourceBlock block = (ImageResourceBlock) blocks.get(i);
+                if (!block.getName().equals(BLOCK_NAME_XMP))
+                    continue;
+                xmpBlocks.add(block);
+            }
+        } else
+            xmpBlocks.addAll(blocks);
+
+        if (xmpBlocks.size() < 1)
+            return null;
+        if (xmpBlocks.size() > 1)
+            throw new ImageReadException(
+                    "PSD contains more than one XMP block.");
+
+        ImageResourceBlock block = (ImageResourceBlock) xmpBlocks.get(0);
+
+        try
+        {
+            // segment data is UTF-8 encoded xml.
+            String xml = new String(block.data, 0, block.data.length, "utf-8");
+            return xml;
+        } catch (UnsupportedEncodingException e)
+        {
+            throw new ImageReadException("Invalid JPEG XMP Segment.");
+        }
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParser.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParser.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParser.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParser.java Fri Sep 10 16:33:35 2010
@@ -24,32 +24,32 @@ import org.apache.sanselan.formats.psd.P
 
 public abstract class DataParser
 {
-	public final void parseData(int data[][][], BufferedImage bi,
-			ImageContents imageContents)
-	{
-		DataBuffer buffer = bi.getRaster().getDataBuffer();
+    public final void parseData(int data[][][], BufferedImage bi,
+            ImageContents imageContents)
+    {
+        DataBuffer buffer = bi.getRaster().getDataBuffer();
 
-		PSDHeaderInfo header = imageContents.header;
-		int width = header.Columns;
-		int height = header.Rows;
+        PSDHeaderInfo header = imageContents.header;
+        int width = header.Columns;
+        int height = header.Rows;
 
-		for (int y = 0; y < height; y++)
-			for (int x = 0; x < width; x++)
-			{
-				int rgb = getRGB(data, x, y, imageContents);
-				buffer.setElem(y * width + x, rgb);
-			}
+        for (int y = 0; y < height; y++)
+            for (int x = 0; x < width; x++)
+            {
+                int rgb = getRGB(data, x, y, imageContents);
+                buffer.setElem(y * width + x, rgb);
+            }
 
-	}
+    }
 
-	protected abstract int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents);
+    protected abstract int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents);
 
-	public abstract int getBasicChannelsCount();
+    public abstract int getBasicChannelsCount();
 
-	public void dump()
-	{
+    public void dump()
+    {
 
-	}
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserBitmap.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserBitmap.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserBitmap.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserBitmap.java Fri Sep 10 16:33:35 2010
@@ -21,26 +21,26 @@ import org.apache.sanselan.formats.psd.I
 public class DataParserBitmap extends DataParser
 {
 
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int sample = 0xff & data[0][y][x];
-		if (sample == 0)
-			sample = 255;
-		else
-			sample = 0;
-		//					sample = 255- sample;
-		int alpha = 0xff;
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int sample = 0xff & data[0][y][x];
+        if (sample == 0)
+            sample = 255;
+        else
+            sample = 0;
+        //                    sample = 255- sample;
+        int alpha = 0xff;
 
-		int rgb = ((0xff & alpha) << 24) | ((0xff & sample) << 16)
-				| ((0xff & sample) << 8) | ((0xff & sample) << 0);
+        int rgb = ((0xff & alpha) << 24) | ((0xff & sample) << 16)
+                | ((0xff & sample) << 8) | ((0xff & sample) << 0);
 
-		return rgb;
-	}
+        return rgb;
+    }
 
-	public int getBasicChannelsCount()
-	{
-		return 1;
-	}
+    public int getBasicChannelsCount()
+    {
+        return 1;
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserCMYK.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserCMYK.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserCMYK.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserCMYK.java Fri Sep 10 16:33:35 2010
@@ -21,28 +21,28 @@ import org.apache.sanselan.formats.psd.I
 
 public class DataParserCMYK extends DataParser
 {
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int sc = 0xff & data[0][y][x];
-		int sm = 0xff & data[1][y][x];
-		int sy = 0xff & data[2][y][x];
-		int sk = 0xff & data[3][y][x];
-
-		// CRAZY adobe has to store the bytes in reverse form.
-		sc = 255 - sc;
-		sm = 255 - sm;
-		sy = 255 - sy;
-		sk = 255 - sk;
-
-		int rgb = ColorConversions.convertCMYKtoRGB(sc, sm, sy, sk);
-
-		return rgb;
-	}
-
-	public int getBasicChannelsCount()
-	{
-		return 4;
-	}
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int sc = 0xff & data[0][y][x];
+        int sm = 0xff & data[1][y][x];
+        int sy = 0xff & data[2][y][x];
+        int sk = 0xff & data[3][y][x];
+
+        // CRAZY adobe has to store the bytes in reverse form.
+        sc = 255 - sc;
+        sm = 255 - sm;
+        sy = 255 - sy;
+        sk = 255 - sk;
+
+        int rgb = ColorConversions.convertCMYKtoRGB(sc, sm, sy, sk);
+
+        return rgb;
+    }
+
+    public int getBasicChannelsCount()
+    {
+        return 4;
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserGrayscale.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserGrayscale.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserGrayscale.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserGrayscale.java Fri Sep 10 16:33:35 2010
@@ -20,21 +20,21 @@ import org.apache.sanselan.formats.psd.I
 
 public class DataParserGrayscale extends DataParser
 {
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int sample = 0xff & data[0][y][x];
-		int alpha = 0xff;
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int sample = 0xff & data[0][y][x];
+        int alpha = 0xff;
 
-		int rgb = ((0xff & alpha) << 24) | ((0xff & sample) << 16)
-				| ((0xff & sample) << 8) | ((0xff & sample) << 0);
+        int rgb = ((0xff & alpha) << 24) | ((0xff & sample) << 16)
+                | ((0xff & sample) << 8) | ((0xff & sample) << 0);
 
-		return rgb;
-	}
+        return rgb;
+    }
 
-	public int getBasicChannelsCount()
-	{
-		return 1;
-	}
+    public int getBasicChannelsCount()
+    {
+        return 1;
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserIndexed.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserIndexed.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserIndexed.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserIndexed.java Fri Sep 10 16:33:35 2010
@@ -20,37 +20,37 @@ import org.apache.sanselan.formats.psd.I
 
 public class DataParserIndexed extends DataParser
 {
-	private final int ColorTable[];
+    private final int ColorTable[];
 
-	public DataParserIndexed(byte ColorModeData[])
-	{
-		ColorTable = new int[256];
-		for (int i = 0; i < 256; i++)
-		{
-			int red = 0xff & ColorModeData[0 * 256 + i];
-			int green = 0xff & ColorModeData[1 * 256 + i];
-			int blue = 0xff & ColorModeData[2 * 256 + i];
-			int alpha = 0xff;
-
-			int rgb = ((0xff & alpha) << 24) | ((0xff & red) << 16)
-					| ((0xff & green) << 8) | ((0xff & blue) << 0);
-
-			ColorTable[i] = rgb;
-		}
-	}
-
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int sample = 0xff & data[0][y][x];
-		int rgb = ColorTable[sample];
-
-		return rgb;
-	}
-
-	public int getBasicChannelsCount()
-	{
-		return 1;
-	}
+    public DataParserIndexed(byte ColorModeData[])
+    {
+        ColorTable = new int[256];
+        for (int i = 0; i < 256; i++)
+        {
+            int red = 0xff & ColorModeData[0 * 256 + i];
+            int green = 0xff & ColorModeData[1 * 256 + i];
+            int blue = 0xff & ColorModeData[2 * 256 + i];
+            int alpha = 0xff;
+
+            int rgb = ((0xff & alpha) << 24) | ((0xff & red) << 16)
+                    | ((0xff & green) << 8) | ((0xff & blue) << 0);
+
+            ColorTable[i] = rgb;
+        }
+    }
+
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int sample = 0xff & data[0][y][x];
+        int rgb = ColorTable[sample];
+
+        return rgb;
+    }
+
+    public int getBasicChannelsCount()
+    {
+        return 1;
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserLab.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserLab.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserLab.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserLab.java Fri Sep 10 16:33:35 2010
@@ -22,36 +22,36 @@ import org.apache.sanselan.formats.psd.I
 public class DataParserLab extends DataParser
 {
 
-	public DataParserLab()
-	{
+    public DataParserLab()
+    {
 
-	}
+    }
 
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int cieL = 0xff & data[0][y][x];
-		int cieA = 0xff & data[1][y][x];
-		int cieB = 0xff & data[2][y][x];
-
-		cieA -= 128;
-		cieB -= 128;
-
-		int rgb = ColorConversions.convertCIELabtoARGBTest(cieL, cieA, cieB);
-
-		return rgb;
-	}
-
-	public int getBasicChannelsCount()
-	{
-		return 3;
-	}
-
-	public void dump()
-	{
-		//		for(int i=0;i<3;i++)
-		//		{
-		//			System.out.println("CIE: " + i + ": min: " + mins[i] + ", max: " + maxs[i]);
-		//		}
-	}
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int cieL = 0xff & data[0][y][x];
+        int cieA = 0xff & data[1][y][x];
+        int cieB = 0xff & data[2][y][x];
+
+        cieA -= 128;
+        cieB -= 128;
+
+        int rgb = ColorConversions.convertCIELabtoARGBTest(cieL, cieA, cieB);
+
+        return rgb;
+    }
+
+    public int getBasicChannelsCount()
+    {
+        return 3;
+    }
+
+    public void dump()
+    {
+        //        for(int i=0;i<3;i++)
+        //        {
+        //            System.out.println("CIE: " + i + ": min: " + mins[i] + ", max: " + maxs[i]);
+        //        }
+    }
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserRGB.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserRGB.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserRGB.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserRGB.java Fri Sep 10 16:33:35 2010
@@ -20,23 +20,23 @@ import org.apache.sanselan.formats.psd.I
 
 public class DataParserRGB extends DataParser
 {
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		int red = 0xff & data[0][y][x];
-		int green = 0xff & data[1][y][x];
-		int blue = 0xff & data[2][y][x];
-		int alpha = 0xff;
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        int red = 0xff & data[0][y][x];
+        int green = 0xff & data[1][y][x];
+        int blue = 0xff & data[2][y][x];
+        int alpha = 0xff;
 
-		int rgb = ((0xff & alpha) << 24) | ((0xff & red) << 16)
-				| ((0xff & green) << 8) | ((0xff & blue) << 0);
+        int rgb = ((0xff & alpha) << 24) | ((0xff & red) << 16)
+                | ((0xff & green) << 8) | ((0xff & blue) << 0);
 
-		return rgb;
-	}
+        return rgb;
+    }
 
-	public int getBasicChannelsCount()
-	{
-		return 3;
-	}
+    public int getBasicChannelsCount()
+    {
+        return 3;
+    }
 
 }
\ No newline at end of file

Modified: commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserStub.java
URL: http://svn.apache.org/viewvc/commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserStub.java?rev=995859&r1=995858&r2=995859&view=diff
==============================================================================
--- commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserStub.java (original)
+++ commons/proper/sanselan/trunk/src/main/java/org/apache/sanselan/formats/psd/dataparsers/DataParserStub.java Fri Sep 10 16:33:35 2010
@@ -20,15 +20,15 @@ import org.apache.sanselan.formats.psd.I
 
 public class DataParserStub extends DataParser
 {
-	protected int getRGB(int data[][][], int x, int y,
-			ImageContents imageContents)
-	{
-		return 0;
-	}
+    protected int getRGB(int data[][][], int x, int y,
+            ImageContents imageContents)
+    {
+        return 0;
+    }
 
-	public int getBasicChannelsCount()
-	{
-		return 1;
-	}
+    public int getBasicChannelsCount()
+    {
+        return 1;
+    }
 
 }
\ No newline at end of file



Mime
View raw message