5
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
6
* (the "License"); you may not use this file except in compliance with
7
7
* the License. You may obtain a copy of the License at
9
9
* http://www.apache.org/licenses/LICENSE-2.0
11
11
* Unless required by applicable law or agreed to in writing, software
12
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
38
import com.sun.image.codec.jpeg.JPEGEncodeParam;
41
* ImageWriter implementation that uses the internal TIFF codec to
41
* ImageWriter implementation that uses the internal TIFF codec to
42
42
* write TIFF files.
44
* @version $Id: TIFFImageWriter.java 750418 2009-03-05 11:03:54Z vhennebert $
46
46
public class TIFFImageWriter extends AbstractImageWriter {
70
70
* @param encodeParams the TIFF encoding parameters
71
71
* @param image the image to be encoded
73
private void updateParams(TIFFEncodeParam encodeParams, ImageWriterParams params,
73
private void updateParams(TIFFEncodeParam encodeParams, ImageWriterParams params,
74
74
RenderedImage image) {
75
75
if (encodeParams.getCompression() == TIFFEncodeParam.COMPRESSION_JPEG_TTN2) {
76
76
ColorModel cm = image.getColorModel();
99
99
colorID = JPEGEncodeParam.COLOR_ID_CMYK;
102
//TODO Don't know how to determine whether image is PYCC or not
102
//TODO Don't know how to determine whether image is PYCC or not
103
103
//(see JPEGEncodeParam)
104
104
colorID = JPEGEncodeParam.COLOR_ID_UNKNOWN;
106
106
JPEGEncodeParam jpegParam = JPEGCodec.getDefaultJPEGEncodeParam(
107
107
image.getData(), colorID);
108
108
if (params.getJPEGQuality() != null || params.getJPEGForceBaseline() != null) {
109
float qual = (params.getJPEGQuality() != null
109
float qual = (params.getJPEGQuality() != null
110
110
? params.getJPEGQuality().floatValue() : 0.75f);
111
111
boolean force = (params.getJPEGForceBaseline() != null
112
112
? params.getJPEGForceBaseline().booleanValue() : false);
113
jpegParam.setQuality(qual, force);
113
jpegParam.setQuality(qual, force);
115
115
encodeParams.setJPEGEncodeParam(jpegParam);
136
136
throw new UnsupportedOperationException("Compression method not supported: "
137
137
+ params.getCompressionMethod());
140
140
if (params.getResolution() != null) {
141
141
// Set target resolution
142
142
float pixSzMM = 25.4f / params.getResolution().floatValue();
143
143
// num Pixs in 100 Meters
144
int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
144
int numPix = (int)(((1000 * 100) / pixSzMM) + 0.5);
145
145
int denom = 100 * 100; // Centimeters per 100 Meters;
146
146
long [] rational = {numPix, denom};
147
147
TIFFField [] fields = {
148
new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
149
TIFFField.TIFF_SHORT, 1,
148
new TIFFField(TIFFImageDecoder.TIFF_RESOLUTION_UNIT,
149
TIFFField.TIFF_SHORT, 1,
150
150
new char[] {(char)3}),
151
new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
152
TIFFField.TIFF_RATIONAL, 1,
151
new TIFFField(TIFFImageDecoder.TIFF_X_RESOLUTION,
152
TIFFField.TIFF_RATIONAL, 1,
153
153
new long[][] {rational}),
154
new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
155
TIFFField.TIFF_RATIONAL, 1,
156
new long[][] {rational})
154
new TIFFField(TIFFImageDecoder.TIFF_Y_RESOLUTION,
155
TIFFField.TIFF_RATIONAL, 1,
156
new long[][] {rational})
158
158
encodeParams.setExtraFields(fields);
161
161
return encodeParams;
165
165
* @see ImageWriter#getMIMEType()
167
167
public String getMIMEType() {
168
168
return "image/tiff";
172
172
* @see org.apache.xmlgraphics.image.writer.ImageWriter#createMultiImageWriter(
173
173
* java.io.OutputStream)
187
187
private TIFFEncodeParam encodeParams;
188
188
private TIFFImageEncoder encoder;
189
189
private Object context;
191
191
public TIFFMultiImageWriter(OutputStream out) throws IOException {
195
195
public void writeImage(RenderedImage image, ImageWriterParams params) throws IOException {
196
196
if (encoder == null) {
197
197
encodeParams = createTIFFEncodeParams(params);