~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/java2d/cmm/lcms/LCMS.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009 Jeroen Frijters
 
3
  Copyright (C) 2010 Volker Berlin (i-net software)
 
4
 
 
5
  This software is provided 'as-is', without any express or implied
 
6
  warranty.  In no event will the authors be held liable for any damages
 
7
  arising from the use of this software.
 
8
 
 
9
  Permission is granted to anyone to use this software for any purpose,
 
10
  including commercial applications, and to alter it and redistribute it
 
11
  freely, subject to the following restrictions:
 
12
 
 
13
  1. The origin of this software must not be misrepresented; you must not
 
14
     claim that you wrote the original software. If you use this software
 
15
     in a product, an acknowledgment in the product documentation would be
 
16
     appreciated but is not required.
 
17
  2. Altered source versions must be plainly marked as such, and must not be
 
18
     misrepresented as being the original software.
 
19
  3. This notice may not be removed or altered from any source distribution.
 
20
 
 
21
  Jeroen Frijters
 
22
  jeroen@frijters.net
 
23
  
 
24
*/
 
25
package sun.java2d.cmm.lcms;
 
26
 
 
27
import gnu.java.awt.color.TagEntry;
 
28
 
 
29
import java.awt.color.CMMException;
 
30
import java.awt.color.ColorSpace;
 
31
import java.awt.color.ICC_Profile;
 
32
import java.awt.color.ICC_ProfileGray;
 
33
import java.awt.color.ICC_ProfileRGB;
 
34
import java.awt.image.BufferedImage;
 
35
import java.awt.image.Raster;
 
36
import java.awt.image.WritableRaster;
 
37
import java.nio.ByteBuffer;
 
38
import java.util.ArrayList;
 
39
import java.util.Hashtable;
 
40
 
 
41
import sun.java2d.cmm.ColorTransform;
 
42
import sun.java2d.cmm.PCMM;
 
43
 
 
44
// dummy color management implementation
 
45
public class LCMS implements PCMM {
 
46
    
 
47
    private static final int HEADER_SIZE = 128;
 
48
    
 
49
    private final ArrayList<ProfileData> profiles = new ArrayList<ProfileData>();
 
50
 
 
51
    public synchronized long loadProfile( byte[] data ) {
 
52
        int free = profiles.indexOf( null );
 
53
        if( free != -1 ) {
 
54
            profiles.set( free, new ProfileData( data.clone()) );
 
55
            return free;
 
56
        } else {
 
57
            long id = profiles.size();
 
58
            profiles.add( new ProfileData( data.clone()) );
 
59
            return id;
 
60
        }
 
61
    }
 
62
 
 
63
    public synchronized void freeProfile( long profileID ) {
 
64
        profiles.set( (int)profileID, null );
 
65
    }
 
66
 
 
67
    public synchronized int getProfileSize( long profileID ) {
 
68
        return profiles.get( (int)profileID ).data.length;
 
69
    }
 
70
 
 
71
    public synchronized void getProfileData( long profileID, byte[] data ) {
 
72
        byte[] src = profiles.get( (int)profileID ).data;
 
73
        System.arraycopy( src, 0, data, 0, src.length );
 
74
    }
 
75
 
 
76
    public void getTagData( long profileID, int tagSignature, byte[] data ) {
 
77
        ProfileData profile = profiles.get( (int)profileID );
 
78
        if( tagSignature == ICC_Profile.icSigHead ) {
 
79
            byte[] src = profile.data;
 
80
            System.arraycopy( src, 0, data, 0, HEADER_SIZE );
 
81
        } else {
 
82
            TagEntry entry = profile.tags.get( tagSignature );
 
83
            if( entry == null ){
 
84
                throw new CMMException( "tag does not exist: " + tagSignature );
 
85
            }
 
86
            byte[] src = entry.getData();
 
87
            System.arraycopy( src, 0, data, 0, src.length );
 
88
        }
 
89
        
 
90
    }
 
91
 
 
92
    public int getTagSize( long profileID, int tagSignature ) {
 
93
        if( tagSignature == ICC_Profile.icSigHead ) {
 
94
            return HEADER_SIZE;
 
95
        }
 
96
        ProfileData profile = profiles.get( (int)profileID );
 
97
        TagEntry entry = profile.tags.get( tagSignature );
 
98
        if( entry == null ){
 
99
            throw new CMMException( "tag does not exist: " + tagSignature );
 
100
        }
 
101
        return entry.getData().length;
 
102
    }
 
103
 
 
104
    public void setTagData(long profileID, int tagSignature, byte[] data)
 
105
    {
 
106
        throw new CMMException("Not implemented");
 
107
    }
 
108
 
 
109
    public ColorTransform createTransform(ICC_Profile profile, int renderType, int transformType)
 
110
    {
 
111
        return new DummyColorTransform();
 
112
    }
 
113
 
 
114
    public ColorTransform createTransform(ColorTransform[] transforms)
 
115
    {
 
116
        return new DummyColorTransform();
 
117
    }
 
118
    
 
119
    private static class ProfileData{
 
120
        
 
121
        private final byte[] data;
 
122
        private final Hashtable<Integer, TagEntry> tags;
 
123
        
 
124
        private ProfileData(byte[] data){
 
125
            this.data = data;
 
126
            this.tags = createTagTable( data );
 
127
        }
 
128
        
 
129
        private static Hashtable<Integer, TagEntry> createTagTable( byte[] data ) throws IllegalArgumentException {
 
130
            ByteBuffer buf = ByteBuffer.wrap( data );
 
131
            int nTags = buf.getInt( HEADER_SIZE );
 
132
 
 
133
            Hashtable<Integer, TagEntry> tagTable = new Hashtable<Integer, TagEntry>();
 
134
            for( int i = 0; i < nTags; i++ ) {
 
135
                int sig = buf.getInt( HEADER_SIZE + i * TagEntry.entrySize + 4 );
 
136
                int offset = buf.getInt( HEADER_SIZE + i * TagEntry.entrySize + 8 );
 
137
                int size = buf.getInt( HEADER_SIZE + i * TagEntry.entrySize + 12 );
 
138
                TagEntry te = new TagEntry( sig, offset, size, data );
 
139
 
 
140
                if( tagTable.put( sig, te ) != null )
 
141
                    throw new IllegalArgumentException( "Duplicate tag in profile:" + te );
 
142
            }
 
143
            return tagTable;
 
144
        }
 
145
 
 
146
    }
 
147
    
 
148
    static class DummyColorTransform implements ColorTransform
 
149
    {
 
150
        public int getNumInComponents()
 
151
        {
 
152
            throw new CMMException("Not implemented");
 
153
        }
 
154
 
 
155
        public int getNumOutComponents()
 
156
        {
 
157
            throw new CMMException("Not implemented");
 
158
        }
 
159
 
 
160
        public void colorConvert(BufferedImage src, BufferedImage dst)
 
161
        {
 
162
            throw new CMMException("Not implemented");
 
163
        }
 
164
 
 
165
        public void colorConvert(Raster src, WritableRaster dst, float[] srcMinVal, float[] srcMaxVal, float[] dstMinVal, float[]dstMaxVal)
 
166
        {
 
167
            throw new CMMException("Not implemented");
 
168
        }
 
169
 
 
170
        public void colorConvert(Raster src, WritableRaster dst)
 
171
        {
 
172
            throw new CMMException("Not implemented");
 
173
        }
 
174
 
 
175
        public short[] colorConvert(short[] src, short[] dest)
 
176
        {
 
177
            throw new CMMException("Not implemented");
 
178
        }
 
179
 
 
180
        public byte[] colorConvert(byte[] src, byte[] dest)
 
181
        {
 
182
            throw new CMMException("Not implemented");
 
183
        }
 
184
    }
 
185
}