some fixes to accented characters
[tangerine.git] / rom / graphics / bltmaskbitmaprastport.c
blobb464c2d8406d9b4d34ffb64c024f066fdd567d94
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <proto/graphics.h>
10 #include <proto/oop.h>
11 #include "graphics_intern.h"
12 #include "gfxfuncsupport.h"
13 #include <hardware/blit.h>
15 struct bltmask_render_data
17 struct render_special_info rsi;
18 struct BitMap *srcbm;
19 OOP_Object *srcbm_obj;
20 OOP_Object *srcpf;
21 HIDDT_ColorModel src_colmod;
22 PLANEPTR mask;
23 ULONG mask_bpr;
24 ULONG minterm;
25 BOOL samebitmapformat;
28 static ULONG bltmask_render(APTR bltmask_rd, LONG srcx, LONG srcy,
29 OOP_Object *dstbm_obj, OOP_Object *dst_gc,
30 LONG x1, LONG y1, LONG x2, LONG y2, struct GfxBase *GfxBase);
32 /*****************************************************************************
34 NAME */
35 #include <clib/graphics_protos.h>
37 AROS_LH10(void, BltMaskBitMapRastPort,
39 /* SYNOPSIS */
40 AROS_LHA(struct BitMap *, srcBitMap, A0),
41 AROS_LHA(LONG , xSrc, D0),
42 AROS_LHA(LONG , ySrc, D1),
43 AROS_LHA(struct RastPort *, destRP, A1),
44 AROS_LHA(LONG , xDest, D2),
45 AROS_LHA(LONG , yDest, D3),
46 AROS_LHA(LONG , xSize, D4),
47 AROS_LHA(LONG , ySize, D5),
48 AROS_LHA(ULONG , minterm, D6),
49 AROS_LHA(PLANEPTR , bltMask, A2),
51 /* LOCATION */
52 struct GfxBase *, GfxBase, 106, Graphics)
54 /* FUNCTION
55 Copies a part of a bitmap to another bitmap with using a mask.
57 INPUTS
58 srcBitMap - Copy from this bitmap.
59 xSrc, ySrc - This is the upper left corner of the area to copy.
60 destRP - Destination RastPort.
61 xDest, yDest - Upper left corner where to place the copy
62 xSize, ySize - The size of the area to copy
63 minterm - How to copy. See BltBitMap() for an explanation.
64 bltMask - The mask bitplane must be of the same size as the source bitmap.
66 RESULT
67 TRUE.
69 NOTES
71 EXAMPLE
73 BUGS
75 SEE ALSO
76 ClipBlit()
78 INPUTS
80 RESULT
82 NOTES
84 INTERNALS
86 HISTORY
87 27-11-96 digulla automatically created from
88 graphics_lib.fd and clib/graphics_protos.h
90 *****************************************************************************/
92 AROS_LIBFUNC_INIT
94 struct bltmask_render_data brd;
95 struct Rectangle rr;
96 HIDDT_DrawMode old_drmd;
97 OOP_Object *gc;
98 Point src;
100 struct TagItem gc_tags[] =
102 { aHidd_GC_DrawMode , 0UL },
103 { TAG_DONE }
106 EnterFunc(bug("BltMaskBitMapRastPort(%d %d %d, %d, %d, %d)\n"
107 , xSrc, ySrc, xDest, yDest, xSize, ySize));
109 FIX_GFXCOORD(xSrc);
110 FIX_GFXCOORD(ySrc);
111 FIX_GFXCOORD(xDest);
112 FIX_GFXCOORD(yDest);
114 if ((xSize < 1) || (ySize < 1)) return;
116 if (!OBTAIN_DRIVERDATA(destRP, GfxBase))
117 return;
119 brd.minterm = minterm;
120 brd.srcbm_obj = OBTAIN_HIDD_BM(srcBitMap);
121 if (NULL == brd.srcbm_obj)
123 RELEASE_DRIVERDATA(destRP, GfxBase);
124 return;
127 brd.srcbm = srcBitMap;
128 brd.mask = bltMask;
130 /* The mask has always the same size as the source bitmap */
131 brd.mask_bpr = 2 * WIDTH_TO_WORDS(GetBitMapAttr(srcBitMap, BMA_WIDTH));
133 OOP_GetAttr(brd.srcbm_obj, aHidd_BitMap_PixFmt, (IPTR *)&brd.srcpf);
135 IPTR attr;
137 OOP_GetAttr(brd.srcpf, aHidd_PixFmt_ColorModel, &attr);
138 brd.src_colmod = (HIDDT_ColorModel)attr;
141 gc = GetDriverData(destRP)->dd_GC;
142 OOP_GetAttr(gc, aHidd_GC_DrawMode, &old_drmd);
144 gc_tags[0].ti_Data = vHidd_GC_DrawMode_Copy;
145 OOP_SetAttrs(gc, gc_tags);
147 rr.MinX = xDest;
148 rr.MinY = yDest;
149 rr.MaxX = xDest + xSize - 1;
150 rr.MaxY = yDest + ySize - 1;
152 src.x = xSrc;
153 src.y = ySrc;
155 do_render_func(destRP, &src, &rr, bltmask_render, &brd, TRUE, GfxBase);
157 RELEASE_HIDD_BM(brd.srcbm_obj, srcBitMap);
159 gc_tags[0].ti_Data = old_drmd;
160 OOP_SetAttrs(gc, gc_tags);
162 RELEASE_DRIVERDATA(destRP, GfxBase);
164 ReturnVoid("BltBitMapRastPort");
166 AROS_LIBFUNC_EXIT
168 } /* BltMaskBitMapRastPort */
170 /****************************************************************************************/
172 static ULONG bltmask_render(APTR bltmask_rd, LONG srcx, LONG srcy,
173 OOP_Object *dstbm_obj, OOP_Object *dst_gc,
174 LONG x1, LONG y1, LONG x2, LONG y2, struct GfxBase *GfxBase)
176 struct bltmask_render_data *brd;
177 OOP_Object *dest_pf;
178 HIDDT_ColorModel dest_colmod;
179 HIDDT_Pixel *pixtab = NULL;
180 ULONG x, y, width, height;
181 LONG lines_done, lines_per_step, doing_lines;
182 BOOL pal_to_true = FALSE;
184 width = x2 - x1 + 1;
185 height = y2 - y1 + 1;
187 OOP_GetAttr(dstbm_obj, aHidd_BitMap_PixFmt, (IPTR *)&dest_pf);
189 IPTR attr;
191 OOP_GetAttr(dest_pf, aHidd_PixFmt_ColorModel, &attr);
192 dest_colmod = (HIDDT_ColorModel)attr;
195 brd = (struct bltmask_render_data *)bltmask_rd;
196 if ((brd->src_colmod == vHidd_ColorModel_Palette) && (dest_colmod == vHidd_ColorModel_Palette))
199 else if ((brd->src_colmod == vHidd_ColorModel_Palette) && (dest_colmod == vHidd_ColorModel_TrueColor))
201 pixtab = IS_HIDD_BM(brd->srcbm) ? HIDD_BM_PIXTAB(brd->srcbm) : NULL;
202 if (!pixtab) pixtab = IS_HIDD_BM(brd->rsi.curbm) ? HIDD_BM_PIXTAB(brd->rsi.curbm) : NULL;
204 if (!pixtab)
206 D(bug("BltMaskBitMapRastPort could not retrieve pixel table for blit from palette to truecolor bitmap"));
207 return width * height;
210 pal_to_true = TRUE;
212 else if ((brd->src_colmod == vHidd_ColorModel_TrueColor) && (dest_colmod == vHidd_ColorModel_TrueColor))
214 if (brd->srcpf != dest_pf)
216 D(bug("BltMaskBitMapRastPort not supporting blit between truecolor bitmaps of different formats yet"));
217 return width * height;
220 else if ((brd->src_colmod == vHidd_ColorModel_TrueColor) && (dest_colmod == vHidd_ColorModel_Palette))
222 D(bug("BltMaskBitMapRastPort from truecolor bitmap to palette bitmap not supported!"));
223 return width * height;
226 lines_per_step = (NUMPIX / (width * 2 * sizeof(HIDDT_Pixel)));
227 if (lines_per_step)
229 UBYTE *srcbuf, *destbuf;
231 LOCK_PIXBUF
233 srcbuf = (UBYTE *)PrivGBase(GfxBase)->pixel_buf;
234 destbuf = srcbuf;
235 destbuf += lines_per_step * width * sizeof(HIDDT_Pixel);
237 for(lines_done = 0; lines_done != height; lines_done += doing_lines)
239 HIDDT_Pixel *srcpixelbuf;
240 HIDDT_Pixel *destpixelbuf;
241 UBYTE *mask;
243 doing_lines = lines_per_step;
244 if (lines_done + doing_lines > height) doing_lines = height - lines_done;
246 HIDD_BM_GetImage(brd->srcbm_obj,
247 srcbuf,
248 width * sizeof(HIDDT_Pixel),
249 srcx, srcy + lines_done,
250 width, doing_lines,
251 vHidd_StdPixFmt_Native32);
253 HIDD_BM_GetImage(dstbm_obj,
254 destbuf,
255 width * sizeof(HIDDT_Pixel),
256 x1, y1 + lines_done,
257 width, doing_lines,
258 vHidd_StdPixFmt_Native32);
260 mask = &brd->mask[COORD_TO_BYTEIDX(0, srcy + lines_done, brd->mask_bpr)];
262 srcpixelbuf = (HIDDT_Pixel *)srcbuf;
263 destpixelbuf = (HIDDT_Pixel *)destbuf;
265 switch(brd->minterm)
267 case (ABC|ABNC|ANBC): /* (ABC|ABNC|ANBC) if copy source and blit thru mask */
268 if (pal_to_true)
270 for(y = 0; y < doing_lines; y++)
272 for(x = 0; x < width; x++)
274 if (mask[XCOORD_TO_BYTEIDX(srcx + x)] & XCOORD_TO_MASK(srcx + x))
276 *destpixelbuf = pixtab[*srcpixelbuf];
278 srcpixelbuf++;
279 destpixelbuf++;
281 mask += brd->mask_bpr;
284 else
286 for(y = 0; y < doing_lines; y++)
288 for(x = 0; x < width; x++)
290 if (mask[XCOORD_TO_BYTEIDX(srcx + x)] & XCOORD_TO_MASK(srcx + x))
292 *destpixelbuf = *srcpixelbuf;
294 srcpixelbuf++;
295 destpixelbuf++;
297 mask += brd->mask_bpr;
300 break;
302 case ANBC: /* (ANBC) if invert source and blit thru mask */
303 D(bug("BltMaskBitMapRastPort does not support ANBC minterm yet"));
304 break;
306 default:
307 D(bug("BltMaskBitMapRastPort: minterm 0x%x not handled.\n", brd->minterm));
308 break;
309 } /* switch(brd->minterm) */
311 HIDD_BM_PutImage(dstbm_obj,
312 dst_gc,
313 destbuf,
314 width * sizeof(HIDDT_Pixel),
315 x1, y1 + lines_done,
316 width, doing_lines,
317 vHidd_StdPixFmt_Native32);
319 } /* for(lines_done = 0; lines_done != height; lines_done += doing_lines) */
321 ULOCK_PIXBUF
323 } /* if (lines_per_step) */
324 else
326 /* urk :-( pixelbuffer too small to hold two lines) */
328 D(bug("BltMaskBitMapRastPort found pixelbuffer to be too small"));
331 return width * height;
334 /****************************************************************************************/