aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-04-07 15:28:37 +0200
committerSven Gothel <[email protected]>2012-04-07 15:28:37 +0200
commit40830196070013432bc5f453eb31cfe4c64e0510 (patch)
treeca31a1e1e27adf9996963176c4f92b84e25623e9 /src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java
parent865c0588de57c9a020a435bc3f08be0f3f6ba162 (diff)
Merge PNGJ 0.85 into namespace
PNGJ Version 0.85 (1 April 2012) Apache 2.0 License http://code.google.com/p/pngj/ Merged code: - Changed namespace ar.com.hjg.pngj -> jogamp.opengl.util.pngj to avoid collision when using a different version of PNGJ. - Removed test and lossy packages and helper classes to reduce footprint. License information is added in main LICENSE.txt file.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java')
-rw-r--r--src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java b/src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java
new file mode 100644
index 000000000..fd6c08273
--- /dev/null
+++ b/src/jogl/classes/jogamp/opengl/util/pngj/chunks/PngChunkZTXT.java
@@ -0,0 +1,62 @@
+package jogamp.opengl.util.pngj.chunks;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+
+import jogamp.opengl.util.pngj.ImageInfo;
+import jogamp.opengl.util.pngj.PngHelper;
+import jogamp.opengl.util.pngj.PngjException;
+
+
+public class PngChunkZTXT extends PngChunkTextVar {
+ // http://www.w3.org/TR/PNG/#11zTXt
+ public PngChunkZTXT(ImageInfo info) {
+ super(ChunkHelper.zTXt, info);
+ }
+
+ @Override
+ public ChunkRaw createChunk() {
+ if (val.isEmpty() || key.isEmpty())
+ return null;
+ try {
+ ByteArrayOutputStream ba = new ByteArrayOutputStream();
+ ba.write(key.getBytes(PngHelper.charsetLatin1));
+ ba.write(0); // separator
+ ba.write(0); // compression method: 0
+ byte[] textbytes = ChunkHelper.compressBytes(val.getBytes(PngHelper.charsetLatin1), true);
+ ba.write(textbytes);
+ byte[] b = ba.toByteArray();
+ ChunkRaw chunk = createEmptyChunk(b.length, false);
+ chunk.data = b;
+ return chunk;
+ } catch (IOException e) {
+ throw new PngjException(e);
+ }
+ }
+
+ @Override
+ public void parseFromChunk(ChunkRaw c) {
+ int nullsep = -1;
+ for (int i = 0; i < c.data.length; i++) { // look for first zero
+ if (c.data[i] != 0)
+ continue;
+ nullsep = i;
+ break;
+ }
+ if (nullsep < 0 || nullsep > c.data.length - 2)
+ throw new PngjException("bad zTXt chunk: no separator found");
+ key = new String(c.data, 0, nullsep, PngHelper.charsetLatin1);
+ int compmet = (int) c.data[nullsep + 1];
+ if (compmet != 0)
+ throw new PngjException("bad zTXt chunk: unknown compression method");
+ byte[] uncomp = ChunkHelper.compressBytes(c.data, nullsep + 2, c.data.length - nullsep - 2, false); // uncompress
+ val = new String(uncomp, PngHelper.charsetLatin1);
+ }
+
+ @Override
+ public void cloneDataFromRead(PngChunk other) {
+ PngChunkZTXT otherx = (PngChunkZTXT) other;
+ key = otherx.key;
+ val = otherx.val;
+ }
+}