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_sCAL.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_sCAL
8   extends Chunk
9   {
10      Chunk_sCAL()
11      {
12          super(sCAL);
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          int unit = in_data.readUnsignedByte();
29          if (unit != PngImage.UNIT_METER && unit != PngImage.UNIT_RADIAN)
30              throw new PngExceptionSoft("Illegal sCAL chunk unit specifier: " + unit);
31  
32          String pixelWidthStr = in_data.readString();
33          int limit = length - pixelWidthStr.length() + 2;
34          try {
35              double pixelWidth = in_data.parseFloatingPoint(pixelWidthStr);
36              double pixelHeight = in_data.parseFloatingPoint(in_data.readString(limit));
37              if (pixelWidth < 0 || pixelHeight < 0) throw new NumberFormatException();
38  
39              img.data.properties.put("pixel scale x", new Double(pixelWidth));
40              img.data.properties.put("pixel scale y", new Double(pixelHeight));
41              img.data.properties.put("pixel scale unit", new Integer(unit));
42          } catch (NumberFormatException e) {
43              throw new PngExceptionSoft("Bad floating point value in sCAL chunk");
44          }
45      }    
46  }