msvcp: Fix some spec file discrepancies.
[wine.git] / dlls / mscms / transform.c
blobfc005062e382d55269bcd15669805dc1cf1ad5cf
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 /******************************************************************************
36 * CreateColorTransformA [MSCMS.@]
38 * See CreateColorTransformW.
40 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest,
41 HPROFILE target, DWORD flags )
43 LOGCOLORSPACEW spaceW;
44 DWORD len;
46 TRACE( "( %p, %p, %p, 0x%08x )\n", space, dest, target, flags );
48 if (!space || !dest) return FALSE;
50 memcpy( &spaceW, space, FIELD_OFFSET(LOGCOLORSPACEA, lcsFilename) );
51 spaceW.lcsSize = sizeof(LOGCOLORSPACEW);
53 len = MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, NULL, 0 );
54 MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, spaceW.lcsFilename, len );
56 return CreateColorTransformW( &spaceW, dest, target, flags );
59 /******************************************************************************
60 * CreateColorTransformW [MSCMS.@]
62 * Create a color transform.
64 * PARAMS
65 * space [I] Input color space.
66 * dest [I] Color profile of destination device.
67 * target [I] Color profile of target device.
68 * flags [I] Flags.
70 * RETURNS
71 * Success: Handle to a transform.
72 * Failure: NULL
74 HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
75 HPROFILE target, DWORD flags )
77 HTRANSFORM ret = NULL;
78 struct transform transform;
79 struct profile *dst, *tgt = NULL;
80 int intent;
82 TRACE( "( %p, %p, %p, 0x%08x )\n", space, dest, target, flags );
84 if (!lcms_funcs) return FALSE;
85 if (!space || !(dst = grab_profile( dest ))) return FALSE;
87 if (target && !(tgt = grab_profile( target )))
89 release_profile( dst );
90 return FALSE;
92 intent = space->lcsIntent > 3 ? INTENT_PERCEPTUAL : space->lcsIntent;
94 TRACE( "lcsIntent: %x\n", space->lcsIntent );
95 TRACE( "lcsCSType: %s\n", dbgstr_tag( space->lcsCSType ) );
96 TRACE( "lcsFilename: %s\n", debugstr_w( space->lcsFilename ) );
98 transform.cmstransform = lcms_funcs->create_transform( dst->cmsprofile,
99 tgt ? tgt->cmsprofile : NULL, intent );
100 if (!transform.cmstransform)
102 if (tgt) release_profile( tgt );
103 release_profile( dst );
104 return FALSE;
107 ret = create_transform( &transform );
109 if (tgt) release_profile( tgt );
110 release_profile( dst );
111 return ret;
114 /******************************************************************************
115 * CreateMultiProfileTransform [MSCMS.@]
117 * Create a color transform from an array of color profiles.
119 * PARAMS
120 * profiles [I] Array of color profiles.
121 * nprofiles [I] Number of color profiles.
122 * intents [I] Array of rendering intents.
123 * flags [I] Flags.
124 * cmm [I] Profile to take the CMM from.
126 * RETURNS
127 * Success: Handle to a transform.
128 * Failure: NULL
130 HTRANSFORM WINAPI CreateMultiProfileTransform( PHPROFILE profiles, DWORD nprofiles,
131 PDWORD intents, DWORD nintents, DWORD flags, DWORD cmm )
133 HTRANSFORM ret = NULL;
134 void *cmsprofiles[2];
135 struct transform transform;
136 struct profile *profile0, *profile1;
138 TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x )\n",
139 profiles, nprofiles, intents, nintents, flags, cmm );
141 if (!lcms_funcs) return NULL;
142 if (!profiles || !nprofiles || !intents) return NULL;
144 if (nprofiles > 2)
146 FIXME("more than 2 profiles not supported\n");
147 return NULL;
150 profile0 = grab_profile( profiles[0] );
151 if (!profile0) return NULL;
152 profile1 = grab_profile( profiles[1] );
153 if (!profile1)
155 release_profile( profile0 );
156 return NULL;
159 cmsprofiles[0] = profile0->cmsprofile;
160 cmsprofiles[1] = profile1->cmsprofile;
162 transform.cmstransform = lcms_funcs->create_multi_transform( cmsprofiles, nprofiles, *intents );
163 if (transform.cmstransform) ret = create_transform( &transform );
165 release_profile( profile0 );
166 release_profile( profile1 );
167 return ret;
170 /******************************************************************************
171 * DeleteColorTransform [MSCMS.@]
173 * Delete a color transform.
175 * PARAMS
176 * transform [I] Handle to a color transform.
178 * RETURNS
179 * Success: TRUE
180 * Failure: FALSE
182 BOOL WINAPI DeleteColorTransform( HTRANSFORM handle )
184 TRACE( "( %p )\n", handle );
186 return close_transform( handle );
189 /******************************************************************************
190 * TranslateBitmapBits [MSCMS.@]
192 * Perform color translation.
194 * PARAMS
195 * transform [I] Handle to a color transform.
196 * srcbits [I] Source bitmap.
197 * input [I] Format of the source bitmap.
198 * width [I] Width of the source bitmap.
199 * height [I] Height of the source bitmap.
200 * inputstride [I] Number of bytes in one scanline.
201 * destbits [I] Destination bitmap.
202 * output [I] Format of the destination bitmap.
203 * outputstride [I] Number of bytes in one scanline.
204 * callback [I] Callback function.
205 * data [I] Callback data.
207 * RETURNS
208 * Success: TRUE
209 * Failure: FALSE
211 BOOL WINAPI TranslateBitmapBits( HTRANSFORM handle, PVOID srcbits, BMFORMAT input,
212 DWORD width, DWORD height, DWORD inputstride, PVOID destbits, BMFORMAT output,
213 DWORD outputstride, PBMCALLBACKFN callback, ULONG data )
215 BOOL ret;
216 struct transform *transform = grab_transform( handle );
218 TRACE( "( %p, %p, 0x%08x, 0x%08x, 0x%08x, 0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x )\n",
219 handle, srcbits, input, width, height, inputstride, destbits, output,
220 outputstride, callback, data );
222 if (!transform) return FALSE;
223 ret = lcms_funcs->translate_bits( transform->cmstransform, srcbits, input,
224 destbits, output, width * height );
225 release_transform( transform );
226 return ret;
229 /******************************************************************************
230 * TranslateColors [MSCMS.@]
232 * Perform color translation.
234 * PARAMS
235 * transform [I] Handle to a color transform.
236 * input [I] Array of input colors.
237 * number [I] Number of colors to translate.
238 * input_type [I] Input color format.
239 * output [O] Array of output colors.
240 * output_type [I] Output color format.
242 * RETURNS
243 * Success: TRUE
244 * Failure: FALSE
246 BOOL WINAPI TranslateColors( HTRANSFORM handle, PCOLOR in, DWORD count,
247 COLORTYPE input_type, PCOLOR out, COLORTYPE output_type )
249 BOOL ret;
250 struct transform *transform = grab_transform( handle );
252 TRACE( "( %p, %p, %d, %d, %p, %d )\n", handle, in, count, input_type, out, output_type );
254 if (!transform) return FALSE;
255 ret = lcms_funcs->translate_colors( transform->cmstransform, in, count, input_type, out, output_type );
256 release_transform( transform );
257 return ret;