Source code: com/sixlegs/image/png/Chunk_sBIT.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.io.IOException;
6
7 final class Chunk_sBIT
8 extends Chunk
9 {
10 Chunk_sBIT()
11 {
12 super(sBIT);
13 }
14
15 protected boolean multipleOK()
16 {
17 return false;
18 }
19
20 protected boolean beforeIDAT()
21 {
22 return true;
23 }
24
25 protected void readData()
26 throws IOException
27 {
28 byte[] sbit = null;
29 if (img.data.palette != null)
30 throw new PngException("sBIT chunk must precede PLTE chunk");
31 int compare_depth = img.data.header.depth;
32 switch (img.data.header.colorType) {
33 case PngImage.COLOR_TYPE_GRAY:
34 sbit = new byte[3];
35 sbit[0] = sbit[1] = sbit[2] = in_data.readByte();
36 break;
37 case PngImage.COLOR_TYPE_PALETTE:
38 compare_depth = 8;
39 /* fall through */
40 case PngImage.COLOR_TYPE_RGB:
41 sbit = new byte[3];
42 sbit[0] = in_data.readByte();
43 sbit[1] = in_data.readByte();
44 sbit[2] = in_data.readByte();
45 break;
46 case PngImage.COLOR_TYPE_GRAY_ALPHA:
47 sbit = new byte[4];
48 sbit[0] = sbit[1] = sbit[2] = in_data.readByte();
49 sbit[3] = in_data.readByte();
50 break;
51 case PngImage.COLOR_TYPE_RGB_ALPHA:
52 sbit = new byte[4];
53 sbit[0] = in_data.readByte();
54 sbit[1] = in_data.readByte();
55 sbit[2] = in_data.readByte();
56 sbit[3] = in_data.readByte();
57 break;
58 }
59 for (int i = 0; i < sbit.length; i++) {
60 if (sbit[i] <= 0 || sbit[i] > compare_depth)
61 throw new PngExceptionSoft("Illegal sBIT component depth");
62 }
63
64 img.data.properties.put("significant bits", sbit);
65 }
66 }