Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sixlegs/image/png/Chunk_bKGD.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.awt.Color;
6   import java.io.IOException;
7   
8   final class Chunk_bKGD
9   extends Chunk
10  {
11      Chunk_bKGD()
12      {
13          super(bKGD);
14      }
15  
16      protected boolean multipleOK()
17      {
18          return false;
19      }
20      
21      protected boolean beforeIDAT()
22      {
23          return true;
24      }
25  
26      protected void readData()
27      throws IOException
28      {
29          int index, r, g, b;
30          switch (img.data.header.colorType) {
31          case PngImage.COLOR_TYPE_PALETTE:
32              if (length != 1) badLength(1);
33              index = in_data.readUnsignedByte();
34              if (img.data.palette == null)
35                  throw new PngException("hIST chunk must follow PLTE chunk");
36              img.data.properties.put("background index", new Integer(index));
37              r = img.data.palette.r_raw[index];
38              g = img.data.palette.g_raw[index];
39              b = img.data.palette.b_raw[index];
40              break;
41  
42          case PngImage.COLOR_TYPE_GRAY:
43          case PngImage.COLOR_TYPE_GRAY_ALPHA:
44              if (length != 2) badLength(2);
45              if (img.data.header.depth == 16) {
46                  r = g = b = in_data.readUnsignedByte();
47                  int low = in_data.readUnsignedByte();
48                  img.data.properties.put("background low bytes", new Color(low, low, low));
49              } else {
50                  r = g = b = in_data.readUnsignedShort();
51              }
52              break;
53  
54          default: // truecolor
55              if (length != 6) badLength(6);
56              if (img.data.header.depth == 16) {
57                  r = in_data.readUnsignedByte();
58                  int low_r = in_data.readUnsignedByte();
59                  g = in_data.readUnsignedByte();
60                  int low_g = in_data.readUnsignedByte();
61                  b = in_data.readUnsignedByte();
62                  int low_b = in_data.readUnsignedByte();
63                  img.data.properties.put("background low bytes", new Color(low_r, low_g, low_b));
64              } else {
65                  r = in_data.readUnsignedShort();
66                  g = in_data.readUnsignedShort();
67                  b = in_data.readUnsignedShort();
68              }
69          }
70          img.data.properties.put("background", new Color(r, g, b));
71      }
72  }