com.sun.javafx.iio.jpeg.JPEGImageLoader Maven / Gradle / Ivy
/*
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.javafx.iio.jpeg;
import com.sun.javafx.iio.ImageFrame;
import com.sun.javafx.iio.ImageMetadata;
import com.sun.javafx.iio.ImageStorage.ImageType;
import com.sun.glass.utils.NativeLibLoader;
import com.sun.javafx.iio.common.ImageLoaderImpl;
import com.sun.javafx.iio.common.ImageTools;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
public class JPEGImageLoader extends ImageLoaderImpl {
// IJG Color codes.
public static final int JCS_UNKNOWN = 0; // error/unspecified
public static final int JCS_GRAYSCALE = 1; // monochrome
public static final int JCS_RGB = 2; // red/green/blue
public static final int JCS_YCbCr = 3; // Y/Cb/Cr (also known as YUV)
public static final int JCS_CMYK = 4; // C/M/Y/K
public static final int JCS_YCC = 5; // PhotoYCC
public static final int JCS_RGBA = 6; // RGB-Alpha
public static final int JCS_YCbCrA = 7; // Y/Cb/Cr/Alpha
// 8 and 9 were old "Legacy" codes which the old code never identified
// on reading anyway. Support for writing them is being dropped, too.
public static final int JCS_YCCA = 10; // PhotoYCC-Alpha
public static final int JCS_YCCK = 11; // Y/Cb/Cr/K
/**
* The following variable contains a pointer to the IJG library
* structure for this reader. It is assigned in the constructor
* and then is passed in to every native call. It is set to 0
* by dispose to avoid disposing twice.
*/
private long structPointer = 0L;
/** Set by setInputAttributes native code callback */
private int inWidth;
/** Set by setInputAttributes native code callback */
private int inHeight;
/**
* Set by setInputAttributes native code callback. A modified
* IJG+NIFTY colorspace code.
*/
private int inColorSpaceCode;
/**
* Set by setInputAttributes native code callback. A modified
* IJG+NIFTY colorspace code.
*/
private int outColorSpaceCode;
/** Set by setInputAttributes native code callback */
private byte[] iccData;
/** Set by setOutputAttributes native code callback. */
private int outWidth;
/** Set by setOutputAttributes native code callback. */
private int outHeight;
private ImageType outImageType;
private boolean isDisposed = false;
private Lock accessLock = new Lock();
/** Sets up static C structures. */
private static native void initJPEGMethodIDs(Class inputStreamClass);
private static native void disposeNative(long structPointer);
/** Sets up per-reader C structure and returns a pointer to it. */
private native long initDecompressor(InputStream stream) throws IOException;
/** Sets output color space and scale factor.
* Returns number of components which native decoder
* will produce for requested output color space.
*/
private native int startDecompression(long structPointer,
int outColorSpaceCode, int scaleNum, int scaleDenom);
private native boolean decompressIndirect(long structPointer, boolean reportProgress, byte[] array) throws IOException;
static {
@SuppressWarnings("removal")
var dummy = AccessController.doPrivileged((PrivilegedAction
© 2015 - 2024 Weber Informatics LLC | Privacy Policy