2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
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
;
19 OOP_Object
*srcbm_obj
;
21 HIDDT_ColorModel src_colmod
;
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 /*****************************************************************************
35 #include <clib/graphics_protos.h>
37 AROS_LH10(void, BltMaskBitMapRastPort
,
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
),
52 struct GfxBase
*, GfxBase
, 106, Graphics
)
55 Copies a part of a bitmap to another bitmap with using a mask.
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.
87 27-11-96 digulla automatically created from
88 graphics_lib.fd and clib/graphics_protos.h
90 *****************************************************************************/
94 struct bltmask_render_data brd
;
96 HIDDT_DrawMode old_drmd
;
100 struct TagItem gc_tags
[] =
102 { aHidd_GC_DrawMode
, 0UL },
106 EnterFunc(bug("BltMaskBitMapRastPort(%d %d %d, %d, %d, %d)\n"
107 , xSrc
, ySrc
, xDest
, yDest
, xSize
, ySize
));
114 if ((xSize
< 1) || (ySize
< 1)) return;
116 if (!OBTAIN_DRIVERDATA(destRP
, GfxBase
))
119 brd
.minterm
= minterm
;
120 brd
.srcbm_obj
= OBTAIN_HIDD_BM(srcBitMap
);
121 if (NULL
== brd
.srcbm_obj
)
123 RELEASE_DRIVERDATA(destRP
, GfxBase
);
127 brd
.srcbm
= srcBitMap
;
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
);
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
);
149 rr
.MaxX
= xDest
+ xSize
- 1;
150 rr
.MaxY
= yDest
+ ySize
- 1;
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");
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
;
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
;
186 height
= y2
- y1
+ 1;
188 OOP_GetAttr(dstbm_obj
, aHidd_BitMap_PixFmt
, (IPTR
*)&dest_pf
);
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
;
207 D(bug("BltMaskBitMapRastPort could not retrieve pixel table for blit from palette to truecolor bitmap"));
208 return width
* height
;
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
)));
229 UBYTE
*srcbuf
, *destbuf
;
233 srcbuf
= (UBYTE
*)PrivGBase(GfxBase
)->pixel_buf
;
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
;
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
,
248 width
* sizeof(HIDDT_Pixel
),
249 srcx
, srcy
+ lines_done
,
253 HIDD_BM_GetImage(dstbm_obj
,
255 width
* sizeof(HIDDT_Pixel
),
260 mask
= &brd
->mask
[COORD_TO_BYTEIDX(0, srcy
+ lines_done
, brd
->mask_bpr
)];
262 srcpixelbuf
= (HIDDT_Pixel
*)srcbuf
;
263 destpixelbuf
= (HIDDT_Pixel
*)destbuf
;
267 case (ABC
|ABNC
|ANBC
): /* (ABC|ABNC|ANBC) if copy source and blit thru mask */
268 case 0xC0: /* compatibility with AOS3 */
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
];
282 mask
+= brd
->mask_bpr
;
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
;
298 mask
+= brd
->mask_bpr
;
303 case ANBC
: /* (ANBC) if invert source and blit thru mask */
304 D(bug("BltMaskBitMapRastPort does not support ANBC minterm yet"));
308 D(bug("BltMaskBitMapRastPort: minterm 0x%x not handled.\n", brd
->minterm
));
310 } /* switch(brd->minterm) */
312 HIDD_BM_PutImage(dstbm_obj
,
315 width
* sizeof(HIDDT_Pixel
),
320 } /* for(lines_done = 0; lines_done != height; lines_done += doing_lines) */
324 } /* if (lines_per_step) */
327 /* urk :-( pixelbuffer too small to hold two lines) */
329 D(bug("BltMaskBitMapRastPort found pixelbuffer to be too small"));
332 return width
* height
;
335 /****************************************************************************************/