added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / graphics / allocspritedataa.c
blob0cdabc8203e4fafbe75627bd8ef314c24b5c5e35
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 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
64 struct ExtSprite *sprite = NULL;
66 if (NULL != bitmap) {
67 #define SCALE_NORMAL 16
68 ULONG height = (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT);
69 ULONG width = 16;
70 struct TagItem * tstate = tagList;
71 struct TagItem * tag;
72 struct BitScaleArgs bsa;
73 LONG xrep = 0, yrep = 0;
75 memset(&bsa, 0, sizeof(bsa));
77 while (NULL != (tag = NextTagItem(&tstate))) {
78 switch (tag->ti_Tag) {
79 case SPRITEA_Width:
80 width = tag->ti_Data;
81 break;
83 case SPRITEA_XReplication:
84 xrep = tag->ti_Data;
85 break;
87 case SPRITEA_YReplication:
88 yrep = tag->ti_Data;
89 break;
91 case SPRITEA_OutputHeight:
92 if (tag->ti_Data > (ULONG)GetBitMapAttr(bitmap, BMA_HEIGHT)) {
93 return NULL;
95 height = tag->ti_Data;
96 break;
98 case SPRITEA_Attached:
100 break;
105 sprite = AllocVec(sizeof(*sprite), MEMF_PUBLIC | MEMF_CLEAR);
106 if (NULL != sprite) {
108 bsa.bsa_SrcWidth = GetBitMapAttr(bitmap, BMA_WIDTH);
109 bsa.bsa_SrcHeight = GetBitMapAttr(bitmap, BMA_HEIGHT);
111 if (xrep > 0) {
112 bsa.bsa_XDestFactor = SCALE_NORMAL << xrep;
113 } else {
114 bsa.bsa_XDestFactor = SCALE_NORMAL >> (-xrep);
117 if (yrep > 0) {
118 bsa.bsa_YDestFactor = SCALE_NORMAL << yrep;
119 } else {
120 bsa.bsa_YDestFactor = SCALE_NORMAL >> (-yrep);
123 bsa.bsa_XSrcFactor = SCALE_NORMAL;
124 bsa.bsa_YSrcFactor = SCALE_NORMAL;
125 bsa.bsa_SrcBitMap = bitmap;
126 bsa.bsa_DestBitMap = AllocBitMap(width,
127 height,
129 BMF_CLEAR|BMF_DISPLAYABLE,
130 NULL);
131 BitMapScale(&bsa);
133 sprite->es_SimpleSprite.height = height;
134 sprite->es_SimpleSprite.x = 0;
135 sprite->es_SimpleSprite.y = 0;
136 sprite->es_SimpleSprite.num = 0;
137 sprite->es_wordwidth = width >> 4;
138 sprite->es_flags = 0;
139 sprite->es_BitMap = bsa.bsa_DestBitMap;
143 return sprite;
145 AROS_LIBFUNC_EXIT
146 } /* AllocSpriteDataA */