~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to substance/src/main/java/org/pushingpixels/substance/internal/contrib/randelshofer/quaqua/colorchooser/ICC_CMYKColorSliderModel.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.pushingpixels.substance.internal.contrib.randelshofer.quaqua.colorchooser;
 
2
 
 
3
/*
 
4
 * @(#)ICC_CMYKColorSliderModel.java  1.0  2005-05-22
 
5
 *
 
6
 * Copyright (c) 2005 Werner Randelshofer
 
7
 * Staldenmattweg 2, Immensee, CH-6405, Switzerland.
 
8
 * All rights reserved.
 
9
 *
 
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.
 
15
 */
 
16
 
 
17
import java.awt.*;
 
18
import java.awt.color.*;
 
19
import java.io.*;
 
20
import javax.swing.*;
 
21
/**
 
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).
 
24
 * <p>
 
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.
 
29
 * 
 
30
 *
 
31
 * @author  Werner Randelshofer
 
32
 * @version 1.0 May 22, 2005 Created.
 
33
 */
 
34
public class ICC_CMYKColorSliderModel extends ColorSliderModel {
 
35
    private ICC_ColorSpace colorSpace;
 
36
    float[] cmyk = new float[4]; 
 
37
    float[] rgb = new float[3]; 
 
38
    /**
 
39
     * Creates a new instance.
 
40
     */
 
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)
 
47
        });
 
48
        this.colorSpace = new ICC_ColorSpace(ICC_Profile.getInstance(iccProfile));
 
49
    }
 
50
    
 
51
    @Override
 
52
    public int getRGB() {
 
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);
 
59
    }
 
60
    
 
61
    @Override
 
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)));        
 
74
    }
 
75
    
 
76
    @Override
 
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);
 
84
    }
 
85
    
 
86
}