[Patchanim-commit] SF.net SVN: patchanim: [138] trunk/patchanim/src/com/mebigfatguy/apng/ APngEncod
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-02-10 06:59:18
|
Revision: 138 http://patchanim.svn.sourceforge.net/patchanim/?rev=138&view=rev Author: dbrosius Date: 2008-02-09 22:59:23 -0800 (Sat, 09 Feb 2008) Log Message: ----------- YEAH! Crc32 to the rescue, APngs work! Modified Paths: -------------- trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java Modified: trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java =================================================================== --- trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java 2008-02-10 06:00:52 UTC (rev 137) +++ trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java 2008-02-10 06:59:23 UTC (rev 138) @@ -25,6 +25,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.util.zip.CRC32; import javax.imageio.ImageIO; @@ -207,23 +208,7 @@ } static class Chunk { - private static long crcTable[] = new long[256]; - static { - long c; - int n, k; - - for (n = 0; n < 256; n++) { - c = (long) n; - for (k = 0; k < 8; k++) { - if ((c & 1) != 0) - c = 0xedb88320L ^ (c >> 1); - else - c = c >> 1; - } - crcTable[n] = c; - } - } - + public int length; public int type; public byte[] data; @@ -256,13 +241,15 @@ } public void calcCRC() { - long c = -1; - for (int n = 0; n < length; n++) { - c = crcTable[(int)((c ^ data[n]) & 0x00FF)] ^ (c >> 8); - } - - c ^= -1; - crc = (int)c; + CRC32 crc32 = new CRC32(); + byte[] typeBytes = new byte[4]; + typeBytes[0] = (byte)(type >> 24 & 0x00FF); + typeBytes[1] = (byte)(type >> 16 & 0x00FF); + typeBytes[2] = (byte)(type >> 8 & 0x00FF); + typeBytes[3] = (byte)(type & 0x00FF); + crc32.update(typeBytes); + crc32.update(data); + crc = (int)crc32.getValue(); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |