ScummVM API documentation
blit.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 GRAPHICS_BLIT_H
23 #define GRAPHICS_BLIT_H
24 
25 #include "graphics/pixelformat.h"
26 #include "graphics/transform_struct.h"
27 
28 namespace Common {
29 struct Point;
30 }
31 
32 class BlendBlitUnfilteredTestSuite;
33 
34 namespace Graphics {
35 
45 struct TransformStruct;
46 
48 inline static void convertPaletteToMap(uint32 *dst, const byte *src, uint colors, const Graphics::PixelFormat &format) {
49  while (colors-- > 0) {
50  *dst++ = format.RGBToColor(src[0], src[1], src[2]);
51  src += 3;
52  }
53 }
54 
66 void copyBlit(byte *dst, const byte *src,
67  const uint dstPitch, const uint srcPitch,
68  const uint w, const uint h,
69  const uint bytesPerPixel);
70 
83 bool keyBlit(byte *dst, const byte *src,
84  const uint dstPitch, const uint srcPitch,
85  const uint w, const uint h,
86  const uint bytesPerPixel, const uint32 key);
87 
105 bool maskBlit(byte *dst, const byte *src, const byte *mask,
106  const uint dstPitch, const uint srcPitch, const uint maskPitch,
107  const uint w, const uint h,
108  const uint bytesPerPixel);
109 
131 bool crossBlit(byte *dst, const byte *src,
132  const uint dstPitch, const uint srcPitch,
133  const uint w, const uint h,
134  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
135 
158 bool crossKeyBlit(byte *dst, const byte *src,
159  const uint dstPitch, const uint srcPitch,
160  const uint w, const uint h,
161  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key);
162 
190 bool crossMaskBlit(byte *dst, const byte *src, const byte *mask,
191  const uint dstPitch, const uint srcPitch, const uint maskPitch,
192  const uint w, const uint h,
193  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
194 
195 bool crossBlitMap(byte *dst, const byte *src,
196  const uint dstPitch, const uint srcPitch,
197  const uint w, const uint h,
198  const uint bytesPerPixel, const uint32 *map);
199 
200 bool crossKeyBlitMap(byte *dst, const byte *src,
201  const uint dstPitch, const uint srcPitch,
202  const uint w, const uint h,
203  const uint bytesPerPixel, const uint32 *map, const uint32 key);
204 
205 bool crossMaskBlitMap(byte *dst, const byte *src, const byte *mask,
206  const uint dstPitch, const uint srcPitch, const uint maskPitch,
207  const uint w, const uint h,
208  const uint bytesPerPixel, const uint32 *map);
209 
210 bool scaleBlit(byte *dst, const byte *src,
211  const uint dstPitch, const uint srcPitch,
212  const uint dstW, const uint dstH,
213  const uint srcW, const uint srcH,
214  const Graphics::PixelFormat &fmt,
215  const byte flip = 0);
216 
217 bool scaleBlitBilinear(byte *dst, const byte *src,
218  const uint dstPitch, const uint srcPitch,
219  const uint dstW, const uint dstH,
220  const uint srcW, const uint srcH,
221  const Graphics::PixelFormat &fmt,
222  const byte flip = 0);
223 
224 bool rotoscaleBlit(byte *dst, const byte *src,
225  const uint dstPitch, const uint srcPitch,
226  const uint dstW, const uint dstH,
227  const uint srcW, const uint srcH,
228  const Graphics::PixelFormat &fmt,
229  const TransformStruct &transform,
230  const Common::Point &newHotspot);
231 
232 bool rotoscaleBlitBilinear(byte *dst, const byte *src,
233  const uint dstPitch, const uint srcPitch,
234  const uint dstW, const uint dstH,
235  const uint srcW, const uint srcH,
236  const Graphics::PixelFormat &fmt,
237  const TransformStruct &transform,
238  const Common::Point &newHotspot);
239 
240 bool applyColorKey(byte *dst, const byte *src,
241  const uint dstPitch, const uint srcPitch,
242  const uint w, const uint h,
243  const Graphics::PixelFormat &format, const bool overwriteAlpha,
244  const uint8 rKey, const uint8 gKey, const uint8 bKey,
245  const uint8 rNew, const uint8 gNew, const uint8 bNew);
246 
247 bool setAlpha(byte *dst, const byte *src,
248  const uint dstPitch, const uint srcPitch,
249  const uint w, const uint h,
250  const Graphics::PixelFormat &format,
251  const bool skipTransparent, const uint8 alpha);
252 
253 // This is a class so that we can declare certain things as private
254 class BlendBlit {
255 private:
256  struct Args {
257  bool rgbmod, alphamod;
258  int xp, yp;
259  int inStep, inoStep;
260  const byte *ino;
261  byte *outo;
262 
263  int scaleX, scaleY, scaleXoff, scaleYoff;
264  uint dstPitch;
265  uint width, height;
266  uint32 color;
267  int flipping;
268 
269  Args(byte *dst, const byte *src,
270  const uint dstPitch, const uint srcPitch,
271  const int posX, const int posY,
272  const uint width, const uint height,
273  const int scaleX, const int scaleY,
274  const int scaleXsrcOff, const int scaleYsrcOff,
275  const uint32 colorMod, const uint flipping);
276  };
277 
278 #ifdef SCUMMVM_NEON
279  static void blitNEON(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
280 #endif
281 #ifdef SCUMMVM_SSE2
282  static void blitSSE2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
283 #endif
284 #ifdef SCUMMVM_AVX2
285  static void blitAVX2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
286 #endif
287  static void blitGeneric(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
288  template<class T>
289  static void blitT(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
290 #undef LOGIC_FUNCS_EXT
291 
292  typedef void(*BlitFunc)(Args &, const TSpriteBlendMode &, const AlphaType &);
293  static BlitFunc blitFunc;
294  friend class ::BlendBlitUnfilteredTestSuite;
295  friend class BlendBlitImpl_Default;
296  friend class BlendBlitImpl_NEON;
297  friend class BlendBlitImpl_SSE2;
298  friend class BlendBlitImpl_AVX2;
299 
300 public:
301  static const int SCALE_THRESHOLD = 0x100;
302  static const int kBModShift = 8;
303  static const int kGModShift = 16;
304  static const int kRModShift = 24;
305  static const int kAModShift = 0;
306 
307  static const uint32 kBModMask = 0x0000ff00;
308  static const uint32 kGModMask = 0x00ff0000;
309  static const uint32 kRModMask = 0xff000000;
310  static const uint32 kAModMask = 0x000000ff;
311  static const uint32 kRGBModMask = (kRModMask | kGModMask | kBModMask);
312 
313 #ifdef SCUMM_LITTLE_ENDIAN
314  static const int kAIndex = 0;
315  static const int kBIndex = 1;
316  static const int kGIndex = 2;
317  static const int kRIndex = 3;
318 #else
319  static const int kAIndex = 3;
320  static const int kBIndex = 2;
321  static const int kGIndex = 1;
322  static const int kRIndex = 0;
323 #endif
324 
325  static inline int getScaleFactor(int srcSize, int dstSize) {
326  return SCALE_THRESHOLD * srcSize / dstSize;
327  }
328 
338  return PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
339  }
340 
363  static void blit(byte *dst, const byte *src,
364  const uint dstPitch, const uint srcPitch,
365  const int posX, const int posY,
366  const uint width, const uint height,
367  const int scaleX, const int scaleY,
368  const int scaleXsrcOff, const int scaleYsrcOff,
369  const uint32 colorMod, const uint flipping,
370  const TSpriteBlendMode blendMode,
371  const AlphaType alphaType);
372 
373 }; // End of class BlendBlit
374 
376 } // End of namespace Graphics
377 
378 #endif // GRAPHICS_BLIT_H
static PixelFormat getSupportedPixelFormat()
Definition: blit.h:337
Definition: pixelformat.h:138
Definition: display_client.h:58
bool crossBlit(byte *dst, const byte *src, const uint dstPitch, const uint srcPitch, const uint w, const uint h, const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt)
bool crossKeyBlit(byte *dst, const byte *src, const uint dstPitch, const uint srcPitch, const uint w, const uint h, const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key)
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: rect.h:45
void copyBlit(byte *dst, const byte *src, const uint dstPitch, const uint srcPitch, const uint w, const uint h, const uint bytesPerPixel)
Definition: blit.h:254
bool crossMaskBlit(byte *dst, const byte *src, const byte *mask, const uint dstPitch, const uint srcPitch, const uint maskPitch, const uint w, const uint h, const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt)
bool keyBlit(byte *dst, const byte *src, const uint dstPitch, const uint srcPitch, const uint w, const uint h, const uint bytesPerPixel, const uint32 key)
bool maskBlit(byte *dst, const byte *src, const byte *mask, const uint dstPitch, const uint srcPitch, const uint maskPitch, const uint w, const uint h, const uint bytesPerPixel)
uint32 RGBToColor(uint8 r, uint8 g, uint8 b) const
Definition: pixelformat.h:207