icm.c 6.33 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
struct enum_profiles
{
43
    ICMENUMPROCA funcA;
44 45 46
    LPARAM data;
};

47
static INT CALLBACK enum_profiles_callbackA( LPWSTR filename, LPARAM lparam )
48 49 50 51 52 53 54 55 56 57
{
    int len, ret = -1;
    struct enum_profiles *ep = (struct enum_profiles *)lparam;
    char *filenameA;

    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 );
58
        ret = ep->funcA( filenameA, ep->data );
59 60 61 62 63
        HeapFree( GetProcessHeap(), 0, filenameA );
    }
    return ret;
}

64 65 66
/***********************************************************************
 *           EnumICMProfilesA    (GDI32.@)
 */
67 68
INT WINAPI EnumICMProfilesA(HDC hdc, ICMENUMPROCA func, LPARAM lparam)
{
69
    struct enum_profiles ep;
70 71

    if (!func) return -1;
72 73 74
    ep.funcA = func;
    ep.data  = lparam;
    return EnumICMProfilesW( hdc, enum_profiles_callbackA, (LPARAM)&ep );
75 76 77 78 79
}

/***********************************************************************
 *           EnumICMProfilesW    (GDI32.@)
 */
80 81
INT WINAPI EnumICMProfilesW(HDC hdc, ICMENUMPROCW func, LPARAM lparam)
{
82
    DC *dc;
83 84 85
    INT ret = -1;

    TRACE("%p, %p, 0x%08lx\n", hdc, func, lparam);
86 87 88

    if (!func) return -1;
    if ((dc = get_dc_ptr(hdc)))
89
    {
90 91
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pEnumICMProfiles );
        ret = physdev->funcs->pEnumICMProfiles( physdev, func, lparam );
92 93 94
        release_dc_ptr(dc);
    }
    return ret;
95
}
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118

/**********************************************************************
 *           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);

119
    if (!hdc || !size) return FALSE;
120 121 122 123

    if (GetICMProfileW(hdc, &buflen, filenameW))
    {
        int len = WideCharToMultiByte(CP_ACP, 0, filenameW, -1, NULL, 0, NULL, NULL);
124 125 126 127 128 129 130

        if (!filename)
        {
            *size = len;
            return FALSE;
        }

131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
        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)
{
147 148
    BOOL ret = FALSE;
    DC *dc = get_dc_ptr(hdc);
149 150 151

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

152
    if (dc)
153
    {
154 155
        PHYSDEV physdev = GET_DC_PHYSDEV( dc, pGetICMProfile );
        ret = physdev->funcs->pGetICMProfile( physdev, size, filename );
156
        release_dc_ptr(dc);
157
    }
158
    return ret;
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
}

/**********************************************************************
 *           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));
185 186 187 188 189 190 191 192 193 194 195

    if (!filename)
    {
        SetLastError( ERROR_INVALID_PARAMETER );
        return FALSE;
    }
    if (!hdc)
    {
        SetLastError( ERROR_INVALID_HANDLE );
        return FALSE;
    }
196 197 198 199 200 201 202 203 204
    return TRUE;
}

/**********************************************************************
 *           SetICMProfileW         (GDI32.@)
 */
BOOL WINAPI SetICMProfileW(HDC hdc, LPWSTR filename)
{
    FIXME("%p %s stub\n", hdc, debugstr_w(filename));
205 206 207 208 209 210 211 212 213 214 215

    if (!filename)
    {
        SetLastError( ERROR_INVALID_PARAMETER );
        return FALSE;
    }
    if (!hdc)
    {
        SetLastError( ERROR_INVALID_HANDLE );
        return FALSE;
    }
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
    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;
}