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 
69 void copyBlit(byte *dst, const byte *src,
70  const uint dstPitch, const uint srcPitch,
71  const uint w, const uint h,
72  const uint bytesPerPixel);
73 
86 bool keyBlit(byte *dst, const byte *src,
87  const uint dstPitch, const uint srcPitch,
88  const uint w, const uint h,
89  const uint bytesPerPixel, const uint32 key);
90 
108 bool maskBlit(byte *dst, const byte *src, const byte *mask,
109  const uint dstPitch, const uint srcPitch, const uint maskPitch,
110  const uint w, const uint h,
111  const uint bytesPerPixel);
112 
134 bool crossBlit(byte *dst, const byte *src,
135  const uint dstPitch, const uint srcPitch,
136  const uint w, const uint h,
137  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
138 
161 bool crossKeyBlit(byte *dst, const byte *src,
162  const uint dstPitch, const uint srcPitch,
163  const uint w, const uint h,
164  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt, const uint32 key);
165 
193 bool crossMaskBlit(byte *dst, const byte *src, const byte *mask,
194  const uint dstPitch, const uint srcPitch, const uint maskPitch,
195  const uint w, const uint h,
196  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt);
197 
198 bool crossBlitMap(byte *dst, const byte *src,
199  const uint dstPitch, const uint srcPitch,
200  const uint w, const uint h,
201  const uint bytesPerPixel, const uint32 *map);
202 
203 bool crossKeyBlitMap(byte *dst, const byte *src,
204  const uint dstPitch, const uint srcPitch,
205  const uint w, const uint h,
206  const uint bytesPerPixel, const uint32 *map, const uint32 key);
207 
208 bool crossMaskBlitMap(byte *dst, const byte *src, const byte *mask,
209  const uint dstPitch, const uint srcPitch, const uint maskPitch,
210  const uint w, const uint h,
211  const uint bytesPerPixel, const uint32 *map);
212 
213 typedef void (*FastBlitFunc)(byte *, const byte *, const uint, const uint, const uint, const uint);
214 
215 #ifdef SCUMMVM_NEON
216 // Fast blit functions for ARM NEON
217 void fastBlitNEON_XRGB1555_RGB565(byte *, const byte *, const uint, const uint, const uint, const uint);
218 #endif
219 
239 FastBlitFunc getFastBlitFunc(const PixelFormat &dstFmt, const PixelFormat &srcFmt);
240 
241 bool scaleBlit(byte *dst, const byte *src,
242  const uint dstPitch, const uint srcPitch,
243  const uint dstW, const uint dstH,
244  const uint srcW, const uint srcH,
245  const Graphics::PixelFormat &fmt,
246  const byte flip = 0);
247 
248 bool scaleBlitBilinear(byte *dst, const byte *src,
249  const uint dstPitch, const uint srcPitch,
250  const uint dstW, const uint dstH,
251  const uint srcW, const uint srcH,
252  const Graphics::PixelFormat &fmt,
253  const byte flip = 0);
254 
255 bool rotoscaleBlit(byte *dst, const byte *src,
256  const uint dstPitch, const uint srcPitch,
257  const uint dstW, const uint dstH,
258  const uint srcW, const uint srcH,
259  const Graphics::PixelFormat &fmt,
260  const TransformStruct &transform,
261  const Common::Point &newHotspot);
262 
263 bool rotoscaleBlitBilinear(byte *dst, const byte *src,
264  const uint dstPitch, const uint srcPitch,
265  const uint dstW, const uint dstH,
266  const uint srcW, const uint srcH,
267  const Graphics::PixelFormat &fmt,
268  const TransformStruct &transform,
269  const Common::Point &newHotspot);
270 
271 bool applyColorKey(byte *dst, const byte *src,
272  const uint dstPitch, const uint srcPitch,
273  const uint w, const uint h,
274  const Graphics::PixelFormat &format, const bool overwriteAlpha,
275  const uint8 rKey, const uint8 gKey, const uint8 bKey,
276  const uint8 rNew, const uint8 gNew, const uint8 bNew);
277 
278 bool setAlpha(byte *dst, const byte *src,
279  const uint dstPitch, const uint srcPitch,
280  const uint w, const uint h,
281  const Graphics::PixelFormat &format,
282  const bool skipTransparent, const uint8 alpha);
283 
284 // This is a class so that we can declare certain things as private
285 class BlendBlit {
286 private:
287  struct Args {
288  bool rgbmod, alphamod;
289  int xp, yp;
290  int inStep, inoStep;
291  const byte *ino;
292  byte *outo;
293 
294  int scaleX, scaleY, scaleXoff, scaleYoff;
295  uint dstPitch;
296  uint width, height;
297  uint32 color;
298  int flipping;
299 
300  Args(byte *dst, const byte *src,
301  const uint dstPitch, const uint srcPitch,
302  const int posX, const int posY,
303  const uint width, const uint height,
304  const int scaleX, const int scaleY,
305  const int scaleXsrcOff, const int scaleYsrcOff,
306  const uint32 colorMod, const uint flipping);
307  };
308 
309 #ifdef SCUMMVM_NEON
310  static void blitNEON(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
311 #endif
312 #ifdef SCUMMVM_SSE2
313  static void blitSSE2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
314 #endif
315 #ifdef SCUMMVM_AVX2
316  static void blitAVX2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
317 #endif
318  static void blitGeneric(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
319  template<class T>
320  static void blitT(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
321 
322  typedef void(*BlitFunc)(Args &, const TSpriteBlendMode &, const AlphaType &);
323  static BlitFunc blitFunc;
324 
325  static void fillGeneric(Args &args, const TSpriteBlendMode &blendMode);
326  template<class T>
327  static void fillT(Args &args, const TSpriteBlendMode &blendMode);
328 
329  typedef void(*FillFunc)(Args &, const TSpriteBlendMode &);
330  static FillFunc fillFunc;
331 
332  friend class ::BlendBlitUnfilteredTestSuite;
333  friend class BlendBlitImpl_Default;
334  friend class BlendBlitImpl_NEON;
335  friend class BlendBlitImpl_SSE2;
336  friend class BlendBlitImpl_AVX2;
337 
338 public:
339  static const int SCALE_THRESHOLD = 0x100;
340  static const int kBModShift = 8;
341  static const int kGModShift = 16;
342  static const int kRModShift = 24;
343  static const int kAModShift = 0;
344 
345  static const uint32 kBModMask = 0x0000ff00;
346  static const uint32 kGModMask = 0x00ff0000;
347  static const uint32 kRModMask = 0xff000000;
348  static const uint32 kAModMask = 0x000000ff;
349  static const uint32 kRGBModMask = (kRModMask | kGModMask | kBModMask);
350 
351 #ifdef SCUMM_LITTLE_ENDIAN
352  static const int kAIndex = 0;
353  static const int kBIndex = 1;
354  static const int kGIndex = 2;
355  static const int kRIndex = 3;
356 #else
357  static const int kAIndex = 3;
358  static const int kBIndex = 2;
359  static const int kGIndex = 1;
360  static const int kRIndex = 0;
361 #endif
362 
363  static inline int getScaleFactor(int srcSize, int dstSize) {
364  return SCALE_THRESHOLD * srcSize / dstSize;
365  }
366 
376  return PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
377  }
378 
401  static void blit(byte *dst, const byte *src,
402  const uint dstPitch, const uint srcPitch,
403  const int posX, const int posY,
404  const uint width, const uint height,
405  const int scaleX, const int scaleY,
406  const int scaleXsrcOff, const int scaleYsrcOff,
407  const uint32 colorMod, const uint flipping,
408  const TSpriteBlendMode blendMode,
409  const AlphaType alphaType);
410 
421  static void fill(byte *dst, const uint dstPitch,
422  const uint width, const uint height,
423  const uint32 colorMod,
424  const TSpriteBlendMode blendMode);
425 
426 }; // End of class BlendBlit
427 
429 } // End of namespace Graphics
430 
431 #endif // GRAPHICS_BLIT_H
static PixelFormat getSupportedPixelFormat()
Definition: blit.h:375
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:144
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:285
signed char * fill(signed char *first, signed char *last, Value val)
Definition: algorithm.h:168
FastBlitFunc getFastBlitFunc(const PixelFormat &dstFmt, const PixelFormat &srcFmt)
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:261