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