< prev index next >

src/java.desktop/share/classes/sun/awt/image/JPEGImageDecoder.java

Print this page
rev 55657 : 8227587: Add internal privileged System.loadLibrary
Reviewed-by: rriggs
   1 /*
   2  * Copyright (c) 1995, 2018, 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


  36 import java.io.InputStream;
  37 import java.io.IOException;
  38 import java.awt.image.*;
  39 
  40 /**
  41  * JPEG Image converter
  42  *
  43  * @author Jim Graham
  44  */
  45 public class JPEGImageDecoder extends ImageDecoder {
  46     private static ColorModel RGBcolormodel;
  47     private static ColorModel ARGBcolormodel;
  48     private static ColorModel Graycolormodel;
  49 
  50     private static final Class<?> InputStreamClass = InputStream.class;
  51     private static native void initIDs(Class<?> InputStreamClass);
  52 
  53     private ColorModel colormodel;
  54 
  55     static {
  56         java.security.AccessController.doPrivileged(
  57             new java.security.PrivilegedAction<Void>() {
  58                 public Void run() {
  59                     System.loadLibrary("javajpeg");
  60                     return null;
  61                 }
  62             });
  63         initIDs(InputStreamClass);
  64         RGBcolormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
  65         ARGBcolormodel = ColorModel.getRGBdefault();
  66         byte[] g = new byte[256];
  67         for (int i = 0; i < 256; i++) {
  68             g[i] = (byte) i;
  69         }
  70         Graycolormodel = new IndexColorModel(8, 256, g, g, g);
  71     }
  72 
  73     private native void readImage(InputStream is, byte[] buf)
  74         throws ImageFormatException, IOException;
  75 
  76     Hashtable<String, Object> props = new Hashtable<>();
  77 
  78     public JPEGImageDecoder(InputStreamImageSource src, InputStream is) {
  79         super(src, is);
  80     }
  81 
  82     /**


   1 /*
   2  * Copyright (c) 1995, 2019, 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


  36 import java.io.InputStream;
  37 import java.io.IOException;
  38 import java.awt.image.*;
  39 
  40 /**
  41  * JPEG Image converter
  42  *
  43  * @author Jim Graham
  44  */
  45 public class JPEGImageDecoder extends ImageDecoder {
  46     private static ColorModel RGBcolormodel;
  47     private static ColorModel ARGBcolormodel;
  48     private static ColorModel Graycolormodel;
  49 
  50     private static final Class<?> InputStreamClass = InputStream.class;
  51     private static native void initIDs(Class<?> InputStreamClass);
  52 
  53     private ColorModel colormodel;
  54 
  55     static {
  56         jdk.internal.access.SharedSecrets.getJavaLangAccess().loadLibrary("javajpeg");






  57         initIDs(InputStreamClass);
  58         RGBcolormodel = new DirectColorModel(24, 0xff0000, 0xff00, 0xff);
  59         ARGBcolormodel = ColorModel.getRGBdefault();
  60         byte[] g = new byte[256];
  61         for (int i = 0; i < 256; i++) {
  62             g[i] = (byte) i;
  63         }
  64         Graycolormodel = new IndexColorModel(8, 256, g, g, g);
  65     }
  66 
  67     private native void readImage(InputStream is, byte[] buf)
  68         throws ImageFormatException, IOException;
  69 
  70     Hashtable<String, Object> props = new Hashtable<>();
  71 
  72     public JPEGImageDecoder(InputStreamImageSource src, InputStream is) {
  73         super(src, is);
  74     }
  75 
  76     /**


< prev index next >