blob: a3bab49950cb959de8344bb75a80c2e8172e2da5 (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package jogamp.opengl.util.pngj.chunks;
import jogamp.opengl.util.pngj.ImageInfo;
import jogamp.opengl.util.pngj.PngHelperInternal;
import jogamp.opengl.util.pngj.PngjException;
/**
* oFFs chunk.
* <p>
* see http://www.libpng.org/pub/png/spec/register/pngext-1.3.0-pdg.html#C.oFFs
*/
public class PngChunkOFFS extends PngChunkSingle {
public final static String ID = "oFFs";
// http://www.libpng.org/pub/png/spec/register/pngext-1.3.0-pdg.html#C.oFFs
private long posX;
private long posY;
private int units; // 0: pixel 1:micrometer
public PngChunkOFFS(ImageInfo info) {
super(ID, info);
}
@Override
public ChunkOrderingConstraint getOrderingConstraint() {
return ChunkOrderingConstraint.BEFORE_IDAT;
}
@Override
public ChunkRaw createRawChunk() {
ChunkRaw c = createEmptyChunk(9, true);
PngHelperInternal.writeInt4tobytes((int) posX, c.data, 0);
PngHelperInternal.writeInt4tobytes((int) posY, c.data, 4);
c.data[8] = (byte) units;
return c;
}
@Override
public void parseFromRaw(ChunkRaw chunk) {
if (chunk.len != 9)
throw new PngjException("bad chunk length " + chunk);
posX = PngHelperInternal.readInt4fromBytes(chunk.data, 0);
if (posX < 0)
posX += 0x100000000L;
posY = PngHelperInternal.readInt4fromBytes(chunk.data, 4);
if (posY < 0)
posY += 0x100000000L;
units = PngHelperInternal.readInt1fromByte(chunk.data, 8);
}
@Override
public void cloneDataFromRead(PngChunk other) {
PngChunkOFFS otherx = (PngChunkOFFS) other;
this.posX = otherx.posX;
this.posY = otherx.posY;
this.units = otherx.units;
}
/**
* 0: pixel, 1:micrometer
*/
public int getUnits() {
return units;
}
/**
* 0: pixel, 1:micrometer
*/
public void setUnits(int units) {
this.units = units;
}
public long getPosX() {
return posX;
}
public void setPosX(long posX) {
this.posX = posX;
}
public long getPosY() {
return posY;
}
public void setPosY(long posY) {
this.posY = posY;
}
}
|