Test initialisation of MUIA_List_AdjustWidth and MUIA_List_AdjustHeight, and
[AROS.git] / arch / .unmaintained / hidd / unused_planar_funcs.c
blob36c895a4444fea1e601159448c3d62cd06ab3d76
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
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)
9 UBYTE *srcptr;
10 UBYTE dest_depth = GetBitMapAttr(dest, BMA_DEPTH);
11 UWORD drmd = GetDrMd(rp);
12 UBYTE apen = GetAPen(rp);
13 UBYTE bpen = GetBPen(rp);
14 LONG x, y;
16 /* Find the exact startbyte. x_src is max 15 */
17 srcptr = ((UBYTE *)source) + XCOORD_TO_BYTEIDX(x_src);
19 /* Find the exact startbit */
20 x_src &= 0x07;
21 /*
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 ++)
29 UBYTE pen;
30 UBYTE mask = XCOORD_TO_MASK( x + x_src );
32 BOOL is_set = ((*byteptr & mask) ? TRUE : FALSE);
33 BOOL set_pixel = FALSE;
35 /*if (is_set)
36 kprintf("X");
37 else
38 kprintf("0");
40 if (drmd & INVERSVID)
42 is_set = ((is_set == TRUE) ? FALSE : TRUE);
45 if (drmd & JAM2)
47 /* Use apen if pixel is et, bpen otherwise */
48 if (is_set)
49 pen = apen;
50 else
51 pen = bpen;
53 set_pixel = TRUE;
56 else if (drmd & COMPLEMENT)
59 pen = getbitmappixel(dest
60 , x + x_dest
61 , y + y_dest
62 , dest_depth
63 , 0xFF
66 pen = ~pen;
70 else /* JAM 1 */
72 /* Only use apen if pixel is set */
73 if (is_set)
75 pen = apen;
76 set_pixel = TRUE;
80 if (set_pixel)
82 /* kprintf("X");
83 */ setbitmappixel(dest
84 , x + x_dest
85 , y + y_dest
86 , pen
87 , dest_depth, 0xFF
90 /* else
91 kprintf("0");
92 */
93 /* Last pixel in this byte ? */
94 if (((x + x_src) & 0x07) == 0x07)
95 byteptr ++;
98 /* kprintf("\n");
99 */ srcptr += modulo;
101 return;
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. */
117 LONG y;
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 ++)
128 LONG x;
130 for (x = 0; x < xsize; x ++)
132 ULONG set_pixel;
133 ULONG pixval;
136 /* Mask supplied ? */
137 if (pi->mask)
139 ULONG idx, mask;
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;
146 else
147 set_pixel = 1UL;
150 if (set_pixel)
154 if (apt)
157 set_pixel = pattern_pen(rp, x + x_src, y + y_src, apen, bpen, &pixval, GfxBase);
158 if (set_pixel)
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) */
172 return;
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
180 , ULONG minterm )
182 /* x_src, y_src is the coordinates int the layer. */
183 LONG y;
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 ++)
196 LONG x;
198 for (x = 0; x < xsize; x ++)
200 ULONG set_pixel;
202 ULONG idx, mask;
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;
208 if (set_pixel)
210 ULONG srcpen, destpen, pixval;
211 srcpen = getbitmappixel(bmi->srcbm
212 , x + x_src
213 , y + y_src
214 , src_depth
215 , 0xFF
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
222 , x + x_dest
223 , y + y_dest
224 , dest_depth
225 , 0xFF
228 APPLY_MINTERM(pixval, srcpen, destpen, minterm);
229 setbitmappixel(destbm
230 , x + x_dest
231 , y + y_dest
232 , pixval
233 , dest_depth
234 , 0xFF
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
250 , APTR dest_info
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) };
265 Object *bm_obj;
267 next_x = 0;
268 next_y = 0;
270 bm_obj = OBTAIN_HIDD_BM(hidd_bm);
271 if (NULL == bm_obj)
272 return;
274 LOCK_PIXBUF
276 while (pixels_left_to_process)
279 current_x = next_x;
280 current_y = next_y;
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;
291 next_x += NUMLUTPIX;
293 else
294 { /* Start at a new line */
296 next_x = 0;
297 next_y ++;
299 tocopy_h = 1;
302 else
304 tocopy_h = MIN(NUMLUTPIX / xsize, ysize - current_y);
305 tocopy_w = xsize;
307 next_x = 0;
308 next_y += tocopy_h;
313 /* Get some more pixels from the HIDD */
314 HIDD_BM_GetImageLUT(bm_obj
315 , (UBYTE *)pixel_buf
316 , tocopy_w
317 , x_src + current_x
318 , y_src + current_y
319 , tocopy_w, tocopy_h
320 , &pixlut);
323 /* Write pixels to the destination */
324 putbuf_hook(dest_info
325 , current_x + x_src
326 , current_y + y_src
327 , current_x + x_dest
328 , current_y + y_dest
329 , tocopy_w, tocopy_h
330 , (UBYTE *)pixel_buf
331 , bm_obj
332 , IS_HIDD_BM(hidd_bm) ? HIDD_BM_PIXTAB(hidd_bm) : NULL
335 pixels_left_to_process -= (tocopy_w * tocopy_h);
339 ULOCK_PIXBUF
341 RELEASE_HIDD_BM(bm_obj, hidd_bm);
343 return;
348 struct blit_info
350 struct BitMap *bitmap;
351 ULONG minterm;
352 ULONG planemask;
353 UBYTE bmdepth;
354 ULONG bmwidth;
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
363 , ULONG *bufptr
364 , Object *dest_bm
365 , HIDDT_Pixel *coltab
366 ) /* destination HIDD bitmap */
369 LONG y;
371 /* Fill buffer with pixels from bitmap */
372 for (y = 0; y < height; y ++)
374 LONG x;
376 for (x = 0; x < width; x ++)
378 UBYTE pen;
380 pen = getbitmappixel(BI(src_info)->bitmap
381 , x + x_src
382 , y + y_src
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
403 , UBYTE *bufptr
404 , Object *src_bm
405 , HIDDT_Pixel *coltab
409 if (BI(dest_info)->minterm == 0x00C0)
411 LONG y;
412 for (y = 0; y < height; y ++)
414 LONG x;
415 for (x = 0; x < width; x ++)
417 setbitmappixel(BI(dest_info)->bitmap
418 , x + x_dest
419 , y + y_dest
420 , *bufptr ++, BI(dest_info)->bmdepth, BI(dest_info)->planemask
429 else
431 LONG y;
433 for (y = 0; y < height; y ++)
435 LONG x;
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
445 , x + x_dest
446 , y + y_dest
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
458 , x + x_dest
459 , y + y_dest
460 , dest, BI(dest_info)->bmdepth
461 , BI(dest_info)->planemask
469 return;
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;
491 return;
495 static VOID setbitmappixel(struct BitMap *bm
496 , LONG x, LONG y
497 , ULONG pen
498 , UBYTE depth
499 , UBYTE plane_mask)
501 UBYTE i;
502 ULONG idx;
503 UBYTE mask, clr_mask;
504 ULONG penmask;
506 idx = COORD_TO_BYTEIDX(x, y, bm->BytesPerRow);
508 mask = XCOORD_TO_MASK( x );
509 clr_mask = ~mask;
511 penmask = 1;
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)
522 plane[idx] |= mask;
523 else
524 plane[idx] &= clr_mask;
528 penmask <<= 1;
531 return;
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)
538 LONG num_whole;
539 UBYTE sb_type;
541 UBYTE plane;
542 UBYTE pre_pixels_to_set,
543 post_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");
587 else
590 /* Say we want to clear two pixels in last byte. We want the mask
591 MSB 00000011 LSB
593 sb_type = SB_FULL;
594 prebyte_mask = 0xFF >> (8 - pre_pixels_to_set);
596 /* Say we want to set two pixels in last byte. We want the mask
597 MSB 11000000 LSB
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 ++)
618 LONG y;
619 UBYTE pixvals;
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))
627 pixvals = 0xFF;
628 else
629 pixvals = 0x00;
631 /* Set the pre and postpixels */
632 switch (sb_type)
634 case SB_FULL:
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 ++)
644 LONG x;
645 UBYTE *ptr = curbyte;
647 *ptr |= prepixels_set;
648 *ptr ++ &= prepixels_clr;
650 for (x = 0; x < num_whole; x ++)
652 *ptr ++ = pixvals;
654 /* Clear the last nonwhole byte */
655 *ptr |= postpixels_set;
656 *ptr ++ &= postpixels_clr;
658 /* Go to next line */
659 curbyte += bm->BytesPerRow;
661 break;
663 case SB_PREPOSTMASK:
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;
686 break;
688 case SB_SINGLEMASK:
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;
703 break;
705 } /* switch() */
707 return;