Skip to content

Commit

Permalink
8294488: Delete KCMS transforms wrappers
Browse files Browse the repository at this point in the history
Reviewed-by: prr
  • Loading branch information
mrserb authored and prrace committed Nov 4, 2022
1 parent f857f79 commit d8573b2
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 263 deletions.
62 changes: 18 additions & 44 deletions src/java.desktop/share/classes/java/awt/color/ICC_ColorSpace.java
Expand Up @@ -200,17 +200,13 @@ public float[] toRGB(float[] colorvalue) {
if (this2srgb == null) {
synchronized (this) {
if (this2srgb == null) {
ColorTransform[] transforms = new ColorTransform[2];
var srgb = (ICC_ColorSpace) getInstance(CS_sRGB);
PCMM mdl = CMSManager.getModule();
transforms[0] = mdl.createTransform(thisProfile,
ColorTransform.Any, ColorTransform.In);
transforms[1] = mdl.createTransform(srgb.getProfile(),
ColorTransform.Any, ColorTransform.Out);
if (needScaleInit) {
setComponentScaling();
}
this2srgb = mdl.createTransform(transforms);
var srgb = ICC_Profile.getInstance(CS_sRGB);
PCMM mdl = CMSManager.getModule();
this2srgb = mdl.createTransform(ColorTransform.Any,
thisProfile, srgb);
}
}
}
Expand Down Expand Up @@ -252,17 +248,13 @@ public float[] fromRGB(float[] rgbvalue) {
if (srgb2this == null) {
synchronized (this) {
if (srgb2this == null) {
ColorTransform[] transforms = new ColorTransform[2];
var srgb = (ICC_ColorSpace) getInstance(CS_sRGB);
PCMM mdl = CMSManager.getModule();
transforms[0] = mdl.createTransform(srgb.getProfile(),
ColorTransform.Any, ColorTransform.In);
transforms[1] = mdl.createTransform(thisProfile,
ColorTransform.Any, ColorTransform.Out);
if (needScaleInit) {
setComponentScaling();
}
srgb2this = mdl.createTransform(transforms);
var srgb = ICC_Profile.getInstance(CS_sRGB);
PCMM mdl = CMSManager.getModule();
srgb2this = mdl.createTransform(ColorTransform.Any,
srgb, thisProfile);
}
}
}
Expand Down Expand Up @@ -384,23 +376,14 @@ public float[] toCIEXYZ(float[] colorvalue) {
if (this2xyz == null) {
synchronized (this) {
if (this2xyz == null) {
ColorTransform[] transforms = new ColorTransform[2];
var xyz = (ICC_ColorSpace) getInstance(CS_CIEXYZ);
PCMM mdl = CMSManager.getModule();
try {
transforms[0] = mdl.createTransform(thisProfile,
ICC_Profile.icRelativeColorimetric,
ColorTransform.In);
} catch (CMMException e) {
transforms[0] = mdl.createTransform(thisProfile,
ColorTransform.Any, ColorTransform.In);
}
transforms[1] = mdl.createTransform(xyz.getProfile(),
ColorTransform.Any, ColorTransform.Out);
if (needScaleInit) {
setComponentScaling();
}
this2xyz = mdl.createTransform(transforms);
var xyz = ICC_Profile.getInstance(CS_CIEXYZ);
PCMM mdl = CMSManager.getModule();
this2xyz = mdl.createTransform(
ICC_Profile.icRelativeColorimetric,
thisProfile, xyz);
}
}
}
Expand Down Expand Up @@ -524,23 +507,14 @@ public float[] fromCIEXYZ(float[] colorvalue) {
if (xyz2this == null) {
synchronized (this) {
if (xyz2this == null) {
ColorTransform[] transforms = new ColorTransform[2];
var xyz = (ICC_ColorSpace) getInstance(CS_CIEXYZ);
PCMM mdl = CMSManager.getModule();
try {
transforms[0] = mdl.createTransform(xyz.getProfile(),
ICC_Profile.icRelativeColorimetric,
ColorTransform.In);
} catch (CMMException e) {
transforms[0] = mdl.createTransform(xyz.getProfile(),
ColorTransform.Any, ColorTransform.In);
}
transforms[1] = mdl.createTransform(thisProfile,
ColorTransform.Any, ColorTransform.Out);
if (needScaleInit) {
setComponentScaling();
}
xyz2this = mdl.createTransform(transforms);
var xyz = ICC_Profile.getInstance(CS_CIEXYZ);
PCMM mdl = CMSManager.getModule();
xyz2this = mdl.createTransform(
ICC_Profile.icRelativeColorimetric,
xyz, thisProfile);
}
}
}
Expand Down
94 changes: 16 additions & 78 deletions src/java.desktop/share/classes/java/awt/image/ColorConvertOp.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2022, 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
Expand Down Expand Up @@ -355,8 +355,7 @@ private BufferedImage ICCBIFilter(BufferedImage src,
private void updateBITransform(ICC_Profile srcProfile,
ICC_Profile destProfile) {
ICC_Profile[] theProfiles;
int i1, nProfiles, nTransforms, whichTrans, renderState;
ColorTransform[] theTransforms;
int i1, nProfiles, nTransforms, renderingIntent;
boolean useSrc = false, useDest = false;

nProfiles = profileList.length;
Expand Down Expand Up @@ -391,51 +390,20 @@ private void updateBITransform(ICC_Profile srcProfile,
theProfiles[idx] = destProfile;
}

/* make the transform list */
theTransforms = new ColorTransform [nTransforms];

/* initialize transform get loop */
if (theProfiles[0].getProfileClass() == ICC_Profile.CLASS_OUTPUT) {
/* if first profile is a printer
render as colorimetric */
renderState = ICC_Profile.icRelativeColorimetric;
renderingIntent = ICC_Profile.icRelativeColorimetric;
}
else {
renderState = ICC_Profile.icPerceptual; /* render any other
renderingIntent = ICC_Profile.icPerceptual; /* render any other
class perceptually */
}

whichTrans = ColorTransform.In;

/* or get this profile's rendering intent to select transform
from next profiles? */
//renderingIntent = getRenderingIntent(theProfiles[0]);
PCMM mdl = CMSManager.getModule();

/* get the transforms from each profile */
for (i1 = 0; i1 < nTransforms; i1++) {
if (i1 == nTransforms -1) { /* last profile? */
whichTrans = ColorTransform.Out; /* get output transform */
}
else { /* check for abstract profile */
if ((whichTrans == ColorTransform.Simulation) &&
(theProfiles[i1].getProfileClass () ==
ICC_Profile.CLASS_ABSTRACT)) {
renderState = ICC_Profile.icPerceptual;
whichTrans = ColorTransform.In;
}
}

theTransforms[i1] = mdl.createTransform (
theProfiles[i1], renderState, whichTrans);

/* get this profile's rendering intent to select transform
from next profile */
renderState = getRenderingIntent(theProfiles[i1]);

/* "middle" profiles use simulation transform */
whichTrans = ColorTransform.Simulation;
}

/* make the net transform */
thisTransform = mdl.createTransform(theTransforms);
thisTransform = mdl.createTransform(renderingIntent, theProfiles);

/* update corresponding source and dest profiles */
thisSrcProfile = srcProfile;
Expand Down Expand Up @@ -497,54 +465,24 @@ public final WritableRaster filter (Raster src, WritableRaster dest) {

/* make a new transform if needed */
if (thisRasterTransform == null) {
int i1, whichTrans, renderState;
ColorTransform[] theTransforms;
int renderingIntent;

/* make the transform list */
theTransforms = new ColorTransform [nProfiles];

/* initialize transform get loop */
if (profileList[0].getProfileClass() == ICC_Profile.CLASS_OUTPUT) {
/* if first profile is a printer
render as colorimetric */
renderState = ICC_Profile.icRelativeColorimetric;
renderingIntent = ICC_Profile.icRelativeColorimetric;
}
else {
renderState = ICC_Profile.icPerceptual; /* render any other
renderingIntent = ICC_Profile.icPerceptual; /* render any other
class perceptually */
}

whichTrans = ColorTransform.In;

/* or get this profile's rendering intent to select transform
from next profiles? */
// renderingIntent = getRenderingIntent(profileList[i1]);
PCMM mdl = CMSManager.getModule();

/* get the transforms from each profile */
for (i1 = 0; i1 < nProfiles; i1++) {
if (i1 == nProfiles -1) { /* last profile? */
whichTrans = ColorTransform.Out; /* get output transform */
}
else { /* check for abstract profile */
if ((whichTrans == ColorTransform.Simulation) &&
(profileList[i1].getProfileClass () ==
ICC_Profile.CLASS_ABSTRACT)) {
renderState = ICC_Profile.icPerceptual;
whichTrans = ColorTransform.In;
}
}

theTransforms[i1] = mdl.createTransform (
profileList[i1], renderState, whichTrans);

/* get this profile's rendering intent to select transform
from next profile */
renderState = getRenderingIntent(profileList[i1]);

/* "middle" profiles use simulation transform */
whichTrans = ColorTransform.Simulation;
}

/* make the net transform */
thisRasterTransform = mdl.createTransform(theTransforms);
thisRasterTransform = mdl.createTransform(renderingIntent,
profileList);
}

int srcTransferType = src.getTransferType();
Expand Down
57 changes: 19 additions & 38 deletions src/java.desktop/share/classes/java/awt/image/ColorModel.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1995, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1995, 2022, 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
Expand Down Expand Up @@ -28,13 +28,15 @@
import java.awt.Transparency;
import java.awt.color.ColorSpace;
import java.awt.color.ICC_ColorSpace;
import sun.java2d.cmm.CMSManager;
import sun.java2d.cmm.ColorTransform;
import sun.java2d.cmm.PCMM;
import java.awt.color.ICC_Profile;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.Arrays;

import sun.java2d.cmm.CMSManager;
import sun.java2d.cmm.ColorTransform;
import sun.java2d.cmm.PCMM;

/**
* The {@code ColorModel} abstract class encapsulates the
Expand Down Expand Up @@ -1791,15 +1793,10 @@ static byte[] getGray8TosRGB8LUT(ICC_ColorSpace grayCS) {
for (int i = 0; i <= 255; i++) {
g8Tos8LUT[i] = (byte) i;
}
ColorTransform[] transformList = new ColorTransform[2];
var srgb = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace srgbCS =
(ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
transformList[0] = mdl.createTransform(
grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform(
srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
ColorTransform t = mdl.createTransform(ColorTransform.Any,
grayCS.getProfile(), srgb);
byte[] tmp = t.colorConvert(g8Tos8LUT, null);
for (int i = 0, j= 2; i <= 255; i++, j += 3) {
// All three components of tmp should be equal, since
Expand Down Expand Up @@ -1832,15 +1829,10 @@ static byte[] getLinearGray16ToOtherGray8LUT(ICC_ColorSpace grayCS) {
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
var lg = ICC_Profile.getInstance(ColorSpace.CS_GRAY);
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace lgCS =
(ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
transformList[0] = mdl.createTransform (
lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform (
grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
ColorTransform t = mdl.createTransform(ColorTransform.Any,
lg, grayCS.getProfile());
tmp = t.colorConvert(tmp, null);
byte[] lg16Toog8LUT = new byte[65536];
for (int i = 0; i <= 65535; i++) {
Expand Down Expand Up @@ -1876,15 +1868,10 @@ static byte[] getGray16TosRGB8LUT(ICC_ColorSpace grayCS) {
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
var srgb = ICC_Profile.getInstance(ColorSpace.CS_sRGB);
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace srgbCS =
(ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_sRGB);
transformList[0] = mdl.createTransform (
grayCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform (
srgbCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(transformList);
ColorTransform t = mdl.createTransform(ColorTransform.Any,
grayCS.getProfile(), srgb);
tmp = t.colorConvert(tmp, null);
byte[] g16Tos8LUT = new byte[65536];
for (int i = 0, j= 2; i <= 65535; i++, j += 3) {
Expand Down Expand Up @@ -1921,16 +1908,10 @@ static short[] getLinearGray16ToOtherGray16LUT(ICC_ColorSpace grayCS) {
for (int i = 0; i <= 65535; i++) {
tmp[i] = (short) i;
}
ColorTransform[] transformList = new ColorTransform[2];
var lg = ICC_Profile.getInstance(ColorSpace.CS_GRAY);
PCMM mdl = CMSManager.getModule();
ICC_ColorSpace lgCS =
(ICC_ColorSpace) ColorSpace.getInstance(ColorSpace.CS_GRAY);
transformList[0] = mdl.createTransform (
lgCS.getProfile(), ColorTransform.Any, ColorTransform.In);
transformList[1] = mdl.createTransform(
grayCS.getProfile(), ColorTransform.Any, ColorTransform.Out);
ColorTransform t = mdl.createTransform(
transformList);
ColorTransform t = mdl.createTransform(ColorTransform.Any,
lg, grayCS.getProfile());
short[] lg16Toog16LUT = t.colorConvert(tmp, null);
if (lg16Toog16Map == null) {
lg16Toog16Map = Collections.synchronizedMap(new WeakHashMap<ICC_ColorSpace, short[]>(2));
Expand Down
17 changes: 6 additions & 11 deletions src/java.desktop/share/classes/sun/java2d/cmm/CMSManager.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2022, 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
Expand Down Expand Up @@ -123,16 +123,11 @@ public void setTagData(Profile p, int tagSignature,
}

/* methods for creating ColorTransforms */
public ColorTransform createTransform(ICC_Profile profile,
int renderType,
int transformType) {
System.err.println(cName + ".createTransform(ICC_Profile,int,int)");
return tcmm.createTransform(profile, renderType, transformType);
}

public ColorTransform createTransform(ColorTransform[] transforms) {
System.err.println(cName + ".createTransform(ColorTransform[])");
return tcmm.createTransform(transforms);
public ColorTransform createTransform(int renderingIntent,
ICC_Profile... profiles)
{
System.err.println(cName + ".createTransform(int, ICC_Profile...)");
return tcmm.createTransform(renderingIntent, profiles);
}

private static String signatureToString(int sig) {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2022, 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
Expand Down Expand Up @@ -30,17 +30,10 @@
import java.awt.image.WritableRaster;

public interface ColorTransform {
public int Any = -1;/* any rendering type, whichever is
available */
public int Any = -1;/* any rendering intent, whichever is available */
/* search order is icPerceptual,
icRelativeColorimetric, icSaturation */

/* Transform types */
public int In = 1;
public int Out = 2;
public int Gamut = 3;
public int Simulation = 4;

public int getNumInComponents();
public int getNumOutComponents();
public void colorConvert(BufferedImage src, BufferedImage dst);
Expand Down

1 comment on commit d8573b2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.