KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > it > stefanochizzolini > clown > documents > contents > entities > Image


1 /*
2   Copyright © 2006 Stefano Chizzolini. http://clown.stefanochizzolini.it
3
4   Contributors:
5     * Stefano Chizzolini (original code developer, info@stefanochizzolini.it):
6       contributed code is Copyright © 2006 by Stefano Chizzolini.
7
8   This file should be part of the source code distribution of "PDF Clown library"
9   (the Program): see the accompanying README files for more info.
10
11   This Program is free software; you can redistribute it and/or modify it under
12   the terms of the GNU General Public License as published by the Free Software
13   Foundation; either version 2 of the License, or (at your option) any later version.
14
15   This Program is distributed in the hope that it will be useful, but WITHOUT ANY
16   WARRANTY, either expressed or implied; without even the implied warranty of
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
18
19   You should have received a copy of the GNU General Public License along with this
20   Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
21
22   Redistribution and use, with or without modification, are permitted provided that such
23   redistributions retain the above copyright notice, license and disclaimer, along with
24   this list of conditions.
25 */

26
27 package it.stefanochizzolini.clown.documents.contents.entities;
28
29 import it.stefanochizzolini.clown.bytes.IInputStream;
30
31 /**
32   Abstract image object [PDF:1.6:4.8].
33 */

34 public abstract class Image
35   extends Entity
36 {
37   // <class>
38
// <static>
39
// <interface>
40
// <public>
41
public static Image get(
42     IInputStream stream
43     )
44   {
45     try
46     {
47       // Get the format identifier!
48
byte[] formatMarkerBytes = new byte[2];
49       stream.read(formatMarkerBytes);
50
51       // Is JPEG?
52
if(formatMarkerBytes[0] == (byte)0xFF
53         && formatMarkerBytes[1] == (byte)0xD8) // JPEG.
54
/*
55         NOTE: JPEG files are identified by a SOI (Start Of Image) marker [ISO 10918-1].
56       */

57       {return new JpegImage(stream);}
58       else // Unknown.
59
{return null;}
60     }
61     catch(Exception JavaDoc e)
62     {throw new RuntimeException JavaDoc(e);}
63   }
64   // </public>
65
// </interface>
66
// </static>
67

68   // <dynamic>
69
// <fields>
70
private int bitsPerComponent;
71   private int height;
72   private int width;
73
74   private IInputStream stream;
75   // </fields>
76

77   // <constructors>
78
protected Image(
79     IInputStream stream
80     )
81   {this.stream = stream;}
82   // </constructors>
83

84   // <interface>
85
// <public>
86
/**
87     Gets the number of bits per color component [PDF:1.6:4.8.2].
88   */

89   public int getBitsPerComponent(
90     )
91   {return bitsPerComponent;}
92
93   /**
94     Gets the height of the image in samples [PDF:1.6:4.8.2].
95   */

96   public int getHeight(
97     )
98   {return height;}
99
100   /**
101     Gets the width of the image in samples [PDF:1.6:4.8.2].
102   */

103   public int getWidth(
104     )
105   {return width;}
106   // </public>
107

108   // <protected>
109
/**
110     Sets the number of bits per color component [PDF:1.6:4.8.2].
111   */

112   protected void setBitsPerComponent(
113     int value
114     )
115   {bitsPerComponent = value;}
116
117   /**
118     Sets the height of the image in samples [PDF:1.6:4.8.2].
119   */

120   protected void setHeight(
121     int value
122     )
123   {height = value;}
124
125   /**
126     Sets the width of the image in samples [PDF:1.6:4.8.2].
127   */

128   protected void setWidth(
129     int value
130     )
131   {width = value;}
132
133   /**
134     Gets the underlying stream.
135   */

136   protected IInputStream getStream(
137     )
138   {return stream;}
139   // </protected>
140
// </interface>
141
// </dynamic>
142
// </class>
143
}
Popular Tags