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_bmformat( BMFORMAT format
)
41 static BOOL quietfixme
= FALSE
;
46 case BM_RGBTRIPLETS
: ret
= TYPE_RGB_8
; break;
47 case BM_BGRTRIPLETS
: ret
= TYPE_BGR_8
; break;
48 case BM_GRAY
: ret
= TYPE_GRAY_8
; break;
49 case BM_xRGBQUADS
: ret
= TYPE_ARGB_8
; break;
50 case BM_xBGRQUADS
: ret
= TYPE_ABGR_8
; break;
54 FIXME( "unhandled bitmap format %08x\n", format
);
60 TRACE( "color space: %08x -> %08x\n", format
, ret
);
64 static DWORD
from_type( COLORTYPE type
)
70 case COLOR_GRAY
: ret
= TYPE_GRAY_16
; break;
71 case COLOR_RGB
: ret
= TYPE_RGB_16
; break;
72 case COLOR_XYZ
: ret
= TYPE_XYZ_16
; break;
73 case COLOR_Yxy
: ret
= TYPE_Yxy_16
; break;
74 case COLOR_Lab
: ret
= TYPE_Lab_16
; break;
75 case COLOR_CMYK
: ret
= TYPE_CMYK_16
; break;
77 FIXME( "unhandled color type %08x\n", type
);
82 TRACE( "color type: %08x -> %08x\n", type
, ret
);
86 #endif /* HAVE_LCMS2 */
88 /******************************************************************************
89 * CreateColorTransformA [MSCMS.@]
91 * See CreateColorTransformW.
93 HTRANSFORM WINAPI
CreateColorTransformA( LPLOGCOLORSPACEA space
, HPROFILE dest
,
94 HPROFILE target
, DWORD flags
)
96 LOGCOLORSPACEW spaceW
;
99 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
101 if (!space
|| !dest
) return FALSE
;
103 memcpy( &spaceW
, space
, FIELD_OFFSET(LOGCOLORSPACEA
, lcsFilename
) );
104 spaceW
.lcsSize
= sizeof(LOGCOLORSPACEW
);
106 len
= MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, NULL
, 0 );
107 MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, spaceW
.lcsFilename
, len
);
109 return CreateColorTransformW( &spaceW
, dest
, target
, flags
);
112 /******************************************************************************
113 * CreateColorTransformW [MSCMS.@]
115 * Create a color transform.
118 * space [I] Input color space.
119 * dest [I] Color profile of destination device.
120 * target [I] Color profile of target device.
124 * Success: Handle to a transform.
127 HTRANSFORM WINAPI
CreateColorTransformW( LPLOGCOLORSPACEW space
, HPROFILE dest
,
128 HPROFILE target
, DWORD flags
)
130 HTRANSFORM ret
= NULL
;
132 struct transform transform
;
133 struct profile
*dst
, *tgt
= NULL
;
134 cmsHPROFILE cmsinput
, cmsoutput
, cmstarget
= NULL
;
138 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
140 if (!space
|| !(dst
= grab_profile( dest
))) return FALSE
;
142 if (target
&& !(tgt
= grab_profile( target
)))
144 release_profile( dst
);
147 intent
= space
->lcsIntent
> 3 ? INTENT_PERCEPTUAL
: space
->lcsIntent
;
149 TRACE( "lcsIntent: %x\n", space
->lcsIntent
);
150 TRACE( "lcsCSType: %s\n", dbgstr_tag( space
->lcsCSType
) );
151 TRACE( "lcsFilename: %s\n", debugstr_w( space
->lcsFilename
) );
153 cmsinput
= cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
156 proofing
= cmsFLAGS_SOFTPROOFING
;
157 cmstarget
= tgt
->cmsprofile
;
159 cmsoutput
= dst
->cmsprofile
;
160 transform
.cmstransform
= cmsCreateProofingTransform(cmsinput
, 0, cmsoutput
, 0, cmstarget
,
161 intent
, INTENT_ABSOLUTE_COLORIMETRIC
,
163 if (!transform
.cmstransform
)
165 if (tgt
) release_profile( tgt
);
166 release_profile( dst
);
170 ret
= create_transform( &transform
);
172 if (tgt
) release_profile( tgt
);
173 release_profile( dst
);
175 #endif /* HAVE_LCMS2 */
179 /******************************************************************************
180 * CreateMultiProfileTransform [MSCMS.@]
182 * Create a color transform from an array of color profiles.
185 * profiles [I] Array of color profiles.
186 * nprofiles [I] Number of color profiles.
187 * intents [I] Array of rendering intents.
189 * cmm [I] Profile to take the CMM from.
192 * Success: Handle to a transform.
195 HTRANSFORM WINAPI
CreateMultiProfileTransform( PHPROFILE profiles
, DWORD nprofiles
,
196 PDWORD intents
, DWORD nintents
, DWORD flags
, DWORD cmm
)
198 HTRANSFORM ret
= NULL
;
200 cmsHPROFILE
*cmsprofiles
;
201 struct transform transform
;
202 struct profile
*profile0
, *profile1
;
204 TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x )\n",
205 profiles
, nprofiles
, intents
, nintents
, flags
, cmm
);
207 if (!profiles
|| !nprofiles
|| !intents
) return NULL
;
211 FIXME("more than 2 profiles not supported\n");
215 profile0
= grab_profile( profiles
[0] );
216 if (!profile0
) return NULL
;
217 profile1
= grab_profile( profiles
[1] );
220 release_profile( profile0
);
224 if ((cmsprofiles
= HeapAlloc( GetProcessHeap(), 0, (nprofiles
+ 1) * sizeof(cmsHPROFILE
) )))
226 cmsprofiles
[0] = profile0
->cmsprofile
;
227 cmsprofiles
[1] = profile1
->cmsprofile
;
229 transform
.cmstransform
= cmsCreateMultiprofileTransform( cmsprofiles
, nprofiles
, 0,
231 HeapFree( GetProcessHeap(), 0, cmsprofiles
);
232 if (!transform
.cmstransform
)
234 release_profile( profile0
);
235 release_profile( profile1
);
238 ret
= create_transform( &transform
);
241 release_profile( profile0
);
242 release_profile( profile1
);
244 #endif /* HAVE_LCMS2 */
248 /******************************************************************************
249 * DeleteColorTransform [MSCMS.@]
251 * Delete a color transform.
254 * transform [I] Handle to a color transform.
260 BOOL WINAPI
DeleteColorTransform( HTRANSFORM handle
)
265 TRACE( "( %p )\n", handle
);
267 ret
= close_transform( handle
);
269 #endif /* HAVE_LCMS2 */
273 /******************************************************************************
274 * TranslateBitmapBits [MSCMS.@]
276 * Perform color translation.
279 * transform [I] Handle to a color transform.
280 * srcbits [I] Source bitmap.
281 * input [I] Format of the source bitmap.
282 * width [I] Width of the source bitmap.
283 * height [I] Height of the source bitmap.
284 * inputstride [I] Number of bytes in one scanline.
285 * destbits [I] Destination bitmap.
286 * output [I] Format of the destination bitmap.
287 * outputstride [I] Number of bytes in one scanline.
288 * callback [I] Callback function.
289 * data [I] Callback data.
295 BOOL WINAPI
TranslateBitmapBits( HTRANSFORM handle
, PVOID srcbits
, BMFORMAT input
,
296 DWORD width
, DWORD height
, DWORD inputstride
, PVOID destbits
, BMFORMAT output
,
297 DWORD outputstride
, PBMCALLBACKFN callback
, ULONG data
)
301 struct transform
*transform
= grab_transform( handle
);
303 TRACE( "( %p, %p, 0x%08x, 0x%08x, 0x%08x, 0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x )\n",
304 handle
, srcbits
, input
, width
, height
, inputstride
, destbits
, output
,
305 outputstride
, callback
, data
);
307 if (!transform
) return FALSE
;
308 if (!cmsChangeBuffersFormat( transform
->cmstransform
, from_bmformat(input
), from_bmformat(output
) ))
311 cmsDoTransform( transform
->cmstransform
, srcbits
, destbits
, width
* height
);
312 release_transform( transform
);
315 #endif /* HAVE_LCMS2 */
319 /******************************************************************************
320 * TranslateColors [MSCMS.@]
322 * Perform color translation.
325 * transform [I] Handle to a color transform.
326 * input [I] Array of input colors.
327 * number [I] Number of colors to translate.
328 * input_type [I] Input color format.
329 * output [O] Array of output colors.
330 * output_type [I] Output color format.
336 BOOL WINAPI
TranslateColors( HTRANSFORM handle
, PCOLOR in
, DWORD count
,
337 COLORTYPE input_type
, PCOLOR out
, COLORTYPE output_type
)
341 struct transform
*transform
= grab_transform( handle
);
345 TRACE( "( %p, %p, %d, %d, %p, %d )\n", handle
, in
, count
, input_type
, out
, output_type
);
347 if (!transform
) return FALSE
;
349 xfrm
= transform
->cmstransform
;
350 if (!cmsChangeBuffersFormat( xfrm
, from_type(input_type
), from_type(output_type
) ))
359 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].rgb
, 1 ); goto done
;
360 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].Lab
, 1 ); goto done
;
361 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].gray
, 1 ); goto done
;
362 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].cmyk
, 1 ); goto done
;
363 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].rgb
, &out
[i
].XYZ
, 1 ); goto done
;
365 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
375 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].rgb
, 1 ); goto done
;
376 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].Lab
, 1 ); goto done
;
377 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].gray
, 1 ); goto done
;
378 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].cmyk
, 1 ); goto done
;
379 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].Lab
, &out
[i
].XYZ
, 1 ); goto done
;
381 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
391 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].rgb
, 1 ); goto done
;
392 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].Lab
, 1 ); goto done
;
393 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].gray
, 1 ); goto done
;
394 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].cmyk
, 1 ); goto done
;
395 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].gray
, &out
[i
].XYZ
, 1 ); goto done
;
397 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
407 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].rgb
, 1 ); goto done
;
408 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].Lab
, 1 ); goto done
;
409 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].gray
, 1 ); goto done
;
410 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].cmyk
, 1 ); goto done
;
411 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].cmyk
, &out
[i
].XYZ
, 1 ); goto done
;
413 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
423 case COLOR_RGB
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].rgb
, 1 ); goto done
;
424 case COLOR_Lab
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].Lab
, 1 ); goto done
;
425 case COLOR_GRAY
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].gray
, 1 ); goto done
;
426 case COLOR_CMYK
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].cmyk
, 1 ); goto done
;
427 case COLOR_XYZ
: for (i
= 0; i
< count
; i
++) cmsDoTransform( xfrm
, &in
[i
].XYZ
, &out
[i
].XYZ
, 1 ); goto done
;
429 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
436 FIXME("unhandled input/output pair: %d/%d\n", input_type
, output_type
);
442 release_transform( transform
);
445 #else /* HAVE_LCMS2 */
447 #endif /* HAVE_LCMS2 */