summaryrefslogtreecommitdiff
path: root/gnu/java/awt/color/ColorLookUpTable.java
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/java/awt/color/ColorLookUpTable.java')
-rw-r--r--gnu/java/awt/color/ColorLookUpTable.java226
1 files changed, 113 insertions, 113 deletions
diff --git a/gnu/java/awt/color/ColorLookUpTable.java b/gnu/java/awt/color/ColorLookUpTable.java
index 6b6418bc2..581320c3e 100644
--- a/gnu/java/awt/color/ColorLookUpTable.java
+++ b/gnu/java/awt/color/ColorLookUpTable.java
@@ -77,7 +77,7 @@ public class ColorLookUpTable
float[][] inMatrix; // input matrix (XYZ only)
boolean useMatrix; // Whether to use the matrix or not.
int[] multiplier;
- int[] offsets; // Hypercube offsets
+ int[] offsets; // Hypercube offsets
boolean inputLab; // Set if the CLUT input CS is Lab
boolean outputLab; // Set if the CLUT output CS is Lab
@@ -95,21 +95,21 @@ public class ColorLookUpTable
case ICC_Profile.icSigAToB0Tag:
case ICC_Profile.icSigAToB1Tag:
case ICC_Profile.icSigAToB2Tag:
- if (profile.getColorSpaceType() == ColorSpace.TYPE_XYZ)
- useMatrix = true;
- inputLab = false;
- outputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
- break;
+ if (profile.getColorSpaceType() == ColorSpace.TYPE_XYZ)
+ useMatrix = true;
+ inputLab = false;
+ outputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
+ break;
case ICC_Profile.icSigBToA0Tag:
case ICC_Profile.icSigBToA1Tag:
case ICC_Profile.icSigBToA2Tag:
- if (profile.getPCSType() == ColorSpace.TYPE_XYZ)
- useMatrix = true;
- inputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
- outputLab = false;
- break;
+ if (profile.getPCSType() == ColorSpace.TYPE_XYZ)
+ useMatrix = true;
+ inputLab = (profile.getPCSType() == ColorSpace.TYPE_Lab);
+ outputLab = false;
+ break;
default:
- throw new IllegalArgumentException("Not a clut-type tag.");
+ throw new IllegalArgumentException("Not a clut-type tag.");
}
byte[] data = profile.getData(tag);
@@ -144,24 +144,24 @@ public class ColorLookUpTable
inMatrix = new float[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
- inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
+ inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
inTable = new double[nIn][nInTableEntries];
for (int channel = 0; channel < nIn; channel++)
for (int i = 0; i < nInTableEntries; i++)
- inTable[channel][i] = (double) ((int) buf.getShort(52
- + (channel * nInTableEntries
- + i) * 2)
- & (0xFFFF)) / 65536.0;
+ inTable[channel][i] = (double) ((int) buf.getShort(52
+ + (channel * nInTableEntries
+ + i) * 2)
+ & (0xFFFF)) / 65536.0;
nClut = nOut;
multiplier = new int[nIn];
multiplier[nIn - 1] = nOut;
for (int i = 0; i < nIn; i++)
{
- nClut *= gridpoints;
- if (i > 0)
- multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
+ nClut *= gridpoints;
+ if (i > 0)
+ multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
}
int clutOffset = 52 + nIn * nInTableEntries * 2;
@@ -172,18 +172,18 @@ public class ColorLookUpTable
outTable = new short[nOut][nOutTableEntries];
for (int channel = 0; channel < nOut; channel++)
for (int i = 0; i < nOutTableEntries; i++)
- outTable[channel][i] = buf.getShort(clutOffset
- + (nClut
- + channel * nOutTableEntries + i) * 2);
+ outTable[channel][i] = buf.getShort(clutOffset
+ + (nClut
+ + channel * nOutTableEntries + i) * 2);
// calculate the hypercube corner offsets
offsets = new int[(1 << nIn)];
offsets[0] = 0;
for (int j = 0; j < nIn; j++)
{
- int factor = 1 << j;
- for (int i = 0; i < factor; i++)
- offsets[factor + i] = offsets[i] + multiplier[j];
+ int factor = 1 << j;
+ for (int i = 0; i < factor; i++)
+ offsets[factor + i] = offsets[i] + multiplier[j];
}
}
@@ -203,23 +203,23 @@ public class ColorLookUpTable
inMatrix = new float[3][3];
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
- inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
+ inMatrix[i][j] = ((float) (buf.getInt(12 + (i * 3 + j) * 4))) / 65536.0f;
inTable = new double[nIn][nInTableEntries];
for (int channel = 0; channel < nIn; channel++)
for (int i = 0; i < nInTableEntries; i++)
- inTable[channel][i] = (double) ((int) buf.get(48
- + (channel * nInTableEntries
- + i)) & (0xFF)) / 255.0;
+ inTable[channel][i] = (double) ((int) buf.get(48
+ + (channel * nInTableEntries
+ + i)) & (0xFF)) / 255.0;
nClut = nOut;
multiplier = new int[nIn];
multiplier[nIn - 1] = nOut;
for (int i = 0; i < nIn; i++)
{
- nClut *= gridpoints;
- if (i > 0)
- multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
+ nClut *= gridpoints;
+ if (i > 0)
+ multiplier[nIn - i - 1] = multiplier[nIn - i] * gridpoints;
}
int clutOffset = 48 + nIn * nInTableEntries;
@@ -230,18 +230,18 @@ public class ColorLookUpTable
outTable = new short[nOut][nOutTableEntries];
for (int channel = 0; channel < nOut; channel++)
for (int i = 0; i < nOutTableEntries; i++)
- outTable[channel][i] = (short) (buf.get(clutOffset + nClut
- + channel * nOutTableEntries
- + i) * 257);
+ outTable[channel][i] = (short) (buf.get(clutOffset + nClut
+ + channel * nOutTableEntries
+ + i) * 257);
// calculate the hypercube corner offsets
offsets = new int[(1 << nIn)];
offsets[0] = 0;
for (int j = 0; j < nIn; j++)
{
- int factor = 1 << j;
- for (int i = 0; i < factor; i++)
- offsets[factor + i] = offsets[i] + multiplier[j];
+ int factor = 1 << j;
+ for (int i = 0; i < factor; i++)
+ offsets[factor + i] = offsets[i] + multiplier[j];
}
}
@@ -260,32 +260,32 @@ public class ColorLookUpTable
float[] in2 = new float[in.length];
if (useMatrix)
{
- for (int i = 0; i < 3; i++)
- in2[i] = in[0] * inMatrix[i][0] + in[1] * inMatrix[i][1]
- + in[2] * inMatrix[i][2];
+ for (int i = 0; i < 3; i++)
+ in2[i] = in[0] * inMatrix[i][0] + in[1] * inMatrix[i][1]
+ + in[2] * inMatrix[i][2];
}
else if (inputLab)
in2 = XYZtoLab(in);
else
System.arraycopy(in, 0, in2, 0, in.length);
- // input table
+ // input table
for (int i = 0; i < nIn; i++)
{
- int index = (int) Math.floor(in2[i] * (double) (nInTableEntries - 1)); // floor in
-
- // clip values.
- if (index >= nInTableEntries - 1)
- in2[i] = (float) inTable[i][nInTableEntries - 1];
- else if (index < 0)
- in2[i] = (float) inTable[i][0];
- else
- {
- // linear interpolation
- double alpha = in2[i] * ((double) nInTableEntries - 1.0) - index;
- in2[i] = (float) (inTable[i][index] * (1 - alpha)
- + inTable[i][index + 1] * alpha);
- }
+ int index = (int) Math.floor(in2[i] * (double) (nInTableEntries - 1)); // floor in
+
+ // clip values.
+ if (index >= nInTableEntries - 1)
+ in2[i] = (float) inTable[i][nInTableEntries - 1];
+ else if (index < 0)
+ in2[i] = (float) inTable[i][0];
+ else
+ {
+ // linear interpolation
+ double alpha = in2[i] * ((double) nInTableEntries - 1.0) - index;
+ in2[i] = (float) (inTable[i][index] * (1 - alpha)
+ + inTable[i][index + 1] * alpha);
+ }
}
// CLUT lookup
@@ -295,31 +295,31 @@ public class ColorLookUpTable
int offset = 0; // = gp
for (int i = 0; i < nIn; i++)
{
- int index = (int) Math.floor(in2[i] * ((double) gridpoints - 1.0));
- double alpha = in2[i] * ((double) gridpoints - 1.0) - (double) index;
-
- // clip values.
- if (index >= gridpoints - 1)
- {
- index = gridpoints - 1;
- alpha = 1.0;
- }
- else if (index < 0)
- index = 0;
- clutalpha[i] = alpha;
- offset += index * multiplier[i];
+ int index = (int) Math.floor(in2[i] * ((double) gridpoints - 1.0));
+ double alpha = in2[i] * ((double) gridpoints - 1.0) - (double) index;
+
+ // clip values.
+ if (index >= gridpoints - 1)
+ {
+ index = gridpoints - 1;
+ alpha = 1.0;
+ }
+ else if (index < 0)
+ index = 0;
+ clutalpha[i] = alpha;
+ offset += index * multiplier[i];
}
// Calculate interpolation weights
weights[0] = 1.0;
for (int j = 0; j < nIn; j++)
{
- int factor = 1 << j;
- for (int i = 0; i < factor; i++)
- {
- weights[factor + i] = weights[i] * clutalpha[j];
- weights[i] *= (1.0 - clutalpha[j]);
- }
+ int factor = 1 << j;
+ for (int i = 0; i < factor; i++)
+ {
+ weights[factor + i] = weights[i] * clutalpha[j];
+ weights[i] *= (1.0 - clutalpha[j]);
+ }
}
for (int i = 0; i < nOut; i++)
@@ -327,32 +327,32 @@ public class ColorLookUpTable
for (int i = 1; i < (1 << nIn); i++)
{
- int offset2 = offset + offsets[i];
- for (int f = 0; f < nOut; f++)
- output2[f] += weights[i] * clut[offset2 + f];
+ int offset2 = offset + offsets[i];
+ for (int f = 0; f < nOut; f++)
+ output2[f] += weights[i] * clut[offset2 + f];
}
- // output table
+ // output table
float[] output = new float[nOut];
for (int i = 0; i < nOut; i++)
{
- int index = (int) Math.floor(output2[i] * ((double) nOutTableEntries
- - 1.0));
-
- // clip values.
- if (index >= nOutTableEntries - 1)
- output[i] = outTable[i][nOutTableEntries - 1];
- else if (index < 0)
- output[i] = outTable[i][0];
- else
- {
- // linear interpolation
- double a = output2[i] * ((double) nOutTableEntries - 1.0)
- - (double) index;
- output[i] = (float) ((double) ((int) outTable[i][index] & (0xFFFF)) * (1
- - a)
- + (double) ((int) outTable[i][index + 1] & (0xFFFF)) * a) / 65536f;
- }
+ int index = (int) Math.floor(output2[i] * ((double) nOutTableEntries
+ - 1.0));
+
+ // clip values.
+ if (index >= nOutTableEntries - 1)
+ output[i] = outTable[i][nOutTableEntries - 1];
+ else if (index < 0)
+ output[i] = outTable[i][0];
+ else
+ {
+ // linear interpolation
+ double a = output2[i] * ((double) nOutTableEntries - 1.0)
+ - (double) index;
+ output[i] = (float) ((double) ((int) outTable[i][index] & (0xFFFF)) * (1
+ - a)
+ + (double) ((int) outTable[i][index + 1] & (0xFFFF)) * a) / 65536f;
+ }
}
if (outputLab)
@@ -365,7 +365,7 @@ public class ColorLookUpTable
*/
private float[] LabtoXYZ(float[] in)
{
- // Convert from byte-packed format to a
+ // Convert from byte-packed format to a
// more convenient one (actual Lab values)
// (See ICC spec for details)
// factor is 100 * 65536 / 65280
@@ -381,12 +381,12 @@ public class ColorLookUpTable
for (int i = 0; i < 3; i++)
{
- double exp = out[i] * out[i] * out[i];
- if (exp <= 0.008856)
- out[i] = (out[i] - 16.0f / 116.0f) / 7.787f;
- else
- out[i] = (float) exp;
- out[i] = D50[i] * out[i];
+ double exp = out[i] * out[i] * out[i];
+ if (exp <= 0.008856)
+ out[i] = (out[i] - 16.0f / 116.0f) / 7.787f;
+ else
+ out[i] = (float) exp;
+ out[i] = D50[i] * out[i];
}
return out;
}
@@ -400,12 +400,12 @@ public class ColorLookUpTable
for (int i = 0; i < 3; i++)
{
- temp[i] = in[i] / D50[i];
+ temp[i] = in[i] / D50[i];
- if (temp[i] <= 0.008856f)
- temp[i] = (7.7870689f * temp[i]) + (16f / 116.0f);
- else
- temp[i] = (float) Math.exp((1.0 / 3.0) * Math.log(temp[i]));
+ if (temp[i] <= 0.008856f)
+ temp[i] = (7.7870689f * temp[i]) + (16f / 116.0f);
+ else
+ temp[i] = (float) Math.exp((1.0 / 3.0) * Math.log(temp[i]));
}
float[] out = new float[3];
@@ -419,10 +419,10 @@ public class ColorLookUpTable
out[2] = (out[2] + 128f) / 256f;
for (int i = 0; i < 3; i++)
{
- if (out[i] < 0f)
- out[i] = 0f;
- if (out[i] > 1f)
- out[i] = 1f;
+ if (out[i] < 0f)
+ out[i] = 0f;
+ if (out[i] > 1f)
+ out[i] = 1f;
}
return out;
}