Autodoc corrections, additions.
[cake.git] / rom / graphics / allocspritedataa.c
blob78c0fb7167a2bb53a15cb9fe5a3d847d37b33e9c
1 /*
2 Copyright © 1995-2007, 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 TAGS
42 SPRITEA_Width (ULONG) - Width of the sprite. If bitmap is smaller it will
43 be filled on the right side with transparent
44 pixels. Defaults to 16.
45 SPRITEA_XReplication (LONG) - 0 - perform a 1 to 1 conversion
46 1 - each pixel from the source is replicated twice
47 2 - each pixel is replicated 4 times.
48 -1 - skip every 2nc pixel in the source bitmap
49 -2 - only include every fourth pixel from the source.
50 SPRITEA_YReplication (LONG) - like SPRITEA_YReplication, but for vertical direction.
51 SPRITEA_OutputHeight (ULONG) - Output height of the sprite. Must be at least as high
52 as the bitmap. Defaults to bitmap height.
53 SPRITEA_Attach - (Not implemented)
55 RESULT
56 SpritePtr - pointer to a ExtSprite structure,
57 or NULL if there is a failure.
58 You should pass this pointer to FreeSpriteData()
59 when this sprite is not needed anymore.
61 NOTES
63 EXAMPLE
65 BUGS
67 SEE ALSO
69 INTERNALS
71 HISTORY
74 ******************************************************************************/
76 AROS_LIBFUNC_INIT
78 struct ExtSprite *sprite = NULL;
80 if (NULL != bitmap) {
81 #define SCALE_NORMAL 16
82 ULONG height = (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT);
83 ULONG width = 16;
84 struct TagItem * tstate = tagList;
85 struct TagItem * tag;
86 struct BitScaleArgs bsa;
87 LONG xrep = 0, yrep = 0;
89 memset(&bsa, 0, sizeof(bsa));
91 while (NULL != (tag = NextTagItem(&tstate))) {
92 switch (tag->ti_Tag) {
93 case SPRITEA_Width:
94 width = tag->ti_Data;
95 break;
97 case SPRITEA_XReplication:
98 xrep = tag->ti_Data;
99 break;
101 case SPRITEA_YReplication:
102 yrep = tag->ti_Data;
103 break;
105 case SPRITEA_OutputHeight:
106 if (tag->ti_Data > (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT)) {
107 return NULL;
109 height = tag->ti_Data;
110 break;
112 case SPRITEA_Attached:
114 break;
119 sprite = AllocVec(sizeof(*sprite), MEMF_PUBLIC | MEMF_CLEAR);
120 if (NULL != sprite) {
122 bsa.bsa_SrcWidth = GetBitMapAttr(bitmap, BMA_WIDTH);
123 bsa.bsa_SrcHeight = GetBitMapAttr(bitmap, BMA_HEIGHT);
125 if (xrep > 0) {
126 bsa.bsa_XDestFactor = SCALE_NORMAL << xrep;
127 } else {
128 bsa.bsa_XDestFactor = SCALE_NORMAL >> (-xrep);
131 if (yrep > 0) {
132 bsa.bsa_YDestFactor = SCALE_NORMAL << yrep;
133 } else {
134 bsa.bsa_YDestFactor = SCALE_NORMAL >> (-yrep);
137 bsa.bsa_XSrcFactor = SCALE_NORMAL;
138 bsa.bsa_YSrcFactor = SCALE_NORMAL;
139 bsa.bsa_SrcBitMap = bitmap;
140 bsa.bsa_DestBitMap = AllocBitMap(width,
141 height,
143 BMF_CLEAR|BMF_DISPLAYABLE,
144 NULL);
145 BitMapScale(&bsa);
147 sprite->es_SimpleSprite.height = height;
148 sprite->es_SimpleSprite.x = 0;
149 sprite->es_SimpleSprite.y = 0;
150 sprite->es_SimpleSprite.num = 0;
151 sprite->es_wordwidth = width >> 4;
152 sprite->es_flags = 0;
153 sprite->es_BitMap = bsa.bsa_DestBitMap;
157 return sprite;
159 AROS_LIBFUNC_EXIT
160 } /* AllocSpriteDataA */