Added some stubs.
[wine] / dlls / wineps / bitmap.c
1 /*
2  *      PostScript driver bitmap functions
3  *
4  * Copyright 1998  Huw D M Davies
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "psdrv.h"
22 #include "wine/debug.h"
23 #include "bitmap.h"
24 #include "winbase.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
27
28
29 /***************************************************************************
30  *                PSDRV_WriteImageHeader
31  *
32  * Helper for PSDRV_StretchDIBits
33  *
34  * BUGS
35  *  Uses level 2 PostScript
36  */
37
38 static BOOL PSDRV_WriteImageHeader(DC *dc, const BITMAPINFO *info, INT xDst,
39                                    INT yDst, INT widthDst, INT heightDst,
40                                    INT widthSrc, INT heightSrc)
41 {
42     COLORREF map[256];
43     int i;
44
45     switch(info->bmiHeader.biBitCount) {
46     case 8:
47         PSDRV_WriteIndexColorSpaceBegin(dc, 255);
48         for(i = 0; i < 256; i++) {
49             map[i] =  info->bmiColors[i].rgbRed |
50               info->bmiColors[i].rgbGreen << 8 |
51               info->bmiColors[i].rgbBlue << 16;
52         }
53         PSDRV_WriteRGB(dc, map, 256);
54         PSDRV_WriteIndexColorSpaceEnd(dc);
55         break;
56
57     case 4:
58         PSDRV_WriteIndexColorSpaceBegin(dc, 15);
59         for(i = 0; i < 16; i++) {
60             map[i] =  info->bmiColors[i].rgbRed |
61               info->bmiColors[i].rgbGreen << 8 |
62               info->bmiColors[i].rgbBlue << 16;
63         }
64         PSDRV_WriteRGB(dc, map, 16);
65         PSDRV_WriteIndexColorSpaceEnd(dc);
66         break;
67
68     case 1:
69         PSDRV_WriteIndexColorSpaceBegin(dc, 1);
70         for(i = 0; i < 2; i++) {
71             map[i] =  info->bmiColors[i].rgbRed |
72               info->bmiColors[i].rgbGreen << 8 |
73               info->bmiColors[i].rgbBlue << 16;
74         }
75         PSDRV_WriteRGB(dc, map, 2);
76         PSDRV_WriteIndexColorSpaceEnd(dc);
77         break;
78
79     case 15:
80     case 16:
81     case 24:
82     case 32:
83       {
84         PSCOLOR pscol;
85         pscol.type = PSCOLOR_RGB;
86         pscol.value.rgb.r = pscol.value.rgb.g = pscol.value.rgb.b = 0.0;
87         PSDRV_WriteSetColor(dc, &pscol);
88         break;
89       }
90
91     default:
92         FIXME("Not implemented yet\n");
93         return FALSE;
94         break;
95     }
96
97     PSDRV_WriteImageDict(dc, info->bmiHeader.biBitCount, xDst, yDst,
98                           widthDst, heightDst, widthSrc, heightSrc, NULL);
99     return TRUE;
100 }
101
102
103 /***************************************************************************
104  *
105  *      PSDRV_StretchDIBits
106  *
107  * BUGS
108  *  Doesn't work correctly if xSrc isn't byte aligned - this affects 1 and 4
109  *  bit depths.
110  *  Compression not implemented.
111  */
112 INT PSDRV_StretchDIBits( DC *dc, INT xDst, INT yDst, INT widthDst,
113                          INT heightDst, INT xSrc, INT ySrc,
114                          INT widthSrc, INT heightSrc, const void *bits,
115                          const BITMAPINFO *info, UINT wUsage, DWORD dwRop )
116 {
117     DWORD fullSrcWidth;
118     INT widthbytes, fullSrcHeight;
119     WORD bpp, compression;
120     const char *ptr;
121     INT line;
122
123     TRACE("%08x (%d,%d %dx%d) -> (%d,%d %dx%d)\n", dc->hSelf,
124           xSrc, ySrc, widthSrc, heightSrc, xDst, yDst, widthDst, heightDst);
125
126     DIB_GetBitmapInfo((const BITMAPINFOHEADER *)info, &fullSrcWidth,
127                       &fullSrcHeight, &bpp, &compression);
128
129     widthbytes = DIB_GetDIBWidthBytes(fullSrcWidth, bpp);
130
131     TRACE("full size=%ldx%d bpp=%d compression=%d\n", fullSrcWidth,
132           fullSrcHeight, bpp, compression);
133
134
135     if(compression != BI_RGB) {
136         FIXME("Compression not supported\n");
137         return FALSE;
138     }
139
140     xDst = XLPTODP(dc, xDst);
141     yDst = YLPTODP(dc, yDst);
142     widthDst = XLSTODS(dc, widthDst);
143     heightDst = YLSTODS(dc, heightDst);
144
145     switch(bpp) {
146
147     case 1:
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 & 7)
154             FIXME("This won't work...\n");
155         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
156             PSDRV_WriteBytes(dc, ptr + xSrc/8, (widthSrc+7)/8);
157         break;
158
159     case 4:
160         PSDRV_WriteGSave(dc);
161         PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
162                                widthSrc, heightSrc);
163         ptr = bits;
164         ptr += (ySrc * widthbytes);
165         if(xSrc & 1)
166             FIXME("This won't work...\n");
167         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
168             PSDRV_WriteBytes(dc, ptr + xSrc/2, (widthSrc+1)/2);
169         break;
170
171     case 8:
172         PSDRV_WriteGSave(dc);
173         PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
174                                widthSrc, heightSrc);
175         ptr = bits;
176         ptr += (ySrc * widthbytes);
177         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
178             PSDRV_WriteBytes(dc, ptr + xSrc, widthSrc);
179         break;
180
181     case 15:
182     case 16:
183         PSDRV_WriteGSave(dc);
184         PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
185                                widthSrc, heightSrc);
186
187         ptr = bits;
188         ptr += (ySrc * widthbytes);
189         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
190             PSDRV_WriteDIBits16(dc, (WORD *)ptr + xSrc, widthSrc);
191         break;
192
193     case 24:
194         PSDRV_WriteGSave(dc);
195         PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
196                                widthSrc, heightSrc);
197
198         ptr = bits;
199         ptr += (ySrc * widthbytes);
200         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
201             PSDRV_WriteDIBits24(dc, ptr + xSrc * 3, widthSrc);
202         break;
203
204     case 32:
205         PSDRV_WriteGSave(dc);
206         PSDRV_WriteImageHeader(dc, info, xDst, yDst, widthDst, heightDst,
207                                widthSrc, heightSrc);
208
209         ptr = bits;
210         ptr += (ySrc * widthbytes);
211         for(line = 0; line < heightSrc; line++, ptr += widthbytes)
212             PSDRV_WriteDIBits32(dc, ptr + xSrc * 3, widthSrc);
213         break;
214
215     default:
216         FIXME("Unsupported depth\n");
217         return FALSE;
218
219     }
220     PSDRV_WriteSpool(dc, ">\n", 2);  /* End-of-Data for /HexASCIIDecodeFilter */
221     PSDRV_WriteGRestore(dc);
222     return TRUE;
223 }
224
225
226
227
228
229