dbgeng: Update to IDebugControl4 stub.
[wine.git] / dlls / mscms / transform.c
blob0d48e217d66c092bfc390f4e5a7607f04e2670bb
1 /*
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
21 #include <stdarg.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winnls.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "icm.h"
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;
38 DWORD ret;
40 switch (format)
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;
48 default:
49 if (!quietfixme)
51 FIXME( "unhandled bitmap format %#x\n", format );
52 quietfixme = TRUE;
54 ret = TYPE_RGB_8;
55 break;
57 TRACE( "color space: %#x -> %#lx\n", format, ret );
58 return ret;
61 static DWORD from_type( COLORTYPE type )
63 DWORD ret;
65 switch (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;
73 default:
74 FIXME( "unhandled color type %08x\n", type );
75 ret = TYPE_RGB_16;
76 break;
79 TRACE( "color type: %#x -> %#lx\n", type, ret );
80 return ret;
83 /******************************************************************************
84 * CreateColorTransformA [MSCMS.@]
86 * See CreateColorTransformW.
88 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest, HPROFILE target, DWORD flags )
90 LOGCOLORSPACEW spaceW;
91 DWORD len;
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.
111 * PARAMS
112 * space [I] Input color space.
113 * dest [I] Color profile of destination device.
114 * target [I] Color profile of target device.
115 * flags [I] Flags.
117 * RETURNS
118 * Success: Handle to a transform.
119 * Failure: NULL
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;
126 DWORD proofing = 0;
127 cmsHPROFILE input;
128 int intent;
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 );
137 return FALSE;
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 );
149 if (!transform)
151 if (tgt) release_profile( tgt );
152 release_profile( dst );
153 return FALSE;
156 ret = create_transform( transform );
158 if (tgt) release_profile( tgt );
159 release_profile( dst );
160 return ret;
163 /******************************************************************************
164 * CreateMultiProfileTransform [MSCMS.@]
166 * Create a color transform from an array of color profiles.
168 * PARAMS
169 * profiles [I] Array of color profiles.
170 * nprofiles [I] Number of color profiles.
171 * intents [I] Array of rendering intents.
172 * flags [I] Flags.
173 * cmm [I] Profile to take the CMM from.
175 * RETURNS
176 * Success: Handle to a transform.
177 * Failure: NULL
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;
191 if (nprofiles > 2)
193 FIXME("more than 2 profiles not supported\n");
194 return NULL;
197 profile0 = grab_profile( profiles[0] );
198 if (!profile0) return NULL;
199 profile1 = grab_profile( profiles[1] );
200 if (!profile1)
202 release_profile( profile0 );
203 return NULL;
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 );
214 return ret;
217 /******************************************************************************
218 * DeleteColorTransform [MSCMS.@]
220 * Delete a color transform.
222 * PARAMS
223 * transform [I] Handle to a color transform.
225 * RETURNS
226 * Success: TRUE
227 * Failure: FALSE
229 BOOL WINAPI DeleteColorTransform( HTRANSFORM handle )
231 TRACE( "( %p )\n", handle );
233 return close_transform( handle );
236 /******************************************************************************
237 * TranslateBitmapBits [MSCMS.@]
239 * Perform color translation.
241 * PARAMS
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.
254 * RETURNS
255 * Success: TRUE
256 * Failure: FALSE
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 )
262 BOOL ret;
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 );
273 return ret;
276 /******************************************************************************
277 * TranslateColors [MSCMS.@]
279 * Perform color translation.
281 * PARAMS
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.
289 * RETURNS
290 * Success: TRUE
291 * Failure: FALSE
293 BOOL WINAPI TranslateColors( HTRANSFORM handle, PCOLOR in, DWORD count,
294 COLORTYPE input_type, PCOLOR out, COLORTYPE output_type )
296 BOOL ret;
297 unsigned int i;
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) );
305 if (ret)
306 for (i = 0; i < count; i++) cmsDoTransform( transform, &in[i], &out[i], 1 );
308 release_transform( transform );
309 return ret;