< prev index next >

src/java.desktop/share/classes/java/awt/image/ComponentColorModel.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2017, 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 --- 1,7 ---- /* ! * Copyright (c) 1997, 2018, 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
*** 800,810 **** switch (transferType) { // Note: we do no clamping of the pixel data here - we // assume that the data is scaled properly case DataBuffer.TYPE_SHORT: { ! short sdata[] = (short[]) inData; float scalefactor = (float) ((1 << precision) - 1); if (needAlpha) { short s = sdata[numColorComponents]; if (s != (short) 0) { return (int) ((((float) sdata[idx]) / --- 800,810 ---- switch (transferType) { // Note: we do no clamping of the pixel data here - we // assume that the data is scaled properly case DataBuffer.TYPE_SHORT: { ! short[] sdata = (short[]) inData; float scalefactor = (float) ((1 << precision) - 1); if (needAlpha) { short s = sdata[numColorComponents]; if (s != (short) 0) { return (int) ((((float) sdata[idx]) /
*** 815,825 **** } else { return (int) ((sdata[idx] / 32767.0f) * scalefactor + 0.5f); } } case DataBuffer.TYPE_FLOAT: { ! float fdata[] = (float[]) inData; float scalefactor = (float) ((1 << precision) - 1); if (needAlpha) { float f = fdata[numColorComponents]; if (f != 0.0f) { return (int) (((fdata[idx] / f) * scalefactor) + 0.5f); --- 815,825 ---- } else { return (int) ((sdata[idx] / 32767.0f) * scalefactor + 0.5f); } } case DataBuffer.TYPE_FLOAT: { ! float[] fdata = (float[]) inData; float scalefactor = (float) ((1 << precision) - 1); if (needAlpha) { float f = fdata[numColorComponents]; if (f != 0.0f) { return (int) (((fdata[idx] / f) * scalefactor) + 0.5f);
*** 829,839 **** } else { return (int) (fdata[idx] * scalefactor + 0.5f); } } case DataBuffer.TYPE_DOUBLE: { ! double ddata[] = (double[]) inData; double scalefactor = (double) ((1 << precision) - 1); if (needAlpha) { double d = ddata[numColorComponents]; if (d != 0.0) { return (int) (((ddata[idx] / d) * scalefactor) + 0.5); --- 829,839 ---- } else { return (int) (fdata[idx] * scalefactor + 0.5f); } } case DataBuffer.TYPE_DOUBLE: { ! double[] ddata = (double[]) inData; double scalefactor = (double) ((1 << precision) - 1); if (needAlpha) { double d = ddata[numColorComponents]; if (d != 0.0) { return (int) (((ddata[idx] / d) * scalefactor) + 0.5);
*** 843,868 **** } else { return (int) (ddata[idx] * scalefactor + 0.5); } } case DataBuffer.TYPE_BYTE: ! byte bdata[] = (byte[])inData; comp = bdata[idx] & mask; precision = 8; if (needAlpha) { alp = bdata[numColorComponents] & mask; } break; case DataBuffer.TYPE_USHORT: ! short usdata[] = (short[])inData; comp = usdata[idx] & mask; if (needAlpha) { alp = usdata[numColorComponents] & mask; } break; case DataBuffer.TYPE_INT: ! int idata[] = (int[])inData; comp = idata[idx]; if (needAlpha) { alp = idata[numColorComponents]; } break; --- 843,868 ---- } else { return (int) (ddata[idx] * scalefactor + 0.5); } } case DataBuffer.TYPE_BYTE: ! byte[] bdata = (byte[])inData; comp = bdata[idx] & mask; precision = 8; if (needAlpha) { alp = bdata[numColorComponents] & mask; } break; case DataBuffer.TYPE_USHORT: ! short[] usdata = (short[])inData; comp = usdata[idx] & mask; if (needAlpha) { alp = usdata[numColorComponents] & mask; } break; case DataBuffer.TYPE_INT: ! int[] idata = (int[])inData; comp = idata[idx]; if (needAlpha) { alp = idata[numColorComponents]; } break;
*** 1052,1082 **** int aIdx = numColorComponents; int mask = (1 << nBits[aIdx]) - 1; switch (transferType) { case DataBuffer.TYPE_SHORT: ! short sdata[] = (short[])inData; alpha = (int) ((sdata[aIdx] / 32767.0f) * 255.0f + 0.5f); return alpha; case DataBuffer.TYPE_FLOAT: ! float fdata[] = (float[])inData; alpha = (int) (fdata[aIdx] * 255.0f + 0.5f); return alpha; case DataBuffer.TYPE_DOUBLE: ! double ddata[] = (double[])inData; alpha = (int) (ddata[aIdx] * 255.0 + 0.5); return alpha; case DataBuffer.TYPE_BYTE: ! byte bdata[] = (byte[])inData; alpha = bdata[aIdx] & mask; break; case DataBuffer.TYPE_USHORT: ! short usdata[] = (short[])inData; alpha = usdata[aIdx] & mask; break; case DataBuffer.TYPE_INT: ! int idata[] = (int[])inData; alpha = idata[aIdx]; break; default: throw new UnsupportedOperationException("This method has not "+ --- 1052,1082 ---- int aIdx = numColorComponents; int mask = (1 << nBits[aIdx]) - 1; switch (transferType) { case DataBuffer.TYPE_SHORT: ! short[] sdata = (short[])inData; alpha = (int) ((sdata[aIdx] / 32767.0f) * 255.0f + 0.5f); return alpha; case DataBuffer.TYPE_FLOAT: ! float[] fdata = (float[])inData; alpha = (int) (fdata[aIdx] * 255.0f + 0.5f); return alpha; case DataBuffer.TYPE_DOUBLE: ! double[] ddata = (double[])inData; alpha = (int) (ddata[aIdx] * 255.0 + 0.5); return alpha; case DataBuffer.TYPE_BYTE: ! byte[] bdata = (byte[])inData; alpha = bdata[aIdx] & mask; break; case DataBuffer.TYPE_USHORT: ! short[] usdata = (short[])inData; alpha = usdata[aIdx] & mask; break; case DataBuffer.TYPE_INT: ! int[] idata = (int[])inData; alpha = idata[aIdx]; break; default: throw new UnsupportedOperationException("This method has not "+
*** 1199,1209 **** // Handle SHORT, FLOAT, & DOUBLE here switch(transferType) { case DataBuffer.TYPE_SHORT: { ! short sdata[]; if (pixel == null) { sdata = new short[numComponents]; } else { sdata = (short[])pixel; } --- 1199,1209 ---- // Handle SHORT, FLOAT, & DOUBLE here switch(transferType) { case DataBuffer.TYPE_SHORT: { ! short[] sdata; if (pixel == null) { sdata = new short[numComponents]; } else { sdata = (short[])pixel; }
*** 1262,1272 **** } } sdata[0] = (short) (gray * factor + 0.5f); } else { factor = 1.0f / 255.0f; ! float norm[] = new float[3]; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (nonStdScale) { --- 1262,1272 ---- } } sdata[0] = (short) (gray * factor + 0.5f); } else { factor = 1.0f / 255.0f; ! float[] norm = new float[3]; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (nonStdScale) {
*** 1298,1308 **** } return sdata; } case DataBuffer.TYPE_FLOAT: { ! float fdata[]; if (pixel == null) { fdata = new float[numComponents]; } else { fdata = (float[])pixel; } --- 1298,1308 ---- } return sdata; } case DataBuffer.TYPE_FLOAT: { ! float[] fdata; if (pixel == null) { fdata = new float[numComponents]; } else { fdata = (float[])pixel; }
*** 1355,1365 **** if (isAlphaPremultiplied) { fdata[0] *= fdata[1]; } } } else { ! float norm[] = new float[3]; factor = 1.0f / 255.0f; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); --- 1355,1365 ---- if (isAlphaPremultiplied) { fdata[0] *= fdata[1]; } } } else { ! float[] norm = new float[3]; factor = 1.0f / 255.0f; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm);
*** 1379,1389 **** } return fdata; } case DataBuffer.TYPE_DOUBLE: { ! double ddata[]; if (pixel == null) { ddata = new double[numComponents]; } else { ddata = (double[])pixel; } --- 1379,1389 ---- } return fdata; } case DataBuffer.TYPE_DOUBLE: { ! double[] ddata; if (pixel == null) { ddata = new double[numComponents]; } else { ddata = (double[])pixel; }
*** 1437,1447 **** ddata[0] *= ddata[1]; } } } else { float factor = 1.0f / 255.0f; ! float norm[] = new float[3]; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (supportsAlpha) { --- 1437,1447 ---- ddata[0] *= ddata[1]; } } } else { float factor = 1.0f / 255.0f; ! float[] norm = new float[3]; norm[0] = red * factor; norm[1] = grn * factor; norm[2] = blu * factor; norm = colorSpace.fromRGB(norm); if (supportsAlpha) {
*** 1464,1474 **** } // Handle BYTE, USHORT, & INT here //REMIND: maybe more efficient not to use int array for //DataBuffer.TYPE_USHORT and DataBuffer.TYPE_INT ! int intpixel[]; if (transferType == DataBuffer.TYPE_INT && pixel != null) { intpixel = (int[])pixel; } else { intpixel = new int[numComponents]; --- 1464,1474 ---- } // Handle BYTE, USHORT, & INT here //REMIND: maybe more efficient not to use int array for //DataBuffer.TYPE_USHORT and DataBuffer.TYPE_INT ! int[] intpixel; if (transferType == DataBuffer.TYPE_INT && pixel != null) { intpixel = (int[])pixel; } else { intpixel = new int[numComponents];
*** 1613,1623 **** } } switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte bdata[]; if (pixel == null) { bdata = new byte[numComponents]; } else { bdata = (byte[])pixel; } --- 1613,1623 ---- } } switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte[] bdata; if (pixel == null) { bdata = new byte[numComponents]; } else { bdata = (byte[])pixel; }
*** 1625,1635 **** bdata[i] = (byte)(0xff&intpixel[i]); } return bdata; } case DataBuffer.TYPE_USHORT:{ ! short sdata[]; if (pixel == null) { sdata = new short[numComponents]; } else { sdata = (short[])pixel; } --- 1625,1635 ---- bdata[i] = (byte)(0xff&intpixel[i]); } return bdata; } case DataBuffer.TYPE_USHORT:{ ! short[] sdata; if (pixel == null) { sdata = new short[numComponents]; } else { sdata = (short[])pixel; }
*** 1739,1749 **** * not null and is not large enough to hold all the color and alpha * components (starting at offset), or if {@code pixel} is not large * enough to hold a pixel value for this ColorModel. */ public int[] getComponents(Object pixel, int[] components, int offset) { ! int intpixel[]; if (needScaleInit) { initScale(); } if (noUnnorm) { throw new --- 1739,1749 ---- * not null and is not large enough to hold all the color and alpha * components (starting at offset), or if {@code pixel} is not large * enough to hold a pixel value for this ColorModel. */ public int[] getComponents(Object pixel, int[] components, int offset) { ! int[] intpixel; if (needScaleInit) { initScale(); } if (noUnnorm) { throw new
*** 2055,2065 **** } Object pixel = getDataElements(normComponents, normOffset, null); switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte bpixel[] = (byte[]) pixel; return bpixel[0] & 0xff; } case DataBuffer.TYPE_USHORT: { short[] uspixel = (short[]) pixel; --- 2055,2065 ---- } Object pixel = getDataElements(normComponents, normOffset, null); switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte[] bpixel = (byte[]) pixel; return bpixel[0] & 0xff; } case DataBuffer.TYPE_USHORT: { short[] uspixel = (short[]) pixel;
*** 2466,2477 **** int rY = raster.getMinY(); int rX; if (isAlphaPremultiplied) { switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte pixel[] = null; ! byte zpixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (byte[])raster.getDataElements(rX, rY, --- 2466,2477 ---- int rY = raster.getMinY(); int rX; if (isAlphaPremultiplied) { switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte[] pixel = null; ! byte[] zpixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (byte[])raster.getDataElements(rX, rY,
*** 2493,2504 **** } } } break; case DataBuffer.TYPE_USHORT: { ! short pixel[] = null; ! short zpixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY, --- 2493,2504 ---- } } } break; case DataBuffer.TYPE_USHORT: { ! short[] pixel = null; ! short[] zpixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY,
*** 2521,2532 **** } } } break; case DataBuffer.TYPE_INT: { ! int pixel[] = null; ! int zpixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (int[])raster.getDataElements(rX, rY, --- 2521,2532 ---- } } } break; case DataBuffer.TYPE_INT: { ! int[] pixel = null; ! int[] zpixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (int[])raster.getDataElements(rX, rY,
*** 2548,2559 **** } } } break; case DataBuffer.TYPE_SHORT: { ! short pixel[] = null; ! short zpixel[] = null; float alphaScale = 1.0f / 32767.0f; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[]) raster.getDataElements(rX, rY, --- 2548,2559 ---- } } } break; case DataBuffer.TYPE_SHORT: { ! short[] pixel = null; ! short[] zpixel = null; float alphaScale = 1.0f / 32767.0f; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[]) raster.getDataElements(rX, rY,
*** 2575,2586 **** } } } break; case DataBuffer.TYPE_FLOAT: { ! float pixel[] = null; ! float zpixel[] = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (float[]) raster.getDataElements(rX, rY, pixel); --- 2575,2586 ---- } } } break; case DataBuffer.TYPE_FLOAT: { ! float[] pixel = null; ! float[] zpixel = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (float[]) raster.getDataElements(rX, rY, pixel);
*** 2600,2611 **** } } } break; case DataBuffer.TYPE_DOUBLE: { ! double pixel[] = null; ! double zpixel[] = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (double[]) raster.getDataElements(rX, rY, pixel); --- 2600,2611 ---- } } } break; case DataBuffer.TYPE_DOUBLE: { ! double[] pixel = null; ! double[] zpixel = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (double[]) raster.getDataElements(rX, rY, pixel);
*** 2633,2643 **** } else { // We are premultiplied and want to divide it out switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte pixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (byte[])raster.getDataElements(rX, rY, --- 2633,2643 ---- } else { // We are premultiplied and want to divide it out switch (transferType) { case DataBuffer.TYPE_BYTE: { ! byte[] pixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (byte[])raster.getDataElements(rX, rY,
*** 2654,2664 **** } } } break; case DataBuffer.TYPE_USHORT: { ! short pixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY, --- 2654,2664 ---- } } } break; case DataBuffer.TYPE_USHORT: { ! short[] pixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY,
*** 2675,2685 **** } } } break; case DataBuffer.TYPE_INT: { ! int pixel[] = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (int[])raster.getDataElements(rX, rY, --- 2675,2685 ---- } } } break; case DataBuffer.TYPE_INT: { ! int[] pixel = null; float alphaScale = 1.0f / ((float) ((1<<nBits[aIdx]) - 1)); for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (int[])raster.getDataElements(rX, rY,
*** 2696,2706 **** } } } break; case DataBuffer.TYPE_SHORT: { ! short pixel[] = null; float alphaScale = 1.0f / 32767.0f; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY, --- 2696,2706 ---- } } } break; case DataBuffer.TYPE_SHORT: { ! short[] pixel = null; float alphaScale = 1.0f / 32767.0f; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (short[])raster.getDataElements(rX, rY,
*** 2717,2727 **** } } } break; case DataBuffer.TYPE_FLOAT: { ! float pixel[] = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (float[])raster.getDataElements(rX, rY, pixel); --- 2717,2727 ---- } } } break; case DataBuffer.TYPE_FLOAT: { ! float[] pixel = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (float[])raster.getDataElements(rX, rY, pixel);
*** 2736,2746 **** } } } break; case DataBuffer.TYPE_DOUBLE: { ! double pixel[] = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (double[])raster.getDataElements(rX, rY, pixel); --- 2736,2746 ---- } } } break; case DataBuffer.TYPE_DOUBLE: { ! double[] pixel = null; for (int y = 0; y < h; y++, rY++) { rX = rminX; for (int x = 0; x < w; x++, rX++) { pixel = (double[])raster.getDataElements(rX, rY, pixel);
< prev index next >