2
* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
26
package com.sun.imageio.plugins.jpeg;
28
import javax.imageio.spi.ImageWriterSpi;
29
import javax.imageio.spi.ServiceRegistry;
30
import javax.imageio.spi.IIORegistry;
31
import javax.imageio.stream.ImageOutputStream;
32
import javax.imageio.ImageWriter;
33
import javax.imageio.ImageTypeSpecifier;
34
import javax.imageio.IIOException;
36
import java.awt.image.ColorModel;
37
import java.awt.image.IndexColorModel;
38
import java.awt.image.SampleModel;
39
import java.util.Locale;
41
public class JPEGImageWriterSpi extends ImageWriterSpi {
43
private static String [] readerSpiNames =
44
{"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"};
46
private boolean registered = false;
48
public JPEGImageWriterSpi() {
54
"com.sun.imageio.plugins.jpeg.JPEGImageWriter",
55
new Class[] { ImageOutputStream.class },
58
JPEG.nativeStreamMetadataFormatName,
59
JPEG.nativeStreamMetadataFormatClassName,
62
JPEG.nativeImageMetadataFormatName,
63
JPEG.nativeImageMetadataFormatClassName,
68
public String getDescription(Locale locale) {
69
return "Standard JPEG Image Writer (not implemented)";
72
public void onRegistration(ServiceRegistry registry,
79
java.security.AccessController.doPrivileged(
80
new sun.security.action.LoadLibraryAction("jpeg"));
81
} catch (Throwable e) { // Fail on any Throwable
82
// if it can't be loaded, deregister and return
83
registry.deregisterServiceProvider(this);
91
public boolean isFormatLossless() {
95
public boolean canEncodeImage(ImageTypeSpecifier type) {
96
SampleModel sampleModel = type.getSampleModel();
98
// Find the maximum bit depth across all channels
99
int[] sampleSize = sampleModel.getSampleSize();
100
int bitDepth = sampleSize[0];
101
for (int i = 1; i < sampleSize.length; i++) {
102
if (sampleSize[i] > bitDepth) {
103
bitDepth = sampleSize[i];
107
// 4450894: Ensure bitDepth is between 1 and 8
108
if (bitDepth < 1 || bitDepth > 8) {
115
public ImageWriter createWriterInstance(Object extension)
116
throws IIOException {
117
return new JPEGImageWriter(this);