2 * Copyright (c) 1999, 2000, 2001 Greg Haerr <greg@censoft.com>
4 * 32bpp Linear Video Driver for Microwindows
6 * Inspired from Ben Pfaff's BOGL <pfaffben@debian.org>
14 /* Calc linelen and mmap size, return 0 on fail*/
16 linear32_init(PSD psd)
19 psd->size = psd->yres * psd->linelen;
20 /* convert linelen from byte to pixel len for bpp 16, 24, 32*/
26 /* Set pixel at x, y, to pixelval c*/
28 linear32_drawpixel(PSD psd, MWCOORD x, MWCOORD y, MWPIXELVAL c)
30 ADDR32 addr = psd->addr;
33 assert (x >= 0 && x < psd->xres);
34 assert (y >= 0 && y < psd->yres);
35 assert (c < psd->ncolors);
38 if (gr_mode == MWMODE_COPY)
39 addr[x + y * psd->linelen] = c;
41 applyOp(gr_mode, c, &addr[x + y * psd->linelen], ADDR32);
45 /* Read pixel at x, y*/
47 linear32_readpixel(PSD psd, MWCOORD x, MWCOORD y)
49 ADDR32 addr = psd->addr;
52 assert (x >= 0 && x < psd->xres);
53 assert (y >= 0 && y < psd->yres);
55 return addr[x + y * psd->linelen];
58 /* Draw horizontal line from x1,y to x2,y including final point*/
60 linear32_drawhorzline(PSD psd, MWCOORD x1, MWCOORD x2, MWCOORD y, MWPIXELVAL c)
62 ADDR32 addr = psd->addr;
65 assert (x1 >= 0 && x1 < psd->xres);
66 assert (x2 >= 0 && x2 < psd->xres);
68 assert (y >= 0 && y < psd->yres);
69 assert (c < psd->ncolors);
72 addr += x1 + y * psd->linelen;
73 if(gr_mode == MWMODE_COPY) {
74 /* FIXME: memsetl(dst, c, x2-x1+1)*/
79 applyOp(gr_mode, c, addr, ADDR32);
86 /* Draw a vertical line from x,y1 to x,y2 including final point*/
88 linear32_drawvertline(PSD psd, MWCOORD x, MWCOORD y1, MWCOORD y2, MWPIXELVAL c)
90 ADDR32 addr = psd->addr;
91 int linelen = psd->linelen;
94 assert (x >= 0 && x < psd->xres);
95 assert (y1 >= 0 && y1 < psd->yres);
96 assert (y2 >= 0 && y2 < psd->yres);
98 assert (c < psd->ncolors);
101 addr += x + y1 * linelen;
102 if(gr_mode == MWMODE_COPY) {
109 applyOp(gr_mode, c, addr, ADDR32);
118 linear32_blit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD w, MWCOORD h,
119 PSD srcpsd, MWCOORD srcx, MWCOORD srcy, long op)
122 ADDR32 dst = dstpsd->addr;
123 ADDR32 src = srcpsd->addr;
125 int dlinelen = dstpsd->linelen;
126 int slinelen = srcpsd->linelen;
127 int dlinelen_minus_w4;
128 int slinelen_minus_w4;
134 assert (dstx >= 0 && dstx < dstpsd->xres);
135 assert (dsty >= 0 && dsty < dstpsd->yres);
139 assert (srcx >= 0 && srcx < srcpsd->xres);
140 assert (srcy >= 0 && srcy < srcpsd->yres);
141 assert (dstx+w <= dstpsd->xres);
142 assert (dsty+h <= dstpsd->yres);
143 assert (srcx+w <= srcpsd->xres);
144 assert (srcy+h <= srcpsd->yres);
147 dst += dstx + dsty * dlinelen;
148 src += srcx + srcy * slinelen;
151 if((op & MWROP_EXTENSION) != MWROP_BLENDCONSTANT)
157 dlinelen_minus_w4 = (dlinelen - w) * 4;
158 slinelen_minus_w4 = (slinelen - w) * 4;
161 register unsigned long s = *src8++;
162 register unsigned long d = *dst8;
163 *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
166 *dst8++ = (unsigned char)(((s - d)*alpha)>>8) + d;
169 *dst8 = (unsigned char)(((s - d)*alpha)>>8) + d;
173 dst8 += dlinelen_minus_w4;
174 src8 += slinelen_minus_w4;
181 if (op == MWROP_COPY) {
182 /* copy from bottom up if dst in src rectangle*/
183 /* memmove is used to handle x case*/
185 src += (h-1) * slinelen;
186 dst += (h-1) * dlinelen;
191 /* a _fast_ memmove is a _must_ in this routine*/
192 memmove(dst, src, w<<2);
197 for(i=0; i < w; ++i) {
198 applyOp(MWROP_TO_MODE(op), *src, dst, ADDR32);
208 /* srccopy stretchblt*/
210 linear32_stretchblit(PSD dstpsd, MWCOORD dstx, MWCOORD dsty, MWCOORD dstw,
211 MWCOORD dsth, PSD srcpsd, MWCOORD srcx, MWCOORD srcy, MWCOORD srcw,
212 MWCOORD srch, long op)
216 int dlinelen = dstpsd->linelen;
217 int slinelen = srcpsd->linelen;
219 int row_pos, row_inc;
220 int col_pos, col_inc;
221 unsigned long pixel = 0;
223 assert (dstpsd->addr != 0);
224 assert (dstx >= 0 && dstx < dstpsd->xres);
225 assert (dsty >= 0 && dsty < dstpsd->yres);
228 assert (srcpsd->addr != 0);
229 assert (srcx >= 0 && srcx < srcpsd->xres);
230 assert (srcy >= 0 && srcy < srcpsd->yres);
233 assert (dstx+dstw <= dstpsd->xres);
234 assert (dsty+dsth <= dstpsd->yres);
235 assert (srcx+srcw <= srcpsd->xres);
236 assert (srcy+srch <= srcpsd->yres);
240 row_inc = (srch << 16) / dsth;
242 /* stretch blit using integer ratio between src/dst height/width*/
243 for (ymax = dsty+dsth; dsty<ymax; ++dsty) {
245 /* find source y position*/
246 while (row_pos >= 0x10000L) {
251 dst = (ADDR32)dstpsd->addr + dstx + dsty*dlinelen;
252 src = (ADDR32)srcpsd->addr + srcx + (srcy-1)*slinelen;
254 /* copy a row of pixels*/
256 col_inc = (srcw << 16) / dstw;
257 for (i=0; i<dstw; ++i) {
258 /* get source x pixel*/
259 while (col_pos >= 0x10000L) {
272 SUBDRIVER fblinear32 = {
276 linear32_drawhorzline,
277 linear32_drawvertline,