Thread: [Patchanim-commit] SF.net SVN: patchanim: [134] trunk/patchanim/src/com/mebigfatguy/apng/ APngEncod
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-02-10 05:36:55
|
Revision: 134 http://patchanim.svn.sourceforge.net/patchanim/?rev=134&view=rev Author: dbrosius Date: 2008-02-09 21:37:00 -0800 (Sat, 09 Feb 2008) Log Message: ----------- make sure finish cleans up 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 05:34:06 UTC (rev 133) +++ trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java 2008-02-10 05:37:00 UTC (rev 134) @@ -98,6 +98,9 @@ if (closeStream) out.close(); } catch (IOException ioe) { + } finally { + out = null; + started = false; } return true; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-10 05:56:01
|
Revision: 136 http://patchanim.svn.sourceforge.net/patchanim/?rev=136&view=rev Author: dbrosius Date: 2008-02-09 21:56:06 -0800 (Sat, 09 Feb 2008) Log Message: ----------- get sequence number right should incr on every fcTL and fdAT 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 05:46:03 UTC (rev 135) +++ trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java 2008-02-10 05:56:06 UTC (rev 136) @@ -95,6 +95,9 @@ if (!started) return false; try { + Chunk iendChunk = new Chunk(0, IEND); + iendChunk.calcCRC(); + iendChunk.write(out); if (closeStream) out.close(); } catch (IOException ioe) { @@ -137,7 +140,7 @@ case IDAT: if (!sawIDAT) { Chunk fcTLChunk = new Chunk(26, fcTL); - fcTLChunk.injectInt(0, seqNum); + fcTLChunk.injectInt(0, seqNum++); fcTLChunk.injectInt(4, im.getWidth()); fcTLChunk.injectInt(8, im.getHeight()); fcTLChunk.injectInt(12, 0); @@ -153,22 +156,16 @@ chunk.write(out); } else { Chunk fdATChunk = new Chunk(chunk.length + 4, fdAT); - fdATChunk.injectInt(0, seqNum); + fdATChunk.injectInt(0, seqNum++); System.arraycopy(chunk.data, 0, fdATChunk.data, 4, chunk.length); fdATChunk.calcCRC(); fdATChunk.write(out); } break; - - case IEND: - if (seqNum >= (frameCount - 1)) - chunk.write(out); - break; } chunk = pStrm.readNextChunk(pStrm); } processedFirstFrame = true; - seqNum++; return true; } catch (IOException ioe) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-02-10 06:00:47
|
Revision: 137 http://patchanim.svn.sourceforge.net/patchanim/?rev=137&view=rev Author: dbrosius Date: 2008-02-09 22:00:52 -0800 (Sat, 09 Feb 2008) Log Message: ----------- fix crc 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 05:56:06 UTC (rev 136) +++ trunk/patchanim/src/com/mebigfatguy/apng/APngEncoder.java 2008-02-10 06:00:52 UTC (rev 137) @@ -261,7 +261,7 @@ c = crcTable[(int)((c ^ data[n]) & 0x00FF)] ^ (c >> 8); } - c &= -1; + c ^= -1; crc = (int)c; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |