2 * MSCMS - Color Management System for Wine
4 * Copyright 2005, 2006, 2008 Hans Leidekker
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
33 #include "mscms_priv.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
39 static DWORD
from_profile( HPROFILE profile
)
43 GetColorProfileHeader( profile
, &header
);
44 TRACE( "color space: 0x%08x %s\n", header
.phDataColorSpace
, MSCMS_dbgstr_tag( header
.phDataColorSpace
) );
46 switch (header
.phDataColorSpace
)
48 case 0x434d594b: return TYPE_CMYK_16
; /* 'CMYK' */
49 case 0x47524159: return TYPE_GRAY_16
; /* 'GRAY' */
50 case 0x4c616220: return TYPE_Lab_16
; /* 'Lab ' */
51 case 0x52474220: return TYPE_RGB_16
; /* 'RGB ' */
52 case 0x58595a20: return TYPE_XYZ_16
; /* 'XYZ ' */
54 WARN("unhandled format\n");
59 static DWORD
from_bmformat( BMFORMAT format
)
61 TRACE( "bitmap format: 0x%08x\n", format
);
65 case BM_RGBTRIPLETS
: return TYPE_RGB_8
;
66 case BM_BGRTRIPLETS
: return TYPE_BGR_8
;
67 case BM_GRAY
: return TYPE_GRAY_8
;
69 FIXME("unhandled bitmap format\n");
74 static DWORD
from_type( COLORTYPE type
)
76 TRACE( "color type: 0x%08x\n", type
);
80 case COLOR_GRAY
: return TYPE_GRAY_16
;
81 case COLOR_RGB
: return TYPE_RGB_16
;
82 case COLOR_XYZ
: return TYPE_XYZ_16
;
83 case COLOR_Yxy
: return TYPE_Yxy_16
;
84 case COLOR_Lab
: return TYPE_Lab_16
;
85 case COLOR_CMYK
: return TYPE_CMYK_16
;
87 FIXME("unhandled color type\n");
92 #endif /* HAVE_LCMS */
94 /******************************************************************************
95 * CreateColorTransformA [MSCMS.@]
97 * See CreateColorTransformW.
99 HTRANSFORM WINAPI
CreateColorTransformA( LPLOGCOLORSPACEA space
, HPROFILE dest
,
100 HPROFILE target
, DWORD flags
)
102 LOGCOLORSPACEW spaceW
;
105 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
107 if (!space
|| !dest
) return FALSE
;
109 memcpy( &spaceW
, space
, FIELD_OFFSET(LOGCOLORSPACEA
, lcsFilename
) );
110 spaceW
.lcsSize
= sizeof(LOGCOLORSPACEW
);
112 len
= MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, NULL
, 0 );
113 MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, spaceW
.lcsFilename
, len
);
115 return CreateColorTransformW( &spaceW
, dest
, target
, flags
);
118 /******************************************************************************
119 * CreateColorTransformW [MSCMS.@]
121 * Create a color transform.
124 * space [I] Input color space.
125 * dest [I] Color profile of destination device.
126 * target [I] Color profile of target device.
130 * Success: Handle to a transform.
133 HTRANSFORM WINAPI
CreateColorTransformW( LPLOGCOLORSPACEW space
, HPROFILE dest
,
134 HPROFILE target
, DWORD flags
)
136 HTRANSFORM ret
= NULL
;
138 struct transform transform
;
139 struct profile
*dst
, *tgt
= NULL
;
140 cmsHPROFILE cmsinput
, cmsoutput
, cmstarget
= NULL
;
141 DWORD in_format
, out_format
, proofing
= 0;
144 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
146 if (!space
|| !(dst
= grab_profile( dest
))) return FALSE
;
148 if (target
&& !(tgt
= grab_profile( target
)))
150 release_profile( dst
);
153 intent
= space
->lcsIntent
> 3 ? INTENT_PERCEPTUAL
: space
->lcsIntent
;
155 TRACE( "lcsIntent: %x\n", space
->lcsIntent
);
156 TRACE( "lcsCSType: %s\n", MSCMS_dbgstr_tag( space
->lcsCSType
) );
157 TRACE( "lcsFilename: %s\n", debugstr_w( space
->lcsFilename
) );
159 in_format
= TYPE_RGB_16
;
160 out_format
= from_profile( dest
);
162 cmsinput
= cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
165 proofing
= cmsFLAGS_SOFTPROOFING
;
166 cmstarget
= tgt
->cmsprofile
;
168 cmsoutput
= dst
->cmsprofile
;
169 transform
.cmstransform
= cmsCreateProofingTransform(cmsinput
, in_format
, cmsoutput
, out_format
, cmstarget
,
170 intent
, INTENT_ABSOLUTE_COLORIMETRIC
, proofing
);
172 ret
= create_transform( &transform
);
174 if (tgt
) release_profile( tgt
);
175 release_profile( dst
);
177 #endif /* HAVE_LCMS */
181 /******************************************************************************
182 * CreateMultiProfileTransform [MSCMS.@]
184 * Create a color transform from an array of color profiles.
187 * profiles [I] Array of color profiles.
188 * nprofiles [I] Number of color profiles.
189 * intents [I] Array of rendering intents.
191 * cmm [I] Profile to take the CMM from.
194 * Success: Handle to a transform.
197 HTRANSFORM WINAPI
CreateMultiProfileTransform( PHPROFILE profiles
, DWORD nprofiles
,
198 PDWORD intents
, DWORD nintents
, DWORD flags
, DWORD cmm
)
200 HTRANSFORM ret
= NULL
;
202 cmsHPROFILE
*cmsprofiles
, cmsconvert
= NULL
;
203 struct transform transform
;
204 struct profile
*profile0
, *profile1
;
205 DWORD in_format
, out_format
;
207 TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x )\n",
208 profiles
, nprofiles
, intents
, nintents
, flags
, cmm
);
210 if (!profiles
|| !nprofiles
|| !intents
) return NULL
;
214 FIXME("more than 2 profiles not supported\n");
218 profile0
= grab_profile( profiles
[0] );
219 if (!profile0
) return NULL
;
220 profile1
= grab_profile( profiles
[1] );
223 release_profile( profile0
);
226 in_format
= from_profile( profiles
[0] );
227 out_format
= from_profile( profiles
[nprofiles
- 1] );
229 if (in_format
!= out_format
)
231 /* insert a conversion profile for pairings that lcms doesn't handle */
232 if (out_format
== TYPE_RGB_16
) cmsconvert
= cmsCreate_sRGBProfile();
233 if (out_format
== TYPE_Lab_16
) cmsconvert
= cmsCreateLabProfile( NULL
);
236 cmsprofiles
= HeapAlloc( GetProcessHeap(), 0, (nprofiles
+ 1) * sizeof(cmsHPROFILE
*) );
239 cmsprofiles
[0] = profile0
->cmsprofile
;
242 cmsprofiles
[1] = cmsconvert
;
243 cmsprofiles
[2] = profile1
->cmsprofile
;
248 cmsprofiles
[1] = profile1
->cmsprofile
;
250 transform
.cmstransform
= cmsCreateMultiprofileTransform( cmsprofiles
, nprofiles
, in_format
, out_format
, *intents
, 0 );
252 HeapFree( GetProcessHeap(), 0, cmsprofiles
);
253 ret
= create_transform( &transform
);
256 release_profile( profile0
);
257 release_profile( profile1
);
259 #endif /* HAVE_LCMS */
263 /******************************************************************************
264 * DeleteColorTransform [MSCMS.@]
266 * Delete a color transform.
269 * transform [I] Handle to a color transform.
275 BOOL WINAPI
DeleteColorTransform( HTRANSFORM handle
)
280 TRACE( "( %p )\n", handle
);
282 ret
= close_transform( handle
);
284 #endif /* HAVE_LCMS */
288 /******************************************************************************
289 * TranslateBitmapBits [MSCMS.@]
291 * Perform color translation.
294 * transform [I] Handle to a color transform.
295 * srcbits [I] Source bitmap.
296 * input [I] Format of the source bitmap.
297 * width [I] Width of the source bitmap.
298 * height [I] Height of the source bitmap.
299 * inputstride [I] Number of bytes in one scanline.
300 * destbits [I] Destination bitmap.
301 * output [I] Format of the destination bitmap.
302 * outputstride [I] Number of bytes in one scanline.
303 * callback [I] Callback function.
304 * data [I] Callback data.
310 BOOL WINAPI
TranslateBitmapBits( HTRANSFORM handle
, PVOID srcbits
, BMFORMAT input
,
311 DWORD width
, DWORD height
, DWORD inputstride
, PVOID destbits
, BMFORMAT output
,
312 DWORD outputstride
, PBMCALLBACKFN callback
, ULONG data
)
316 struct transform
*transform
= grab_transform( handle
);
318 TRACE( "( %p, %p, 0x%08x, 0x%08x, 0x%08x, 0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x )\n",
319 handle
, srcbits
, input
, width
, height
, inputstride
, destbits
, output
,
320 outputstride
, callback
, data
);
322 if (!transform
) return FALSE
;
323 cmsChangeBuffersFormat( transform
->cmstransform
, from_bmformat(input
), from_bmformat(output
) );
325 cmsDoTransform( transform
->cmstransform
, srcbits
, destbits
, width
* height
);
326 release_transform( transform
);
329 #endif /* HAVE_LCMS */
333 /******************************************************************************
334 * TranslateColors [MSCMS.@]
336 * Perform color translation.
339 * transform [I] Handle to a color transform.
340 * input [I] Array of input colors.
341 * number [I] Number of colors to translate.
342 * input_type [I] Input color format.
343 * output [O] Array of output colors.
344 * output_type [I] Output color format.
350 BOOL WINAPI
TranslateColors( HTRANSFORM handle
, PCOLOR in
, DWORD count
,
351 COLORTYPE input_type
, PCOLOR out
, COLORTYPE output_type
)
355 struct transform
*transform
= grab_transform( handle
);
359 TRACE( "( %p, %p, %d, %d, %p, %d )\n", handle
, in
, count
, input_type
, out
, output_type
);
361 if (!transform
) return FALSE
;
363 xfrm
= transform
->cmstransform
;
364 cmsChangeBuffersFormat( xfrm
, from_type(input_type
), from_type(output_type
) );
372 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].rgb
, 1 ); return TRUE
;
373 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].Lab
, 1 ); return TRUE
;
374 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].gray
, 1 ); return TRUE
;
375 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].cmyk
, 1 ); return TRUE
;
376 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].XYZ
, 1 ); return TRUE
;
378 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
386 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].rgb
, 1 ); return TRUE
;
387 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].Lab
, 1 ); return TRUE
;
388 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].gray
, 1 ); return TRUE
;
389 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].cmyk
, 1 ); return TRUE
;
390 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].XYZ
, 1 ); return TRUE
;
392 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
400 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].rgb
, 1 ); return TRUE
;
401 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].Lab
, 1 ); return TRUE
;
402 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].gray
, 1 ); return TRUE
;
403 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].cmyk
, 1 ); return TRUE
;
404 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].XYZ
, 1 ); return TRUE
;
406 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
414 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].rgb
, 1 ); return TRUE
;
415 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].Lab
, 1 ); return TRUE
;
416 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].gray
, 1 ); return TRUE
;
417 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].cmyk
, 1 ); return TRUE
;
418 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].XYZ
, 1 ); return TRUE
;
420 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
428 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].rgb
, 1 ); return TRUE
;
429 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].Lab
, 1 ); return TRUE
;
430 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].gray
, 1 ); return TRUE
;
431 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].cmyk
, 1 ); return TRUE
;
432 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].XYZ
, 1 ); return TRUE
;
434 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
439 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
442 release_transform( transform
);
444 #endif /* HAVE_LCMS */