icm.c 6.89 KB
Newer Older
1 2 3 4
/*
 * Image Color Management
 *
 * Copyright 2004 Marcus Meissner
5
 * Copyright 2008 Hans Leidekker
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23 24 25
 */

#include "config.h"

#include <stdarg.h>
#include <string.h>
26

27 28 29
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
30
#include "winnls.h"
31
#include "winreg.h"
32

33 34
#include "gdi_private.h"

35
#include "wine/debug.h"
36
#include "wine/unicode.h"
37 38 39 40

WINE_DEFAULT_DEBUG_CHANNEL(icm);


41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
struct enum_profiles
{
    BOOL unicode;
    union
    {
        ICMENUMPROCA funcA;
        ICMENUMPROCW funcW;
    } callback;
    LPARAM data;
};

INT CALLBACK enum_profiles_callback( LPWSTR filename, LPARAM lparam )
{
    int len, ret = -1;
    struct enum_profiles *ep = (struct enum_profiles *)lparam;
    char *filenameA;

    if (ep->unicode)
        return ep->callback.funcW( filename, ep->data );

    len = WideCharToMultiByte( CP_ACP, 0, filename, -1, NULL, 0, NULL, NULL );
    filenameA = HeapAlloc( GetProcessHeap(), 0, len );
    if (filenameA)
    {
        WideCharToMultiByte( CP_ACP, 0, filename, -1, filenameA, len, NULL, NULL );
        ret = ep->callback.funcA( filenameA, ep->data );
        HeapFree( GetProcessHeap(), 0, filenameA );
    }
    return ret;
}

72 73 74
/***********************************************************************
 *           EnumICMProfilesA    (GDI32.@)
 */
75 76
INT WINAPI EnumICMProfilesA(HDC hdc, ICMENUMPROCA func, LPARAM lparam)
{
77
    DC *dc;
78 79 80
    INT ret = -1;

    TRACE("%p, %p, 0x%08lx\n", hdc, func, lparam);
81 82 83

    if (!func) return -1;
    if ((dc = get_dc_ptr(hdc)))
84 85 86 87 88 89 90 91 92 93 94 95 96
    {
        if (dc->funcs->pEnumICMProfiles)
        {
            struct enum_profiles ep;

            ep.unicode        = FALSE;
            ep.callback.funcA = func;
            ep.data           = lparam;
            ret = dc->funcs->pEnumICMProfiles(dc->physDev, enum_profiles_callback, (LPARAM)&ep);
        }
        release_dc_ptr(dc);
    }
    return ret;
97 98 99 100 101
}

/***********************************************************************
 *           EnumICMProfilesW    (GDI32.@)
 */
102 103
INT WINAPI EnumICMProfilesW(HDC hdc, ICMENUMPROCW func, LPARAM lparam)
{
104
    DC *dc;
105 106 107
    INT ret = -1;

    TRACE("%p, %p, 0x%08lx\n", hdc, func, lparam);
108 109 110

    if (!func) return -1;
    if ((dc = get_dc_ptr(hdc)))
111 112 113 114 115 116 117 118 119 120 121 122 123
    {
        if (dc->funcs->pEnumICMProfiles)
        {
            struct enum_profiles ep;

            ep.unicode        = TRUE;
            ep.callback.funcW = func;
            ep.data           = lparam;
            ret = dc->funcs->pEnumICMProfiles(dc->physDev, enum_profiles_callback, (LPARAM)&ep);
        }
        release_dc_ptr(dc);
    }
    return ret;
124
}
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168

/**********************************************************************
 *           GetICMProfileA   (GDI32.@)
 *
 * Returns the filename of the specified device context's color
 * management profile, even if color management is not enabled
 * for that DC.
 *
 * RETURNS
 *    TRUE if filename is copied successfully.
 *    FALSE if the buffer length pointed to by size is too small.
 *
 * FIXME
 *    How does Windows assign these? Some registry key?
 */
BOOL WINAPI GetICMProfileA(HDC hdc, LPDWORD size, LPSTR filename)
{
    WCHAR filenameW[MAX_PATH];
    DWORD buflen = MAX_PATH;
    BOOL ret = FALSE;

    TRACE("%p, %p, %p\n", hdc, size, filename);

    if (!hdc || !size || !filename) return FALSE;

    if (GetICMProfileW(hdc, &buflen, filenameW))
    {
        int len = WideCharToMultiByte(CP_ACP, 0, filenameW, -1, NULL, 0, NULL, NULL);
        if (*size >= len)
        {
            WideCharToMultiByte(CP_ACP, 0, filenameW, -1, filename, *size, NULL, NULL);
            ret = TRUE;
        }
        else SetLastError(ERROR_INSUFFICIENT_BUFFER);
        *size = len;
    }
    return ret;
}

/**********************************************************************
 *           GetICMProfileW     (GDI32.@)
 */
BOOL WINAPI GetICMProfileW(HDC hdc, LPDWORD size, LPWSTR filename)
{
169 170
    BOOL ret = FALSE;
    DC *dc = get_dc_ptr(hdc);
171 172 173

    TRACE("%p, %p, %p\n", hdc, size, filename);

174
    if (dc)
175
    {
176 177 178
        if (dc->funcs->pGetICMProfile)
            ret = dc->funcs->pGetICMProfile(dc->physDev, size, filename);
        release_dc_ptr(dc);
179
    }
180
    return ret;
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
}

/**********************************************************************
 *           GetLogColorSpaceA     (GDI32.@)
 */
BOOL WINAPI GetLogColorSpaceA(HCOLORSPACE colorspace, LPLOGCOLORSPACEA buffer, DWORD size)
{
    FIXME("%p %p 0x%08x stub\n", colorspace, buffer, size);
    return FALSE;
}

/**********************************************************************
 *           GetLogColorSpaceW      (GDI32.@)
 */
BOOL WINAPI GetLogColorSpaceW(HCOLORSPACE colorspace, LPLOGCOLORSPACEW buffer, DWORD size)
{
    FIXME("%p %p 0x%08x stub\n", colorspace, buffer, size);
    return FALSE;
}

/**********************************************************************
 *           SetICMProfileA         (GDI32.@)
 */
BOOL WINAPI SetICMProfileA(HDC hdc, LPSTR filename)
{
    FIXME("%p %s stub\n", hdc, debugstr_a(filename));
207 208 209 210 211 212 213 214 215 216 217

    if (!filename)
    {
        SetLastError( ERROR_INVALID_PARAMETER );
        return FALSE;
    }
    if (!hdc)
    {
        SetLastError( ERROR_INVALID_HANDLE );
        return FALSE;
    }
218 219 220 221 222 223 224 225 226
    return TRUE;
}

/**********************************************************************
 *           SetICMProfileW         (GDI32.@)
 */
BOOL WINAPI SetICMProfileW(HDC hdc, LPWSTR filename)
{
    FIXME("%p %s stub\n", hdc, debugstr_w(filename));
227 228 229 230 231 232 233 234 235 236 237

    if (!filename)
    {
        SetLastError( ERROR_INVALID_PARAMETER );
        return FALSE;
    }
    if (!hdc)
    {
        SetLastError( ERROR_INVALID_HANDLE );
        return FALSE;
    }
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
    return TRUE;
}

/**********************************************************************
 *           UpdateICMRegKeyA       (GDI32.@)
 */
BOOL WINAPI UpdateICMRegKeyA(DWORD reserved, LPSTR cmid, LPSTR filename, UINT command)
{
    FIXME("0x%08x, %s, %s, 0x%08x stub\n", reserved, debugstr_a(cmid), debugstr_a(filename), command);
    return TRUE;
}

/**********************************************************************
 *           UpdateICMRegKeyW       (GDI32.@)
 */
BOOL WINAPI UpdateICMRegKeyW(DWORD reserved, LPWSTR cmid, LPWSTR filename, UINT command)
{
    FIXME("0x%08x, %s, %s, 0x%08x stub\n", reserved, debugstr_w(cmid), debugstr_w(filename), command);
    return TRUE;
}