d3d10/effect: Add a helper to read raw variable values.
[wine.git] / dlls / mscms / transform.c
blob8296341f7b772836ebe893f5d37b80ae3236a1a0
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 %08x\n", format );
52 quietfixme = TRUE;
54 ret = TYPE_RGB_8;
55 break;
57 TRACE( "color space: %08x -> %08x\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: %08x -> %08x\n", type, ret );
80 return ret;
83 /******************************************************************************
84 * CreateColorTransformA [MSCMS.@]
86 * See CreateColorTransformW.
88 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest,
89 HPROFILE target, DWORD flags )
91 LOGCOLORSPACEW spaceW;
92 DWORD len;
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.
112 * PARAMS
113 * space [I] Input color space.
114 * dest [I] Color profile of destination device.
115 * target [I] Color profile of target device.
116 * flags [I] Flags.
118 * RETURNS
119 * Success: Handle to a transform.
120 * Failure: NULL
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;
128 DWORD proofing = 0;
129 cmsHPROFILE input;
130 int intent;
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 );
139 return FALSE;
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 );
151 if (!transform)
153 if (tgt) release_profile( tgt );
154 release_profile( dst );
155 return FALSE;
158 ret = create_transform( transform );
160 if (tgt) release_profile( tgt );
161 release_profile( dst );
162 return ret;
165 /******************************************************************************
166 * CreateMultiProfileTransform [MSCMS.@]
168 * Create a color transform from an array of color profiles.
170 * PARAMS
171 * profiles [I] Array of color profiles.
172 * nprofiles [I] Number of color profiles.
173 * intents [I] Array of rendering intents.
174 * flags [I] Flags.
175 * cmm [I] Profile to take the CMM from.
177 * RETURNS
178 * Success: Handle to a transform.
179 * Failure: NULL
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;
194 if (nprofiles > 2)
196 FIXME("more than 2 profiles not supported\n");
197 return NULL;
200 profile0 = grab_profile( profiles[0] );
201 if (!profile0) return NULL;
202 profile1 = grab_profile( profiles[1] );
203 if (!profile1)
205 release_profile( profile0 );
206 return NULL;
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 );
217 return ret;
220 /******************************************************************************
221 * DeleteColorTransform [MSCMS.@]
223 * Delete a color transform.
225 * PARAMS
226 * transform [I] Handle to a color transform.
228 * RETURNS
229 * Success: TRUE
230 * Failure: FALSE
232 BOOL WINAPI DeleteColorTransform( HTRANSFORM handle )
234 TRACE( "( %p )\n", handle );
236 return close_transform( handle );
239 /******************************************************************************
240 * TranslateBitmapBits [MSCMS.@]
242 * Perform color translation.
244 * PARAMS
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.
257 * RETURNS
258 * Success: TRUE
259 * Failure: FALSE
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 )
265 BOOL ret;
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 );
276 return ret;
279 /******************************************************************************
280 * TranslateColors [MSCMS.@]
282 * Perform color translation.
284 * PARAMS
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.
292 * RETURNS
293 * Success: TRUE
294 * Failure: FALSE
296 BOOL WINAPI TranslateColors( HTRANSFORM handle, PCOLOR in, DWORD count,
297 COLORTYPE input_type, PCOLOR out, COLORTYPE output_type )
299 BOOL ret;
300 unsigned int i;
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) );
308 if (ret)
309 for (i = 0; i < count; i++) cmsDoTransform( transform, &in[i], &out[i], 1 );
311 release_transform( transform );
312 return ret;