File: dotmatrix.cpp

package info (click to toggle)
scummvm 2.9.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 450,268 kB
  • sloc: cpp: 4,297,604; asm: 28,322; python: 12,901; sh: 11,219; java: 8,477; xml: 7,843; perl: 2,633; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (129 lines) | stat: -rw-r--r-- 4,344 bytes parent folder | download | duplicates (3)
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
/* 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/>.
 */

#include "graphics/scaler/dotmatrix.h"
#include "graphics/scaler.h"

DotMatrixScaler::DotMatrixScaler(const Graphics::PixelFormat &format) : Scaler(format) {
	_factor = 2;

	if (format.bytesPerPixel == 2) {
		uint16 *lookup16 = (uint16 *)lookup;
		lookup16[0] = lookup16[10] = format.RGBToColor(0, 63, 0);
		lookup16[1] = lookup16[11] = format.RGBToColor(0, 0, 63);
		lookup16[2] = lookup16[8] = format.RGBToColor(63, 0, 0);
		lookup16[4] = lookup16[6] =
			lookup16[12] = lookup16[14] = format.RGBToColor(63, 63, 63);
		lookup16[3] = lookup16[5] = lookup16[7] =
			lookup16[9] = lookup16[13] =
			lookup16[15] = lookup16[16] = format.RGBToColor(0, 0, 0);
	} else {
		uint32 *lookup32 = (uint32 *)lookup;
		lookup32[0] = lookup32[10] = format.ARGBToColor(0, 0, 63, 0);
		lookup32[1] = lookup32[11] = format.ARGBToColor(0, 0, 0, 63);
		lookup32[2] = lookup32[8] = format.ARGBToColor(0, 63, 0, 0);
		lookup32[4] = lookup32[6] =
			lookup32[12] = lookup32[14] = format.ARGBToColor(0, 63, 63, 63);
		lookup32[3] = lookup32[5] = lookup32[7] =
			lookup32[9] = lookup32[13] =
			lookup32[15] = lookup32[16] = format.ARGBToColor(0, 0, 0, 0);
	}
}

void DotMatrixScaler::scaleIntern(const uint8 *srcPtr, uint32 srcPitch,
							uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y) {
	if (_format.bytesPerPixel == 2) {
		scaleIntern<uint16>(srcPtr, srcPitch, dstPtr, dstPitch, width, height, x, y);
	} else {
		scaleIntern<uint32>(srcPtr, srcPitch, dstPtr, dstPitch, width, height, x, y);
	}
}

uint DotMatrixScaler::increaseFactor() {
	return _factor;
}

uint DotMatrixScaler::decreaseFactor() {
	return _factor;
}

template<typename Pixel>
static inline Pixel DOT(const Pixel *dotmatrix, Pixel c, int j, int i) {
	return c - ((c >> 2) & dotmatrix[((j & 3) << 2) + (i & 3)]);
}

template<typename Pixel>
void DotMatrixScaler::scaleIntern(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch,
					int width, int height, int x, int y) {

	const Pixel *dotmatrix = (Pixel *)lookup;

	const uint32 nextlineSrc = srcPitch / sizeof(Pixel);
	const Pixel *p = (const Pixel *)srcPtr;

	const uint32 nextlineDst = dstPitch / sizeof(Pixel);
	Pixel *q = (Pixel *)dstPtr;

	int ja = (y * 2) & 3;
	int ia = (x * 2) & 3;

	for (int j = 0, jj = 0; j < height; ++j, jj += 2) {
		for (int i = 0, ii = 0; i < width; ++i, ii += 2) {
			Pixel c = *(p + i);
			*(q + ii) = DOT<Pixel>(dotmatrix, c, jj + ja, ii + ia);
			*(q + ii + 1) = DOT<Pixel>(dotmatrix, c, jj + ja, ii + ia + 1);
			*(q + ii + nextlineDst) = DOT<Pixel>(dotmatrix, c, jj + ja + 1, ii + ia);
			*(q + ii + nextlineDst + 1) = DOT<Pixel>(dotmatrix, c, jj + ja + 1, ii + ia+ 1);
		}
		p += nextlineSrc;
		q += nextlineDst << 1;
	}
}


class DotMatrixPlugin final : public ScalerPluginObject {
public:
	DotMatrixPlugin();

	Scaler *createInstance(const Graphics::PixelFormat &format) const override;

	bool canDrawCursor() const override { return false; }
	uint extraPixels() const override { return 0; }
	const char *getName() const override;
	const char *getPrettyName() const override;
};

DotMatrixPlugin::DotMatrixPlugin() {
	_factors.push_back(2);
}

Scaler *DotMatrixPlugin::createInstance(const Graphics::PixelFormat &format) const {
	return new DotMatrixScaler(format);
}

const char *DotMatrixPlugin::getName() const {
	return "dotmatrix";
}

const char *DotMatrixPlugin::getPrettyName() const {
	return "DotMatrix";
}

REGISTER_PLUGIN_STATIC(DOTMATRIX, PLUGIN_TYPE_SCALER, DotMatrixPlugin);