Fixed a warning (missing type cast)
[tangerine.git] / rom / graphics / allocspritedataa.c
blob9667f8e1d04242e2c58363a3df2e479c61bb0660
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function AllocSpriteDataA()
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <proto/graphics.h>
10 #include <proto/utility.h>
11 #include <aros/debug.h>
12 #include <graphics/gfx.h>
13 #include <graphics/sprite.h>
14 #include <graphics/scale.h>
15 #include <utility/tagitem.h>
16 #include <exec/exec.h>
17 #include <string.h>
18 #include "graphics_intern.h"
20 /*****************************************************************************
22 NAME */
23 #include <proto/graphics.h>
25 AROS_LH2(struct ExtSprite *, AllocSpriteDataA,
27 /* SYNOPSIS */
28 AROS_LHA(struct BitMap *, bitmap, A2),
29 AROS_LHA(struct TagItem *, tagList, A1),
31 /* LOCATION */
32 struct GfxBase *, GfxBase, 170, Graphics)
34 /* FUNCTION
36 INPUTS
37 bitmap - pointer to a bitmap. This bitmap provides the source data
38 for the sprite image
39 tags - pointer to a taglist
41 RESULT
42 SpritePtr - pointer to a ExtSprite structure,
43 or NULL if there is a failure.
44 You should pass this pointer to FreeSpriteData()
45 when this sprite is not needed anymore.
47 NOTES
49 EXAMPLE
51 BUGS
53 SEE ALSO
55 INTERNALS
57 HISTORY
60 ******************************************************************************/
62 AROS_LIBFUNC_INIT
63 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
65 struct ExtSprite *sprite = NULL;
67 if (NULL != bitmap) {
68 #define SCALE_NORMAL 16
69 ULONG height = (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT);
70 ULONG width = 16;
71 struct TagItem * tstate = tagList;
72 struct TagItem * tag;
73 struct BitScaleArgs bsa;
74 LONG xrep = 0, yrep = 0;
76 memset(&bsa, 0, sizeof(bsa));
78 while (NULL != (tag = NextTagItem(&tstate))) {
79 switch (tag->ti_Tag) {
80 case SPRITEA_Width:
81 width = tag->ti_Data;
82 break;
84 case SPRITEA_XReplication:
85 xrep = tag->ti_Data;
86 break;
88 case SPRITEA_YReplication:
89 yrep = tag->ti_Data;
90 break;
92 case SPRITEA_OutputHeight:
93 if (tag->ti_Data > (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT)) {
94 return NULL;
96 height = tag->ti_Data;
97 break;
99 case SPRITEA_Attached:
101 break;
106 sprite = AllocVec(sizeof(*sprite), MEMF_PUBLIC | MEMF_CLEAR);
107 if (NULL != sprite) {
109 bsa.bsa_SrcWidth = GetBitMapAttr(bitmap, BMA_WIDTH);
110 bsa.bsa_SrcHeight = GetBitMapAttr(bitmap, BMA_HEIGHT);
112 if (xrep > 0) {
113 bsa.bsa_XDestFactor = SCALE_NORMAL << xrep;
114 } else {
115 bsa.bsa_XDestFactor = SCALE_NORMAL >> (-xrep);
118 if (yrep > 0) {
119 bsa.bsa_YDestFactor = SCALE_NORMAL << yrep;
120 } else {
121 bsa.bsa_YDestFactor = SCALE_NORMAL >> (-yrep);
124 bsa.bsa_XSrcFactor = SCALE_NORMAL;
125 bsa.bsa_YSrcFactor = SCALE_NORMAL;
126 bsa.bsa_SrcBitMap = bitmap;
127 bsa.bsa_DestBitMap = AllocBitMap(width,
128 height,
130 BMF_CLEAR|BMF_DISPLAYABLE,
131 NULL);
132 BitMapScale(&bsa);
134 sprite->es_SimpleSprite.height = height;
135 sprite->es_SimpleSprite.x = 0;
136 sprite->es_SimpleSprite.y = 0;
137 sprite->es_SimpleSprite.num = 0;
138 sprite->es_wordwidth = width >> 4;
139 sprite->es_flags = 0;
140 sprite->es_BitMap = bsa.bsa_DestBitMap;
144 return sprite;
146 AROS_LIBFUNC_EXIT
147 } /* AllocSpriteDataA */