typo
[AROS.git] / workbench / libs / cgfx / scalepixelarray.c
blob8c41aa6c181906044113578bcf8822a1271d93da
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <hidd/graphics.h>
11 #include <proto/cybergraphics.h>
13 #include "cybergraphics_intern.h"
14 #include "gfxfuncsupport.h"
16 struct render_data
18 OOP_Object *srcbm_obj;
19 OOP_Object *gfx_hidd;
22 static ULONG RenderHook(struct render_data *data, LONG srcx, LONG srcy,
23 OOP_Object *dstbm_obj, OOP_Object *dst_gc, struct Rectangle *rect,
24 struct GfxBase *GfxBase);
26 /*****************************************************************************
28 NAME */
29 #include <proto/cybergraphics.h>
31 AROS_LH10(LONG, ScalePixelArray,
33 /* SYNOPSIS */
34 AROS_LHA(APTR , srcRect, A0),
35 AROS_LHA(UWORD , SrcW, D0),
36 AROS_LHA(UWORD , SrcH, D1),
37 AROS_LHA(UWORD , SrcMod, D2),
38 AROS_LHA(struct RastPort *, RastPort, A1),
39 AROS_LHA(UWORD , DestX, D3),
40 AROS_LHA(UWORD , DestY, D4),
41 AROS_LHA(UWORD , DestW, D5),
42 AROS_LHA(UWORD , DestH, D6),
43 AROS_LHA(UBYTE , SrcFormat, D7),
45 /* LOCATION */
46 struct Library *, CyberGfxBase, 15, Cybergraphics)
48 /* FUNCTION
49 Fills all or part of a RastPort with a rectangular block of raw pixel
50 values. The source pixels are scaled to fit the destination area, i.e.
51 some pixels may be duplicated or dropped according to the need to
52 stretch or compress the source block.
54 INPUTS
55 srcRect - pointer to the pixel values.
56 SrcW, SrcH - width and height of the source rectangle (in pixels).
57 SrcMod - the number of bytes in each row of the source rectangle.
58 RastPort - the RastPort to write to.
59 DestX, DestY - top-lefthand corner of portion of destination RastPort
60 to write to (in pixels).
61 DestW, DestH - size of the destination rectangle (in pixels).
62 SrcFormat - the format of the source pixels. See WritePixelArray for
63 possible values.
65 RESULT
66 count - the number of pixels written to.
68 NOTES
70 EXAMPLE
72 BUGS
74 SEE ALSO
75 WritePixelArray()
77 INTERNALS
79 *****************************************************************************/
81 AROS_LIBFUNC_INIT
83 ULONG result = 0;
84 struct render_data data;
85 struct Rectangle rr;
86 OOP_Object *gfx_hidd, *tempbm_obj, *tempbm2_obj, *gc;
87 struct BitScaleArgs scale_args = {0};
88 struct TagItem bm_tags[] =
90 {aHidd_BitMap_GfxHidd, 0},
91 {aHidd_BitMap_Width, SrcW},
92 {aHidd_BitMap_Height, SrcH},
93 {aHidd_BitMap_StdPixFmt, 0},
94 {TAG_END, 0}
96 struct TagItem gc_tags[] =
98 {aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy},
99 {TAG_DONE, 0UL}
102 D(bug("ScalePixelArray(%p, %d, %d, %d, %p, %d, %d, %d, %d, %d)\n",
103 srcRect, SrcW, SrcH, SrcMod, RastPort, DestX, DestY, DestW, DestH,
104 SrcFormat));
106 if (SrcW == 0 || SrcH == 0 || DestW == 0 || DestH == 0)
107 return 0;
109 /* This is cybergraphx. We only work wih HIDD bitmaps */
111 if (!IS_HIDD_BM(RastPort->BitMap))
113 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ScalePixelArray() !!!\n"));
114 return 0;
117 /* Get graphics HIDD and a graphics context */
119 OOP_GetAttr(HIDD_BM_OBJ(RastPort->BitMap), aHidd_BitMap_GfxHidd,
120 (IPTR *)&gfx_hidd);
121 gc = HIDD_Gfx_CreateObject(gfx_hidd, GetCGFXBase(CyberGfxBase)->basegc, gc_tags);
122 if (gc)
124 /* Create two temporary bitmap objects: one the size of the source area
125 and another the size of the destination area */
127 bm_tags[0].ti_Data = (IPTR)gfx_hidd;
128 bm_tags[3].ti_Data = GetHIDDRectFmt(SrcFormat, RastPort, CyberGfxBase);
129 tempbm_obj = HIDD_Gfx_CreateObject(gfx_hidd, GetCGFXBase(CyberGfxBase)->basebm, bm_tags);
130 if (tempbm_obj)
132 bm_tags[1].ti_Data = DestW;
133 bm_tags[2].ti_Data = DestH;
134 #if 0
135 // FIXME: This doesn't work (X11 and VESA). Should it?
136 bm_tags[3].ti_Tag = aHidd_BitMap_Friend;
137 bm_tags[3].ti_Data = (IPTR)HIDD_BM_OBJ(RastPort->BitMap);
138 #endif
139 tempbm2_obj = HIDD_Gfx_CreateObject(gfx_hidd, GetCGFXBase(CyberGfxBase)->basebm, bm_tags);
140 if (tempbm2_obj)
142 /* Copy the source array to its temporary bitmap object */
144 HIDD_BM_PutImage(tempbm_obj, gc, srcRect, SrcMod, 0, 0, SrcW, SrcH,
145 vHidd_StdPixFmt_Native);
147 /* Scale temporary source bitmap on to temporary destination bitmap */
149 scale_args.bsa_SrcWidth = SrcW;
150 scale_args.bsa_SrcHeight = SrcH;
151 scale_args.bsa_DestWidth = DestW;
152 scale_args.bsa_DestHeight = DestH;
153 HIDD_BM_BitMapScale(tempbm2_obj, tempbm_obj, tempbm2_obj, &scale_args,
154 gc);
156 /* Render temporary destination bitmap to destination bitmap */
158 data.srcbm_obj = tempbm2_obj;
159 data.gfx_hidd = gfx_hidd;
160 rr.MinX = DestX;
161 rr.MinY = DestY;
162 rr.MaxX = DestX + DestW - 1;
163 rr.MaxY = DestY + DestH - 1;
164 result = DoRenderFunc(RastPort, NULL, &rr, RenderHook, &data, TRUE);
166 // Discard temporary resources ...
168 OOP_DisposeObject(tempbm2_obj);
170 OOP_DisposeObject(tempbm_obj);
172 OOP_DisposeObject(gc);
175 return result;
177 AROS_LIBFUNC_EXIT
178 } /* ScalePixelArray */
180 static ULONG RenderHook(struct render_data *data, LONG srcx, LONG srcy,
181 OOP_Object *dstbm_obj, OOP_Object *dst_gc, struct Rectangle *rect,
182 struct GfxBase *GfxBase)
184 ULONG width = rect->MaxX - rect->MinX + 1;
185 ULONG height = rect->MaxY - rect->MinY + 1;
187 HIDD_Gfx_CopyBox(data->gfx_hidd, data->srcbm_obj, srcx, srcy, dstbm_obj,
188 rect->MinX, rect->MinY, width, height, dst_gc);
190 return width * height;