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
29 #include "wine/debug.h"
31 #include "mscms_priv.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mscms
);
35 static DWORD
from_bmformat( BMFORMAT format
)
37 static BOOL quietfixme
= FALSE
;
42 case BM_RGBTRIPLETS
: ret
= TYPE_RGB_8
; break;
43 case BM_BGRTRIPLETS
: ret
= TYPE_BGR_8
; break;
44 case BM_GRAY
: ret
= TYPE_GRAY_8
; break;
45 case BM_xRGBQUADS
: ret
= TYPE_ARGB_8
; break;
46 case BM_xBGRQUADS
: ret
= TYPE_ABGR_8
; break;
47 case BM_KYMCQUADS
: ret
= TYPE_KYMC_8
; break;
51 FIXME( "unhandled bitmap format %#x\n", format
);
57 TRACE( "color space: %#x -> %#lx\n", format
, ret
);
61 static DWORD
from_type( COLORTYPE type
)
67 case COLOR_GRAY
: ret
= TYPE_GRAY_16
; break;
68 case COLOR_RGB
: ret
= TYPE_RGB_16
; break;
69 case COLOR_XYZ
: ret
= TYPE_XYZ_16
; break;
70 case COLOR_Yxy
: ret
= TYPE_Yxy_16
; break;
71 case COLOR_Lab
: ret
= TYPE_Lab_16
; break;
72 case COLOR_CMYK
: ret
= TYPE_CMYK_16
; break;
74 FIXME( "unhandled color type %08x\n", type
);
79 TRACE( "color type: %#x -> %#lx\n", type
, ret
);
83 /******************************************************************************
84 * CreateColorTransformA [MSCMS.@]
86 * See CreateColorTransformW.
88 HTRANSFORM WINAPI
CreateColorTransformA( LPLOGCOLORSPACEA space
, HPROFILE dest
, HPROFILE target
, DWORD flags
)
90 LOGCOLORSPACEW spaceW
;
93 TRACE( "( %p, %p, %p, %#lx )\n", space
, dest
, target
, flags
);
95 if (!space
|| !dest
) return FALSE
;
97 memcpy( &spaceW
, space
, FIELD_OFFSET(LOGCOLORSPACEA
, lcsFilename
) );
98 spaceW
.lcsSize
= sizeof(LOGCOLORSPACEW
);
100 len
= MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, NULL
, 0 );
101 MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, spaceW
.lcsFilename
, len
);
103 return CreateColorTransformW( &spaceW
, dest
, target
, flags
);
106 /******************************************************************************
107 * CreateColorTransformW [MSCMS.@]
109 * Create a color transform.
112 * space [I] Input color space.
113 * dest [I] Color profile of destination device.
114 * target [I] Color profile of target device.
118 * Success: Handle to a transform.
121 HTRANSFORM WINAPI
CreateColorTransformW( LPLOGCOLORSPACEW space
, HPROFILE dest
, HPROFILE target
, DWORD flags
)
123 HTRANSFORM ret
= NULL
;
124 cmsHTRANSFORM transform
;
125 struct profile
*dst
, *tgt
= NULL
;
130 TRACE( "( %p, %p, %p, %#lx )\n", space
, dest
, target
, flags
);
132 if (!space
|| !(dst
= grab_profile( dest
))) return FALSE
;
134 if (target
&& !(tgt
= grab_profile( target
)))
136 release_profile( dst
);
139 intent
= space
->lcsIntent
> 3 ? INTENT_PERCEPTUAL
: space
->lcsIntent
;
141 TRACE( "lcsIntent: %#lx\n", space
->lcsIntent
);
142 TRACE( "lcsCSType: %s\n", dbgstr_tag( space
->lcsCSType
) );
143 TRACE( "lcsFilename: %s\n", debugstr_w( space
->lcsFilename
) );
145 input
= cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
146 if (target
) proofing
= cmsFLAGS_SOFTPROOFING
;
147 transform
= cmsCreateProofingTransform( input
, 0, dst
->cmsprofile
, 0, tgt
? tgt
->cmsprofile
: NULL
,
148 intent
, INTENT_ABSOLUTE_COLORIMETRIC
, proofing
);
151 if (tgt
) release_profile( tgt
);
152 release_profile( dst
);
156 ret
= create_transform( transform
);
158 if (tgt
) release_profile( tgt
);
159 release_profile( dst
);
163 /******************************************************************************
164 * CreateMultiProfileTransform [MSCMS.@]
166 * Create a color transform from an array of color profiles.
169 * profiles [I] Array of color profiles.
170 * nprofiles [I] Number of color profiles.
171 * intents [I] Array of rendering intents.
173 * cmm [I] Profile to take the CMM from.
176 * Success: Handle to a transform.
179 HTRANSFORM WINAPI
CreateMultiProfileTransform( PHPROFILE profiles
, DWORD nprofiles
,
180 PDWORD intents
, DWORD nintents
, DWORD flags
, DWORD cmm
)
182 HTRANSFORM ret
= NULL
;
183 cmsHPROFILE cmsprofiles
[2];
184 cmsHTRANSFORM transform
;
185 struct profile
*profile0
, *profile1
;
187 TRACE( "( %p, %#lx, %p, %lu, %#lx, %#lx )\n", profiles
, nprofiles
, intents
, nintents
, flags
, cmm
);
189 if (!profiles
|| !nprofiles
|| !intents
) return NULL
;
193 FIXME("more than 2 profiles not supported\n");
197 profile0
= grab_profile( profiles
[0] );
198 if (!profile0
) return NULL
;
199 profile1
= grab_profile( profiles
[1] );
202 release_profile( profile0
);
206 cmsprofiles
[0] = profile0
->cmsprofile
;
207 cmsprofiles
[1] = profile1
->cmsprofile
;
209 transform
= cmsCreateMultiprofileTransform( cmsprofiles
, nprofiles
, 0, 0, *intents
, 0 );
210 if (transform
) ret
= create_transform( transform
);
212 release_profile( profile0
);
213 release_profile( profile1
);
217 /******************************************************************************
218 * DeleteColorTransform [MSCMS.@]
220 * Delete a color transform.
223 * transform [I] Handle to a color transform.
229 BOOL WINAPI
DeleteColorTransform( HTRANSFORM handle
)
231 TRACE( "( %p )\n", handle
);
233 return close_transform( handle
);
236 /******************************************************************************
237 * TranslateBitmapBits [MSCMS.@]
239 * Perform color translation.
242 * transform [I] Handle to a color transform.
243 * srcbits [I] Source bitmap.
244 * input [I] Format of the source bitmap.
245 * width [I] Width of the source bitmap.
246 * height [I] Height of the source bitmap.
247 * inputstride [I] Number of bytes in one scanline.
248 * destbits [I] Destination bitmap.
249 * output [I] Format of the destination bitmap.
250 * outputstride [I] Number of bytes in one scanline.
251 * callback [I] Callback function.
252 * data [I] Callback data.
258 BOOL WINAPI
TranslateBitmapBits( HTRANSFORM handle
, PVOID srcbits
, BMFORMAT input
,
259 DWORD width
, DWORD height
, DWORD inputstride
, PVOID destbits
, BMFORMAT output
,
260 DWORD outputstride
, PBMCALLBACKFN callback
, ULONG data
)
263 cmsHTRANSFORM transform
= grab_transform( handle
);
265 TRACE( "( %p, %p, %#x, %lu, %lu, %lu, %p, %#x, %lu, %p, %#lx )\n",
266 handle
, srcbits
, input
, width
, height
, inputstride
, destbits
, output
,
267 outputstride
, callback
, data
);
269 if (!transform
) return FALSE
;
270 ret
= cmsChangeBuffersFormat( transform
, from_bmformat(input
), from_bmformat(output
) );
271 if (ret
) cmsDoTransform( transform
, srcbits
, destbits
, width
* height
);
272 release_transform( transform
);
276 /******************************************************************************
277 * TranslateColors [MSCMS.@]
279 * Perform color translation.
282 * transform [I] Handle to a color transform.
283 * input [I] Array of input colors.
284 * number [I] Number of colors to translate.
285 * input_type [I] Input color format.
286 * output [O] Array of output colors.
287 * output_type [I] Output color format.
293 BOOL WINAPI
TranslateColors( HTRANSFORM handle
, PCOLOR in
, DWORD count
,
294 COLORTYPE input_type
, PCOLOR out
, COLORTYPE output_type
)
298 cmsHTRANSFORM transform
= grab_transform( handle
);
300 TRACE( "( %p, %p, %lu, %d, %p, %d )\n", handle
, in
, count
, input_type
, out
, output_type
);
302 if (!transform
) return FALSE
;
304 ret
= cmsChangeBuffersFormat( transform
, from_type(input_type
), from_type(output_type
) );
306 for (i
= 0; i
< count
; i
++) cmsDoTransform( transform
, &in
[i
], &out
[i
], 1 );
308 release_transform( transform
);