blob: b0f02ea377eb380403bc7ab7dffa209f5a642d9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
package jogamp.opengl.util.pngj.chunks;
import jogamp.opengl.util.pngj.ImageInfo;
import jogamp.opengl.util.pngj.PngHelper;
import jogamp.opengl.util.pngj.PngjException;
/*
*/
public class PngChunkHIST extends PngChunk {
// http://www.w3.org/TR/PNG/#11hIST
// only for palette images
private int[] hist = new int[0]; // should have same lenght as palette
public PngChunkHIST(ImageInfo info) {
super(ChunkHelper.hIST, info);
}
@Override
public boolean mustGoBeforeIDAT() {
return true;
}
@Override
public boolean mustGoAfterPLTE() {
return true;
}
@Override
public void parseFromChunk(ChunkRaw c) {
if (!imgInfo.indexed)
throw new PngjException("only indexed images accept a HIST chunk");
int nentries = c.data.length / 2;
hist = new int[nentries];
for (int i = 0; i < hist.length; i++) {
hist[i] = PngHelper.readInt2fromBytes(c.data, i * 2);
}
}
@Override
public ChunkRaw createChunk() {
if (!imgInfo.indexed)
throw new PngjException("only indexed images accept a HIST chunk");
ChunkRaw c = null;
c = createEmptyChunk(hist.length * 2, true);
for (int i = 0; i < hist.length; i++) {
PngHelper.writeInt2tobytes(hist[i], c.data, i * 2);
}
return c;
}
@Override
public void cloneDataFromRead(PngChunk other) {
PngChunkHIST otherx = (PngChunkHIST) other;
hist = new int[otherx.hist.length];
System.arraycopy(otherx.hist, 0, hist, 0, otherx.hist.length);
}
public int[] getHist() {
return hist;
}
public void setHist(int[] hist) {
this.hist = hist;
}
}
|