0N/A/*
2362N/A * Copyright (c) 1995, 2003, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A/*-
0N/A * Reads JPEG images from an InputStream and reports the
0N/A * image data to an InputStreamImageSource object.
0N/A *
0N/A * The native implementation of the JPEG image decoder was adapted from
0N/A * release 6 of the free JPEG software from the Independent JPEG Group.
0N/A */
0N/Apackage sun.awt.image;
0N/A
0N/Aimport java.util.Vector;
0N/Aimport java.util.Hashtable;
0N/Aimport java.io.InputStream;
0N/Aimport java.io.IOException;
0N/Aimport java.awt.image.*;
0N/A
0N/A/**
0N/A * JPEG Image converter
0N/A *
0N/A * @author Jim Graham
0N/A */
0N/Apublic class JPEGImageDecoder extends ImageDecoder {
0N/A private static ColorModel RGBcolormodel;
0N/A private static ColorModel ARGBcolormodel;
0N/A private static ColorModel Graycolormodel;
0N/A
0N/A private static final Class InputStreamClass = InputStream.class;
0N/A private static native void initIDs(Class InputStreamClass);
0N/A
0N/A private ColorModel colormodel;
0N/A
0N/A static {
0N/A java.security.AccessController.doPrivileged(
0N/A new sun.security.action.LoadLibraryAction("jpeg"));
0N/A initIDs(InputStreamClass);
0N/A RGBcolormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
0N/A ARGBcolormodel = ColorModel.getRGBdefault();
0N/A byte g[] = new byte[256];
0N/A for (int i = 0; i < 256; i++) {
0N/A g[i] = (byte) i;
0N/A }
0N/A Graycolormodel = new IndexColorModel(8, 256, g, g, g);
0N/A }
0N/A
0N/A private native void readImage(InputStream is, byte buf[])
0N/A throws ImageFormatException, IOException;
0N/A
0N/A Hashtable props = new Hashtable();
0N/A
0N/A public JPEGImageDecoder(InputStreamImageSource src, InputStream is) {
0N/A super(src, is);
0N/A }
0N/A
0N/A /**
0N/A * An error has occurred. Throw an exception.
0N/A */
0N/A private static void error(String s1) throws ImageFormatException {
0N/A throw new ImageFormatException(s1);
0N/A }
0N/A
0N/A public boolean sendHeaderInfo(int width, int height,
0N/A boolean gray, boolean hasalpha,
0N/A boolean multipass)
0N/A {
0N/A setDimensions(width, height);
0N/A
0N/A setProperties(props);
0N/A if (gray) {
0N/A colormodel = Graycolormodel;
0N/A } else {
0N/A if (hasalpha) {
0N/A colormodel = ARGBcolormodel;
0N/A } else {
0N/A colormodel = RGBcolormodel;
0N/A }
0N/A }
0N/A
0N/A setColorModel(colormodel);
0N/A
0N/A int flags = hintflags;
0N/A if (!multipass) {
0N/A flags |= ImageConsumer.SINGLEPASS;
0N/A }
0N/A setHints(hintflags);
0N/A headerComplete();
0N/A
0N/A return true;
0N/A }
0N/A
0N/A public boolean sendPixels(int pixels[], int y) {
0N/A int count = setPixels(0, y, pixels.length, 1, colormodel,
0N/A pixels, 0, pixels.length);
0N/A if (count <= 0) {
0N/A aborted = true;
0N/A }
0N/A return !aborted;
0N/A }
0N/A
0N/A public boolean sendPixels(byte pixels[], int y) {
0N/A int count = setPixels(0, y, pixels.length, 1, colormodel,
0N/A pixels, 0, pixels.length);
0N/A if (count <= 0) {
0N/A aborted = true;
0N/A }
0N/A return !aborted;
0N/A }
0N/A
0N/A /**
0N/A * produce an image from the stream.
0N/A */
0N/A public void produceImage() throws IOException, ImageFormatException {
0N/A try {
0N/A readImage(input, new byte[1024]);
0N/A if (!aborted) {
0N/A imageComplete(ImageConsumer.STATICIMAGEDONE, true);
0N/A }
0N/A } catch (IOException e) {
0N/A if (!aborted) {
0N/A throw e;
0N/A }
0N/A } finally {
0N/A close();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The ImageConsumer hints flag for a JPEG image.
0N/A */
0N/A private static final int hintflags =
0N/A ImageConsumer.TOPDOWNLEFTRIGHT | ImageConsumer.COMPLETESCANLINES |
0N/A ImageConsumer.SINGLEFRAME;
0N/A}