ScummVM API documentation
scalerplugin.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 #ifndef GRAPHICS_SCALERPLUGIN_H
22 #define GRAPHICS_SCALERPLUGIN_H
23 
24 #include "base/plugins.h"
25 #include "graphics/pixelformat.h"
26 #include "graphics/surface.h"
27 
28 class Scaler {
29 public:
30  Scaler(const Graphics::PixelFormat &format) : _format(format) {}
31  virtual ~Scaler() {}
32 
45  void scale(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr,
46  uint32 dstPitch, int width, int height, int x, int y);
47 
52  virtual uint increaseFactor() = 0;
53 
58  virtual uint decreaseFactor() = 0;
59 
60  virtual uint getFactor() const { return _factor; }
61 
69  virtual uint setFactor(uint factor) {
70  uint oldFactor = _factor;
71  _factor = factor;
72  return oldFactor;
73  }
74 
81  virtual void setSource(const byte *src, uint pitch, int width, int height, int padding) {
82  // Should not be called unless overriden
83  assert(0);
84  }
85 
92  virtual void enableSource(bool enable) {
93  // Should not be called unless overriden
94  assert(0);
95  }
96 
97 protected:
101  virtual void scaleIntern(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr,
102  uint32 dstPitch, int width, int height, int x, int y) = 0;
103 
104  uint _factor;
105  Graphics::PixelFormat _format;
106 };
107 
112 class SourceScaler : public Scaler {
113 
114 public:
115 
116  SourceScaler(const Graphics::PixelFormat &format);
117  virtual ~SourceScaler();
118 
119  virtual void setSource(const byte *src, uint pitch, int width, int height, int padding) final;
120 
121  virtual void enableSource(bool enable) final { _enable = enable; }
122 
123  virtual uint setFactor(uint factor) final;
124 
125 protected:
126 
127  virtual void scaleIntern(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr,
128  uint32 dstPitch, int width, int height, int x, int y) final;
129 
137  virtual void internScale(const uint8 *srcPtr, uint32 srcPitch,
138  uint8 *dstPtr, uint32 dstPitch,
139  const uint8 *oldSrcPtr, uint32 oldSrcPitch,
140  int width, int height, const uint8 *buffer, uint32 bufferPitch) = 0;
141 
142 private:
143 
144  int _width, _height, _padding;
145  bool _enable;
146  byte *_oldSrc;
147  Graphics::Surface _bufferedOutput;
148 };
149 
151 public:
152 
153  virtual ~ScalerPluginObject() {}
154 
155  virtual Scaler *createInstance(const Graphics::PixelFormat &format) const = 0;
156 
157  const Common::Array<uint> &getFactors() const { return _factors; }
158 
159  bool hasFactor(uint factor) const {
160  const Common::Array<uint> &factors = getFactors();
161  for (Common::Array<uint>::const_iterator it = factors.begin(); it != factors.end(); it++) {
162  if ((*it) == factor)
163  return true;
164  }
165 
166  return false;
167  }
168 
173  virtual uint extraPixels() const = 0;
174 
179  virtual bool canDrawCursor() const = 0;
180 
184  virtual const char *getPrettyName() const = 0;
185 
189  virtual uint getDefaultFactor() const { return 2; }
190 
200  virtual bool useOldSource() const { return false; }
201 
202 protected:
203  Common::Array<uint> _factors;
204 };
205 
209 class ScalerManager : public Common::Singleton<ScalerManager> {
210 private:
211  friend class Common::Singleton<SingletonBaseType>;
212 
213 public:
214  const PluginList &getPlugins() const;
215 
221  uint getMaxExtraPixels() const;
222 
226  Plugin *findScalerPlugin(const char *name) const;
227 
231  uint findScalerPluginIndex(const char *name) const;
232 
236  void updateOldSettings();
237 
241  bool isOldGraphicsSetting(const Common::String &gfxMode);
242 };
243 
245 #define ScalerMan ScalerManager::instance()
246 
247 #endif
virtual void enableSource(bool enable)
Definition: scalerplugin.h:92
Definition: str.h:59
Definition: scalerplugin.h:112
Definition: surface.h:67
Definition: pixelformat.h:138
virtual uint decreaseFactor()=0
iterator end()
Definition: array.h:379
iterator begin()
Definition: array.h:374
virtual void setSource(const byte *src, uint pitch, int width, int height, int padding)
Definition: scalerplugin.h:81
Definition: plugins.h:145
virtual void scaleIntern(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y)=0
const T * const_iterator
Definition: array.h:55
Definition: scalerplugin.h:150
Definition: plugins.h:131
virtual uint getDefaultFactor() const
Definition: scalerplugin.h:189
virtual bool useOldSource() const
Definition: scalerplugin.h:200
Definition: scalerplugin.h:209
Definition: scalerplugin.h:28
virtual uint increaseFactor()=0
virtual uint setFactor(uint factor)
Definition: scalerplugin.h:69
void scale(const uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height, int x, int y)
Definition: singleton.h:42
virtual void enableSource(bool enable) final
Definition: scalerplugin.h:121