8294488: Delete KCMS transforms wrappers

Reviewed-by: prr
This commit is contained in:
Sergey Bylokhov 2022-11-04 20:57:38 +00:00 committed by Phil Race
parent f857f795a9
commit d8573b2c5b
9 changed files with 105 additions and 262 deletions

@ -200,17 +200,13 @@ public class ICC_ColorSpace extends ColorSpace {
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);
}
}
}
@ -252,17 +248,13 @@ public class ICC_ColorSpace extends ColorSpace {
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);
}
}
}
@ -384,23 +376,14 @@ public class ICC_ColorSpace extends ColorSpace {
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);
}
}
}
@ -524,23 +507,14 @@ public class ICC_ColorSpace extends ColorSpace {
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);
}
}
}

@ -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
@ -355,8 +355,7 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp {
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;
@ -391,51 +390,20 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp {
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;
@ -497,54 +465,24 @@ public class ColorConvertOp implements BufferedImageOp, RasterOp {
/* 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();

@ -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
@ -28,13 +28,15 @@ package java.awt.image;
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
@ -1791,15 +1793,10 @@ public abstract class ColorModel implements Transparency{
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
@ -1832,15 +1829,10 @@ public abstract class ColorModel implements Transparency{
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++) {
@ -1876,15 +1868,10 @@ public abstract class ColorModel implements Transparency{
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) {
@ -1921,16 +1908,10 @@ public abstract class ColorModel implements Transparency{
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));

@ -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
@ -123,16 +123,11 @@ public final class CMSManager {
}
/* 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) {

@ -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
@ -30,17 +30,10 @@ import java.awt.image.Raster;
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);

@ -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
@ -32,14 +32,12 @@ import java.awt.color.ICC_Profile;
public interface PCMM {
/* methods invoked from ICC_Profile */
public Profile loadProfile(byte[] data);
public byte[] getProfileData(Profile p);
public byte[] getTagData(Profile p, int tagSignature);
public void setTagData(Profile p, int tagSignature, byte[] data);
Profile loadProfile(byte[] data);
byte[] getProfileData(Profile p);
byte[] getTagData(Profile p, int tagSignature);
void setTagData(Profile p, int tagSignature, byte[] data);
/* methods for creating ColorTransforms */
public ColorTransform createTransform(ICC_Profile profile, int renderType,
int transformType);
public ColorTransform createTransform(ColorTransform[] transforms);
/* Creates ColorTransform */
ColorTransform createTransform(int renderingIntent,
ICC_Profile... profiles);
}

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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
@ -99,7 +99,7 @@ final class LCMS implements PCMM {
/* Helper method used from LCMSColorTransfrom */
static long createTransform(
LCMSProfile[] profiles, int renderType,
LCMSProfile[] profiles, int renderingIntent,
int inFormatter, boolean isInIntPacked,
int outFormatter, boolean isOutIntPacked,
Object disposerRef)
@ -114,7 +114,7 @@ final class LCMS implements PCMM {
ptrs[i] = profiles[i].getLcmsPtr();
}
return createNativeTransform(ptrs, renderType, inFormatter,
return createNativeTransform(ptrs, renderingIntent, inFormatter,
isInIntPacked, outFormatter, isOutIntPacked, disposerRef);
} finally {
lock.unlockRead(stamp);
@ -122,29 +122,18 @@ final class LCMS implements PCMM {
}
private static native long createNativeTransform(
long[] profileIDs, int renderType,
long[] profileIDs, int renderingIntent,
int inFormatter, boolean isInIntPacked,
int outFormatter, boolean isOutIntPacked,
Object disposerRef);
/**
* Constructs ColorTransform object corresponding to an ICC_profile
*/
public ColorTransform createTransform(ICC_Profile profile,
int renderType,
int transformType)
{
return new LCMSTransform(profile, renderType, renderType);
}
/**
* Constructs an ColorTransform object from a list of ColorTransform
* objects
* Constructs ColorTransform object corresponding to the ICC_profiles.
*/
public synchronized ColorTransform createTransform(
ColorTransform[] transforms)
public ColorTransform createTransform(int renderingIntent,
ICC_Profile... profiles)
{
return new LCMSTransform(transforms);
return new LCMSTransform(renderingIntent, profiles);
}
/* methods invoked from LCMSTransform */

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 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
@ -68,58 +68,33 @@ final class LCMSTransform implements ColorTransform {
}
private volatile NativeTransform transform;
ICC_Profile[] profiles;
LCMSProfile[] lcmsProfiles;
int renderType;
int transformType;
private final LCMSProfile[] lcmsProfiles;
private final int renderingIntent;
private int numInComponents = -1;
private int numOutComponents = -1;
private final int numInComponents;
private final int numOutComponents;
public LCMSTransform(ICC_Profile profile, int renderType,
int transformType)
{
/* Actually, it is not a complete transform but just part of it */
profiles = new ICC_Profile[1];
profiles[0] = profile;
lcmsProfiles = new LCMSProfile[1];
lcmsProfiles[0] = LCMS.getProfileID(profile);
this.renderType = (renderType == ColorTransform.Any)?
ICC_Profile.icPerceptual : renderType;
this.transformType = transformType;
/* Note that ICC_Profile.getNumComponents() is quite expensive
* (it may results in a reading of the profile header).
* So, here we cache the number of components of input and
* output profiles for further usage.
*/
numInComponents = profiles[0].getNumComponents();
numOutComponents = profiles[profiles.length - 1].getNumComponents();
}
public LCMSTransform (ColorTransform[] transforms) {
int size = 0;
for (int i=0; i < transforms.length; i++) {
size+=((LCMSTransform)transforms[i]).profiles.length;
/**
* Creates a transform based on the list of profiles and rendering intent.
* The first profile will be considered input, and the last profile will be
* considered output.
*
* @param renderingIntent the desired rendering intent, could be ignored if
* unsupported. If the {@link ColorTransform#Any} is passed then we
* will try to use {@code ICC_Profile.icPerceptual} intent.
* @param profiles the list of color profiles
*/
LCMSTransform(int renderingIntent, ICC_Profile... profiles) {
lcmsProfiles = new LCMSProfile[profiles.length];
for (int i = 0; i < profiles.length; i++) {
lcmsProfiles[i] = LCMS.getProfileID(profiles[i]);
profiles[i].getNumComponents(); // force header initialization
}
profiles = new ICC_Profile[size];
lcmsProfiles = new LCMSProfile[size];
int j = 0;
for (int i=0; i < transforms.length; i++) {
LCMSTransform curTrans = (LCMSTransform)transforms[i];
System.arraycopy(curTrans.profiles, 0, profiles, j,
curTrans.profiles.length);
System.arraycopy(curTrans.lcmsProfiles, 0, lcmsProfiles, j,
curTrans.lcmsProfiles.length);
j += curTrans.profiles.length;
}
renderType = ((LCMSTransform)transforms[0]).renderType;
/* Note that ICC_Profile.getNumComponents() is quite expensive
* (it may results in a reading of the profile header).
* So, here we cache the number of components of input and
* output profiles for further usage.
*/
this.renderingIntent = (renderingIntent == ColorTransform.Any) ?
ICC_Profile.icPerceptual : renderingIntent;
// Note that ICC_Profile.getNumComponents() is quite expensive (it may
// result in a reading of the profile header). So, here we cache the
// number of components of input and output profiles for further usage.
numInComponents = profiles[0].getNumComponents();
numOutComponents = profiles[profiles.length - 1].getNumComponents();
}
@ -146,7 +121,7 @@ final class LCMSTransform implements ColorTransform {
tfm.outFormatter = out.pixelType;
tfm.isOutIntPacked = out.isIntPacked;
tfm.ID = LCMS.createTransform(lcmsProfiles, renderType,
tfm.ID = LCMS.createTransform(lcmsProfiles, renderingIntent,
tfm.inFormatter,
tfm.isInIntPacked,
tfm.outFormatter,

@ -141,7 +141,7 @@ static void ThrowIllegalArgumentException(JNIEnv *env, const char *msg) {
* Signature: ([JIIZIZLjava/lang/Object;)J
*/
JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform
(JNIEnv *env, jclass cls, jlongArray profileIDs, jint renderType,
(JNIEnv *env, jclass cls, jlongArray profileIDs, jint renderingIntent,
jint inFormatter, jboolean isInIntPacked,
jint outFormatter, jboolean isOutIntPacked, jobject disposerRef)
{
@ -200,7 +200,7 @@ JNIEXPORT jlong JNICALL Java_sun_java2d_cmm_lcms_LCMS_createNativeTransform
}
sTrans = cmsCreateMultiprofileTransform(iccArray, j,
inFormatter, outFormatter, renderType, cmsFLAGS_COPY_ALPHA);
inFormatter, outFormatter, renderingIntent, cmsFLAGS_COPY_ALPHA);
(*env)->ReleaseLongArrayElements(env, profileIDs, ids, 0);