this repo has no description
1/*
2 SCRNMAPR.h
3
4 Copyright (C) 2012 Paul C. Pratt
5
6 You can redistribute this file and/or modify it under the terms
7 of version 2 of the GNU General Public License as published by
8 the Free Software Foundation. You should have received a copy
9 of the license along with this file; see the file COPYING.
10
11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 license for more details.
15*/
16
17/*
18 SCReeN MAPpeR
19*/
20
21/* required arguments for this template */
22
23#ifndef ScrnMapr_DoMap /* procedure to be created by this template */
24#error "ScrnMapr_DoMap not defined"
25#endif
26#ifndef ScrnMapr_Src
27#error "ScrnMapr_Src not defined"
28#endif
29#ifndef ScrnMapr_Dst
30#error "ScrnMapr_Dst not defined"
31#endif
32#ifndef ScrnMapr_SrcDepth
33#error "ScrnMapr_SrcDepth not defined"
34#endif
35#ifndef ScrnMapr_DstDepth
36#error "ScrnMapr_DstDepth not defined"
37#endif
38#ifndef ScrnMapr_Map
39#error "ScrnMapr_Map not defined"
40#endif
41
42/* optional argument for this template */
43
44#ifndef ScrnMapr_Scale
45#define ScrnMapr_Scale 1
46#endif
47
48/* check of parameters */
49
50#if (ScrnMapr_SrcDepth < 0) || (ScrnMapr_SrcDepth > 3)
51#error "bad ScrnMapr_SrcDepth"
52#endif
53
54#if (ScrnMapr_DstDepth < ScrnMapr_SrcDepth)
55#error "bad ScrnMapr_Dst"
56#endif
57
58/* calculate a few things local to this template */
59
60#define ScrnMapr_MapElSz \
61 (ScrnMapr_Scale << (ScrnMapr_DstDepth - ScrnMapr_SrcDepth))
62
63#if 0 == (ScrnMapr_MapElSz & 3)
64#define ScrnMapr_TranT ui5b
65#define ScrnMapr_TranLn2Sz 2
66#elif 0 == (ScrnMapr_MapElSz & 1)
67#define ScrnMapr_TranT ui4b
68#define ScrnMapr_TranLn2Sz 1
69#else
70#define ScrnMapr_TranT ui3b
71#define ScrnMapr_TranLn2Sz 0
72#endif
73
74#define ScrnMapr_TranN (ScrnMapr_MapElSz >> ScrnMapr_TranLn2Sz)
75
76#define ScrnMapr_ScrnWB (vMacScreenWidth >> (3 - ScrnMapr_SrcDepth))
77
78/* now define the procedure */
79
80LOCALPROC ScrnMapr_DoMap(si4b top, si4b left,
81 si4b bottom, si4b right)
82{
83 int i;
84 int j;
85#if (ScrnMapr_TranN > 4) || (ScrnMapr_Scale > 2)
86 int k;
87#endif
88 ui5r t0;
89 ScrnMapr_TranT *pMap;
90#if ScrnMapr_Scale > 1
91 ScrnMapr_TranT *p3;
92#endif
93
94 ui4r leftB = left >> (3 - ScrnMapr_SrcDepth);
95 ui4r rightB = (right + (1 << (3 - ScrnMapr_SrcDepth)) - 1)
96 >> (3 - ScrnMapr_SrcDepth);
97 ui4r jn = rightB - leftB;
98 ui4r SrcSkip = ScrnMapr_ScrnWB - jn;
99 ui3b *pSrc = ((ui3b *)ScrnMapr_Src)
100 + leftB + ScrnMapr_ScrnWB * (ui5r)top;
101 ScrnMapr_TranT *pDst = ((ScrnMapr_TranT *)ScrnMapr_Dst)
102 + ((leftB + ScrnMapr_ScrnWB * ScrnMapr_Scale * (ui5r)top)
103 * ScrnMapr_TranN);
104 ui5r DstSkip = SrcSkip * ScrnMapr_TranN;
105
106 for (i = bottom - top; --i >= 0; ) {
107#if ScrnMapr_Scale > 1
108 p3 = pDst;
109#endif
110
111 for (j = jn; --j >= 0; ) {
112 t0 = *pSrc++;
113 pMap =
114 &((ScrnMapr_TranT *)ScrnMapr_Map)[t0 * ScrnMapr_TranN];
115
116#if ScrnMapr_TranN > 4
117 for (k = ScrnMapr_TranN; --k >= 0; ) {
118 *pDst++ = *pMap++;
119 }
120#else
121
122#if ScrnMapr_TranN >= 2
123 *pDst++ = *pMap++;
124#endif
125#if ScrnMapr_TranN >= 3
126 *pDst++ = *pMap++;
127#endif
128#if ScrnMapr_TranN >= 4
129 *pDst++ = *pMap++;
130#endif
131 *pDst++ = *pMap;
132
133#endif /* ! ScrnMapr_TranN > 4 */
134
135 }
136 pSrc += SrcSkip;
137 pDst += DstSkip;
138
139#if ScrnMapr_Scale > 1
140#if ScrnMapr_Scale > 2
141 for (k = ScrnMapr_Scale - 1; --k >= 0; )
142#endif
143 {
144 pMap = p3;
145 for (j = ScrnMapr_TranN * jn; --j >= 0; ) {
146 *pDst++ = *pMap++;
147 }
148 pDst += DstSkip;
149 }
150#endif /* ScrnMapr_Scale > 1 */
151 }
152}
153
154/* undefine template locals and parameters */
155
156#undef ScrnMapr_ScrnWB
157#undef ScrnMapr_TranN
158#undef ScrnMapr_TranLn2Sz
159#undef ScrnMapr_TranT
160#undef ScrnMapr_MapElSz
161
162#undef ScrnMapr_DoMap
163#undef ScrnMapr_Src
164#undef ScrnMapr_Dst
165#undef ScrnMapr_SrcDepth
166#undef ScrnMapr_DstDepth
167#undef ScrnMapr_Map
168#undef ScrnMapr_Scale