4
#include "xdvi-config.h"
10
RGBQUAD QuadWhite = { 255, 255, 255, 0};
11
RGBQUAD QuadBlack = { 0, 0, 0, 0};
13
colormap_t win32_color_map[] =
15
{"snow" , MYRGB (255,250,250)},
16
{"ghost white" , MYRGB (248,248,255)},
17
{"GhostWhite" , MYRGB (248,248,255)},
18
{"white smoke" , MYRGB (245,245,245)},
19
{"WhiteSmoke" , MYRGB (245,245,245)},
20
{"gainsboro" , MYRGB (220,220,220)},
21
{"floral white" , MYRGB (255,250,240)},
22
{"FloralWhite" , MYRGB (255,250,240)},
23
{"old lace" , MYRGB (253,245,230)},
24
{"OldLace" , MYRGB (253,245,230)},
25
{"linen" , MYRGB (250,240,230)},
26
{"antique white" , MYRGB (250,235,215)},
27
{"AntiqueWhite" , MYRGB (250,235,215)},
28
{"papaya whip" , MYRGB (255,239,213)},
29
{"PapayaWhip" , MYRGB (255,239,213)},
30
{"blanched almond" , MYRGB (255,235,205)},
31
{"BlanchedAlmond" , MYRGB (255,235,205)},
32
{"bisque" , MYRGB (255,228,196)},
33
{"peach puff" , MYRGB (255,218,185)},
34
{"PeachPuff" , MYRGB (255,218,185)},
35
{"navajo white" , MYRGB (255,222,173)},
36
{"NavajoWhite" , MYRGB (255,222,173)},
37
{"moccasin" , MYRGB (255,228,181)},
38
{"cornsilk" , MYRGB (255,248,220)},
39
{"ivory" , MYRGB (255,255,240)},
40
{"lemon chiffon" , MYRGB (255,250,205)},
41
{"LemonChiffon" , MYRGB (255,250,205)},
42
{"seashell" , MYRGB (255,245,238)},
43
{"honeydew" , MYRGB (240,255,240)},
44
{"mint cream" , MYRGB (245,255,250)},
45
{"MintCream" , MYRGB (245,255,250)},
46
{"azure" , MYRGB (240,255,255)},
47
{"alice blue" , MYRGB (240,248,255)},
48
{"AliceBlue" , MYRGB (240,248,255)},
49
{"lavender" , MYRGB (230,230,250)},
50
{"lavender blush" , MYRGB (255,240,245)},
51
{"LavenderBlush" , MYRGB (255,240,245)},
52
{"misty rose" , MYRGB (255,228,225)},
53
{"MistyRose" , MYRGB (255,228,225)},
54
{"white" , MYRGB (255,255,255)},
55
{"black" , MYRGB ( 0, 0, 0)},
56
{"dark slate gray" , MYRGB ( 47, 79, 79)},
57
{"DarkSlateGray" , MYRGB ( 47, 79, 79)},
58
{"dark slate grey" , MYRGB ( 47, 79, 79)},
59
{"DarkSlateGrey" , MYRGB ( 47, 79, 79)},
60
{"dim gray" , MYRGB (105,105,105)},
61
{"DimGray" , MYRGB (105,105,105)},
62
{"dim grey" , MYRGB (105,105,105)},
63
{"DimGrey" , MYRGB (105,105,105)},
64
{"slate gray" , MYRGB (112,128,144)},
65
{"SlateGray" , MYRGB (112,128,144)},
66
{"slate grey" , MYRGB (112,128,144)},
67
{"SlateGrey" , MYRGB (112,128,144)},
68
{"light slate gray" , MYRGB (119,136,153)},
69
{"LightSlateGray" , MYRGB (119,136,153)},
70
{"light slate grey" , MYRGB (119,136,153)},
71
{"LightSlateGrey" , MYRGB (119,136,153)},
72
{"gray" , MYRGB (190,190,190)},
73
{"grey" , MYRGB (190,190,190)},
74
{"light grey" , MYRGB (211,211,211)},
75
{"LightGrey" , MYRGB (211,211,211)},
76
{"light gray" , MYRGB (211,211,211)},
77
{"LightGray" , MYRGB (211,211,211)},
78
{"midnight blue" , MYRGB ( 25, 25,112)},
79
{"MidnightBlue" , MYRGB ( 25, 25,112)},
80
{"navy" , MYRGB ( 0, 0,128)},
81
{"navy blue" , MYRGB ( 0, 0,128)},
82
{"NavyBlue" , MYRGB ( 0, 0,128)},
83
{"cornflower blue" , MYRGB (100,149,237)},
84
{"CornflowerBlue" , MYRGB (100,149,237)},
85
{"dark slate blue" , MYRGB ( 72, 61,139)},
86
{"DarkSlateBlue" , MYRGB ( 72, 61,139)},
87
{"slate blue" , MYRGB (106, 90,205)},
88
{"SlateBlue" , MYRGB (106, 90,205)},
89
{"medium slate blue" , MYRGB (123,104,238)},
90
{"MediumSlateBlue" , MYRGB (123,104,238)},
91
{"light slate blue" , MYRGB (132,112,255)},
92
{"LightSlateBlue" , MYRGB (132,112,255)},
93
{"medium blue" , MYRGB ( 0, 0,205)},
94
{"MediumBlue" , MYRGB ( 0, 0,205)},
95
{"royal blue" , MYRGB ( 65,105,225)},
96
{"RoyalBlue" , MYRGB ( 65,105,225)},
97
{"blue" , MYRGB ( 0, 0,255)},
98
{"dodger blue" , MYRGB ( 30,144,255)},
99
{"DodgerBlue" , MYRGB ( 30,144,255)},
100
{"deep sky blue" , MYRGB ( 0,191,255)},
101
{"DeepSkyBlue" , MYRGB ( 0,191,255)},
102
{"sky blue" , MYRGB (135,206,235)},
103
{"SkyBlue" , MYRGB (135,206,235)},
104
{"light sky blue" , MYRGB (135,206,250)},
105
{"LightSkyBlue" , MYRGB (135,206,250)},
106
{"steel blue" , MYRGB ( 70,130,180)},
107
{"SteelBlue" , MYRGB ( 70,130,180)},
108
{"light steel blue" , MYRGB (176,196,222)},
109
{"LightSteelBlue" , MYRGB (176,196,222)},
110
{"light blue" , MYRGB (173,216,230)},
111
{"LightBlue" , MYRGB (173,216,230)},
112
{"powder blue" , MYRGB (176,224,230)},
113
{"PowderBlue" , MYRGB (176,224,230)},
114
{"pale turquoise" , MYRGB (175,238,238)},
115
{"PaleTurquoise" , MYRGB (175,238,238)},
116
{"dark turquoise" , MYRGB ( 0,206,209)},
117
{"DarkTurquoise" , MYRGB ( 0,206,209)},
118
{"medium turquoise" , MYRGB ( 72,209,204)},
119
{"MediumTurquoise" , MYRGB ( 72,209,204)},
120
{"turquoise" , MYRGB ( 64,224,208)},
121
{"cyan" , MYRGB ( 0,255,255)},
122
{"light cyan" , MYRGB (224,255,255)},
123
{"LightCyan" , MYRGB (224,255,255)},
124
{"cadet blue" , MYRGB ( 95,158,160)},
125
{"CadetBlue" , MYRGB ( 95,158,160)},
126
{"medium aquamarine" , MYRGB (102,205,170)},
127
{"MediumAquamarine" , MYRGB (102,205,170)},
128
{"aquamarine" , MYRGB (127,255,212)},
129
{"dark green" , MYRGB ( 0,100, 0)},
130
{"DarkGreen" , MYRGB ( 0,100, 0)},
131
{"dark olive green" , MYRGB ( 85,107, 47)},
132
{"DarkOliveGreen" , MYRGB ( 85,107, 47)},
133
{"dark sea green" , MYRGB (143,188,143)},
134
{"DarkSeaGreen" , MYRGB (143,188,143)},
135
{"sea green" , MYRGB ( 46,139, 87)},
136
{"SeaGreen" , MYRGB ( 46,139, 87)},
137
{"medium sea green" , MYRGB ( 60,179,113)},
138
{"MediumSeaGreen" , MYRGB ( 60,179,113)},
139
{"light sea green" , MYRGB ( 32,178,170)},
140
{"LightSeaGreen" , MYRGB ( 32,178,170)},
141
{"pale green" , MYRGB (152,251,152)},
142
{"PaleGreen" , MYRGB (152,251,152)},
143
{"spring green" , MYRGB ( 0,255,127)},
144
{"SpringGreen" , MYRGB ( 0,255,127)},
145
{"lawn green" , MYRGB (124,252, 0)},
146
{"LawnGreen" , MYRGB (124,252, 0)},
147
{"green" , MYRGB ( 0,255, 0)},
148
{"chartreuse" , MYRGB (127,255, 0)},
149
{"medium spring green" , MYRGB ( 0,250,154)},
150
{"MediumSpringGreen" , MYRGB ( 0,250,154)},
151
{"green yellow" , MYRGB (173,255, 47)},
152
{"GreenYellow" , MYRGB (173,255, 47)},
153
{"lime green" , MYRGB ( 50,205, 50)},
154
{"LimeGreen" , MYRGB ( 50,205, 50)},
155
{"yellow green" , MYRGB (154,205, 50)},
156
{"YellowGreen" , MYRGB (154,205, 50)},
157
{"forest green" , MYRGB ( 34,139, 34)},
158
{"ForestGreen" , MYRGB ( 34,139, 34)},
159
{"olive drab" , MYRGB (107,142, 35)},
160
{"OliveDrab" , MYRGB (107,142, 35)},
161
{"dark khaki" , MYRGB (189,183,107)},
162
{"DarkKhaki" , MYRGB (189,183,107)},
163
{"khaki" , MYRGB (240,230,140)},
164
{"pale goldenrod" , MYRGB (238,232,170)},
165
{"PaleGoldenrod" , MYRGB (238,232,170)},
166
{"light goldenrod yellow" , MYRGB (250,250,210)},
167
{"LightGoldenrodYellow" , MYRGB (250,250,210)},
168
{"light yellow" , MYRGB (255,255,224)},
169
{"LightYellow" , MYRGB (255,255,224)},
170
{"yellow" , MYRGB (255,255, 0)},
171
{"gold" , MYRGB (255,215, 0)},
172
{"light goldenrod" , MYRGB (238,221,130)},
173
{"LightGoldenrod" , MYRGB (238,221,130)},
174
{"goldenrod" , MYRGB (218,165, 32)},
175
{"dark goldenrod" , MYRGB (184,134, 11)},
176
{"DarkGoldenrod" , MYRGB (184,134, 11)},
177
{"rosy brown" , MYRGB (188,143,143)},
178
{"RosyBrown" , MYRGB (188,143,143)},
179
{"indian red" , MYRGB (205, 92, 92)},
180
{"IndianRed" , MYRGB (205, 92, 92)},
181
{"saddle brown" , MYRGB (139, 69, 19)},
182
{"SaddleBrown" , MYRGB (139, 69, 19)},
183
{"sienna" , MYRGB (160, 82, 45)},
184
{"peru" , MYRGB (205,133, 63)},
185
{"burlywood" , MYRGB (222,184,135)},
186
{"beige" , MYRGB (245,245,220)},
187
{"wheat" , MYRGB (245,222,179)},
188
{"sandy brown" , MYRGB (244,164, 96)},
189
{"SandyBrown" , MYRGB (244,164, 96)},
190
{"tan" , MYRGB (210,180,140)},
191
{"chocolate" , MYRGB (210,105, 30)},
192
{"firebrick" , MYRGB (178,34, 34)},
193
{"brown" , MYRGB (165,42, 42)},
194
{"dark salmon" , MYRGB (233,150,122)},
195
{"DarkSalmon" , MYRGB (233,150,122)},
196
{"salmon" , MYRGB (250,128,114)},
197
{"light salmon" , MYRGB (255,160,122)},
198
{"LightSalmon" , MYRGB (255,160,122)},
199
{"orange" , MYRGB (255,165, 0)},
200
{"dark orange" , MYRGB (255,140, 0)},
201
{"DarkOrange" , MYRGB (255,140, 0)},
202
{"coral" , MYRGB (255,127, 80)},
203
{"light coral" , MYRGB (240,128,128)},
204
{"LightCoral" , MYRGB (240,128,128)},
205
{"tomato" , MYRGB (255, 99, 71)},
206
{"orange red" , MYRGB (255, 69, 0)},
207
{"OrangeRed" , MYRGB (255, 69, 0)},
208
{"red" , MYRGB (255, 0, 0)},
209
{"hot pink" , MYRGB (255,105,180)},
210
{"HotPink" , MYRGB (255,105,180)},
211
{"deep pink" , MYRGB (255, 20,147)},
212
{"DeepPink" , MYRGB (255, 20,147)},
213
{"pink" , MYRGB (255,192,203)},
214
{"light pink" , MYRGB (255,182,193)},
215
{"LightPink" , MYRGB (255,182,193)},
216
{"pale violet red" , MYRGB (219,112,147)},
217
{"PaleVioletRed" , MYRGB (219,112,147)},
218
{"maroon" , MYRGB (176, 48, 96)},
219
{"medium violet red" , MYRGB (199, 21,133)},
220
{"MediumVioletRed" , MYRGB (199, 21,133)},
221
{"violet red" , MYRGB (208, 32,144)},
222
{"VioletRed" , MYRGB (208, 32,144)},
223
{"magenta" , MYRGB (255, 0,255)},
224
{"violet" , MYRGB (238,130,238)},
225
{"plum" , MYRGB (221,160,221)},
226
{"orchid" , MYRGB (218,112,214)},
227
{"medium orchid" , MYRGB (186, 85,211)},
228
{"MediumOrchid" , MYRGB (186, 85,211)},
229
{"dark orchid" , MYRGB (153, 50,204)},
230
{"DarkOrchid" , MYRGB (153, 50,204)},
231
{"dark violet" , MYRGB (148, 0,211)},
232
{"DarkViolet" , MYRGB (148, 0,211)},
233
{"blue violet" , MYRGB (138, 43,226)},
234
{"BlueViolet" , MYRGB (138, 43,226)},
235
{"purple" , MYRGB (160, 32,240)},
236
{"medium purple" , MYRGB (147,112,219)},
237
{"MediumPurple" , MYRGB (147,112,219)},
238
{"thistle" , MYRGB (216,191,216)},
239
{"gray0" , MYRGB ( 0, 0, 0)},
240
{"grey0" , MYRGB ( 0, 0, 0)},
241
{"dark grey" , MYRGB (169,169,169)},
242
{"DarkGrey" , MYRGB (169,169,169)},
243
{"dark gray" , MYRGB (169,169,169)},
244
{"DarkGray" , MYRGB (169,169,169)},
245
{"dark blue" , MYRGB ( 0, 0,139)},
246
{"DarkBlue" , MYRGB ( 0, 0,139)},
247
{"dark cyan" , MYRGB ( 0,139,139)},
248
{"DarkCyan" , MYRGB ( 0,139,139)},
249
{"dark magenta" , MYRGB (139, 0,139)},
250
{"DarkMagenta" , MYRGB (139, 0,139)},
251
{"dark red" , MYRGB (139, 0, 0)},
252
{"DarkRed" , MYRGB (139, 0, 0)},
253
{"light green" , MYRGB (144,238,144)},
254
{"LightGreen" , MYRGB (144,238,144)}
257
int win32_color_map_size = sizeof(win32_color_map)/sizeof(colormap_t);
264
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
265
if (GetVersionEx(&os) == 0)
266
Win32Error("GetVersionEx");
267
is_nt = (os.dwPlatformId == VER_PLATFORM_WIN32_NT);
270
return si.wProcessorLevel <= 3;
272
return si.dwProcessorType == PROCESSOR_INTEL_386;
276
swap count bytes starting at address p
279
void bswap_asm(void *p, unsigned count)
282
mov edx, DWORD PTR p;
286
mov eax, DWORD PTR [edx];
288
mov DWORD PTR [edx], eax;
297
void bswap_c(void *p, unsigned count)
302
q < (unsigned char *)p + 4*count;
304
temp = *(q); *(q) = *(q+3); *(q+3) = temp;
305
temp = *(q+1); *(q+1) = *(q+2); *(q+2) = temp;
310
XsraSelFile(Widget toplevel, char *prompt, char *ok, char *cancel,
311
char *failed, char *init_path, char *mode,
312
int (*show_entry)(), char **name_return)
314
OPENFILENAME ofn; /* common dialog box structure */
315
char szFile[260]; /* buffer for filename */
317
char currentDir[260];
320
GetCurrentDirectory(sizeof(currentDir), currentDir);
323
/* Initialize OPENFILENAME */
324
ZeroMemory(&ofn, sizeof(OPENFILENAME));
325
ofn.lStructSize = sizeof(OPENFILENAME);
326
ofn.hwndOwner = toplevel;
327
ofn.lpstrFile = szFile;
328
ofn.nMaxFile = sizeof(szFile);
329
ofn.lpstrFilter = "Dvi Files\0*.dvi\0All Files\0*.*\0\0";
330
ofn.nFilterIndex = 1;
331
ofn.lpstrFileTitle = NULL;
332
ofn.nMaxFileTitle = 0;
333
ofn.lpstrInitialDir = NULL; /* FIXME : we should use init_path */
334
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
336
/* Display the Open dialog box. */
338
if (GetOpenFileName(&ofn)==TRUE) {
339
*name_return = xstrdup(szFile);
340
fret = fopen(*name_return, mode);
343
SetCurrentDirectory(currentDir);
344
if (CommDlgExtendedError() != 0)
345
MessageBox(toplevel, failed, NULL, MB_OK|MB_ICONERROR||MB_APPLMODAL);
350
COLORREF string_to_colorref(char *p)
353
float cyan, magenta, yellow, black, red, green, blue, gray;
355
while ( *p <= ' ' ) p++ ;
356
if (memicmp(p, "cmyk", 4) == 0) {
357
sscanf(p+4, "%f %f %f %f", &cyan, &magenta, &yellow, &black);
362
red = (float)fabs(magenta-yellow);
363
blue = (float)fabs(magenta - cyan);
364
green = (float)fabs(yellow - cyan);
366
c = MYRGB((unsigned)(red*255), (unsigned)(green*255), (unsigned)(blue*255));
368
else if (memicmp(p, "gray", 4) == 0) {
369
sscanf(p+4, "%f", &gray);
370
c = MYRGB((unsigned)(255*gray), (unsigned)(255*gray), (unsigned)(255*gray));
372
else if (memicmp(p, "rgb", 3) == 0) {
373
sscanf(p+3, "%f %f %f", &red, &green, &blue);
374
c = MYRGB((unsigned)(red*255), (unsigned)(green*255), (unsigned)(blue*255));
377
c = x_to_win32_color(p);
383
HRGN hClipRgn = NULL;
388
Time to clean up this routine.
389
Should handle clipping automatically.
390
Should handle transformations.
391
Grey scaling for colors is handled by complex rop code.
394
/* trial version : uses SetDIBits(), no temp DIB */
395
void XPutImage(void *scrn, HWND w, HDC hdc, XImage *img,
396
int src_x, int src_y,
397
int dest_x, int dest_y,
398
unsigned int width, unsigned int height)
404
HRGN hNewClipRgn = NULL;
405
XFORM xfrm, xfrm_temp;
406
extern BOOL bTransfInUse;
409
if (!allowDrawingChars) {
411
fprintf(stderr, "Not allowing chars drawing\n");
417
fprintf(stderr, "Back color is %-8x, mode is %s\n",
419
(GetBkMode(hdc) == OPAQUE ? "opaque" :
420
(GetBkMode(hdc) == TRANSPARENT ? "transparent" : "failed")));
425
fprintf(stderr, "fore = %x\n", fore_Pixel);
426
fprintf(stderr, "src_x = %d, src_y = %d, dest_x = %d, dest_y = %d\n",
427
src_x, src_y, dest_x, dest_y);
431
if (!img->width || !img->height) {
432
/* Nothing to do ! */
437
if (img->endian_permuted !=NULL && *(img->endian_permuted) == 0) {
438
bswap((BMUNIT*)img->data,
439
(img->bytes_per_line * height)/BMBYTES);
440
*(img->endian_permuted) = 1;
445
if (resource.use_xform && bTransfInUse) {
447
BOOL bClipped1, bClipped2;
448
extern XFORM current_transf;
451
rTemp.right = dest_x + width;
452
rTemp.bottom = dest_y + height;
453
if (SetWorldTransform(hdc, ¤t_transf) == 0)
454
Win32Error("XPutImage/SetWorldTransform/current");
458
lppt[1].x = dest_x + width;
460
lppt[2].x = dest_x + width;
461
lppt[2].y = dest_y + height;
463
lppt[3].y = dest_y + height;
464
LPtoDP(hdc, lppt, 4);
465
if ((hNewClipRgn = CreatePolygonRgn(lppt, 4, ALTERNATE)) == NULL) {
466
Win32Error("XPutImage/CreatePolygonRgn");
468
if (SelectClipRgn(hdc, hNewClipRgn) == ERROR) {
469
Win32Error("XPutImage/SelectClipRgn");
471
bClipped2 = RectVisible(hdc, &rTemp);
481
rTemp.right = dest_x + width;
482
rTemp.bottom = dest_y + height;
483
if (!RectVisible(hdc, &rTemp))
488
fprintf(stderr, "XPutImage at (%d %d) of (%d, %d, w=%d x h=%d)\n",
489
dest_x, dest_y, src_x, src_y, width, height);
491
switch (img->depth) {
493
bmi1.bmiHeader.biWidth = img->width;
494
bmi1.bmiHeader.biHeight = (img->height == 1 ? img->height : -img->height);
495
bmi1.bmiHeader.biSizeImage =
496
WIDTHBYTES((DWORD)img->width * img->depth)
497
* (img->height > 0 ? img->height : -img->height);
499
fprintf(stderr, "XPutImage at (%d %d) of (%d, %d, w=%d x h=%d)\n",
500
dest_x, dest_y, src_x, src_y, width, height);
501
fprintf(stderr, "bmiColors: 0 = %x, 1 = %x\n",
502
bmi1.bmiColors[0], bmi1.bmiColors[1]);
505
c1 = bmi1.bmiColors[0];
506
c2 = bmi1.bmiColors[1];
508
if (isPrinting && !(bColorPage || psToDisplay)) {
511
bmi1.bmiColors[0] = QuadWhite;
512
bmi1.bmiColors[1] = QuadBlack;
514
oldBrush = SelectObject(hdc, foreBrush);
516
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
517
src_x, src_y, width, height,
518
img->data, (LPBITMAPINFO)&bmi1,
519
DIB_RGB_COLORS, SRCAND /* 0x00B8074A 0x00E61CE8 */ ) == GDI_ERROR)
520
Win32Error("XPutImage/SetDIBits");
521
bmi1.bmiColors[0] = c1;
522
bmi1.bmiColors[1] = c2;
524
SelectObject(hdc, oldBrush);
529
init_pix( MYRGB(255,255,255), MYRGB(0,0,0));
530
oldBrush = SelectObject(hdc, foreBrush);
531
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
532
src_x, src_y, width, height,
533
img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, 0x00B8074A ) == GDI_ERROR)
534
Win32Error("XPutImage/SetDIBits");
535
SelectObject(hdc, oldBrush);
539
/* this is the 2 passes solution, but does not seem to work ok
541
bmi1.bmiColors[0] = QuadWhite;
542
bmi1.bmiColors[1] = QuadBlack;
544
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
545
src_x, src_y, width, height,
546
img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, SRCAND ) == GDI_ERROR)
547
Win32Error("XPutImage/SetDIBits");
549
bmi1.bmiColors[0] = QuadBlack;
550
bmi1.bmiColors[1] = Color2Quad(fore_Pixel);
552
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
553
src_x, src_y, width, height,
554
img->data, (LPBITMAPINFO)&bmi1, DIB_RGB_COLORS, SRCPAINT ) == GDI_ERROR)
555
Win32Error("XPutImage/SetDIBits");
556
bmi1.bmiColors[0] = c1;
557
bmi1.bmiColors[1] = Color2Quad(fore_Pixel);
564
RECT rcClip, rcGlyph, rcDest;
566
bmi4.bmiHeader.biWidth = img->width;
567
bmi4.bmiHeader.biHeight = (img->height == 1 ? img->height : -img->height);
568
bmi4.bmiHeader.biSizeImage =
569
WIDTHBYTES((DWORD)img->width * img->depth)
570
* (img->height > 0 ? img->height : -img->height);
573
fprintf(stderr, "XPutImage @ (%d %d) w %d h %d fore %-8x back %-8x\n",
574
dest_x, dest_y, width, height, fore_Pixel, back_Pixel);
578
fprintf(stderr, "This is%s a color page!\n", bColorPage ? "" : " not");
580
/* If this is a monochrome page, no antialiasing */
582
/* Don't bother with color antialiasing in this case ! */
589
for (pixel = 0; pixel < 16; pixel++)
590
fprintf(stderr, "color %d = %-8x %-8x %-8x\n", pixel,
591
pal_rgb[pixel], pal_bw[pixel], pal_mask[pixel]);
594
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
595
src_x, src_y, width, height,
596
img->data, (LPBITMAPINFO)&bmi4, DIB_RGB_COLORS, SRCAND ) == GDI_ERROR) {
597
Win32Error("XPutImage/SetDIBits");
603
init_pix( MYRGB(255,255,255), MYRGB(0,0,0));
604
oldBrush = SelectObject(hdc, foreBrush);
605
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
606
src_x, src_y, width, height,
607
img->data, (LPBITMAPINFO)&bmi4, DIB_RGB_COLORS, 0x00B8074A ) == GDI_ERROR)
608
Win32Error("XPutImage/SetDIBits");
609
SelectObject(hdc, oldBrush);
618
bmi8.bmiHeader.biWidth = img->width;
619
bmi8.bmiHeader.biHeight = (img->height == 1 ? img->height : -img->height);
620
bmi8.bmiHeader.biSizeImage =
621
WIDTHBYTES((DWORD)img->width * img->depth)
622
* (img->height > 0 ? img->height : -img->height);
624
if (StretchDIBits(hdc, dest_x, dest_y, width, height,
625
src_x, src_y, width, height,
626
img->data, (LPBITMAPINFO)&bmi8, DIB_RGB_COLORS, SRCPAINT ) == GDI_ERROR)
627
Win32Error("XPutImage/SetDIBits");
631
fprintf(stderr, "XPutImage: image depth is %d, non implemented.\n",
636
if (resource.use_xform && bTransfInUse) {
637
SelectClipRgn(hdc, NULL);
638
if (hNewClipRgn) DeleteObject(hNewClipRgn);
639
ModifyWorldTransform(hdc, &xfrm_temp, MWT_IDENTITY);
644
/* Trial version : assumes 16 colors DIBS, computes the nibble to be
646
void XPutPixel(XImage *img, int x, int y, COLORREF c)
650
if (x < 0 || x > img->width || y < 0 || y > img->height) {
652
"XPutPixel error : x = %d y = %d width = %d height = %d\n",
653
x, y, img->width, img->height);
655
switch (img->depth) {
658
for (pixel = 0; pixel < 16; pixel++)
659
fprintf(stderr, "color %d = %-8x\n", pixel, palette[pixel]);
660
fprintf(stderr, "looked for %-8x\n", c);
662
for (pixel = 0; (palette[pixel] != c) && (pixel < 16); pixel++);
664
Win32Error("XPutPixel/Color not found");
667
fprintf(stderr, "Found pixel = %d color = %-8x\n", pixel, palette[pixel]);
669
pos = (unsigned char *)img->data + y * img->bytes_per_line + x / 2;
671
fprintf(stderr, "img w = %d h = %d b/l = %d data = %x\nx = %d y = %d pos = %x\n", img->width , img->height, img->bytes_per_line, img->data, x, y, pos);
675
*pos = (*pos & 0x0F) | ((pixel & 0x0F) << 4);
679
*pos = (*pos & 0xF0) | (pixel & 0x0F);
683
Win32Error("XPutPixel/not a 16 colors DIB");
688
XImage* XCreateImage(void* d, HDC hdc, unsigned int depth,
689
int format, int offset, char* data,
690
unsigned int width, unsigned int height,
691
int bitmap_pad, int bytes_per_line)
694
img = (XImage *)xmalloc(sizeof(XImage));
696
img->height = height;
698
if (! bytes_per_line) {
699
img->bytes_per_line =
700
WIDTHBYTES((DWORD)img->width * img->depth) ;
703
img->bytes_per_line = bytes_per_line;
708
void XClearWindow(void *disp, HWND win)
711
if (debug & DBG_EVENT) {
712
fprintf(stderr, "Clearing window %-8x\n", win);
714
SendMessage(win, WM_ERASEBKGND, (WPARAM)GetDC(win), 0);
719
void XClearArea(void *disp, HWND win, int x, int y, int width, int height,
722
HDC maneGC = GetDC(win);
725
r.left = x; r.top = y;
727
r.bottom = y + height;
729
/* Blank the bitmap */
731
if (!PatBlt(maneGC, x, y, x+width, y+height, PATCOPY))
732
Win32Error("XClearArea: PatBlt");
736
if (!FillRect(maneGC, &r, backBrush))
737
Win32Error("XClearArea: PatBlt");
739
ReleaseDC(win, maneGC);
742
void XFlush(void *disp)
747
void XDestroyImage(XImage *img)
749
/* An XImage is a DIB basically */
751
if (img->data) free(img->data);
756
void XDrawLine(void *d, HWND hwnd, HDC hdc, int x1, int y1, int x2, int y2)
758
static int xprev = 0, yprev = 0;
759
if (xprev != x1 || yprev != y1) {
761
fprintf(stderr, "Moving to (%d, %d)\n", x1, y1);
763
MoveToEx(hdc, x1, y1, NULL);
766
fprintf(stderr, "Drawing to (%d, %d)\n", x2, y2);
773
void XDrawPoint(void *w, HWND hwnd, HDC hdc, int x1, int y1)
776
fprintf(stderr, "Drawing point at (%d %d)\n", x1, y1);
778
if (MoveToEx(hdc, x1, y1, NULL) == 0) {
779
Win32Error("XDrawPoint/MoveToEx failed!");
781
if (LineTo(hdc, x1, y1) == 0) {
782
Win32Error("XDrawPoint/LineTo failed!");
786
void XFillRectangle(void *d, HWND w, HDC hdc, int x, int y,
787
unsigned int width, unsigned int height)
790
/* Rectangle(hdc, x, y, x+width, y+height); */
791
r.left = x; r.top = y;
793
r.bottom = y + height;
795
fprintf(stderr, "FillRect (%d %d) - (%d %d) hdc %x color %-8x\n",
796
r.left, r.top, r.right, r.bottom, hdc, fore_Pixel);
798
FillRect(hdc, &r, foreBrush);
802
HBITMAP CreateDIB(HDC hdc, int x, int y, int bitCount,
803
BITMAPINFO_256 *header, void **data)
812
lpbmi = (LPBITMAPINFO)(header ? header : &bmi);
814
lpbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
815
lpbmi->bmiHeader.biPlanes = 1;
816
lpbmi->bmiHeader.biBitCount = bitCount;
817
lpbmi->bmiHeader.biCompression = BI_RGB;
818
lpbmi->bmiHeader.biWidth = x;
819
lpbmi->bmiHeader.biHeight = y;
820
lpbmi->bmiHeader.biSizeImage =
821
WIDTHBYTES((DWORD)x * bitCount) * (y > 0 ? y : -y);
822
if (lpbmi->bmiHeader.biCompression != BI_RGB)
823
lpbmi->bmiHeader.biSizeImage = (lpbmi->bmiHeader.biSizeImage * 3) / 2;
824
lpbmi->bmiHeader.biXPelsPerMeter = 0;
825
lpbmi->bmiHeader.biYPelsPerMeter = 0;
826
lpbmi->bmiHeader.biClrUsed = 0;
827
lpbmi->bmiHeader.biClrImportant = 0;
829
/* SelectPalette(hdc,hpal,FALSE); */
831
lpbmi->bmiColors[1] = Color2Quad(back_Pixel);
832
lpbmi->bmiColors[0] = Color2Quad(fore_Pixel);
835
else if (bitCount <= 8) {
836
for (i = 0; i < (1 << bitCount); i++) {
837
lpbmi->bmiColors[i] = Color2Quad(palette[i]);
842
hbm = CreateDIBSection(hdc, lpbmi, DIB_RGB_COLORS, &ppvBits, NULL, 0);
843
/* fprintf(stderr, "Nb DIBS = %d\n", ++nbDIBS); */
845
Win32Error("CreateDIB/CreateDIBSection");
851
/* These ones are taken from NTEmacs */
854
* XParseGeometry parses strings of the form
855
* "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
856
* width, height, xoffset, and yoffset are unsigned integers.
857
* Example: "=80x24+300-49"
858
* The equal sign is optional.
859
* It returns a bitmask that indicates which of the four values
860
* were actually found in the string. For each value found,
861
* the corresponding argument is updated; for each value
862
* not found, the corresponding argument is left unchanged.
866
read_integer (char *s, char **NextString)
868
register int Result = 0;
878
for (; (*s >= '0') && (*s <= '9'); s++)
880
Result = (Result * 10) + (*s - '0');
890
XParseGeometry (char *s, int *x, int *y,
891
unsigned int *width, unsigned int *height)
894
register char *strind;
895
unsigned int tempWidth, tempHeight;
899
if ((s == NULL) || (*s == '\0')) return (mask);
901
s++; /* ignore possible '=' at beg of geometry spec */
904
if (*strind != '+' && *strind != '-' && *strind != 'x')
906
tempWidth = read_integer (strind, &nextCharacter);
907
if (strind == nextCharacter)
909
strind = nextCharacter;
913
if (*strind == 'x' || *strind == 'X')
916
tempHeight = read_integer (strind, &nextCharacter);
917
if (strind == nextCharacter)
919
strind = nextCharacter;
923
if ((*strind == '+') || (*strind == '-'))
928
tempX = -read_integer (strind, &nextCharacter);
929
if (strind == nextCharacter)
931
strind = nextCharacter;
938
tempX = read_integer (strind, &nextCharacter);
939
if (strind == nextCharacter)
941
strind = nextCharacter;
944
if ((*strind == '+') || (*strind == '-'))
949
tempY = -read_integer (strind, &nextCharacter);
950
if (strind == nextCharacter)
952
strind = nextCharacter;
959
tempY = read_integer (strind, &nextCharacter);
960
if (strind == nextCharacter)
962
strind = nextCharacter;
968
/* If strind isn't at the end of the string the it's an invalid
969
geometry specification. */
971
if (*strind != '\0') return (0);
977
if (mask & WidthValue)
979
if (mask & HeightValue)
980
*height = tempHeight;
985
x_to_win32_color (const char *colorname)
991
if (colorname[0] == '#')
993
/* Could be an old-style RGB Device specification. */
996
color = colorname + 1;
998
size = strlen(color);
999
if (size == 3 || size == 6 || size == 9 || size == 12)
1007
for (i = 0; i < 3; i++)
1011
unsigned long value;
1013
/* The check for 'x' in the following conditional takes into
1014
account the fact that strtol allows a "0x" in front of
1015
our numbers, and we don't. */
1016
if (!isxdigit(color[0]) || color[1] == 'x')
1020
value = strtoul(color, &end, 16);
1022
if (errno == ERANGE || end - color != size)
1027
value = value * 0x10;
1038
colorval |= (value << pos);
1042
return MYADJUSTRGB(colorval);
1048
else if (strnicmp(colorname, "rgb:", 4) == 0)
1056
color = colorname + 4;
1057
for (i = 0; i < 3; i++)
1060
unsigned long value;
1062
/* The check for 'x' in the following conditional takes into
1063
account the fact that strtol allows a "0x" in front of
1064
our numbers, and we don't. */
1065
if (!isxdigit(color[0]) || color[1] == 'x')
1067
value = strtoul(color, &end, 16);
1068
if (errno == ERANGE)
1070
switch (end - color)
1073
value = value * 0x10 + value;
1086
if (value == ULONG_MAX)
1088
colorval |= (value << pos);
1094
return MYADJUSTRGB(colorval);
1101
else if (strnicmp(colorname, "rgbi:", 5) == 0)
1103
/* This is an RGB Intensity specification. */
1110
color = colorname + 5;
1111
for (i = 0; i < 3; i++)
1117
value = strtod(color, &end);
1118
if (errno == ERANGE)
1120
if (value < 0.0 || value > 1.0)
1122
val = (UINT)(0x100 * value);
1123
/* We used 0x100 instead of 0xFF to give an continuous
1124
range between 0.0 and 1.0 inclusive. The next statement
1125
fixes the 1.0 case. */
1128
colorval |= (val << pos);
1134
return MYADJUSTRGB(colorval);
1141
/* I am not going to attempt to handle any of the CIE color schemes
1142
or TekHVC, since I don't know the algorithms for conversion to
1145
for (tail = win32_color_map, i = 0;
1146
i < sizeof(win32_color_map)/sizeof(colormap_t);
1149
char *tem = tail->name;
1151
if (lstrcmpi (tem, colorname) == 0)
1153
ret = tail->colorref;