< prev index next >
src/java.desktop/share/classes/java/awt/image/DirectColorModel.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1995, 2013, 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) 1995, 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
*** 309,320 ****
* Given an int pixel in this ColorModel's ColorSpace, converts
* it to the default sRGB ColorSpace and returns the R, G, and B
* components as float values between 0.0 and 1.0.
*/
private float[] getDefaultRGBComponents(int pixel) {
! int components[] = getComponents(pixel, null, 0);
! float norm[] = getNormalizedComponents(components, 0, null, 0);
// Note that getNormalizedComponents returns non-premultiplied values
return colorSpace.toRGB(norm);
}
--- 309,320 ----
* Given an int pixel in this ColorModel's ColorSpace, converts
* it to the default sRGB ColorSpace and returns the R, G, and B
* components as float values between 0.0 and 1.0.
*/
private float[] getDefaultRGBComponents(int pixel) {
! int[] components = getComponents(pixel, null, 0);
! float[] norm = getNormalizedComponents(components, 0, null, 0);
// Note that getNormalizedComponents returns non-premultiplied values
return colorSpace.toRGB(norm);
}
*** 369,379 ****
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 0);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 0);
}
! float rgb[] = getDefaultRGBComponents(pixel);
return (int) (rgb[0] * 255.0f + 0.5f);
}
/**
* Returns the green color component for the specified pixel, scaled
--- 369,379 ----
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 0);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 0);
}
! float[] rgb = getDefaultRGBComponents(pixel);
return (int) (rgb[0] * 255.0f + 0.5f);
}
/**
* Returns the green color component for the specified pixel, scaled
*** 392,402 ****
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 1);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 1);
}
! float rgb[] = getDefaultRGBComponents(pixel);
return (int) (rgb[1] * 255.0f + 0.5f);
}
/**
* Returns the blue color component for the specified pixel, scaled
--- 392,402 ----
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 1);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 1);
}
! float[] rgb = getDefaultRGBComponents(pixel);
return (int) (rgb[1] * 255.0f + 0.5f);
}
/**
* Returns the blue color component for the specified pixel, scaled
*** 415,425 ****
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 2);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 2);
}
! float rgb[] = getDefaultRGBComponents(pixel);
return (int) (rgb[2] * 255.0f + 0.5f);
}
/**
* Returns the alpha component for the specified pixel, scaled
--- 415,425 ----
if (is_sRGB) {
return getsRGBComponentFromsRGB(pixel, 2);
} else if (is_LinearRGB) {
return getsRGBComponentFromLinearRGB(pixel, 2);
}
! float[] rgb = getDefaultRGBComponents(pixel);
return (int) (rgb[2] * 255.0f + 0.5f);
}
/**
* Returns the alpha component for the specified pixel, scaled
*** 455,465 ****
return (getAlpha(pixel) << 24)
| (getRed(pixel) << 16)
| (getGreen(pixel) << 8)
| (getBlue(pixel) << 0);
}
! float rgb[] = getDefaultRGBComponents(pixel);
return (getAlpha(pixel) << 24)
| (((int) (rgb[0] * 255.0f + 0.5f)) << 16)
| (((int) (rgb[1] * 255.0f + 0.5f)) << 8)
| (((int) (rgb[2] * 255.0f + 0.5f)) << 0);
}
--- 455,465 ----
return (getAlpha(pixel) << 24)
| (getRed(pixel) << 16)
| (getGreen(pixel) << 8)
| (getBlue(pixel) << 0);
}
! float[] rgb = getDefaultRGBComponents(pixel);
return (getAlpha(pixel) << 24)
| (((int) (rgb[0] * 255.0f + 0.5f)) << 16)
| (((int) (rgb[1] * 255.0f + 0.5f)) << 8)
| (((int) (rgb[2] * 255.0f + 0.5f)) << 0);
}
*** 497,515 ****
*/
public int getRed(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 497,515 ----
*/
public int getRed(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 550,568 ****
*/
public int getGreen(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 550,568 ----
*/
public int getGreen(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 603,621 ****
*/
public int getBlue(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 603,621 ----
*/
public int getBlue(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 653,671 ****
*/
public int getAlpha(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 653,671 ----
*/
public int getAlpha(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 701,719 ****
*/
public int getRGB(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 701,719 ----
*/
public int getRGB(Object inData) {
int pixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])inData;
pixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])inData;
pixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])inData;
pixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 756,766 ****
* @see SampleModel#setDataElements
*/
public Object getDataElements(int rgb, Object pixel) {
//REMIND: maybe more efficient not to use int array for
//DataBuffer.TYPE_USHORT and DataBuffer.TYPE_INT
! int intpixel[] = null;
if (transferType == DataBuffer.TYPE_INT &&
pixel != null) {
intpixel = (int[])pixel;
intpixel[0] = 0;
} else {
--- 756,766 ----
* @see SampleModel#setDataElements
*/
public Object getDataElements(int rgb, Object pixel) {
//REMIND: maybe more efficient not to use int array for
//DataBuffer.TYPE_USHORT and DataBuffer.TYPE_INT
! int[] intpixel = null;
if (transferType == DataBuffer.TYPE_INT &&
pixel != null) {
intpixel = (int[])pixel;
intpixel[0] = 0;
} else {
*** 874,894 ****
(grn << maskOffsets[1]) |
(blu << maskOffsets[2]);
switch (transferType) {
case DataBuffer.TYPE_BYTE: {
! byte bdata[];
if (pixel == null) {
bdata = new byte[1];
} else {
bdata = (byte[])pixel;
}
bdata[0] = (byte)(0xff&intpixel[0]);
return bdata;
}
case DataBuffer.TYPE_USHORT:{
! short sdata[];
if (pixel == null) {
sdata = new short[1];
} else {
sdata = (short[])pixel;
}
--- 874,894 ----
(grn << maskOffsets[1]) |
(blu << maskOffsets[2]);
switch (transferType) {
case DataBuffer.TYPE_BYTE: {
! byte[] bdata;
if (pixel == null) {
bdata = new byte[1];
} else {
bdata = (byte[])pixel;
}
bdata[0] = (byte)(0xff&intpixel[0]);
return bdata;
}
case DataBuffer.TYPE_USHORT:{
! short[] sdata;
if (pixel == null) {
sdata = new short[1];
} else {
sdata = (short[])pixel;
}
*** 977,995 ****
public final int[] getComponents(Object pixel, int[] components,
int offset) {
int intpixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte bdata[] = (byte[])pixel;
intpixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short sdata[] = (short[])pixel;
intpixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int idata[] = (int[])pixel;
intpixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
--- 977,995 ----
public final int[] getComponents(Object pixel, int[] components,
int offset) {
int intpixel=0;
switch (transferType) {
case DataBuffer.TYPE_BYTE:
! byte[] bdata = (byte[])pixel;
intpixel = bdata[0] & 0xff;
break;
case DataBuffer.TYPE_USHORT:
! short[] sdata = (short[])pixel;
intpixel = sdata[0] & 0xffff;
break;
case DataBuffer.TYPE_INT:
! int[] idata = (int[])pixel;
intpixel = idata[0];
break;
default:
throw new UnsupportedOperationException("This method has not been "+
"implemented for transferType " + transferType);
*** 1116,1148 ****
pixel |= ((components[offset+i]<<maskOffsets[i])&maskArray[i]);
}
switch (transferType) {
case DataBuffer.TYPE_BYTE:
if (obj instanceof byte[]) {
! byte bdata[] = (byte[])obj;
bdata[0] = (byte)(pixel&0xff);
return bdata;
} else {
! byte bdata[] = {(byte)(pixel&0xff)};
return bdata;
}
case DataBuffer.TYPE_USHORT:
if (obj instanceof short[]) {
! short sdata[] = (short[])obj;
sdata[0] = (short)(pixel&0xffff);
return sdata;
} else {
! short sdata[] = {(short)(pixel&0xffff)};
return sdata;
}
case DataBuffer.TYPE_INT:
if (obj instanceof int[]) {
! int idata[] = (int[])obj;
idata[0] = pixel;
return idata;
} else {
! int idata[] = {pixel};
return idata;
}
default:
throw new ClassCastException("This method has not been "+
"implemented for transferType " + transferType);
--- 1116,1148 ----
pixel |= ((components[offset+i]<<maskOffsets[i])&maskArray[i]);
}
switch (transferType) {
case DataBuffer.TYPE_BYTE:
if (obj instanceof byte[]) {
! byte[] bdata = (byte[])obj;
bdata[0] = (byte)(pixel&0xff);
return bdata;
} else {
! byte[] bdata = {(byte)(pixel&0xff)};
return bdata;
}
case DataBuffer.TYPE_USHORT:
if (obj instanceof short[]) {
! short[] sdata = (short[])obj;
sdata[0] = (short)(pixel&0xffff);
return sdata;
} else {
! short[] sdata = {(short)(pixel&0xffff)};
return sdata;
}
case DataBuffer.TYPE_INT:
if (obj instanceof int[]) {
! int[] idata = (int[])obj;
idata[0] = pixel;
return idata;
} else {
! int[] idata = {pixel};
return idata;
}
default:
throw new ClassCastException("This method has not been "+
"implemented for transferType " + transferType);
*** 1188,1199 ****
float alphaScale = 1.0f / ((float) ((1 << nBits[aIdx]) - 1));
int rminX = raster.getMinX();
int rY = raster.getMinY();
int rX;
! int pixel[] = null;
! int zpixel[] = null;
if (isAlphaPremultiplied) {
// Must mean that we are currently not premultiplied so
// multiply by alpha
switch (transferType) {
--- 1188,1199 ----
float alphaScale = 1.0f / ((float) ((1 << nBits[aIdx]) - 1));
int rminX = raster.getMinX();
int rY = raster.getMinY();
int rX;
! int[] pixel = null;
! int[] zpixel = null;
if (isAlphaPremultiplied) {
// Must mean that we are currently not premultiplied so
// multiply by alpha
switch (transferType) {
< prev index next >