You are viewing a plain text version of this content. The canonical link for it is here.
Posted to sanselan-commits@incubator.apache.org by cm...@apache.org on 2008/08/01 22:33:30 UTC

svn commit: r681876 - /incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java

Author: cmchen
Date: Fri Aug  1 15:33:30 2008
New Revision: 681876

URL: http://svn.apache.org/viewvc?rev=681876&view=rev
Log:
Three changes to the Gif format handling.

When writing a GIF, we now always include a Graphic Control Extension block, even if its not necessary.
We are more defensive about missing GCEs.
Lastly, we now set a minimum bound on initial code sizes for LZW-compressed gif image data.

Modified:
    incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java

Modified: incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java
URL: http://svn.apache.org/viewvc/incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java?rev=681876&r1=681875&r2=681876&view=diff
==============================================================================
--- incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java (original)
+++ incubator/sanselan/trunk/src/main/java/org/apache/sanselan/formats/gif/GifImageParser.java Fri Aug  1 15:33:30 2008
@@ -240,7 +240,7 @@
 		while (true)
 		{
 			int code = is.read();
-			// this.debugNumber("code: ", code);
+//			 this.debugNumber("code: ", code);
 
 			switch (code)
 			{
@@ -614,11 +614,8 @@
 				+ ((char) blocks.gifHeaderInfo.version3);
 
 		boolean isTransparent = false;
-		if (gce != null)
-		{
-			if (gce.transparency)
+		if (gce != null && gce.transparency)
 				isTransparent = true;
-		}
 
 		boolean usesPalette = true;
 		int colorType = ImageInfo.COLOR_TYPE_RGB;
@@ -639,11 +636,11 @@
 		pw.println("gif.dumpImageFile");
 
 		{
-			ImageInfo fImageData = getImageInfo(byteSource);
-			if (fImageData == null)
+			ImageInfo imageData = getImageInfo(byteSource);
+			if (imageData == null)
 				return false;
 
-			fImageData.toString(pw, "");
+			imageData.toString(pw, "");
 		}
 		{
 			ImageContents blocks = readFile(byteSource, false);
@@ -725,7 +722,10 @@
 		int width = ghi.logicalScreenWidth;
 		int height = ghi.logicalScreenHeight;
 
-		boolean hasAlpha = gce.transparency;
+		boolean hasAlpha = false;
+		if (gce != null && gce.transparency)
+			hasAlpha = true;
+
 		BufferedImage result = getBufferedImageFactory(params)
 				.getColorBufferedImage(width, height, hasAlpha);
 
@@ -739,7 +739,7 @@
 				throw new ImageReadException("Gif: No Color Table");
 
 			int transparentIndex = -1;
-			if (gce.transparency)
+			if (hasAlpha)
 				transparentIndex = gce.transparentColorIndex;
 
 			// Debug.debug("charles TransparentIndex", TransparentIndex);
@@ -935,16 +935,15 @@
 
 			}
 
-			if (hasAlpha)
-			{ // write GraphicControlExtension
+			{ // ALWAYS write GraphicControlExtension
 				bos.write(EXTENSION_CODE);
 				bos.write((byte) 0xf9);
 				// bos.write(0xff & (kGraphicControlExtension >> 8));
 				// bos.write(0xff & (kGraphicControlExtension >> 0));
 
 				bos.write((byte) 4); // block size;
-				int fPackedFields = hasAlpha ? 1 : 0; // transparency flag
-				bos.write((byte) fPackedFields);
+				int packedFields = hasAlpha ? 1 : 0; // transparency flag
+				bos.write((byte) packedFields);
 				bos.write((byte) 0); // Delay Time
 				bos.write((byte) 0); // Delay Time
 				bos.write((byte) (hasAlpha ? palette2.length() : 0)); // Transparent
@@ -1023,6 +1022,8 @@
 				int image_data_total = 0;
 
 				int LZWMinimumCodeSize = colorTableScaleLessOne + 1;
+				LZWMinimumCodeSize = Math.max(8, LZWMinimumCodeSize);
+				Debug.debug("LZWMinimumCodeSize", LZWMinimumCodeSize);
 				// TODO:
 				// make
 				// better