2 Copyright © 1995-2005, The AROS Development Team. All rights reserved.
6 #include <exec/alerts.h>
7 #include <aros/macros.h>
11 #include <aros/debug.h>
13 /****************************************************************************************/
15 /* stegerg: maybe more safe, even if Unix malloc is used and not AROS malloc */
18 #define DO_ENDIAN_FIX 1 /* fix if X11 server running on remote server with different endianess */
20 /****************************************************************************************/
24 /****************************************************************************************/
27 #define NEEDS_ENDIAN_FIX(image) (((image)->bits_per_pixel >= 15) && ((image)->byte_order != MSBFirst))
28 #define SWAP16(x) AROS_WORD2LE(x)
29 #define SWAP32(x) AROS_LONG2LE(x)
30 #define AROS_BYTEORDER MSBFirst
32 #define NEEDS_ENDIAN_FIX(image) (((image)->bits_per_pixel >= 15) && ((image)->byte_order != LSBFirst))
33 #define SWAP16(x) AROS_WORD2BE(x)
34 #define SWAP32(x) AROS_LONG2BE(x)
35 #define AROS_BYTEORDER LSBFirst
38 #if 0 /* stegerg: to test above stuff*/
39 #define NEEDS_ENDIAN_FIX(image) ((image)->bits_per_pixel >= 15)
40 #define AROS_BYTEORDER MSBFirst
41 #define SWAP16(x) AROS_WORD2BE(x)
42 #define SWAP32(x) AROS_LONG2BE(x)
45 #define XFLUSH(x) XCALL(XFlush, x)
48 /****************************************************************************************/
50 static void SwapImageEndianess(XImage
*image
)
52 LONG x
, y
, height
, width
, bpp
;
53 UBYTE
*imdata
= (UBYTE
*)image
->data
;
56 height
= image
->height
;
57 bpp
= (image
->bits_per_pixel
+ 7) / 8;
59 for (y
= 0; y
< height
; y
++)
64 for (x
= 0; x
< width
; x
++, imdata
+= 2)
66 UWORD pix
= *(UWORD
*)imdata
;
70 *(UWORD
*)imdata
= pix
;
72 imdata
+= (image
->bytes_per_line
- width
* 2);
76 for (x
= 0; x
< width
; x
++, imdata
+= 3)
78 UBYTE pix1
= imdata
[0];
79 UBYTE pix3
= imdata
[2];
84 imdata
+= (image
->bytes_per_line
- width
* 3);
88 for (x
= 0; x
< width
; x
++, imdata
+= 4)
90 ULONG pix
= *(ULONG
*)imdata
;
94 *(ULONG
*)imdata
= pix
;
96 imdata
+= (image
->bytes_per_line
- width
* 4);
101 } /* for (y = 0; y < height; y ++) */
103 image
->byte_order
= AROS_BYTEORDER
;
106 /****************************************************************************************/
108 #endif /* DO_ENDIAN_FIX */
110 /****************************************************************************************/
112 BOOL
MNAME(Hidd_BitMap__SetColors
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
114 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
115 HIDDT_PixelFormat
*pf
;
120 if (vHidd_ColorModel_StaticPalette
== HIDD_PF_COLMODEL(pf
) ||
121 vHidd_ColorModel_TrueColor
== HIDD_PF_COLMODEL(pf
) )
123 /* Superclass takes care of this case */
125 return OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
128 /* Ve have a vHidd_GT_Palette bitmap */
130 if (!OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
)) return FALSE
;
132 if (data
->flags
& BMDF_COLORMAP_ALLOCED
)
136 for ( xc_i
= msg
->firstColor
, col_i
= 0;
137 col_i
< msg
->numColors
;
142 xcol
.red
= msg
->colors
[col_i
].red
;
143 xcol
.green
= msg
->colors
[col_i
].green
;
144 xcol
.blue
= msg
->colors
[col_i
].blue
;
147 xcol
.flags
= DoRed
| DoGreen
| DoBlue
;
149 XCALL(XStoreColor
, data
->display
, data
->colmap
, &xcol
);
155 } /* if (data->flags & BMDF_COLORMAP_ALLOCED) */
161 /****************************************************************************************/
163 VOID
MNAME(Hidd_BitMap__PutPixel
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPixel
*msg
)
165 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
169 XCALL(XSetForeground
, data
->display
, data
->gc
, msg
->pixel
);
170 XCALL(XDrawPoint
, data
->display
, DRAWABLE(data
), data
->gc
, msg
->x
, msg
->y
);
171 XFLUSH(data
->display
);
176 /****************************************************************************************/
178 HIDDT_Pixel
MNAME(Hidd_BitMap__GetPixel
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetPixel
*msg
)
180 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
181 HIDDT_Pixel pixel
= -1;
186 XCALL(XSync
, data
->display
, False
);
188 image
= XCALL(XGetImage
, data
->display
, DRAWABLE(data
), msg
->x
, msg
->y
,
189 1, 1, AllPlanes
, ZPixmap
);
193 pixel
= XGetPixel(image
, 0, 0);
194 XDestroyImage(image
);
203 /****************************************************************************************/
205 ULONG
MNAME(Hidd_BitMap__DrawPixel
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawPixel
*msg
)
207 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
210 gcval
.function
= GC_DRMD(msg
->gc
);
211 gcval
.foreground
= GC_FG(msg
->gc
);
212 gcval
.background
= GC_BG(msg
->gc
);
215 XCALL(XChangeGC
, data
->display
, data
->gc
, GCFunction
| GCForeground
| GCBackground
, &gcval
);
216 XCALL(XDrawPoint
, data
->display
, DRAWABLE(data
), data
->gc
, msg
->x
, msg
->y
);
217 XFLUSH(data
->display
); /* stegerg: uncommented */
223 /****************************************************************************************/
225 VOID
MNAME(Hidd_BitMap__FillRect
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
)
227 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
230 EnterFunc(bug("X11Gfx.BitMap::FillRect(%d,%d,%d,%d)\n",
231 msg
->minX
, msg
->minY
, msg
->maxX
, msg
->maxY
));
233 D(bug("Drawmode: %d\n", mode
));
235 gcval
.function
= GC_DRMD(msg
->gc
);
236 gcval
.foreground
= GC_FG(msg
->gc
);
237 gcval
.background
= GC_BG(msg
->gc
);
240 XCALL(XChangeGC
, data
->display
, data
->gc
, GCFunction
| GCForeground
| GCBackground
, &gcval
);
242 XCALL(XFillRectangle
, data
->display
, DRAWABLE(data
), data
->gc
,
243 msg
->minX
, msg
->minY
,
244 msg
->maxX
- msg
->minX
+ 1, msg
->maxY
- msg
->minY
+ 1);
246 XFLUSH(data
->display
);
249 ReturnVoid("X11Gfx.BitMap::FillRect");
252 /****************************************************************************************/
254 static ULONG
*ximage_to_buf(OOP_Class
*cl
, OOP_Object
*bm
, HIDDT_Pixel
*buf
,
255 XImage
*image
, ULONG width
, ULONG height
, ULONG depth
,
256 struct pHidd_BitMap_GetImage
*msg
)
260 case vHidd_StdPixFmt_Native
:
262 UBYTE
*imdata
= image
->data
;
265 for (y
= 0; y
< height
; y
++)
267 memcpy(buf
, imdata
, msg
->width
* image
->bits_per_pixel
/ 8);
269 imdata
+= image
->bytes_per_line
;
270 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
275 case vHidd_StdPixFmt_Native32
:
276 switch (image
->bits_per_pixel
)
280 UBYTE
*imdata
= (UBYTE
*)image
->data
;
283 for (y
= 0; y
< height
; y
++)
285 HIDDT_Pixel
*p
= buf
;
287 for (x
= 0; x
< width
; x
++)
291 imdata
+= (image
->bytes_per_line
- width
);
292 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
299 UWORD
*imdata
= (UWORD
*)image
->data
;
302 for (y
= 0; y
< height
; y
++)
304 HIDDT_Pixel
*p
= buf
;
306 for (x
= 0; x
< width
; x
++)
310 imdata
+= image
->bytes_per_line
/2 - width
;
311 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
318 ULONG
*imdata
= (ULONG
*)image
->data
;
321 for (y
= 0; y
< height
; y
++)
323 HIDDT_Pixel
*p
= buf
;
325 for (x
= 0; x
< width
; x
++)
329 imdata
+= image
->bytes_per_line
/4 - width
;
330 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
340 for (y
= 0; y
< height
; y
++)
345 for (x
= 0; x
< width
; x
++)
347 *p
++ = XGetPixel(image
, x
, y
);
349 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
355 } /* switch (image->bits_per_pixel) */
362 OOP_Object
*srcpf
, *dstpf
, *gfxhidd
;
363 APTR srcPixels
= image
->data
, dstBuf
= buf
;
365 //kprintf("DEFAULT PIXEL CONVERSION\n");
367 OOP_GetAttr(bm
, aHidd_BitMap_GfxHidd
, (IPTR
*)&gfxhidd
);
368 dstpf
= HIDD_Gfx_GetPixFmt(gfxhidd
, msg
->pixFmt
);
370 OOP_GetAttr(bm
, aHidd_BitMap_PixFmt
, (IPTR
*)&srcpf
);
372 //kprintf("CALLING ConvertPixels()\n");
374 HIDD_BM_ConvertPixels(bm
, &srcPixels
, (HIDDT_PixelFormat
*)srcpf
,
375 image
->bytes_per_line
, &dstBuf
,
376 (HIDDT_PixelFormat
*)dstpf
, msg
->modulo
,
377 width
, height
, NULL
/* We have no CLUT */
380 //kprintf("CONVERTPIXELS DONE\n");
382 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
* height
);
386 } /* switch (msg->pixFmt) */
391 /****************************************************************************************/
393 #define ABS(a) ((a) < 0 ? -(a) : a)
395 /****************************************************************************************/
397 static inline UBYTE
pix_to_lut(HIDDT_Pixel pixel
, HIDDT_PixelLUT
*plut
,
398 HIDDT_PixelFormat
*pf
)
400 HIDDT_ColComp red
, green
, blue
;
402 ULONG diff
, lowest_diff
= 0xFFFFFFFF;
404 red
= RED_COMP(pixel
, pf
);
405 green
= GREEN_COMP(pixel
, pf
);
406 blue
= BLUE_COMP(pixel
, pf
);
408 for (i
= 0; i
< plut
->entries
; i
++)
410 register HIDDT_Pixel cur_lut
= plut
->pixels
[i
];
412 if (pixel
== cur_lut
)
413 return i
; /* Exact match found */
415 /* How well does these pixels match ? */
416 diff
= ABS(red
- RED_COMP(cur_lut
, pf
)) +
417 ABS(green
- GREEN_COMP(cur_lut
, pf
)) +
418 ABS(blue
- BLUE_COMP(cur_lut
, pf
));
420 if (diff
< lowest_diff
)
431 /****************************************************************************************/
433 static UBYTE
*ximage_to_buf_lut(OOP_Class
*cl
, OOP_Object
*bm
, UBYTE
*buf
,
434 XImage
*image
, ULONG width
, ULONG height
,
435 ULONG depth
, struct pHidd_BitMap_GetImageLUT
*msg
)
437 /* This one is trickier, as we have to reverse-lookup the lut.
438 This costs CPU ! Maybe one could do some kind of caching here ?
439 Ie. one stores the most often used RGB combinations
440 in a trie and looks up this first to see if whe can find an exact match
443 HIDDT_PixelFormat
*pf
= BM_PIXFMT(bm
);
444 UBYTE
*pixarray
= msg
->pixels
;
446 if (image
->bits_per_pixel
== 16)
448 UWORD
*imdata
= (UWORD
*)image
->data
;
451 for (y
= 0; y
< height
; y
++)
453 UBYTE
*buf
= pixarray
;
455 for (x
= 0; x
< width
; x
++)
457 *buf
++ = pix_to_lut((HIDDT_Pixel
)*imdata
, msg
->pixlut
, pf
);
461 imdata
+= ((image
->bytes_per_line
/ 2) - width
); /*sg*/
463 pixarray
+= msg
->modulo
;
472 for (y
= 0; y
< height
; y
++)
474 UBYTE
*buf
= pixarray
;
475 for (x
= 0; x
< width
; x
++)
477 *buf
++ = pix_to_lut((HIDDT_Pixel
)XGetPixel(image
, x
, y
), msg
->pixlut
, pf
);;
479 pixarray
+= msg
->modulo
;
490 /****************************************************************************************/
494 /****************************************************************************************/
496 static void getimage_xshm(OOP_Class
*cl
, OOP_Object
*o
, LONG x
, LONG y
,
497 ULONG width
, ULONG height
, APTR pixarray
,
498 APTR (*fromimage_func
)(), APTR fromimage_data
)
500 struct bitmap_data
*data
;
510 ASSERT(width
> 0 && height
> 0);
512 data
= OOP_INST_DATA(cl
, o
);
514 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)&pf
);
515 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
517 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
520 image
= create_xshm_ximage(data
->display
,
521 DefaultVisual(data
->display
, data
->screen
),
530 ReturnVoid("X11Gfx.BitMap::PutImage(XShmCreateImage failed)");
532 bperline
= image
->bytes_per_line
;
534 ASSERT(image
->bytes_per_line
> 0);
536 /* Calculate how many scanline can be stored in the buffer */
537 maxlines
= XSHM_MEMSIZE
/ image
->bytes_per_line
;
541 kprintf("ALERT !!! NOT ENOUGH MEMORY TO READ A COMPLETE SCANLINE\n");
542 kprintf("THROUGH XSHM IN X11GF X HIDD !!!\n");
547 ysize
= image
->height
;
549 ObtainSemaphore(&XSD(cl
)->shm_sema
);
553 /* Get some more pixels from the Ximage */
555 lines_to_copy
= MIN(maxlines
, ysize
);
557 ysize
-= lines_to_copy
;
558 image
->height
= lines_to_copy
;
561 get_xshm_ximage(data
->display
, DRAWABLE(data
), image
,
565 current_y
+= lines_to_copy
;
567 pixarray
= fromimage_func(cl
, o
, pixarray
, image
, image
->width
,
568 lines_to_copy
, depth
, fromimage_data
);
570 } /* while (pixels left to copy) */
572 ReleaseSemaphore(&XSD(cl
)->shm_sema
);
575 destroy_xshm_ximage(image
);
582 /****************************************************************************************/
586 /****************************************************************************************/
588 static void getimage_xlib(OOP_Class
*cl
, OOP_Object
*o
, LONG x
, LONG y
,
589 ULONG width
, ULONG height
, APTR pixels
,
590 APTR (*fromimage_func
)(), APTR fromimage_data
)
592 struct bitmap_data
*data
;
594 ULONG
*pixarray
= (ULONG
*)pixels
;
598 data
= OOP_INST_DATA(cl
, o
);
600 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)&pf
);
601 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
604 image
= XCALL(XGetImage
, data
->display
, DRAWABLE(data
), x
, y
,
605 width
, height
, AllPlanes
, ZPixmap
);
612 if (NEEDS_ENDIAN_FIX(image
))
614 SwapImageEndianess(image
);
617 XCALL(XInitImage
, image
);
622 fromimage_func(cl
, o
, pixarray
, image
, width
, height
, depth
, fromimage_data
);
625 XDestroyImage(image
);
631 /****************************************************************************************/
633 VOID
MNAME(Hidd_BitMap__GetImage
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
)
635 ASSERT(msg
->width
> 0 && msg
->height
> 0);
638 if (XSD(cl
)->use_xshm
)
640 getimage_xshm(cl
, o
, msg
->x
, msg
->y
, msg
->width
, msg
->height
,
641 msg
->pixels
, (APTR (*)())ximage_to_buf
, msg
);
646 getimage_xlib(cl
, o
, msg
->x
, msg
->y
, msg
->width
, msg
->height
,
647 msg
->pixels
, (APTR (*)())ximage_to_buf
, msg
);
651 /****************************************************************************************/
653 VOID
MNAME(Hidd_BitMap__GetImageLUT
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImageLUT
*msg
)
655 ASSERT(msg
->width
!= 0 && msg
->height
!= 0);
657 if (XSD(cl
)->use_xshm
)
659 getimage_xshm(cl
, o
, msg
->x
, msg
->y
, msg
->width
, msg
->height
,
660 msg
->pixels
, (APTR (*)())ximage_to_buf_lut
, msg
);
665 getimage_xlib(cl
, o
, msg
->x
, msg
->y
, msg
->width
, msg
->height
,
666 msg
->pixels
, (APTR (*)())ximage_to_buf_lut
, msg
);
670 /****************************************************************************************/
675 #include <aros/debug.h>
677 /****************************************************************************************/
679 static ULONG
*buf_to_ximage(OOP_Class
*cl
, OOP_Object
*bm
, HIDDT_Pixel
*buf
,
680 XImage
*image
, ULONG width
, ULONG height
, ULONG depth
,
681 struct pHidd_BitMap_PutImage
*msg
)
685 case vHidd_StdPixFmt_Native
:
687 UBYTE
*imdata
= image
->data
;
690 for (y
= 0; y
< height
; y
++)
692 memcpy(imdata
, buf
, msg
->width
* image
->bits_per_pixel
/ 8);
694 imdata
+= image
->bytes_per_line
;
695 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
700 case vHidd_StdPixFmt_Native32
:
701 switch (image
->bits_per_pixel
)
705 UBYTE
*imdata
= (UBYTE
*)image
->data
;
708 for (y
= 0; y
< height
; y
++)
710 HIDDT_Pixel
*p
= buf
;
712 for (x
= 0; x
< width
; x
++)
714 *imdata
++ = (UBYTE
)*p
++;
716 imdata
+= image
->bytes_per_line
- width
;
717 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
724 UWORD
*imdata
= (UWORD
*)image
->data
;
727 for (y
= 0; y
< height
; y
++)
729 HIDDT_Pixel
*p
= buf
;
731 for (x
= 0; x
< width
; x
++)
733 *imdata
++ = (UWORD
)*p
++;
735 imdata
+= image
->bytes_per_line
/2 - width
;
736 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
744 HIDDT_PixelFormat
*pf
;
745 UBYTE
*imdata
= image
->data
;
750 for (y
= 0; y
< height
; y
++)
753 HIDDT_Pixel
*p
= buf
;
755 for (x
= 0; x
< width
; x
++)
757 register HIDDT_Pixel pix
;
760 #if (AROS_BIG_ENDIAN == 1)
761 *imdata
++ = pix
>> 16;
762 *imdata
++ = (pix
& pf
->green_mask
) >> 8;
763 *imdata
++ = (pix
& pf
->blue_mask
);
765 *imdata
++ = (pix
& pf
->blue_mask
);
766 *imdata
++ = (pix
& pf
->green_mask
) >> 8;
767 *imdata
++ = pix
>> 16;
770 imdata
+= image
->bytes_per_line
- width
* 3;
771 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
778 ULONG
*imdata
= (ULONG
*)image
->data
;
781 for (y
= 0; y
< height
; y
++)
783 HIDDT_Pixel
*p
= buf
;
785 for (x
= 0; x
< width
; x
++)
787 *imdata
++ = (ULONG
)*p
++;
789 imdata
+= image
->bytes_per_line
/4 - width
;
790 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
800 for (y
= 0; y
< height
; y
++)
805 for (x
= 0; x
< width
; x
++)
807 XPutPixel(image
, x
, y
, *p
++);
809 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
);
815 } /* switch (image->bits_per_pixel) */
822 OOP_Object
*srcpf
, *dstpf
, *gfxhidd
;
823 APTR srcPixels
= buf
, dstBuf
= image
->data
;
825 //kprintf("DEFAULT PIXEL CONVERSION\n");
827 OOP_GetAttr(bm
, aHidd_BitMap_GfxHidd
, (IPTR
*)&gfxhidd
);
828 srcpf
= HIDD_Gfx_GetPixFmt(gfxhidd
, msg
->pixFmt
);
830 OOP_GetAttr(bm
, aHidd_BitMap_PixFmt
, (IPTR
*)&dstpf
);
832 //kprintf("CALLING ConvertPixels()\n");
834 HIDD_BM_ConvertPixels(bm
, &srcPixels
, (HIDDT_PixelFormat
*)srcpf
,
835 msg
->modulo
, &dstBuf
, (HIDDT_PixelFormat
*)dstpf
,
836 image
->bytes_per_line
, width
, height
, NULL
); /* We have no CLUT */
838 //kprintf("CONVERTPIXELS DONE\n");
840 buf
= (HIDDT_Pixel
*)((UBYTE
*)buf
+ msg
->modulo
* height
);
844 } /* switch (msg->pixFmt) */
850 /****************************************************************************************/
852 static UBYTE
*buf_to_ximage_lut(OOP_Class
*cl
, OOP_Object
*bm
, UBYTE
*pixarray
,
853 XImage
*image
, ULONG width
, ULONG height
, ULONG depth
,
854 struct pHidd_BitMap_PutImageLUT
*msg
)
856 HIDDT_Pixel
*lut
= msg
->pixlut
->pixels
;
858 switch(image
->bits_per_pixel
)
862 UBYTE
*imdata
= (UBYTE
*)image
->data
;
865 for (y
= 0; y
< height
; y
++)
867 UBYTE
*buf
= pixarray
;
869 for (x
= 0; x
< width
; x
++)
871 *imdata
++ = (UBYTE
)lut
[*buf
++];
873 pixarray
+= msg
->modulo
;
874 imdata
+= (image
->bytes_per_line
- width
); /*sg*/
881 UWORD
*imdata
= (UWORD
*)image
->data
;
884 for (y
= 0; y
< height
; y
++)
886 UBYTE
*buf
= pixarray
;
888 for (x
= 0; x
< width
; x
++)
890 *imdata
++ = (UWORD
)lut
[*buf
++];
892 pixarray
+= msg
->modulo
;
893 imdata
+= ((image
->bytes_per_line
/ 2) - width
); /*sg*/
900 ULONG
*imdata
= (ULONG
*)image
->data
;
903 for (y
= 0; y
< height
; y
++)
905 UBYTE
*buf
= pixarray
;
907 for (x
= 0; x
< width
; x
++)
909 *imdata
++ = (ULONG
)lut
[*buf
++];
912 pixarray
+= msg
->modulo
;
913 imdata
+= ((image
->bytes_per_line
/ 4) - width
); /*sg*/
922 for (y
= 0; y
< height
; y
++)
924 UBYTE
*buf
= pixarray
;
926 for (x
= 0; x
< width
; x
++)
928 XPutPixel(image
, x
, y
, lut
[*buf
++]);
931 pixarray
+= msg
->modulo
;
938 } /* switch(image->bits_per_pixel) */
943 /****************************************************************************************/
947 /****************************************************************************************/
949 static void putimage_xshm(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
,
950 LONG x
, LONG y
, ULONG width
, ULONG height
,
951 APTR pixarray
, APTR (*toimage_func
)(), APTR toimage_data
)
954 struct bitmap_data
*data
;
964 data
= OOP_INST_DATA(cl
, o
);
966 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)&pf
);
967 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
969 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
972 image
= create_xshm_ximage(data
->display
,
973 DefaultVisual(data
->display
, data
->screen
),
982 ReturnVoid("X11Gfx.BitMap::PutImage(XShmCreateImage failed)");
984 bperline
= image
->bytes_per_line
;
986 /* Calculate how many scanline can be stored in the buffer */
987 maxlines
= XSHM_MEMSIZE
/ image
->bytes_per_line
;
991 kprintf("ALERT !!! NOT ENOUGH MEMORY TO WRITE A COMPLETE SCANLINE\n");
992 kprintf("THROUGH XSHM IN X11GF X HIDD !!!\n");
997 ysize
= image
->height
;
999 ObtainSemaphore(&XSD(cl
)->shm_sema
);
1003 /* Get some more pixels from the HIDD */
1005 lines_to_copy
= MIN(maxlines
, ysize
);
1007 ysize
-= lines_to_copy
;
1008 image
->height
= lines_to_copy
;
1010 pixarray
= toimage_func(cl
, o
, pixarray
, image
, image
->width
,
1011 lines_to_copy
, depth
, toimage_data
);
1014 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(gc
));
1016 put_xshm_ximage(data
->display
,
1022 image
->width
, lines_to_copy
,
1027 current_y
+= lines_to_copy
;
1029 } /* while (pixels left to copy) */
1031 ReleaseSemaphore(&XSD(cl
)->shm_sema
);
1034 XFLUSH(data
->display
); /* stegerg: added */
1035 destroy_xshm_ximage(image
);
1042 /****************************************************************************************/
1046 /****************************************************************************************/
1048 static void putimage_xlib(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
,
1049 LONG x
, LONG y
, ULONG width
, ULONG height
,
1050 APTR pixarray
, APTR (*toimage_func
)(), APTR toimage_data
)
1053 struct bitmap_data
*data
;
1059 data
= OOP_INST_DATA(cl
, o
);
1061 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)&pf
);
1062 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
1065 image
= XCALL(XCreateImage
, data
->display
,
1066 DefaultVisual(data
->display
, data
->screen
),
1078 ReturnVoid("X11Gfx.BitMap::PutImage(XCreateImage failed)");
1081 if (NEEDS_ENDIAN_FIX(image
))
1083 image
->byte_order
= AROS_BYTEORDER
;
1086 XCALL(XInitImage
, image
);
1091 bperline
= image
->bytes_per_line
;
1094 image
->data
= (char *)AllocVec((size_t)height
* bperline
, MEMF_PUBLIC
);
1096 image
->data
= (char *)malloc((size_t)height
* bperline
);
1102 XCALL(XFree
, image
);
1105 ReturnVoid("X11Gfx.BitMap::PutImage(malloc(image data) failed)");
1108 toimage_func(cl
, o
, pixarray
, image
, width
, height
, depth
, toimage_data
);
1111 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(gc
));
1112 XCALL(XPutImage
, data
->display
, DRAWABLE(data
), data
->gc
, image
,
1113 0, 0, x
, y
, width
, height
);
1114 XFLUSH(data
->display
);
1118 FreeVec(image
->data
);
1124 XCALL(XFree
, image
);
1129 /****************************************************************************************/
1131 VOID
MNAME(Hidd_BitMap__PutImage
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImage
*msg
)
1133 EnterFunc(bug("X11Gfx.BitMap::PutImage(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
1134 msg
->pixels
, msg
->x
, msg
->y
, msg
->width
, msg
->height
));
1137 if (XSD(cl
)->use_xshm
)
1139 putimage_xshm(cl
, o
, msg
->gc
, msg
->x
, msg
->y
,
1140 msg
->width
, msg
->height
, msg
->pixels
,
1141 (APTR (*)()) buf_to_ximage
, msg
);
1146 putimage_xlib(cl
, o
, msg
->gc
, msg
->x
, msg
->y
,
1147 msg
->width
, msg
->height
, msg
->pixels
,
1148 (APTR (*)()) buf_to_ximage
, msg
);
1151 ReturnVoid("X11Gfx.BitMap::PutImage");
1154 /****************************************************************************************/
1156 VOID
MNAME(Hidd_BitMap__PutImageLUT
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImageLUT
*msg
)
1158 EnterFunc(bug("X11Gfx.BitMap::PutImage(pa=%p, x=%d, y=%d, w=%d, h=%d)\n",
1159 msg
->pixels
, msg
->x
, msg
->y
, msg
->width
, msg
->height
));
1162 if (XSD(cl
)->use_xshm
)
1164 putimage_xshm(cl
, o
, msg
->gc
, msg
->x
, msg
->y
,
1165 msg
->width
, msg
->height
, msg
->pixels
,
1166 (APTR (*)())buf_to_ximage_lut
, msg
);
1171 putimage_xlib(cl
, o
, msg
->gc
, msg
->x
, msg
->y
,
1172 msg
->width
, msg
->height
, msg
->pixels
,
1173 (APTR (*)())buf_to_ximage_lut
, msg
);
1176 ReturnVoid("X11Gfx.BitMap::PutImageLUT");
1179 /****************************************************************************************/
1183 #include <aros/debug.h>
1185 /****************************************************************************************/
1187 VOID
MNAME(Hidd_BitMap__BlitColorExpansion
)(OOP_Class
*cl
, OOP_Object
*o
,
1188 struct pHidd_BitMap_BlitColorExpansion
*msg
1191 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
1198 EnterFunc(bug("X11Gfx.BitMap::BlitColorExpansion(%p, %d, %d, %d, %d, %d, %d)\n",
1199 msg
->srcBitMap
, msg
->srcX
, msg
->srcY
, msg
->destX
, msg
->destY
, msg
->width
, msg
->height
));
1202 OOP_GetAttr(msg
->srcBitMap
, aHidd_X11BitMap_Drawable
, (IPTR
*)&d
);
1206 /* We know nothing about the source bitmap. Let the superclass handle this */
1207 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1211 fg
= GC_FG(msg
->gc
);
1212 bg
= GC_BG(msg
->gc
);
1213 cemd
= GC_COLEXP(msg
->gc
);
1219 XCALL(XSetForeground
, data
->display
, data
->gc
, fg
);
1221 if (cemd
& vHidd_GC_ColExp_Opaque
)
1223 XCALL(XSetBackground
, data
->display
, data
->gc
, bg
);
1224 XCALL(XSetFunction
, data
->display
, data
->gc
, GXcopy
);
1226 XCALL(XCopyPlane
, data
->display
, d
, DRAWABLE(data
), data
->gc
,
1227 msg
->srcX
, msg
->srcY
, msg
->width
, msg
->height
,
1228 msg
->destX
, msg
->destY
, 0x01);
1232 /* Do transparent blit */
1237 val
.ts_x_origin
= msg
->destX
- msg
->srcX
;
1238 val
.ts_y_origin
= msg
->destY
- msg
->srcY
;
1239 val
.fill_style
= FillStippled
;
1241 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(msg
->gc
));
1243 XCALL(XChangeGC
, data
->display
, data
->gc
,
1244 GCStipple
|GCTileStipXOrigin
|GCTileStipYOrigin
|GCFillStyle
,
1247 XCALL(XFillRectangle
, data
->display
, DRAWABLE(data
), data
->gc
,
1248 msg
->destX
, msg
->destY
, msg
->width
, msg
->height
);
1250 XCALL(XSetFillStyle
, data
->display
, data
->gc
, FillSolid
);
1259 /* We know nothing about the format of the source bitmap
1260 an must get single pixels
1264 dest_im
= XCALL(XGetImage
, data
->display
, DRAWABLE(data
),
1265 msg
->destX
, msg
->destY
, msg
->width
, msg
->height
,
1266 AllPlanes
, ZPixmap
);
1270 ReturnVoid("X11Gfx.BitMap::BlitColorExpansion()");
1272 D(bug("Src bm: %p\n", msg
->srcBitMap
));
1274 for (y
= 0; y
< msg
->height
; y
++)
1276 for (x
= 0; x
< msg
->width
; x
++)
1280 is_set
= HIDD_BM_GetPixel(msg
->srcBitMap
, x
+ msg
->srcX
, y
+ msg
->srcY
);
1284 XPutPixel(dest_im
, x
, y
, fg
);
1289 if (cemd
& vHidd_GC_ColExp_Opaque
)
1291 XPutPixel(dest_im
, x
, y
, bg
);
1295 } /* for (each x) */
1297 } /* for (each y) */
1299 /* Put image back into display */
1302 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(msg
->gc
));
1303 XCALL(XPutImage
, data
->display
, DRAWABLE(data
), data
->gc
, dest_im
,
1304 0, 0, msg
->destX
, msg
->destY
, msg
->width
, msg
->height
);
1305 XDestroyImage(dest_im
);
1310 XFLUSH(data
->display
);
1313 ReturnVoid("X11Gfx.BitMap::BlitColorExpansion");
1316 /****************************************************************************************/
1320 #include <aros/debug.h>
1322 /****************************************************************************************/
1324 VOID
MNAME(Root__Get
)(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
1326 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
1329 if (IS_X11BM_ATTR(msg
->attrID
, idx
))
1333 case aoHidd_X11BitMap_Drawable
:
1334 *msg
->storage
= (IPTR
)DRAWABLE(data
);
1337 case aoHidd_X11BitMap_MasterWindow
:
1338 *msg
->storage
= (IPTR
)data
->masterxwindow
;
1342 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1348 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1353 /****************************************************************************************/
1355 VOID
MNAME(Hidd_BitMap__DrawLine
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawLine
*msg
)
1357 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
1358 OOP_Object
*gc
= msg
->gc
;
1360 if (GC_LINEPAT(gc
) != (UWORD
)~0)
1362 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1373 cr
.x
= GC_CLIPX1(gc
);
1374 cr
.y
= GC_CLIPY1(gc
);
1375 cr
.width
= GC_CLIPX2(gc
) - cr
.x
+ 1;
1376 cr
.height
= GC_CLIPY2(gc
) - cr
.y
+ 1;
1378 XCALL(XSetClipRectangles
, data
->display
, data
->gc
,
1379 0, 0, &cr
, 1, Unsorted
);
1382 XCALL(XSetForeground
, data
->display
, data
->gc
, GC_FG(gc
));
1383 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(gc
));
1385 XCALL(XDrawLine
, data
->display
, DRAWABLE(data
), data
->gc
,
1386 msg
->x1
, msg
->y1
, msg
->x2
, msg
->y2
);
1390 XCALL(XSetClipMask
, data
->display
, data
->gc
, None
);
1393 XFLUSH(data
->display
);
1398 /****************************************************************************************/
1400 VOID
MNAME(Hidd_BitMap__DrawEllipse
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawEllipse
*msg
)
1402 struct bitmap_data
*data
= OOP_INST_DATA(cl
, o
);
1403 OOP_Object
*gc
= msg
->gc
;
1411 /* kprintf("X11::Drawllipse: clip %d %d %d %d\n"
1412 , GC_CLIPX1(gc), GC_CLIPY1(gc), GC_CLIPX2(gc), GC_CLIPY2(gc));
1415 cr
.x
= GC_CLIPX1(gc
);
1416 cr
.y
= GC_CLIPY1(gc
);
1417 cr
.width
= GC_CLIPX2(gc
) - cr
.x
+ 1;
1418 cr
.height
= GC_CLIPY2(gc
) - cr
.y
+ 1;
1420 XCALL(XSetClipRectangles
, data
->display
, data
->gc
,
1421 0, 0, &cr
, 1, Unsorted
);
1424 XCALL(XSetForeground
, data
->display
, data
->gc
, GC_FG(gc
));
1425 XCALL(XSetFunction
, data
->display
, data
->gc
, GC_DRMD(gc
));
1427 /* kprintf("X11::Drawllipse: coord %d %d %d %d\n"
1428 , msg->x, msg->y, msg->rx, msg->ry);
1432 XCALL(XDrawArc
, data
->display
, DRAWABLE(data
), data
->gc
,
1433 msg
->x
- msg
->rx
, msg
->y
- msg
->ry
,
1434 msg
->rx
* 2, msg
->ry
* 2, 0, 360 * 64);
1438 XCALL(XSetClipMask
, data
->display
, data
->gc
, None
);
1441 XFLUSH(data
->display
);
1446 /****************************************************************************************/