File: alpha.cpp

package info (click to toggle)
postal1 2015.git20250526%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 14,024 kB
  • sloc: cpp: 130,877; ansic: 38,942; python: 874; makefile: 351; sh: 61
file content (315 lines) | stat: -rw-r--r-- 7,819 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//	alpha.cpp
// 
// History:
//		10/04/96 JMI	Started.
//
//
//////////////////////////////////////////////////////////////////////////////
//
// Cheezy ass alpha blit.
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Includes.
//////////////////////////////////////////////////////////////////////////////
/*
#include "System.h"

#ifdef PATHS_IN_INCLUDES
	#include "GREEN/Image/Image.h"
	#include "GREEN/BLiT/BLIT.H"
#else
	#include "Image.h"
	#include "BLIT.H"
#endif
#else
*/
#include "RSPiX.h"
#include "alpha.h"


//////////////////////////////////////////////////////////////////////////////
// Macros.
//////////////////////////////////////////////////////////////////////////////
#define TRANS_INDEX	14

//////////////////////////////////////////////////////////////////////////////
// HACKS.
//////////////////////////////////////////////////////////////////////////////
#if 0
//========================================================================================
extern	short	rspBlitT(U8 u8Trans, RImage* pimSrc,RImage* pimDst,short sSrcX,short sSrcY,short sDstX,
			  short sDstY,short sW,short sH,RRect* prDst,const RRect* prSrc);
//========================================================================================
#endif

//////////////////////////////////////////////////////////////////////////////
// Instantiate statics.
//////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// Con/Destruction.
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
// Functions.
///////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////
//
// Whatever this ends up doing, it will suck and eventually be replaced
// so that's the comment or something.
//
///////////////////////////////////////////////////////////////////////////
static int16_t Alpha(	// Returns 0 on success.
	RImage*	pimSrc,	// Source to blit through pimMask.
	RImage*	pimMask,	// Mask.
	RImage*	pimDst,	// Destination for masked blit.
	int16_t		sSrcX,	// X coordinate in source.
	int16_t		sSrcY,	// Y coordinate in source.
	int16_t		sDstX,	// X coordinate in dest.
	int16_t		sDstY,	// Y coordinate in dest.
	int16_t		sW,		// Width to blt.
	int16_t		sH)		// Height to blt.
	{
	int16_t	sRes	= 0;	// Assume success.

	int16_t	sMaskX	= 0;
	int16_t	sMaskY	= 0;

	// X/W Clip.
	if (sSrcX < 0)
		{
		sW		+= sSrcX;
		sDstX -= sSrcX;
		sMaskX	-= sSrcX;
		sSrcX	= 0;
		}

	if (sDstX < 0)
		{
		sW		+= sDstX;
		sSrcX	-= sDstX;
		sMaskX	-= sDstX;
		sDstX	= 0;
		}

	if (sSrcX + sW > pimSrc->m_sWidth)
		{
		sW	= pimSrc->m_sWidth - sSrcX;
		}

	if (sDstX + sW > pimDst->m_sWidth)
		{
		sW	= pimDst->m_sWidth - sDstX;
		}

	if (sMaskX + sW > pimMask->m_sWidth)
		{
		sW	= pimMask->m_sWidth;
		}

	// Y/H Clip.
	if (sSrcY < 0)
		{
		sH		+= sSrcY;
		sDstY -= sSrcY;
		sMaskY	-= sSrcY;
		sSrcY	= 0;
		}

	if (sDstY < 0)
		{
		sH		+= sDstY;
		sSrcY	-= sDstY;
		sMaskY	-= sDstY;
		sDstY	= 0;
		}

	if (sSrcY + sH > pimSrc->m_sHeight)
		{
		sH	= pimSrc->m_sHeight - sSrcY;
		}

	if (sDstY + sH > pimDst->m_sHeight)
		{
		sH	= pimDst->m_sHeight - sDstY;
		}

	if (sMaskY + sH > pimMask->m_sHeight)
		{
		sH	= pimMask->m_sHeight;
		}

	// If there's anything left . . .
	if (sW > 0 && sH > 0)
		{
		U8*	pu8SrcRow	= pimSrc->m_pData + sSrcX + sSrcY * pimSrc->m_lPitch;
		U8*	pu8SrcBlt;
		U8*	pu8MaskRow	= pimMask->m_pData + sMaskX + sMaskY * pimMask->m_lPitch;
		U8*	pu8MaskBlt;
		U8*	pu8DstRow	= pimDst->m_pData + sDstX + sDstY * pimDst->m_lPitch;
		U8*	pu8DstBlt;
		
		int16_t	sWidth;

		while (sH--)
			{
			pu8SrcBlt	= pu8SrcRow;
			pu8MaskBlt	= pu8MaskRow;
			pu8DstBlt	= pu8DstRow;

			sWidth	= sW;
			while (sWidth--)
				{
				if (*pu8MaskBlt++ != 0)
					{
					*pu8DstBlt	= *pu8SrcBlt;
					}

				pu8DstBlt++;
				pu8SrcBlt++;
				}

			pu8SrcRow	+= pimSrc->m_lPitch;
			pu8MaskRow	+= pimMask->m_lPitch;
			pu8DstRow	+= pimDst->m_lPitch;
			}
		}

	return sRes;
	}

///////////////////////////////////////////////////////////////////////////
//
// BLiTs using loaded m_imMask (8 bpp only) as mask.
// 0 in mask indicates opaque.  Other values are punch through.
//
///////////////////////////////////////////////////////////////////////////
int16_t CAlpha::Blit(	// Returns 0 on success.
	RImage*	pimSrc,	// Source image.
	RImage*	pimDst,	// Destination image.
	int16_t	sSrcX,		// Source coordinate in pimSrc to start effect.  Can
							// be negative.
	int16_t	sSrcY,		// Source coordinate in pimSrc to start effect.  Can
							// be negative.
	int16_t	sDstX,		// Destination coordinate in pimDst for pimSrc(0,0).
	int16_t	sDstY,		// Destination coordinate in pimDst for pimSrc(0,0).
	RRect*	prc)			// Rectangle to clip Dst to.
	{
	int16_t	sRes	= 0;	// Assume success.

	// If there is any data . . .
	if (m_imMask.m_pData != NULL || m_imMask.m_pSpecial != NULL)
		{
		RImage	imDecompress;
		// Allocate image.
		if (imDecompress.CreateImage(
			pimSrc->m_sWidth, 
			pimSrc->m_sHeight, 
			RImage::BMP8, 
			0,		// Use default pitch.
			pimSrc->m_sDepth) == 0)
			{
			// Decompress sprite.
			rspBlit(pimSrc, &imDecompress, 0, 0);
			
			// Blit transparency into decompression buffer.
			rspBlitT(TRANS_INDEX,
				&m_imMask, 
				&imDecompress, 
				0, 0,
				sSrcX, sSrcY,
				m_imMask.m_sWidth, m_imMask.m_sHeight, 
				NULL, 
				NULL);

			// Blit to screen.
			rspBlitT(
				0,
				&imDecompress, 
				pimDst, 
				0, 0, 
				sDstX, sDstY, 
				imDecompress.m_sWidth, imDecompress.m_sHeight, 
				prc,
				NULL);
			}
		else
			{
			TRACE("Blit(): Unable to allocate image to decompress pimSrc.\n");
			sRes	= -2;
			}
		}
	else
		{
		TRACE("Blit(): No mask!  Use regular blt.\n");
		sRes	= -1;
		}

	return sRes;
	}

///////////////////////////////////////////////////////////////////////////
//
// Loads the specified file into m_imMask using RImage::Load() and calls
// Convert(FSPR1) to prepare the data.
//
///////////////////////////////////////////////////////////////////////////
int16_t CAlpha::Load(		// Returns 0 on success.
	char*	pszFileName)	// Filename to load.
	{
	int16_t	sRes	= 0;	// Assume success.


	if (m_imMask.Load(pszFileName) == 0)
		{
#if 0
		rspSetConvertToFSPR1(128, 0);

		if (m_imMask.Convert(FSPR1) == FSPR1)
			{
			// Success.
			}
		else
			{
			TRACE("Load(): RImage::Convert(FSPR1) failed.\n");
			sRes	= -2;
			}
#endif
		m_sShadowW	= m_imMask.m_sWidth;
		m_sShadowH	= 5;
		m_sShadowX	= 0;
		m_sShadowY	= m_imMask.m_sHeight - m_sShadowH;
		}
	else
		{
		TRACE("Load(): RImage::Load() failed.\n");
		sRes	= -1;
		}

	return sRes;
	}


//////////////////////////////////////////////////////////////////////////////
// EOF
//////////////////////////////////////////////////////////////////////////////