2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
6 static VOID
blttemplate_amiga(PLANEPTR source
, LONG x_src
, LONG modulo
, struct BitMap
*dest
7 , LONG x_dest
, LONG y_dest
, ULONG xsize
, ULONG ysize
, struct RastPort
*rp
, struct GfxBase
*GfxBase
)
10 UBYTE dest_depth
= GetBitMapAttr(dest
, BMA_DEPTH
);
11 UWORD drmd
= GetDrMd(rp
);
12 UBYTE apen
= GetAPen(rp
);
13 UBYTE bpen
= GetBPen(rp
);
16 /* Find the exact startbyte. x_src is max 15 */
17 srcptr
= ((UBYTE
*)source
) + XCOORD_TO_BYTEIDX(x_src
);
19 /* Find the exact startbit */
22 kprintf("DRMD: %d, APEN: %d, BPEN: %d\n", drmd, apen, bpen);
24 for (y
= 0; y
< ysize
; y
++)
26 UBYTE
*byteptr
= srcptr
;
27 for (x
= 0; x
< xsize
; x
++)
30 UBYTE mask
= XCOORD_TO_MASK( x
+ x_src
);
32 BOOL is_set
= ((*byteptr
& mask
) ? TRUE
: FALSE
);
33 BOOL set_pixel
= FALSE
;
42 is_set
= ((is_set
== TRUE
) ? FALSE
: TRUE
);
47 /* Use apen if pixel is et, bpen otherwise */
56 else if (drmd
& COMPLEMENT
)
59 pen
= getbitmappixel(dest
72 /* Only use apen if pixel is set */
83 */ setbitmappixel(dest
93 /* Last pixel in this byte ? */
94 if (((x
+ x_src
) & 0x07) == 0x07)
107 static VOID
bltpattern_amiga(struct pattern_info
*pi
108 , struct BitMap
*dest_bm
109 , LONG x_src
, LONG y_src
/* offset into layer */
110 , LONG x_dest
, LONG y_dest
/* offset into bitmap */
111 , ULONG xsize
, LONG ysize
112 , struct GfxBase
*GfxBase
116 /* x_src, y_src is the coordinates int the layer. */
118 struct RastPort
*rp
= pi
->rp
;
119 ULONG apen
= GetAPen(rp
);
120 ULONG bpen
= GetBPen(rp
);
122 UBYTE
*apt
= (UBYTE
*)rp
->AreaPtrn
;
124 UBYTE dest_depth
= GetBitMapAttr(dest_bm
, BMA_DEPTH
);
126 for (y
= 0; y
< ysize
; y
++)
130 for (x
= 0; x
< xsize
; x
++)
136 /* Mask supplied ? */
140 idx
= COORD_TO_BYTEIDX(x
+ pi
->mask_xmin
, y
+ pi
->mask_ymin
, pi
->mask_bpr
);
141 mask
= XCOORD_TO_MASK(x
+ pi
->mask_xmin
);
143 set_pixel
= pi
->mask
[idx
] & mask
;
157 set_pixel
= pattern_pen(rp
, x
+ x_src
, y
+ y_src
, apen
, bpen
, &pixval
, GfxBase
);
160 setbitmappixel(dest_bm
, x
+ x_dest
, y
+ y_dest
, pixval
, dest_depth
, 0xFF);
165 } /* if (pixel should be set */
168 } /* for (each column) */
170 } /* for (each row) */
175 static VOID
bltmask_amiga(struct bltmask_info
*bmi
176 , LONG x_src
, LONG y_src
177 , struct BitMap
*destbm
178 , LONG x_dest
, LONG y_dest
179 , ULONG xsize
, ULONG ysize
182 /* x_src, y_src is the coordinates int the layer. */
184 UBYTE src_depth
, dest_depth
;
187 EnterFunc(bug("bltmask_amiga(%p, %d, %d, %d, %d, %d, %d, %p)\n"
188 , bmi
, x_src
, y_src
, x_dest
, y_dest
, xsize
, ysize
));
190 src_depth
= GetBitMapAttr(bmi
->srcbm
, BMA_DEPTH
);
191 dest_depth
= GetBitMapAttr(destbm
, BMA_DEPTH
);
194 for (y
= 0; y
< ysize
; y
++)
198 for (x
= 0; x
< xsize
; x
++)
203 idx
= COORD_TO_BYTEIDX(x
+ bmi
->mask_xmin
, y
+ bmi
->mask_ymin
, bmi
->mask_bpr
);
204 mask
= XCOORD_TO_MASK(x
+ bmi
->mask_xmin
);
206 set_pixel
= bmi
->mask
[idx
] & mask
;
210 ULONG srcpen
, destpen
, pixval
;
211 srcpen
= getbitmappixel(bmi
->srcbm
218 /* Could optimize plain copy (0x00C0) here. (does not nead to get dest)
219 and clear (0x0000) (needs neither src or dest)*/
221 destpen
= getbitmappixel(destbm
228 APPLY_MINTERM(pixval
, srcpen
, destpen
, minterm
);
229 setbitmappixel(destbm
240 } /* for (each column) */
242 } /* for (each row) */
244 ReturnVoid("bltmask_amiga");
248 static VOID
hidd2amiga_fast(struct BitMap
*hidd_bm
249 , LONG x_src
, LONG y_src
251 , LONG x_dest
, LONG y_dest
252 , ULONG xsize
, ULONG ysize
253 , VOID (*putbuf_hook
)()
257 ULONG tocopy_w
, tocopy_h
;
259 LONG pixels_left_to_process
= xsize
* ysize
;
260 ULONG current_x
, current_y
, next_x
, next_y
;
262 #warning Src bitmap migh be user initialized so we should not use HIDD_BM_PIXTAB() below
263 HIDDT_PixelLUT pixlut
= { AROS_PALETTE_SIZE
, HIDD_BM_PIXTAB(hidd_bm
) };
270 bm_obj
= OBTAIN_HIDD_BM(hidd_bm
);
276 while (pixels_left_to_process
)
282 if (NUMLUTPIX
< xsize
)
284 /* buffer cant hold a single horizontal line, and must
285 divide each line into copies */
286 tocopy_w
= xsize
- current_x
;
287 if (tocopy_w
> NUMLUTPIX
)
289 /* Not quite finished with current horizontal pixel line */
290 tocopy_w
= NUMLUTPIX
;
294 { /* Start at a new line */
304 tocopy_h
= MIN(NUMLUTPIX
/ xsize
, ysize
- current_y
);
313 /* Get some more pixels from the HIDD */
314 HIDD_BM_GetImageLUT(bm_obj
323 /* Write pixels to the destination */
324 putbuf_hook(dest_info
332 , IS_HIDD_BM(hidd_bm
) ? HIDD_BM_PIXTAB(hidd_bm
) : NULL
335 pixels_left_to_process
-= (tocopy_w
* tocopy_h
);
341 RELEASE_HIDD_BM(bm_obj
, hidd_bm
);
350 struct BitMap
*bitmap
;
358 #define BI(x) ((struct blit_info *)x)
359 static VOID
bitmap_to_buf(APTR src_info
360 , LONG x_src
, LONG y_src
361 , LONG x_dest
, LONG y_dest
362 , LONG width
, LONG height
365 , HIDDT_Pixel
*coltab
366 ) /* destination HIDD bitmap */
371 /* Fill buffer with pixels from bitmap */
372 for (y
= 0; y
< height
; y
++)
376 for (x
= 0; x
< width
; x
++)
380 pen
= getbitmappixel(BI(src_info
)->bitmap
383 , BI(src_info
)->bmdepth
384 , BI(src_info
)->planemask
);
388 *bufptr
++ = (coltab
!= NULL
) ? coltab
[pen
] : pen
;
389 // kprintf("(%d, %d) pen=%d buf=%d\n", x, y, pen, coltab[pen]);
399 static VOID
buf_to_bitmap(APTR dest_info
400 , LONG x_src
, LONG y_src
401 , LONG x_dest
, LONG y_dest
402 , ULONG width
, ULONG height
405 , HIDDT_Pixel
*coltab
409 if (BI(dest_info
)->minterm
== 0x00C0)
412 for (y
= 0; y
< height
; y
++)
415 for (x
= 0; x
< width
; x
++)
417 setbitmappixel(BI(dest_info
)->bitmap
420 , *bufptr
++, BI(dest_info
)->bmdepth
, BI(dest_info
)->planemask
433 for (y
= 0; y
< height
; y
++)
437 for (x
= 0; x
< width
; x
++)
439 ULONG src
= *bufptr
++ , dest
= 0;
440 ULONG minterm
= BI(dest_info
)->minterm
;
442 /* Set the pixel using correct minterm */
444 dest
= getbitmappixel(BI(dest_info
)->bitmap
447 , BI(dest_info
)->bmdepth
448 , BI(dest_info
)->planemask
451 #warning Do reverse coltab lookup
452 if (minterm
& 0x0010) dest
= ~src
& ~dest
;
453 if (minterm
& 0x0020) dest
|= ~src
& dest
;
454 if (minterm
& 0x0040) dest
|= src
& ~dest
;
455 if (minterm
& 0x0080) dest
|= src
& dest
;
457 setbitmappixel(BI(dest_info
)->bitmap
460 , dest
, BI(dest_info
)->bmdepth
461 , BI(dest_info
)->planemask
474 static VOID
setbitmapfast(struct BitMap
*bm
, LONG x_start
, LONG y_start
, LONG xsize
, LONG ysize
, ULONG pen
);
478 static VOID
clipagainstbitmap(struct BitMap
*bm
, LONG
*x1
, LONG
*y1
, LONG
*x2
, LONG
*y2
, struct GfxBase
*GfxBase
)
480 ULONG width
= GetBitMapAttr(bm
, BMA_WIDTH
);
481 ULONG height
= GetBitMapAttr(bm
, BMA_HEIGHT
);
483 /* Clip against bitmap bounds */
485 if (*x1
< 0) *x1
= 0;
486 if (*y1
< 0) *y1
= 0;
488 if (*x2
>= width
) *x2
= width
- 1;
489 if (*y2
>= height
) *y2
= height
- 1;
495 static VOID
setbitmappixel(struct BitMap
*bm
503 UBYTE mask
, clr_mask
;
506 idx
= COORD_TO_BYTEIDX(x
, y
, bm
->BytesPerRow
);
508 mask
= XCOORD_TO_MASK( x
);
512 for (i
= 0; i
< depth
; i
++)
515 if ((1L << i
) & plane_mask
)
517 UBYTE
*plane
= bm
->Planes
[i
];
519 if ((plane
!= NULL
) && (plane
!= (PLANEPTR
)-1))
521 if ((penmask
& pen
) != 0)
524 plane
[idx
] &= clr_mask
;
535 enum { SB_SINGLEMASK
, SB_PREPOSTMASK
, SB_FULL
};
536 static VOID
setbitmapfast(struct BitMap
*bm
, LONG x_start
, LONG y_start
, LONG xsize
, LONG ysize
, ULONG pen
)
542 UBYTE pre_pixels_to_set
,
544 pre_and_post
; /* number pixels to clear in pre and post byte */
546 UBYTE prebyte_mask
, postbyte_mask
;
548 /* kprintf("x_start: %d, y_start: %d, xsize: %d, ysize: %d, pen: %d\n",
549 x_start, y_start, xsize, ysize, pen);
552 pre_pixels_to_set
= (7 - (x_start
& 0x07)) + 1;
553 post_pixels_to_set
= ((x_start
+ xsize
- 1) & 0x07) + 1;
556 pre_and_post
= pre_pixels_to_set
+ post_pixels_to_set
;
558 if (pre_and_post
> xsize
)
560 UBYTE start_bit
, stop_bit
;
561 /* Check whether the pixels are kept within a byte */
562 sb_type
= SB_SINGLEMASK
;
563 pre_pixels_to_set
= MIN(pre_pixels_to_set
, xsize
);
565 /* Mask out the needed bits */
566 start_bit
= 7 - (x_start
& 0x07) + 1;
567 stop_bit
= 7 - ((x_start
+ xsize
- 1) & 0x07);
569 /* kprintf("start_bit: %d, stop_bit: %d\n", start_bit, stop_bit);
571 prebyte_mask
= ((1L << start_bit
) - 1) - ((1L << stop_bit
) - 1) ;
572 /* kprintf("prebyte_mask: %d\n", prebyte_mask);
574 kprintf("SB_SINGLE\n");
577 else if (pre_and_post
== xsize
)
579 /* We have bytes within to neighbour pixels */
580 sb_type
= SB_PREPOSTMASK
;
581 prebyte_mask
= 0xFF >> (8 - pre_pixels_to_set
);
582 postbyte_mask
= 0xFF << (8 - post_pixels_to_set
);
584 /* kprintf("SB_PREPOSTMASK\n");
590 /* Say we want to clear two pixels in last byte. We want the mask
594 prebyte_mask
= 0xFF >> (8 - pre_pixels_to_set
);
596 /* Say we want to set two pixels in last byte. We want the mask
599 postbyte_mask
= 0xFF << (8 - post_pixels_to_set
);
601 /* We have at least one whole byte of pixels */
602 num_whole
= xsize
- pre_pixels_to_set
- post_pixels_to_set
;
603 num_whole
>>= 3; /* number of bytes */
605 /* kprintf("SB_FULL\n");
610 kprintf("pre_pixels_to_set: %d, post_pixels_to_set: %d, numwhole: %d\n"
611 , pre_pixels_to_set, post_pixels_to_set, num_whole);
613 kprintf("prebyte_mask: %d, postbyte_mask: %d, numwhole: %d\n", prebyte_mask, postbyte_mask, num_whole);
615 for (plane
= 0; plane
< GetBitMapAttr(bm
, BMA_DEPTH
); plane
++)
620 UBYTE prepixels_set
, prepixels_clr
;
621 UBYTE postpixels_set
, postpixels_clr
;
622 UBYTE
*curbyte
= ((UBYTE
*)bm
->Planes
[plane
]) + COORD_TO_BYTEIDX(x_start
, y_start
, bm
->BytesPerRow
);
625 /* Set or clear current bit of pixval ? */
626 if (pen
& (1L << plane
))
631 /* Set the pre and postpixels */
635 prepixels_set
= (pixvals
& prebyte_mask
);
636 postpixels_set
= (pixvals
& postbyte_mask
);
639 prepixels_clr
= (pixvals
& prebyte_mask
) | (~prebyte_mask
);
640 postpixels_clr
= (pixvals
& postbyte_mask
) | (~postbyte_mask
);
642 for (y
= 0; y
< ysize
; y
++)
645 UBYTE
*ptr
= curbyte
;
647 *ptr
|= prepixels_set
;
648 *ptr
++ &= prepixels_clr
;
650 for (x
= 0; x
< num_whole
; x
++)
654 /* Clear the last nonwhole byte */
655 *ptr
|= postpixels_set
;
656 *ptr
++ &= postpixels_clr
;
658 /* Go to next line */
659 curbyte
+= bm
->BytesPerRow
;
665 prepixels_set
= (pixvals
& prebyte_mask
);
666 postpixels_set
= (pixvals
& postbyte_mask
);
669 prepixels_clr
= (pixvals
& prebyte_mask
) | (~prebyte_mask
);
670 postpixels_clr
= (pixvals
& postbyte_mask
) | (~postbyte_mask
);
672 for (y
= 0; y
< ysize
; y
++)
674 UBYTE
*ptr
= curbyte
;
676 *ptr
|= prepixels_set
;
677 *ptr
++ &= prepixels_clr
;
679 /* Clear the last nonwhole byte */
680 *ptr
|= postpixels_set
;
681 *ptr
++ &= postpixels_clr
;
683 /* Go to next line */
684 curbyte
+= bm
->BytesPerRow
;
690 prepixels_set
= (pixvals
& prebyte_mask
);
691 prepixels_clr
= (pixvals
& prebyte_mask
) | (~prebyte_mask
);
693 for (y
= 0; y
< ysize
; y
++)
695 UBYTE
*ptr
= curbyte
;
697 *ptr
|= prepixels_set
;
698 *ptr
++ &= prepixels_clr
;
700 /* Go to next line */
701 curbyte
+= bm
->BytesPerRow
;