File: aastr.cpp

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (218 lines) | stat: -rw-r--r-- 5,666 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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * aastr.c --- anti-aliased stretching for Allegro
 *
 * This file is gift-ware.  This file is given to you freely
 * as a gift.  You may use, modify, redistribute, and generally hack
 * it about in any way you like, and you do not have to give anyone
 * anything in return.
 *
 * I do not accept any responsibility for any effects, adverse or
 * otherwise, that this code may have on just about anything that
 * you can think of.  Use it at your own risk.
 *
 * Copyright (C) 1998, 1999  Michael Bukin
 */

#include "ags/lib/aastr-0.1.1/aastr.h"
#include "ags/lib/aastr-0.1.1/aautil.h"

namespace AGS3 {

/*
 * Engine of anti-aliased stretching.
 */
static void _aa_stretch_blit(BITMAP *_src, BITMAP *_dst,
                             int _sx, int _sy, int _sw, int _sh,
                             int _dx, int _dy, int _dw, int _dh, int _masked) {
	int sx, sy, dx, dy, ydx, ysx;
	int xinc, yinc, dsx, dsy;
	int xi1, xi2, xdd, yxdd;
	int yi1, yi2, ydd;
	int dxbeg, dxend, dybeg, dyend;
	uint32_t num;
	void (*add)(BITMAP * _src, int _sx1, int _sx2, int _sy1, int _sy2, uint32_t _num);
	void (*put)(byte * _addr, int _x);

	if ((_dw <= 0) || (_dh <= 0) || (_sw <= 0) || (_sh <= 0))
		return;

	if (_dst->clip) {
		dybeg = ((_dy > _dst->ct) ? _dy : _dst->ct);
		dyend = (((_dy + _dh) < _dst->cb) ? (_dy + _dh) : _dst->cb);
		if (dybeg >= dyend)
			return;

		dxbeg = ((_dx > _dst->cl) ? _dx : _dst->cl);
		dxend = (((_dx + _dw) < _dst->cr) ? (_dx + _dw) : _dst->cr);
		if (dxbeg >= dxend)
			return;
	} else {
		dxbeg = _dx;
		dybeg = _dy;
		dxend = _dx + _dw;
		dyend = _dy + _dh;
	}

	_sx <<= aa_BITS;
	_sw <<= aa_BITS;
	dsx = _sw / _dw;

	if (dsx < (int)aa_SIZE) {
		/* Exploding by x.  */
		_dw--;
		_sw -= aa_SIZE;
		dsx = aa_SIZE;
	}

	_sy <<= aa_BITS;
	_sh <<= aa_BITS;
	dsy = _sh / _dh;

	if (dsy < (int)aa_SIZE) {
		/* Exploding by y.  */
		_dh--;
		_sh -= aa_SIZE;
		dsy = aa_SIZE;
	}

	num = dsx * dsy;

	if (num > aa_MAX_NUM) {
		if (dsx > (int)aa_MAX_SIZE)
			dsx = aa_MAX_SIZE;
		if (dsy > (int)aa_MAX_SIZE)
			dsy = aa_MAX_SIZE;
		num = dsx * dsy;
	}

	/* Walk in x direction up to dxbeg and save Bresenham state there.
	 * Later, it will be used to restart at any line.  */
	aa_PREPARE(xinc, yxdd, xi1, xi2, _sw, _dw);
	for (ydx = _dx, ysx = _sx; ydx < dxbeg; ydx++) {
		aa_ADVANCE(ysx, xinc, yxdd, xi1, xi2);
	}

	/* Color manipulation routines.  */
	if (is_screen_bitmap(_src))
		return;
	else {
		switch (bitmap_color_depth(_src)) {
		case 8:
			add = ((_masked != 0) ? _aa_masked_add_rgb8 : _aa_add_rgb8);
			break;
#ifdef ALLEGRO_COLOR16
		case 15:
			add = ((_masked != 0) ? _aa_masked_add_rgb15 : _aa_add_rgb15);
			break;
		case 16:
			add = ((_masked != 0) ? _aa_masked_add_rgb16 : _aa_add_rgb16);
			break;
#endif
#ifdef ALLEGRO_COLOR24
		case 24:
			add = ((_masked != 0) ? _aa_masked_add_rgb24 : _aa_add_rgb24);
			_aa_prepare_for_24bpp();
			break;
#endif
#ifdef ALLEGRO_COLOR32
		case 32:
			add = ((_masked != 0) ? _aa_masked_add_rgb32 : _aa_add_rgb32);
			break;
#endif
		default:
			return;
		}
	}

	if (is_planar_bitmap(_dst))
		return;
	else {
		switch (bitmap_color_depth(_dst)) {
		case 8:
			put = ((_masked != 0) ? _aa_masked_put_rgb8 : _aa_put_rgb8);
			break;
#ifdef ALLEGRO_COLOR16
		case 15:
			put = ((_masked != 0) ? _aa_masked_put_rgb15 : _aa_put_rgb15);
			break;
		case 16:
			put = ((_masked != 0) ? _aa_masked_put_rgb16 : _aa_put_rgb16);
			break;
#endif
#ifdef ALLEGRO_COLOR24
		case 24:
			put = ((_masked != 0) ? _aa_masked_put_rgb24 : _aa_put_rgb24);
			_aa_prepare_for_24bpp();
			break;
#endif
#ifdef ALLEGRO_COLOR32
		case 32:
			put = ((_masked != 0) ? _aa_masked_put_rgb32 : _aa_put_rgb32);
			break;
#endif
		default:
			return;
		}
	}

	/* Walk in y until we reach first non-clipped line.  */
	aa_PREPARE(yinc, ydd, yi1, yi2, _sh, _dh);
	for (dy = _dy, sy = _sy; dy < dybeg; dy++) {
		aa_ADVANCE(sy, yinc, ydd, yi1, yi2);
	}

	bmp_select(_dst);

	/* Stretch all non-clipped lines.  */
	for (; dy < dyend; dy++) {
		byte *daddr = bmp_write_line(_dst, dy);

		for (dx = ydx, sx = ysx, xdd = yxdd; dx < dxend; dx++) {
			(*add)(_src, sx, sx + dsx, sy, sy + dsy, num);
			(*put)(daddr, dx);

			aa_ADVANCE(sx, xinc, xdd, xi1, xi2);
		}

		aa_ADVANCE(sy, yinc, ydd, yi1, yi2);
	}
}

/*
 * Anti-aliased bitmap stretching with blit.
 */
void aa_stretch_blit(BITMAP *_src, BITMAP *_dst,
                     int _sx, int _sy, int _sw, int _sh,
                     int _dx, int _dy, int _dw, int _dh) {
	_aa_stretch_blit(_src, _dst, _sx, _sy, _sw, _sh, _dx, _dy, _dw, _dh, 0);
}

/*
 * Anti-aliased bitmap stretching with blit (masked).
 */
void aa_stretch_sprite(BITMAP *_dst, BITMAP *_src, int _dx, int _dy, int _dw, int _dh) {
	_aa_stretch_blit(_src, _dst, 0, 0, _src->w, _src->h, _dx, _dy, _dw, _dh, 1);
}

} // namespace AGS3