ScummVM API documentation
render_table.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef ZVISION_RENDER_TABLE_H
23#define ZVISION_RENDER_TABLE_H
24
25#include "common/rect.h"
26#include "graphics/surface.h"
27#include "zvision/zvision.h"
28
29class OSystem;
30namespace ZVision {
31
33public:
34 // Bitfields representing sequential direction of contraction
35 bool _xDir = false; // false left, true right
36 bool _yDir = false; // false up, true down
37 Common::Rect _src = Common::Rect(0, 0); // Coordinates of four panorama image pixels around actual working window pixel
38
39 float _fX, _fY, _fTL, _fTR, _fBL, _fBR;
40
41 FilterPixel() {}
42 FilterPixel(float x, float y, bool highQuality = false) {
43 _src.left = int16(floor(x));
44 _src.right = int16(ceil(x));
45 _src.top = int16(floor(y));
46 _src.bottom = int16(ceil(y));
47 if (highQuality) {
48 _fX = x - (float)_src.left;
49 _fY = y - (float)_src.top;
50 _fTL = (1 - _fX) * (1 - _fY);
51 _fTR = _fX * (1 - _fY);
52 _fBL = (1 - _fX) * _fY;
53 _fBR = _fX * _fY;
54 } else {
55 // Nearest neighbour
56 _xDir = (x - _src.left) > 0.5f;
57 _yDir = (y - _src.top) > 0.5f;
58 }
59 }
60 ~FilterPixel() {}
61 inline void flipH() {
62 _src.left = -_src.left;
63 _src.right = -_src.right;
64 }
65 inline void flipV() {
66 _src.top = -_src.top;
67 _src.bottom = -_src.bottom;
68 }
69};
70
72public:
73 RenderTable(ZVision *engine, uint16 numRows, uint16 numColumns, const Graphics::PixelFormat &pixelFormat);
75
76// Common::Point testPixel = Common::Point(255,0);
77public:
78 enum RenderState {
79 PANORAMA,
80 TILT,
81 FLAT
82 };
83
84private:
85 ZVision *_engine;
86 OSystem *_system;
87 uint16 _numRows, _numColumns, _halfRows, _halfColumns; // Working area width, height; half width, half height, in whole pixels
88 float _halfWidth, _halfHeight; // Centre axis to midpoint of outermost pixel
89 FilterPixel *_internalBuffer;
90 RenderState _renderState;
91 bool _highQuality = false;
92 const Graphics::PixelFormat _pixelFormat;
93
94 inline void splitColor(uint16 &color, uint32 &r, uint32 &g, uint32 &b) const {
95 // NB Left & right shifting unnecessary for interpolating & recombining, so not bothering in order to save cycles
96 r = color & 0x001f;
97 g = color & 0x03e0;
98 b = color & 0x7c00;
99 }
100 inline uint16 mergeColor(const uint32 &r, const uint32 &g, const uint32 &b) const {
101 // NB Red uses the lowest bits in RGB555 and so doesn't need its fractional bits masked away after averaging
102 return r | (g & 0x03e0) | (b & 0x7c00);
103 }
104
105
106 struct {
107 float verticalFOV; // Radians
108 float linearScale;
109 bool reverse;
110 uint16 zeroPoint;
111 } _panoramaOptions;
112
113 struct {
114 float verticalFOV; // Radians
115 float linearScale;
116 bool reverse;
117 float gap;
118 } _tiltOptions;
119
120public:
121 RenderState getRenderState() {
122 return _renderState;
123 }
124 void setRenderState(RenderState newState);
125
126 const Common::Point convertWarpedCoordToFlatCoord(const Common::Point &point); // input point in working area coordinates
127
128// void mutateImage(uint16 *sourceBuffer, uint16 *destBuffer, uint32 destWidth, const Common::Rect &subRect);
129 void mutateImage(Graphics::Surface *dstBuf, Graphics::Surface *srcBuf, bool filter = false);
130 template <typename I>
131 Common::String pixelToBinary(const I &pixel, bool splitColors = true) const {
132 uint8 bits = sizeof(pixel) << 3;
133 Common::String str("0b");
134 I spaceMask = 0;
135 for (uint8 i = 0; i < 3; i++)
136 spaceMask = (spaceMask << 5) + 0x10;
137 for (I mask = 0x01 << (bits - 1); mask; mask >>= 1) {
138 if (splitColors && (spaceMask & mask))
139 str += " ";
140 str += mask & pixel ? "1" : "0";
141 }
142 return str;
143 }
144 void generateRenderTable();
145
146 void setPanoramaFoV(float fov); // Degrees
147 void setPanoramaScale(float scale);
148 void setPanoramaReverse(bool reverse);
149 void setPanoramaZeroPoint(uint16 point);
150 uint16 getPanoramaZeroPoint();
151 bool getPanoramaReverse();
152
153 void setTiltFoV(float fov); // Degrees
154 void setTiltScale(float scale);
155 void setTiltReverse(bool reverse);
156
157 float getTiltGap();
158 float getAngle();
159 float getLinscale();
160
161private:
162 void generateLookupTable(bool tilt = false);
163 void generatePanoramaLookupTable();
164 void generateTiltLookupTable();
165};
166
167} // End of namespace ZVision
168
169#endif
Definition: str.h:59
Definition: system.h:166
Definition: render_table.h:32
Definition: render_table.h:71
Definition: focus_list.h:27
Definition: rect.h:144
T right
Definition: rect.h:171
T left
Definition: rect.h:170
Definition: rect.h:536
Definition: pixelformat.h:138
Definition: surface.h:67