d3d9: Remove a few more incorrect D3DLOCK_DISCARDs.
[wine] / dlls / mscms / transform.c
1 /*
2  * MSCMS - Color Management System for Wine
3  *
4  * Copyright 2005, 2006 Hans Leidekker
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include "config.h"
22 #include "wine/debug.h"
23
24 #include <stdarg.h>
25
26 #include "windef.h"
27 #include "winbase.h"
28 #include "winnls.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "icm.h"
32
33 #include "mscms_priv.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(mscms);
36
37 /******************************************************************************
38  * CreateColorTransformA            [MSCMS.@]
39  *
40  * See CreateColorTransformW.
41  */
42 HTRANSFORM WINAPI CreateColorTransformA( LPLOGCOLORSPACEA space, HPROFILE dest,
43     HPROFILE target, DWORD flags )
44 {
45     LOGCOLORSPACEW spaceW;
46     DWORD len;
47
48     TRACE( "( %p, %p, %p, 0x%08x )\n", space, dest, target, flags );
49
50     if (!space || !dest) return FALSE;
51
52     memcpy( &spaceW, space, FIELD_OFFSET(LOGCOLORSPACEA, lcsFilename) );
53     spaceW.lcsSize = sizeof(LOGCOLORSPACEW);
54
55     len = MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, NULL, 0 );
56     MultiByteToWideChar( CP_ACP, 0, space->lcsFilename, -1, spaceW.lcsFilename, len );
57
58     return CreateColorTransformW( &spaceW, dest, target, flags );
59 }
60
61 /******************************************************************************
62  * CreateColorTransformW            [MSCMS.@]
63  *
64  * Create a color transform.
65  *
66  * PARAMS
67  *  space  [I] Input color space.
68  *  dest   [I] Color profile of destination device.
69  *  target [I] Color profile of target device.
70  *  flags  [I] Flags.
71  *
72  * RETURNS
73  *  Success: Handle to a transform.
74  *  Failure: NULL
75  */
76 HTRANSFORM WINAPI CreateColorTransformW( LPLOGCOLORSPACEW space, HPROFILE dest,
77     HPROFILE target, DWORD flags )
78 {
79     HTRANSFORM ret = NULL;
80 #ifdef HAVE_LCMS
81     cmsHTRANSFORM cmstransform;
82     cmsHPROFILE cmsprofiles[3];
83     int intent;
84
85     TRACE( "( %p, %p, %p, 0x%08x )\n", space, dest, target, flags );
86
87     if (!space || !dest) return FALSE;
88
89     intent = space->lcsIntent > 3 ? INTENT_PERCEPTUAL : space->lcsIntent;
90
91     cmsprofiles[0] = cmsCreate_sRGBProfile(); /* FIXME: create from supplied color space */
92     cmsprofiles[1] = MSCMS_hprofile2cmsprofile( dest ); 
93
94     if (target)
95     {
96         cmsprofiles[2] = MSCMS_hprofile2cmsprofile( target );
97         cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, 3, TYPE_BGR_8,
98                                                        TYPE_BGR_8, intent, 0 );
99     }
100     else
101         cmstransform = cmsCreateTransform( cmsprofiles[0], TYPE_BGR_8, cmsprofiles[1],
102                                            TYPE_BGR_8, intent, 0 );
103
104     ret = MSCMS_create_htransform_handle( cmstransform );
105
106 #endif /* HAVE_LCMS */
107     return ret;
108 }
109
110 /******************************************************************************
111  * CreateMultiProfileTransform      [MSCMS.@]
112  *
113  * Create a color transform from an array of color profiles.
114  *
115  * PARAMS
116  *  profiles  [I] Array of color profiles.
117  *  nprofiles [I] Number of color profiles.
118  *  intents   [I] Array of rendering intents.
119  *  flags     [I] Flags.
120  *  cmm       [I] Profile to take the CMM from.
121  *
122  * RETURNS
123  *  Success: Handle to a transform.
124  *  Failure: NULL
125  */ 
126 HTRANSFORM WINAPI CreateMultiProfileTransform( PHPROFILE profiles, DWORD nprofiles,
127     PDWORD intents, DWORD nintents, DWORD flags, DWORD cmm )
128 {
129     HTRANSFORM ret = NULL;
130 #ifdef HAVE_LCMS
131     cmsHPROFILE *cmsprofiles;
132     cmsHTRANSFORM cmstransform;
133     DWORD i;
134
135     TRACE( "( %p, 0x%08x, %p, 0x%08x, 0x%08x, 0x%08x ) stub\n",
136            profiles, nprofiles, intents, nintents, flags, cmm );
137
138     if (!profiles || !intents) return NULL;
139
140     cmsprofiles = HeapAlloc( GetProcessHeap(), 0, nprofiles * sizeof(cmsHPROFILE) );
141
142     if (cmsprofiles)
143     {
144         for (i = 0; i < nprofiles; i++)
145             cmsprofiles[i] = MSCMS_hprofile2cmsprofile( profiles[i] );
146     }
147
148     cmstransform = cmsCreateMultiprofileTransform( cmsprofiles, nprofiles, TYPE_BGR_8,
149                                                    TYPE_BGR_8, *intents, 0 );
150     HeapFree( GetProcessHeap(), 0, cmsprofiles );
151     ret = MSCMS_create_htransform_handle( cmstransform );
152
153 #endif /* HAVE_LCMS */
154     return ret;
155 }
156
157 /******************************************************************************
158  * DeleteColorTransform             [MSCMS.@]
159  *
160  * Delete a color transform.
161  *
162  * PARAMS
163  *  transform [I] Handle to a color transform.
164  *
165  * RETURNS
166  *  Success: TRUE
167  *  Failure: FALSE
168  */ 
169 BOOL WINAPI DeleteColorTransform( HTRANSFORM transform )
170 {
171     BOOL ret = FALSE;
172 #ifdef HAVE_LCMS
173     cmsHTRANSFORM cmstransform;
174
175     TRACE( "( %p )\n", transform );
176
177     cmstransform = MSCMS_htransform2cmstransform( transform );
178     cmsDeleteTransform( cmstransform );
179
180     MSCMS_destroy_htransform_handle( transform );
181     ret = TRUE;
182
183 #endif /* HAVE_LCMS */
184     return ret;
185 }
186
187 /******************************************************************************
188  * TranslateBitmapBits              [MSCMS.@]
189  *
190  * Perform color translation.
191  *
192  * PARAMS
193  *  transform    [I] Handle to a color transform.
194  *  srcbits      [I] Source bitmap.
195  *  input        [I] Format of the source bitmap.
196  *  width        [I] Width of the source bitmap.
197  *  height       [I] Height of the source bitmap.
198  *  inputstride  [I] Number of bytes in one scanline.
199  *  destbits     [I] Destination bitmap.
200  *  output       [I] Format of the destination bitmap.
201  *  outputstride [I] Number of bytes in one scanline. 
202  *  callback     [I] Callback function.
203  *  data         [I] Callback data. 
204  *
205  * RETURNS
206  *  Success: TRUE
207  *  Failure: FALSE
208  */
209 BOOL WINAPI TranslateBitmapBits( HTRANSFORM transform, PVOID srcbits, BMFORMAT input,
210     DWORD width, DWORD height, DWORD inputstride, PVOID destbits, BMFORMAT output,
211     DWORD outputstride, PBMCALLBACKFN callback, ULONG data )
212 {
213     BOOL ret = FALSE;
214 #ifdef HAVE_LCMS
215     cmsHTRANSFORM cmstransform;
216
217     TRACE( "( %p, %p, 0x%08x, 0x%08x, 0x%08x, 0x%08x, %p, 0x%08x, 0x%08x, %p, 0x%08x )\n",
218            transform, srcbits, input, width, height, inputstride, destbits, output,
219            outputstride, callback, data );
220
221     cmstransform = MSCMS_htransform2cmstransform( transform );
222     cmsDoTransform( cmstransform, srcbits, destbits, width * height );
223     ret = TRUE;
224
225 #endif /* HAVE_LCMS */
226     return ret;
227 }