color.c 3.18 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3 4 5
/*
 *	PostScript colour functions
 *
 *	Copyright 1998  Huw D M Davies
 *
6 7 8 9 10 11 12 13 14 15 16 17
 * 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
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
Alexandre Julliard's avatar
Alexandre Julliard committed
19 20 21
 */

#include "psdrv.h"
22
#include "wine/debug.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
23

24
WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
25

Alexandre Julliard's avatar
Alexandre Julliard committed
26 27 28 29 30

/**********************************************************************
 *	     PSDRV_CopyColor
 *
 * Copies col2 into col1. Return FALSE on error.
31
 */
32
BOOL PSDRV_CopyColor(PSCOLOR *col1, PSCOLOR *col2)
Alexandre Julliard's avatar
Alexandre Julliard committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46
{

    switch(col2->type) {
    case PSCOLOR_GRAY:
        col1->value.gray.i = col2->value.gray.i;
	break;

    case PSCOLOR_RGB:
        col1->value.rgb.r = col2->value.rgb.r;
	col1->value.rgb.g = col2->value.rgb.g;
	col1->value.rgb.b = col2->value.rgb.b;
	break;

    default:
47
        ERR("Unknown colour type %d\n", col1->type);
Alexandre Julliard's avatar
Alexandre Julliard committed
48 49 50 51 52 53 54
	return FALSE;
    }

    col1->type = col2->type;
    return TRUE;
}

55 56 57 58 59 60
PSRGB rgb_to_grayscale_scale( void )
{
    static const PSRGB scale = {0.3, 0.59, 0.11};
    /* FIXME configurable */
    return scale;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
61 62 63 64 65

/**********************************************************************
 *	     PSDRV_CreateColor
 *
 * Creates a PostScript colour from a COLORREF.
66
 * Result is grey scale if ColorDevice field of ppd is CD_False else an
Alexandre Julliard's avatar
Alexandre Julliard committed
67 68
 * rgb colour is produced.
 */
69
void PSDRV_CreateColor( PHYSDEV dev, PSCOLOR *pscolor, COLORREF wincolor )
Alexandre Julliard's avatar
Alexandre Julliard committed
70
{
71
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
Alexandre Julliard's avatar
Alexandre Julliard committed
72 73 74
    int ctype = wincolor >> 24;
    float r, g, b;

75
    if(ctype != 0 && ctype != 2)
76
        FIXME("Colour is %08x\n", wincolor);
Alexandre Julliard's avatar
Alexandre Julliard committed
77 78 79 80 81

    r = (wincolor & 0xff) / 256.0;
    g = ((wincolor >> 8) & 0xff) / 256.0;
    b = ((wincolor >> 16) & 0xff) / 256.0;

82
    if(physDev->pi->ppd->ColorDevice != CD_False) {
Alexandre Julliard's avatar
Alexandre Julliard committed
83 84 85 86 87
        pscolor->type = PSCOLOR_RGB;
	pscolor->value.rgb.r = r;
	pscolor->value.rgb.g = g;
	pscolor->value.rgb.b = b;
    } else {
88
        PSRGB scale = rgb_to_grayscale_scale();
Alexandre Julliard's avatar
Alexandre Julliard committed
89
        pscolor->type = PSCOLOR_GRAY;
90
        pscolor->value.gray.i = r * scale.r + g * scale.g + b * scale.b;
Alexandre Julliard's avatar
Alexandre Julliard committed
91 92 93 94 95 96 97 98
    }
    return;
}


/***********************************************************************
 *           PSDRV_SetBkColor
 */
99
COLORREF PSDRV_SetBkColor( PHYSDEV dev, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
100
{
101 102
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
    PSDRV_CreateColor(dev, &physDev->bkColor, color);
103
    return color;
Alexandre Julliard's avatar
Alexandre Julliard committed
104 105 106 107 108 109
}


/***********************************************************************
 *           PSDRV_SetTextColor
 */
110
COLORREF PSDRV_SetTextColor( PHYSDEV dev, COLORREF color )
Alexandre Julliard's avatar
Alexandre Julliard committed
111
{
112 113
    PSDRV_PDEVICE *physDev = get_psdrv_dev( dev );
    PSDRV_CreateColor(dev, &physDev->font.color, color);
Alexandre Julliard's avatar
Alexandre Julliard committed
114
    physDev->font.set = FALSE;
115
    return color;
Alexandre Julliard's avatar
Alexandre Julliard committed
116
}