8318850: Duplicate code in the LCMSImageLayout
Reviewed-by: prr
This commit is contained in:
parent
c593f8bf59
commit
d2260146c9
src/java.desktop/share/classes/sun/java2d/cmm/lcms
test/jdk/java/awt/image/BufferedImage
@ -42,7 +42,7 @@ import static java.nio.ByteOrder.LITTLE_ENDIAN;
|
||||
|
||||
final class LCMSImageLayout {
|
||||
|
||||
static int BYTES_SH(int x) {
|
||||
private static int BYTES_SH(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
@ -50,13 +50,11 @@ final class LCMSImageLayout {
|
||||
return x << 7;
|
||||
}
|
||||
|
||||
static int CHANNELS_SH(int x) {
|
||||
private static int CHANNELS_SH(int x) {
|
||||
return x << 3;
|
||||
}
|
||||
|
||||
static int PREMUL_SH(int x) {
|
||||
return x << 23;
|
||||
}
|
||||
private static final int PREMUL = 1 << 23;
|
||||
private static final int SWAPFIRST = 1 << 14;
|
||||
private static final int DOSWAP = 1 << 10;
|
||||
private static final int PT_GRAY_8 = CHANNELS_SH(1) | BYTES_SH(1);
|
||||
@ -64,10 +62,10 @@ final class LCMSImageLayout {
|
||||
private static final int PT_RGB_8 = CHANNELS_SH(3) | BYTES_SH(1);
|
||||
private static final int PT_RGBA_8 = PT_RGB_8 | EXTRA_SH(1);
|
||||
private static final int PT_ARGB_8 = PT_RGBA_8 | SWAPFIRST;
|
||||
private static final int PT_ARGB_8_PREMUL = PT_ARGB_8 | PREMUL_SH(1);
|
||||
private static final int PT_ARGB_8_PREMUL = PT_ARGB_8 | PREMUL;
|
||||
private static final int PT_BGR_8 = PT_RGB_8 | DOSWAP;
|
||||
private static final int PT_ABGR_8 = PT_BGR_8 | EXTRA_SH(1);
|
||||
private static final int PT_ABGR_8_PREMUL = PT_ABGR_8 | PREMUL_SH(1);
|
||||
private static final int PT_ABGR_8_PREMUL = PT_ABGR_8 | PREMUL;
|
||||
// private static final int PT_BGRA_8 = PT_ABGR_8 | SWAPFIRST;
|
||||
private static final int SWAP_ENDIAN =
|
||||
ByteOrder.nativeOrder() == LITTLE_ENDIAN ? DOSWAP : 0;
|
||||
@ -186,7 +184,8 @@ final class LCMSImageLayout {
|
||||
l.dataArrayLength = 4 * intRaster.getDataStorage().length;
|
||||
l.dataType = DT_INT;
|
||||
}
|
||||
case BufferedImage.TYPE_3BYTE_BGR, BufferedImage.TYPE_4BYTE_ABGR,
|
||||
case BufferedImage.TYPE_BYTE_GRAY, BufferedImage.TYPE_3BYTE_BGR,
|
||||
BufferedImage.TYPE_4BYTE_ABGR,
|
||||
BufferedImage.TYPE_4BYTE_ABGR_PRE ->
|
||||
{
|
||||
var byteRaster = (ByteComponentRaster) image.getRaster();
|
||||
@ -198,15 +197,6 @@ final class LCMSImageLayout {
|
||||
l.dataArrayLength = byteRaster.getDataStorage().length;
|
||||
l.dataType = DT_BYTE;
|
||||
}
|
||||
case BufferedImage.TYPE_BYTE_GRAY -> {
|
||||
var byteRaster = (ByteComponentRaster) image.getRaster();
|
||||
l.nextRowOffset = byteRaster.getScanlineStride();
|
||||
l.nextPixelOffset = byteRaster.getPixelStride();
|
||||
l.offset = byteRaster.getDataOffset(0);
|
||||
l.dataArray = byteRaster.getDataStorage();
|
||||
l.dataArrayLength = byteRaster.getDataStorage().length;
|
||||
l.dataType = DT_BYTE;
|
||||
}
|
||||
case BufferedImage.TYPE_USHORT_GRAY -> {
|
||||
var shortRaster = (ShortComponentRaster) image.getRaster();
|
||||
l.nextRowOffset = safeMult(2, shortRaster.getScanlineStride());
|
||||
@ -297,7 +287,7 @@ final class LCMSImageLayout {
|
||||
l.pixelType = (hasAlpha ? CHANNELS_SH(numBands - 1) | EXTRA_SH(1)
|
||||
: CHANNELS_SH(numBands)) | BYTES_SH(1);
|
||||
if (hasAlpha && cm.isAlphaPremultiplied()) {
|
||||
l.pixelType |= PREMUL_SH(1);
|
||||
l.pixelType |= PREMUL;
|
||||
}
|
||||
|
||||
int[] bandOffsets = csm.getBandOffsets();
|
||||
|
56
test/jdk/java/awt/image/BufferedImage/VerifyNumBands.java
Normal file
56
test/jdk/java/awt/image/BufferedImage/VerifyNumBands.java
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright Amazon.com Inc. 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.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8318850
|
||||
* @summary Checks the total number of bands of image data
|
||||
*/
|
||||
public final class VerifyNumBands {
|
||||
|
||||
public static void main(String[] args) {
|
||||
test(BufferedImage.TYPE_INT_RGB, 3);
|
||||
test(BufferedImage.TYPE_INT_ARGB, 4);
|
||||
test(BufferedImage.TYPE_INT_ARGB_PRE, 4);
|
||||
test(BufferedImage.TYPE_INT_BGR, 3);
|
||||
test(BufferedImage.TYPE_3BYTE_BGR, 3);
|
||||
test(BufferedImage.TYPE_4BYTE_ABGR, 4);
|
||||
test(BufferedImage.TYPE_4BYTE_ABGR_PRE, 4);
|
||||
test(BufferedImage.TYPE_USHORT_565_RGB, 3);
|
||||
test(BufferedImage.TYPE_USHORT_555_RGB, 3);
|
||||
test(BufferedImage.TYPE_BYTE_GRAY, 1);
|
||||
test(BufferedImage.TYPE_USHORT_GRAY, 1);
|
||||
}
|
||||
|
||||
private static void test(int type, int expected) {
|
||||
BufferedImage bi = new BufferedImage(1, 1, type);
|
||||
int numBands = bi.getRaster().getSampleModel().getNumBands();
|
||||
if (numBands != expected) {
|
||||
System.err.println("Expected: " + expected);
|
||||
System.err.println("Actual: " + numBands);
|
||||
throw new RuntimeException("wrong number of bands");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user