2
Copyright (C) 2009 Jeroen Frijters
3
Copyright (C) 2010 Volker Berlin (i-net software)
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.
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:
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.
25
package sun.java2d.cmm.lcms;
27
import gnu.java.awt.color.TagEntry;
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;
41
import sun.java2d.cmm.ColorTransform;
42
import sun.java2d.cmm.PCMM;
44
// dummy color management implementation
45
public class LCMS implements PCMM {
47
private static final int HEADER_SIZE = 128;
49
private final ArrayList<ProfileData> profiles = new ArrayList<ProfileData>();
51
public synchronized long loadProfile( byte[] data ) {
52
int free = profiles.indexOf( null );
54
profiles.set( free, new ProfileData( data.clone()) );
57
long id = profiles.size();
58
profiles.add( new ProfileData( data.clone()) );
63
public synchronized void freeProfile( long profileID ) {
64
profiles.set( (int)profileID, null );
67
public synchronized int getProfileSize( long profileID ) {
68
return profiles.get( (int)profileID ).data.length;
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 );
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 );
82
TagEntry entry = profile.tags.get( tagSignature );
84
throw new CMMException( "tag does not exist: " + tagSignature );
86
byte[] src = entry.getData();
87
System.arraycopy( src, 0, data, 0, src.length );
92
public int getTagSize( long profileID, int tagSignature ) {
93
if( tagSignature == ICC_Profile.icSigHead ) {
96
ProfileData profile = profiles.get( (int)profileID );
97
TagEntry entry = profile.tags.get( tagSignature );
99
throw new CMMException( "tag does not exist: " + tagSignature );
101
return entry.getData().length;
104
public void setTagData(long profileID, int tagSignature, byte[] data)
106
throw new CMMException("Not implemented");
109
public ColorTransform createTransform(ICC_Profile profile, int renderType, int transformType)
111
return new DummyColorTransform();
114
public ColorTransform createTransform(ColorTransform[] transforms)
116
return new DummyColorTransform();
119
private static class ProfileData{
121
private final byte[] data;
122
private final Hashtable<Integer, TagEntry> tags;
124
private ProfileData(byte[] data){
126
this.tags = createTagTable( data );
129
private static Hashtable<Integer, TagEntry> createTagTable( byte[] data ) throws IllegalArgumentException {
130
ByteBuffer buf = ByteBuffer.wrap( data );
131
int nTags = buf.getInt( HEADER_SIZE );
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 );
140
if( tagTable.put( sig, te ) != null )
141
throw new IllegalArgumentException( "Duplicate tag in profile:" + te );
148
static class DummyColorTransform implements ColorTransform
150
public int getNumInComponents()
152
throw new CMMException("Not implemented");
155
public int getNumOutComponents()
157
throw new CMMException("Not implemented");
160
public void colorConvert(BufferedImage src, BufferedImage dst)
162
throw new CMMException("Not implemented");
165
public void colorConvert(Raster src, WritableRaster dst, float[] srcMinVal, float[] srcMaxVal, float[] dstMinVal, float[]dstMaxVal)
167
throw new CMMException("Not implemented");
170
public void colorConvert(Raster src, WritableRaster dst)
172
throw new CMMException("Not implemented");
175
public short[] colorConvert(short[] src, short[] dest)
177
throw new CMMException("Not implemented");
180
public byte[] colorConvert(byte[] src, byte[] dest)
182
throw new CMMException("Not implemented");