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 %08x\n", format
);
57 TRACE( "color space: %08x -> %08x\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: %08x -> %08x\n", type
, ret
);
83 /******************************************************************************
84 * CreateColorTransformA [MSCMS.@]
86 * See CreateColorTransformW.
88 HTRANSFORM WINAPI
CreateColorTransformA( LPLOGCOLORSPACEA space
, HPROFILE dest
,
89 HPROFILE target
, DWORD flags
)
91 LOGCOLORSPACEW spaceW
;
94 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
96 if (!space
|| !dest
) return FALSE
;
98 memcpy( &spaceW
, space
, FIELD_OFFSET(LOGCOLORSPACEA
, lcsFilename
) );
99 spaceW
.lcsSize
= sizeof(LOGCOLORSPACEW
);
101 len
= MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, NULL
, 0 );
102 MultiByteToWideChar( CP_ACP
, 0, space
->lcsFilename
, -1, spaceW
.lcsFilename
, len
);
104 return CreateColorTransformW( &spaceW
, dest
, target
, flags
);
107 /******************************************************************************
108 * CreateColorTransformW [MSCMS.@]
110 * Create a color transform.
113 * space [I] Input color space.
114 * dest [I] Color profile of destination device.
115 * target [I] Color profile of target device.
119 * Success: Handle to a transform.
122 HTRANSFORM WINAPI
CreateColorTransformW( LPLOGCOLORSPACEW space
, HPROFILE dest
,
123 HPROFILE target
, DWORD flags
)
125 HTRANSFORM ret
= NULL
;
126 cmsHTRANSFORM transform
;
127 struct profile
*dst
, *tgt
= NULL
;
132 TRACE( "( %p, %p, %p, 0x%08x )\n", space
, dest
, target
, flags
);
134 if (!space
|| !(dst
= grab_profile( dest
))) return FALSE
;
136 if (target
&& !(tgt
= grab_profile( target
)))
138 release_profile( dst
);
141 intent
= space
->lcsIntent
> 3 ? INTENT_PERCEPTUAL
: space
->lcsIntent
;
143 TRACE( "lcsIntent: %x\n", space
->lcsIntent
);
144 TRACE( "lcsCSType: %s\n", dbgstr_tag( space
->lcsCSType
) );
145 TRACE( "lcsFilename: %s\n", debugstr_w( space
->lcsFilename
) );
147 input
= cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
148 if (target
) proofing
= cmsFLAGS_SOFTPROOFING
;
149 transform
= cmsCreateProofingTransform( input
, 0, dst
->cmsprofile
, 0, tgt
? tgt
->cmsprofile
: NULL
,
150 intent
, INTENT_ABSOLUTE_COLORIMETRIC
, proofing
);
153 if (tgt
) release_profile( tgt
);
154 release_profile( dst
);
158 ret
= create_transform( transform
);
160 if (tgt
) release_profile( tgt
);
161 release_profile( dst
);
165 /******************************************************************************
166 * CreateMultiProfileTransform [MSCMS.@]
168 * Create a color transform from an array of color profiles.
171 * profiles [I] Array of color profiles.
172 * nprofiles [I] Number of color profiles.
173 * intents [I] Array of rendering intents.
175 * cmm [I] Profile to take the CMM from.
178 * Success: Handle to a transform.
181 HTRANSFORM WINAPI
CreateMultiProfileTransform( PHPROFILE profiles
, DWORD nprofiles
,
182 PDWORD intents
, DWORD nintents
, DWORD flags
, DWORD cmm
)
184 HTRANSFORM ret
= NULL
;
185 cmsHPROFILE cmsprofiles
[2];
186 cmsHTRANSFORM transform
;
187 struct profile
*profile0
, *profile1
;
189 TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x )\n",
190 profiles
, nprofiles
, intents
, nintents
, flags
, cmm
);
192 if (!profiles
|| !nprofiles
|| !intents
) return NULL
;
196 FIXME("more than 2 profiles not supported\n");
200 profile0
= grab_profile( profiles
[0] );
201 if (!profile0
) return NULL
;
202 profile1
= grab_profile( profiles
[1] );
205 release_profile( profile0
);
209 cmsprofiles
[0] = profile0
->cmsprofile
;
210 cmsprofiles
[1] = profile1
->cmsprofile
;
212 transform
= cmsCreateMultiprofileTransform( cmsprofiles
, nprofiles
, 0, 0, *intents
, 0 );
213 if (transform
) ret
= create_transform( transform
);
215 release_profile( profile0
);
216 release_profile( profile1
);
220 /******************************************************************************
221 * DeleteColorTransform [MSCMS.@]
223 * Delete a color transform.
226 * transform [I] Handle to a color transform.
232 BOOL WINAPI
DeleteColorTransform( HTRANSFORM handle
)
234 TRACE( "( %p )\n", handle
);
236 return close_transform( handle
);
239 /******************************************************************************
240 * TranslateBitmapBits [MSCMS.@]
242 * Perform color translation.
245 * transform [I] Handle to a color transform.
246 * srcbits [I] Source bitmap.
247 * input [I] Format of the source bitmap.
248 * width [I] Width of the source bitmap.
249 * height [I] Height of the source bitmap.
250 * inputstride [I] Number of bytes in one scanline.
251 * destbits [I] Destination bitmap.
252 * output [I] Format of the destination bitmap.
253 * outputstride [I] Number of bytes in one scanline.
254 * callback [I] Callback function.
255 * data [I] Callback data.
261 BOOL WINAPI
TranslateBitmapBits( HTRANSFORM handle
, PVOID srcbits
, BMFORMAT input
,
262 DWORD width
, DWORD height
, DWORD inputstride
, PVOID destbits
, BMFORMAT output
,
263 DWORD outputstride
, PBMCALLBACKFN callback
, ULONG data
)
266 cmsHTRANSFORM transform
= grab_transform( handle
);
268 TRACE( "( %p, %p, 0x%08x, 0x%08x, 0x%08x, 0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x )\n",
269 handle
, srcbits
, input
, width
, height
, inputstride
, destbits
, output
,
270 outputstride
, callback
, data
);
272 if (!transform
) return FALSE
;
273 ret
= cmsChangeBuffersFormat( transform
, from_bmformat(input
), from_bmformat(output
) );
274 if (ret
) cmsDoTransform( transform
, srcbits
, destbits
, width
* height
);
275 release_transform( transform
);
279 /******************************************************************************
280 * TranslateColors [MSCMS.@]
282 * Perform color translation.
285 * transform [I] Handle to a color transform.
286 * input [I] Array of input colors.
287 * number [I] Number of colors to translate.
288 * input_type [I] Input color format.
289 * output [O] Array of output colors.
290 * output_type [I] Output color format.
296 BOOL WINAPI
TranslateColors( HTRANSFORM handle
, PCOLOR in
, DWORD count
,
297 COLORTYPE input_type
, PCOLOR out
, COLORTYPE output_type
)
301 cmsHTRANSFORM transform
= grab_transform( handle
);
303 TRACE( "( %p, %p, %d, %d, %p, %d )\n", handle
, in
, count
, input_type
, out
, output_type
);
305 if (!transform
) return FALSE
;
307 ret
= cmsChangeBuffersFormat( transform
, from_type(input_type
), from_type(output_type
) );
309 for (i
= 0; i
< count
; i
++) cmsDoTransform( transform
, &in
[i
], &out
[i
], 1 );
311 release_transform( transform
);