grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / libs / cgfx / writepixelarrayalpha.c
blobe807d18b3efdbfab3a735316698bce7a2be0db20
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <hidd/graphics.h>
10 #include <aros/debug.h>
12 #include "cybergraphics_intern.h"
13 #include "gfxfuncsupport.h"
15 struct render_data
17 UBYTE *array;
18 ULONG modulo;
21 static ULONG RenderHook(struct render_data *data, LONG srcx, LONG srcy,
22 OOP_Object *dstbm_obj, OOP_Object *dst_gc, struct Rectangle *rect,
23 struct GfxBase *GfxBase);
25 /*****************************************************************************
27 NAME */
28 #include <proto/cybergraphics.h>
30 AROS_LH10(ULONG, WritePixelArrayAlpha,
32 /* SYNOPSIS */
33 AROS_LHA(APTR , src , A0),
34 AROS_LHA(UWORD , srcx , D0),
35 AROS_LHA(UWORD , srcy , D1),
36 AROS_LHA(UWORD , srcmod , D2),
37 AROS_LHA(struct RastPort *, rp , A1),
38 AROS_LHA(UWORD , destx , D3),
39 AROS_LHA(UWORD , desty , D4),
40 AROS_LHA(UWORD , width , D5),
41 AROS_LHA(UWORD , height , D6),
42 AROS_LHA(ULONG , globalalpha , D7),
44 /* LOCATION */
45 struct Library *, CyberGfxBase, 36, Cybergraphics)
47 /* FUNCTION
48 Alpha-blends all or part of a rectangular block of raw pixel values
49 into a RastPort. The source data must be in 32-bit ARGB format: 1 byte
50 per component, in the order alpha, red, green, blue.
52 INPUTS
53 srcRect - pointer to the pixel values.
54 srcx, srcy - top-lefthand corner of portion of source rectangle to
55 use (in pixels).
56 srcmod - the number of bytes in each row of the source rectangle.
57 rp - the RastPort to write to.
58 destx, desty - top-lefthand corner of portion of destination RastPort
59 to write to (in pixels).
60 width, height - size of the affected area (in pixels).
61 globalalpha - an alpha value applied globally to every pixel taken
62 from the source rectangle (the full 32-bit range of values is
63 used: 0 to 0xFFFFFFFF).
65 RESULT
66 count - the number of pixels written to.
68 NOTES
69 Because of the X11 driver you have to set the drawmode
70 to JAM1 with SetDrMd().
72 EXAMPLE
74 BUGS
75 The globalalpha parameter is currently ignored.
77 SEE ALSO
78 WritePixelArray(), graphics.library/SetDrMd()
80 INTERNALS
82 *****************************************************************************/
84 AROS_LIBFUNC_INIT
86 ULONG start_offset;
87 LONG pixwritten = 0;
88 struct render_data data;
89 struct Rectangle rr;
91 if (width == 0 || height == 0)
92 return 0;
94 /* This is cybergraphx. We only work wih HIDD bitmaps */
95 if (!IS_HIDD_BM(rp->BitMap))
97 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap "
98 "in WritePixelArrayAlpha() !!!\n"));
99 return 0;
102 /* Compute the start of the array */
104 start_offset = ((ULONG)srcy) * srcmod + srcx * 4;
106 data.array = ((UBYTE *)src) + start_offset;
107 data.modulo = srcmod;
109 rr.MinX = destx;
110 rr.MinY = desty;
111 rr.MaxX = destx + width - 1;
112 rr.MaxY = desty + height - 1;
114 pixwritten = DoRenderFunc(rp, NULL, &rr, RenderHook, &data, TRUE);
116 return pixwritten;
118 AROS_LIBFUNC_EXIT
119 } /* WritePixelArrayAlpha */
121 static ULONG RenderHook(struct render_data *data, LONG srcx, LONG srcy,
122 OOP_Object *dstbm_obj, OOP_Object *dst_gc, struct Rectangle *rect,
123 struct GfxBase *GfxBase)
125 ULONG width = rect->MaxX - rect->MinX + 1;
126 ULONG height = rect->MaxY - rect->MinY + 1;
127 UBYTE *array = data->array + data->modulo * srcy + 4 * srcx;
129 HIDD_BM_PutAlphaImage(dstbm_obj, dst_gc, array, data->modulo,
130 rect->MinX, rect->MinY, width, height);
132 return width * height;