~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/com/sun/imageio/plugins/jpeg/JPEGImageWriterSpi.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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.
 
4
 *
 
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.
 
10
 *
 
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).
 
16
 *
 
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.
 
20
 *
 
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
 
23
 * questions.
 
24
 */
 
25
 
 
26
package com.sun.imageio.plugins.jpeg;
 
27
 
 
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;
 
35
 
 
36
import java.awt.image.ColorModel;
 
37
import java.awt.image.IndexColorModel;
 
38
import java.awt.image.SampleModel;
 
39
import java.util.Locale;
 
40
 
 
41
public class JPEGImageWriterSpi extends ImageWriterSpi {
 
42
 
 
43
    private static String [] readerSpiNames = 
 
44
        {"com.sun.imageio.plugins.jpeg.JPEGImageReaderSpi"};
 
45
 
 
46
    private boolean registered = false;
 
47
    
 
48
    public JPEGImageWriterSpi() {
 
49
        super(JPEG.vendor,
 
50
              JPEG.version,
 
51
              JPEG.names,
 
52
              JPEG.suffixes,
 
53
              JPEG.MIMETypes,
 
54
              "com.sun.imageio.plugins.jpeg.JPEGImageWriter",
 
55
              new Class[] { ImageOutputStream.class },
 
56
              readerSpiNames,
 
57
              true,
 
58
              JPEG.nativeStreamMetadataFormatName,
 
59
              JPEG.nativeStreamMetadataFormatClassName,
 
60
              null, null,
 
61
              true,
 
62
              JPEG.nativeImageMetadataFormatName,
 
63
              JPEG.nativeImageMetadataFormatClassName,
 
64
              null, null
 
65
              );
 
66
    }
 
67
 
 
68
    public String getDescription(Locale locale) {
 
69
        return "Standard JPEG Image Writer (not implemented)";
 
70
    }
 
71
 
 
72
    public void onRegistration(ServiceRegistry registry,
 
73
                               Class<?> category) {
 
74
        if (registered) {
 
75
            return;
 
76
        }
 
77
    /*
 
78
        try {
 
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);
 
84
            return;
 
85
        }
 
86
     */
 
87
 
 
88
        registered = true;
 
89
    }
 
90
 
 
91
    public boolean isFormatLossless() {
 
92
        return false;
 
93
    }
 
94
 
 
95
    public boolean canEncodeImage(ImageTypeSpecifier type) {
 
96
        SampleModel sampleModel = type.getSampleModel();
 
97
 
 
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];
 
104
            }
 
105
        }
 
106
 
 
107
        // 4450894: Ensure bitDepth is between 1 and 8
 
108
        if (bitDepth < 1 || bitDepth > 8) {
 
109
            return false;
 
110
        }
 
111
 
 
112
        return true;
 
113
    }
 
114
 
 
115
    public ImageWriter createWriterInstance(Object extension)
 
116
        throws IIOException {
 
117
        return new JPEGImageWriter(this);
 
118
    }
 
119
}