1 /* libwmf ("ipa/x/bmp.h"): library for wmf conversion
2    Copyright (C) 2000 - various; see CREDITS, ChangeLog, and sources
3 
4    The libwmf Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public License as
6    published by the Free Software Foundation; either version 2 of the
7    License, or (at your option) any later version.
8 
9    The libwmf Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public
15    License along with the libwmf Library; see the file COPYING.  If not,
16    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17    Boston, MA 02111-1307, USA.  */
18 
19 
wmf_x_rop_draw(wmfAPI * API,wmfROP_Draw_t * rop_draw)20 static void wmf_x_rop_draw (wmfAPI* API,wmfROP_Draw_t* rop_draw)
21 {	wmf_x_t* ddata = WMF_X_GetData (API);
22 
23 	XPoint TL;
24 	XPoint BR;
25 
26 	WMF_DEBUG (API,"wmf_[x_]rop_draw");
27 
28 	if (!TO_FILL (rop_draw)) return;
29 
30 	setbrushstyle (API,rop_draw->dc);
31 
32 	switch (rop_draw->ROP) /* Ternary raster operations */
33 	{
34 	case SRCCOPY: /* dest = source */
35 	break;
36 	case SRCPAINT: /* dest = source OR dest */
37 	break;
38 	case SRCAND: /* dest = source AND dest */
39 	break;
40 	case SRCINVERT: /* dest = source XOR dest */
41 	break;
42 	case SRCERASE: /* dest = source AND (NOT dest) */
43 	break;
44 	case NOTSRCCOPY: /* dest = (NOT source) */
45 	break;
46 	case NOTSRCERASE: /* dest = (NOT src) AND (NOT dest) */
47 	break;
48 	case MERGECOPY: /* dest = (source AND pattern) */
49 	break;
50 	case MERGEPAINT: /* dest = (NOT source) OR dest */
51 	break;
52 	case PATCOPY: /* dest = pattern */
53 	break;
54 	case PATPAINT: /* dest = DPSnoo */
55 	break;
56 	case PATINVERT: /* dest = pattern XOR dest */
57 	break;
58 	case DSTINVERT: /* dest = (NOT dest) */
59 	break;
60 	case BLACKNESS: /* dest = BLACK */
61 		XSetForeground (ddata->display,ddata->gc,ddata->black);
62 	break;
63 	case WHITENESS: /* dest = WHITE */
64 		XSetForeground (ddata->display,ddata->gc,ddata->white);
65 	break;
66 	default:
67 	break;
68 	}
69 
70 	TL = x_translate (API,rop_draw->TL);
71 	BR = x_translate (API,rop_draw->BR);
72 
73 	BR.x -= TL.x;
74 	BR.y -= TL.y;
75 
76 	if (ddata->window != None)
77 	{	XFillRectangle (ddata->display,ddata->window,ddata->gc,TL.x,TL.y,BR.x,BR.y);
78 	}
79 	if (ddata->pixmap != None)
80 	{	XFillRectangle (ddata->display,ddata->pixmap,ddata->gc,TL.x,TL.y,BR.x,BR.y);
81 	}
82 }
83 
wmf_x_bmp_draw(wmfAPI * API,wmfBMP_Draw_t * bmp_draw)84 static void wmf_x_bmp_draw (wmfAPI* API,wmfBMP_Draw_t* bmp_draw)
85 {	wmf_x_t* ddata = WMF_X_GetData (API);
86 
87 	wmfRGB rgb;
88 
89 	int opacity;
90 
91 	float bmp_width;
92 	float bmp_height;
93 
94 	float x;
95 	float y;
96 
97 	unsigned int i;
98 	unsigned int j;
99 
100 	unsigned int width;
101 	unsigned int height;
102 
103 	XPoint pt;
104 
105 	WMF_DEBUG (API,"wmf_[x_]bmp_draw");
106 
107 	setdefaultstyle (API);
108 
109 	pt = x_translate (API,bmp_draw->pt);
110 
111 	bmp_width  = x_width  (API,(float) ((double) bmp_draw->crop.w * bmp_draw->pixel_width ));
112 	bmp_height = x_height (API,(float) ((double) bmp_draw->crop.h * bmp_draw->pixel_height));
113 
114 	width  = (unsigned int) ceil (1.0 + bmp_width ); /* The 1.0 is a bit of a fudge factor... */
115 	height = (unsigned int) ceil (1.0 + bmp_height); /* Works with test11.wmf, anyway.   [??] */
116 
117 	for (j = 0; j < height; j++)
118 	{	y = (float) ((double) j * (double) (bmp_draw->crop.h - 1) / (double) (height - 1));
119 		y += (float) bmp_draw->crop.y;
120 
121 		for (i = 0; i < width; i++)
122 		{	x = (float) ((double) i * (double) (bmp_draw->crop.w - 1) / (double) (width - 1));
123 			x += (float) bmp_draw->crop.x;
124 
125 			opacity = wmf_ipa_bmp_interpolate (API,&(bmp_draw->bmp),&rgb,x,y);
126 
127 			if (opacity < 0) break;
128 
129 			XSetForeground (ddata->display,ddata->gc,get_color (API,&rgb));
130 
131 			if (ddata->window != None)
132 			{	XDrawPoint (ddata->display,ddata->window,ddata->gc,i+pt.x,(height-1-j)+pt.y);
133 			}
134 			if (ddata->pixmap != None)
135 			{	XDrawPoint (ddata->display,ddata->pixmap,ddata->gc,i+pt.x,(height-1-j)+pt.y);
136 			}
137 		}
138 	}
139 }
140 
wmf_x_bmp_read(wmfAPI * API,wmfBMP_Read_t * bmp_read)141 static void wmf_x_bmp_read (wmfAPI* API,wmfBMP_Read_t* bmp_read)
142 {	WMF_DEBUG (API,"wmf_[x_]bmp_read");
143 
144 	wmf_ipa_bmp_read (API,bmp_read);
145 }
146 
wmf_x_bmp_free(wmfAPI * API,wmfBMP * bmp)147 static void wmf_x_bmp_free (wmfAPI* API,wmfBMP* bmp)
148 {	WMF_DEBUG (API,"wmf_[x_]bmp_free");
149 
150 	wmf_ipa_bmp_free (API,bmp);
151 }
152