Pass the main exe name in the CREATE_PROCESS debug event.
[wine.git] / dlls / wineps / bitmap.c
blobe6e76d003ca76fb736c557cac25fd18d24b65b10
1 /*
2 * PostScript driver bitmap functions
4 * Copyright 1998 Huw D M Davies
6 */
8 #include "gdi.h"
9 #include "psdrv.h"
10 #include "debugtools.h"
11 #include "bitmap.h"
12 #include "winbase.h"
14 DEFAULT_DEBUG_CHANNEL(psdrv)
17 /***************************************************************************
18 * PSDRV_WriteImageHeader
20 * Helper for PSDRV_StretchDIBits
22 * BUGS
23 * Uses level 2 PostScript
26 static BOOL PSDRV_WriteImageHeader(DC *dc, const BITMAPINFO *info, INT xDst,
27 INT yDst, INT widthDst, INT heightDst,
28 INT widthSrc, INT heightSrc)
30 COLORREF map[256];
31 int i;
33 switch(info->bmiHeader.biBitCount) {
34 case 8:
35 PSDRV_WriteIndexColorSpaceBegin(dc, 255);
36 for(i = 0; i < 256; i++) {
37 map[i] = info->bmiColors[i].rgbRed |
38 info->bmiColors[i].rgbGreen << 8 |
39 info->bmiColors[i].rgbBlue << 16;
41 PSDRV_WriteRGB(dc, map, 256);
42 PSDRV_WriteIndexColorSpaceEnd(dc);
43 break;
45 case 4:
46 PSDRV_WriteIndexColorSpaceBegin(dc, 15);
47 for(i = 0; i < 16; i++) {
48 map[i] = info->bmiColors[i].rgbRed |
49 info->bmiColors[i].rgbGreen << 8 |
50 info->bmiColors[i].rgbBlue << 16;
52 PSDRV_WriteRGB(dc, map, 16);
53 PSDRV_WriteIndexColorSpaceEnd(dc);
54 break;
56 case 1:
57 PSDRV_WriteIndexColorSpaceBegin(dc, 1);
58 for(i = 0; i < 2; i++) {
59 map[i] = info->bmiColors[i].rgbRed |
60 info->bmiColors[i].rgbGreen << 8 |
61 info->bmiColors[i].rgbBlue << 16;
63 PSDRV_WriteRGB(dc, map, 2);
64 PSDRV_WriteIndexColorSpaceEnd(dc);
65 break;
67 case 15:
68 case 16:
69 case 24:
70 case 32:
72 PSCOLOR pscol;
73 pscol.type = PSCOLOR_RGB;
74 pscol.value.rgb.r = pscol.value.rgb.g = pscol.value.rgb.b = 0.0;
75 PSDRV_WriteSetColor(dc, &pscol);
76 break;
79 default:
80 FIXME("Not implemented yet\n");
81 return FALSE;
82 break;
85 PSDRV_WriteImageDict(dc, info->bmiHeader.biBitCount, xDst, yDst,
86 widthDst, heightDst, widthSrc, heightSrc, NULL);
87 return TRUE;
91 /***************************************************************************
93 * PSDRV_StretchDIBits
95 * BUGS
96 * Doesn't work correctly if xSrc isn't byte aligned - this affects 1 and 4
97 * bit depths.
98 * Compression not implemented.
100 INT PSDRV_StretchDIBits( DC *dc, INT xDst, INT yDst, INT widthDst,
101 INT heightDst, INT xSrc, INT ySrc,
102 INT widthSrc, INT heightSrc, const void *bits,
103 const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
105 DWORD fullSrcWidth;
106 INT widthbytes, fullSrcHeight;
107 WORD bpp, compression;
108 const char *ptr;
109 INT line;
111 TRACE("%08x (%d,%d %dx%d) -> (%d,%d %dx%d)\n", dc->hSelf,
112 xSrc, ySrc, widthSrc, heightSrc, xDst, yDst, widthDst, heightDst);
114 DIB_GetBitmapInfo((const BITMAPINFOHEADER *)info, &fullSrcWidth,
115 &fullSrcHeight, &bpp, &compression);
117 widthbytes = DIB_GetDIBWidthBytes(fullSrcWidth, bpp);
119 TRACE("full size=%ldx%d bpp=%d compression=%d\n", fullSrcWidth,
120 fullSrcHeight, bpp, compression);
123 if(compression != BI_RGB) {
124 FIXME("Compression not supported\n");
125 return FALSE;
128 xDst = XLPTODP(dc, xDst);
129 yDst = YLPTODP(dc, yDst);
130 widthDst = XLSTODS(dc, widthDst);
131 heightDst = YLSTODS(dc, heightDst);
133 switch(bpp) {
135 case 1:
136 PSDRV_WriteGSave(dc);
137 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
138 widthSrc, heightSrc);
139 ptr = bits;
140 ptr += (ySrc * widthbytes);
141 if(xSrc & 7)
142 FIXME("This won't work...\n");
143 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
144 PSDRV_WriteBytes(dc, ptr + xSrc/8, (widthSrc+7)/8);
145 break;
147 case 4:
148 PSDRV_WriteGSave(dc);
149 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
150 widthSrc, heightSrc);
151 ptr = bits;
152 ptr += (ySrc * widthbytes);
153 if(xSrc & 1)
154 FIXME("This won't work...\n");
155 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
156 PSDRV_WriteBytes(dc, ptr + xSrc/2, (widthSrc+1)/2);
157 break;
159 case 8:
160 PSDRV_WriteGSave(dc);
161 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
162 widthSrc, heightSrc);
163 ptr = bits;
164 ptr += (ySrc * widthbytes);
165 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
166 PSDRV_WriteBytes(dc, ptr + xSrc, widthSrc);
167 break;
169 case 15:
170 case 16:
171 PSDRV_WriteGSave(dc);
172 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
173 widthSrc, heightSrc);
175 ptr = bits;
176 ptr += (ySrc * widthbytes);
177 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
178 PSDRV_WriteDIBits16(dc, (WORD *)ptr + xSrc, widthSrc);
179 break;
181 case 24:
182 PSDRV_WriteGSave(dc);
183 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
184 widthSrc, heightSrc);
186 ptr = bits;
187 ptr += (ySrc * widthbytes);
188 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
189 PSDRV_WriteDIBits24(dc, ptr + xSrc * 3, widthSrc);
190 break;
192 case 32:
193 PSDRV_WriteGSave(dc);
194 PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
195 widthSrc, heightSrc);
197 ptr = bits;
198 ptr += (ySrc * widthbytes);
199 for(line = 0; line < heightSrc; line++, ptr += widthbytes)
200 PSDRV_WriteDIBits32(dc, ptr + xSrc * 3, widthSrc);
201 break;
203 default:
204 FIXME("Unsupported depth\n");
205 return FALSE;
208 PSDRV_WriteSpool(dc, "%\n", 2); /* some versions of ghostscript seem to
209 eat one too many chars after the image
210 operator */
211 PSDRV_WriteGRestore(dc);
212 return TRUE;