Source code: com/sixlegs/image/png/Chunk_sPLT.java
1 // Copyright (C) 1998, 1999, 2001 Chris Nokleberg
2 // Please see included LICENSE.TXT
3
4 package com.sixlegs.image.png;
5 import java.util.Hashtable;
6 import java.io.IOException;
7
8 final class Chunk_sPLT
9 extends Chunk
10 {
11 Chunk_sPLT()
12 {
13 super(sPLT);
14 }
15
16 protected boolean beforeIDAT()
17 {
18 return true;
19 }
20
21 protected void readData()
22 throws IOException
23 {
24 String name;
25 if ((name = in_data.readString()).length() > 79)
26 throw new PngExceptionSoft("sPLT palette name too long");
27 name = KeyValueChunk.repairKey(name);
28 if (img.data.palettes.containsKey(name))
29 throw new PngExceptionSoft("Duplicate sPLT names");
30 int depth = in_data.readUnsignedByte();
31 int L = length - name.length();
32 int[][] prop;
33 if (depth == 8) {
34 if (L % 6 != 0) badLength();
35 int n = L / 6;
36 prop = new int[5][n];
37 for (int i = 0; i < n; i++) {
38 prop[0][i] = in_data.readUnsignedByte();
39 prop[1][i] = in_data.readUnsignedByte();
40 prop[2][i] = in_data.readUnsignedByte();
41 prop[3][i] = in_data.readUnsignedByte();
42 prop[4][i] = in_data.readUnsignedShort();
43 }
44 } else if (depth == 16) {
45 if (L % 10 != 0) badLength();
46 int n = L / 10;
47 prop = new int[5][n];
48 for (int i = 0; i < n; i++) {
49 prop[0][i] = in_data.readUnsignedShort();
50 prop[1][i] = in_data.readUnsignedShort();
51 prop[2][i] = in_data.readUnsignedShort();
52 prop[3][i] = in_data.readUnsignedShort();
53 prop[4][i] = in_data.readUnsignedShort();
54 }
55 } else {
56 throw new PngExceptionSoft("Bad sPLT sample depth: " + depth);
57 }
58 img.data.palettes.put(name, prop);
59 }
60 }