Top level make file improvements and simplifications.
[AROS.git] / rom / graphics / bltmaskbitmaprastport.c
blob1fdfe557e72b1cfe166f234f3686819bfa1489f5
1 /*
2 Copyright © 1995-2011, 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, 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;
183 ULONG pixfmt = vHidd_StdPixFmt_Native32;
185 width = x2 - x1 + 1;
186 height = y2 - y1 + 1;
188 OOP_GetAttr(dstbm_obj, aHidd_BitMap_PixFmt, (IPTR *)&dest_pf);
190 IPTR attr;
192 OOP_GetAttr(dest_pf, aHidd_PixFmt_ColorModel, &attr);
193 dest_colmod = (HIDDT_ColorModel)attr;
196 brd = (struct bltmask_render_data *)bltmask_rd;
197 if ((brd->src_colmod == vHidd_ColorModel_Palette) && (dest_colmod == vHidd_ColorModel_Palette))
200 else if ((brd->src_colmod == vHidd_ColorModel_Palette) && (dest_colmod == vHidd_ColorModel_TrueColor))
202 pixtab = IS_HIDD_BM(brd->srcbm) ? HIDD_BM_PIXTAB(brd->srcbm) : NULL;
203 if (!pixtab) pixtab = IS_HIDD_BM(brd->rsi.curbm) ? HIDD_BM_PIXTAB(brd->rsi.curbm) : NULL;
205 if (!pixtab)
207 D(bug("BltMaskBitMapRastPort could not retrieve pixel table for blit from palette to truecolor bitmap"));
208 return width * height;
211 pal_to_true = TRUE;
213 else if ((brd->src_colmod == vHidd_ColorModel_TrueColor) && (dest_colmod == vHidd_ColorModel_TrueColor))
215 if (brd->srcpf != dest_pf)
217 pixfmt = vHidd_StdPixFmt_ARGB32;
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 pixfmt);
253 HIDD_BM_GetImage(dstbm_obj,
254 destbuf,
255 width * sizeof(HIDDT_Pixel),
256 x1, y1 + lines_done,
257 width, doing_lines,
258 pixfmt);
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 case 0xC0: /* compatibility with AOS3 */
269 if (pal_to_true)
271 for(y = 0; y < doing_lines; y++)
273 for(x = 0; x < width; x++)
275 if (mask[XCOORD_TO_BYTEIDX(srcx + x)] & XCOORD_TO_MASK(srcx + x))
277 *destpixelbuf = pixtab[*srcpixelbuf];
279 srcpixelbuf++;
280 destpixelbuf++;
282 mask += brd->mask_bpr;
285 else
287 for(y = 0; y < doing_lines; y++)
289 for(x = 0; x < width; x++)
291 if (mask[XCOORD_TO_BYTEIDX(srcx + x)] & XCOORD_TO_MASK(srcx + x))
293 *destpixelbuf = *srcpixelbuf;
295 srcpixelbuf++;
296 destpixelbuf++;
298 mask += brd->mask_bpr;
301 break;
303 case ANBC: /* (ANBC) if invert source and blit thru mask */
304 D(bug("BltMaskBitMapRastPort does not support ANBC minterm yet"));
305 break;
307 default:
308 D(bug("BltMaskBitMapRastPort: minterm 0x%x not handled.\n", brd->minterm));
309 break;
310 } /* switch(brd->minterm) */
312 HIDD_BM_PutImage(dstbm_obj,
313 dst_gc,
314 destbuf,
315 width * sizeof(HIDDT_Pixel),
316 x1, y1 + lines_done,
317 width, doing_lines,
318 pixfmt);
320 } /* for(lines_done = 0; lines_done != height; lines_done += doing_lines) */
322 ULOCK_PIXBUF
324 } /* if (lines_per_step) */
325 else
327 /* urk :-( pixelbuffer too small to hold two lines) */
329 D(bug("BltMaskBitMapRastPort found pixelbuffer to be too small"));
332 return width * height;
335 /****************************************************************************************/