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

Quick Search    Search Deep

Source code: com/sixlegs/image/png/BitMover.java


1   // Copyright (C) 1998, 1999, 2001 Chris Nokleberg
2   // Please see included LICENSE.TXT
3   
4   package com.sixlegs.image.png;
5   
6   import java.io.IOException;
7   import java.io.InputStream;
8   
9   abstract class BitMover
10  {
11      int trans = -1;
12      int transgray = -1;
13      int translow = -1;
14      int[] gammaTable;
15  
16      abstract int fill(int[] pixels, InputStream str, int off, int len)
17      throws IOException;
18  
19      static BitMover getBitMover(PngImage img)
20      throws PngException
21      {
22          StringBuffer clsname = new StringBuffer("com.sixlegs.image.png.BitMover");
23          clsname.append(img.data.header.depth);
24          if (img.data.header.paletteUsed) {
25              clsname.append('P');
26          } else {
27              clsname.append(img.data.header.colorUsed ? "RGB" : "G");
28          }
29          if (img.data.header.alphaUsed) clsname.append('A');
30          try {
31              BitMover b = (BitMover)Class.forName(clsname.toString()).newInstance();
32              b.gammaTable = img.data.gammaTable;
33              if (img.data.header.colorType == PngImage.COLOR_TYPE_GRAY || 
34                  img.data.header.colorType == PngImage.COLOR_TYPE_RGB) {
35                  Chunk_tRNS trans = (Chunk_tRNS)img.getChunk(Chunk.tRNS);
36                  if (trans != null) {
37                      b.trans = trans.rgb;
38                      b.translow = trans.rgb_low;
39                      b.transgray = trans.r;
40                  }
41              }
42              return b;
43          } catch (Exception e) {
44              throw new PngException("Error loading " + clsname);
45          }
46      }
47  }
48