< prev index next >

src/java.desktop/macosx/classes/sun/java2d/OSXOffScreenSurfaceData.java

Print this page


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


 154             case BufferedImage.TYPE_BYTE_GRAY:
 155                 sData = createDataBC(bufImg, SurfaceType.ByteGray, 0);
 156                 break;
 157             case BufferedImage.TYPE_USHORT_GRAY:
 158                 sData = createDataSC(bufImg, SurfaceType.UshortGray, null);
 159                 break;
 160             case BufferedImage.TYPE_BYTE_BINARY:
 161             case BufferedImage.TYPE_CUSTOM:
 162             default: {
 163                 Raster raster = bufImg.getRaster();
 164 
 165                 // we try to fit a custom image into one of the predefined BufferedImages (BufferedImage does that
 166                 // first, we further refine it here)
 167                 // we can do that because a pointer in C is a pointer (pixel pointer not dependent on DataBuffer type)
 168                 SampleModel sm = bufImg.getSampleModel();
 169                 SurfaceType sType = SurfaceType.Custom;
 170                 int transferType = cm.getTransferType();
 171                 int pixelSize = cm.getPixelSize();
 172                 int numOfComponents = cm.getNumColorComponents();
 173                 if ((numOfComponents == 3) && (cm instanceof ComponentColorModel) && (sm instanceof PixelInterleavedSampleModel)) {
 174                     int sizes[] = cm.getComponentSize();
 175                     boolean validsizes = (sizes[0] == 8) && (sizes[1] == 8) && (sizes[2] == 8);
 176                     int[] offs = ((ComponentSampleModel) sm).getBandOffsets();
 177                     int numBands = raster.getNumBands();
 178                     boolean bigendian = (offs[0] == numBands - 3) && (offs[1] == numBands - 2) && (offs[2] == numBands - 1);
 179                     boolean littleendian = (offs[0] == numBands - 1) && (offs[1] == numBands - 2) && (offs[2] == numBands - 3);
 180 
 181                     if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_INT)) {
 182                         if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
 183                             try {
 184                                 sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB_PRE);
 185                             } catch (ClassCastException e) {
 186                                 sData = null;
 187                             }
 188                         } else if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {
 189                             try {
 190                                 sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB);
 191                             } catch (ClassCastException e) {
 192                                 sData = null;
 193                             }
 194                         } else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {


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


 154             case BufferedImage.TYPE_BYTE_GRAY:
 155                 sData = createDataBC(bufImg, SurfaceType.ByteGray, 0);
 156                 break;
 157             case BufferedImage.TYPE_USHORT_GRAY:
 158                 sData = createDataSC(bufImg, SurfaceType.UshortGray, null);
 159                 break;
 160             case BufferedImage.TYPE_BYTE_BINARY:
 161             case BufferedImage.TYPE_CUSTOM:
 162             default: {
 163                 Raster raster = bufImg.getRaster();
 164 
 165                 // we try to fit a custom image into one of the predefined BufferedImages (BufferedImage does that
 166                 // first, we further refine it here)
 167                 // we can do that because a pointer in C is a pointer (pixel pointer not dependent on DataBuffer type)
 168                 SampleModel sm = bufImg.getSampleModel();
 169                 SurfaceType sType = SurfaceType.Custom;
 170                 int transferType = cm.getTransferType();
 171                 int pixelSize = cm.getPixelSize();
 172                 int numOfComponents = cm.getNumColorComponents();
 173                 if ((numOfComponents == 3) && (cm instanceof ComponentColorModel) && (sm instanceof PixelInterleavedSampleModel)) {
 174                     int[] sizes = cm.getComponentSize();
 175                     boolean validsizes = (sizes[0] == 8) && (sizes[1] == 8) && (sizes[2] == 8);
 176                     int[] offs = ((ComponentSampleModel) sm).getBandOffsets();
 177                     int numBands = raster.getNumBands();
 178                     boolean bigendian = (offs[0] == numBands - 3) && (offs[1] == numBands - 2) && (offs[2] == numBands - 1);
 179                     boolean littleendian = (offs[0] == numBands - 1) && (offs[1] == numBands - 2) && (offs[2] == numBands - 3);
 180 
 181                     if ((pixelSize == 32) && (transferType == DataBuffer.TYPE_INT)) {
 182                         if (validsizes && bigendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {
 183                             try {
 184                                 sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB_PRE);
 185                             } catch (ClassCastException e) {
 186                                 sData = null;
 187                             }
 188                         } else if (validsizes && bigendian && cm.hasAlpha() && sizes[3] == 8) {
 189                             try {
 190                                 sData = createDataIC(bufImg, sType, BufferedImage.TYPE_INT_ARGB);
 191                             } catch (ClassCastException e) {
 192                                 sData = null;
 193                             }
 194                         } else if (validsizes && littleendian && cm.hasAlpha() && cm.isAlphaPremultiplied() && sizes[3] == 8) {


< prev index next >