1
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.colorchooser;
4
* @(#)ICC_CMYKColorSliderModel.java 1.0 2005-05-22
6
* Copyright (c) 2005 Werner Randelshofer
7
* Staldenmattweg 2, Immensee, CH-6405, Switzerland.
10
* This software is the confidential and proprietary information of
11
* Werner Randelshofer. ("Confidential Information"). You shall not
12
* disclose such Confidential Information and shall use it only in
13
* accordance with the terms of the license agreement you entered into
14
* with Werner Randelshofer.
18
import java.awt.color.*;
22
* A ColorSliderModel for CMYK color models (cyan, magenta, yellow, black) in
23
* a color space defined by a ICC color profile (International Color Consortium).
25
* XXX - This does not work. I think this is because of
26
* Java bug #4760025 at
27
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4760025
28
* but maybe I am doing something in the wrong way.
31
* @author Werner Randelshofer
32
* @version 1.0 May 22, 2005 Created.
34
public class ICC_CMYKColorSliderModel extends ColorSliderModel {
35
private ICC_ColorSpace colorSpace;
36
float[] cmyk = new float[4];
37
float[] rgb = new float[3];
39
* Creates a new instance.
41
public ICC_CMYKColorSliderModel(InputStream iccProfile) throws IOException {
42
super(new DefaultBoundedRangeModel[] {
43
new DefaultBoundedRangeModel(0, 0, 0, 100),
44
new DefaultBoundedRangeModel(0, 0, 0, 100),
45
new DefaultBoundedRangeModel(0, 0, 0, 100),
46
new DefaultBoundedRangeModel(0, 0, 0, 100)
48
this.colorSpace = new ICC_ColorSpace(ICC_Profile.getInstance(iccProfile));
53
cmyk[0] = components[0].getValue() / 100f;
54
cmyk[1] = components[1].getValue() / 100f;
55
cmyk[2] = components[2].getValue() / 100f;
56
cmyk[3] = components[3].getValue() / 100f;
57
rgb = colorSpace.toRGB(cmyk);
58
return 0xff000000 | ((int) (rgb[0] * 255f) << 16) | ((int) (rgb[1] * 255f) << 8) | (int) (rgb[2] * 255f);
62
public void setRGB(int newRGB) {
63
rgb[0] = ((newRGB & 0xff0000) >>> 16) / 255f;
64
rgb[1] = ((newRGB & 0x00ff00) >>> 8) / 255f;
65
rgb[2] = (newRGB & 0x0000ff) / 255f;
66
cmyk = colorSpace.fromRGB(rgb);
67
System.out.print("rgb in:"+new Color(newRGB));
68
components[0].setValue((int) (cmyk[0] * 100f));
69
components[1].setValue((int) (cmyk[1] * 100f));
70
components[2].setValue((int) (cmyk[2] * 100f));
71
components[3].setValue((int) (cmyk[3] * 100f));
72
rgb = colorSpace.toRGB(cmyk);
73
System.out.println(" out:"+new Color((int) (rgb[0]*255f), (int)(rgb[1]*255f), (int)(rgb[2]*255f)));
77
public int toRGB(int[] values) {
78
cmyk[0] = values[0] / 100f;
79
cmyk[1] = values[1] / 100f;
80
cmyk[2] = values[2] / 100f;
81
cmyk[3] = values[3] / 100f;
82
rgb = colorSpace.toRGB(cmyk);
83
return 0xff000000 | ((int) (rgb[0] * 255f) << 16) | ((int) (rgb[1] * 255f) << 8) | (int) (rgb[2] * 255f);