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 bool alphaBlit(byte *dst, const byte *src,
214  const uint dstPitch, const uint srcPitch,
215  const uint w, const uint h,
216  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt,
217  const byte flip, const byte aMod);
218 
219 bool alphaKeyBlit(byte *dst, const byte *src,
220  const uint dstPitch, const uint srcPitch,
221  const uint w, const uint h,
222  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt,
223  const uint32 key, const byte flip, const byte aMod);
224 
225 bool alphaMaskBlit(byte *dst, const byte *src, const byte *mask,
226  const uint dstPitch, const uint srcPitch, const uint maskPitch,
227  const uint w, const uint h,
228  const Graphics::PixelFormat &dstFmt, const Graphics::PixelFormat &srcFmt,
229  const byte flip, const byte aMod);
230 
231 bool alphaBlitMap(byte *dst, const byte *src,
232  const uint dstPitch, const uint srcPitch,
233  const uint w, const uint h,
234  const Graphics::PixelFormat &dstFmt, const uint32 *map,
235  const byte flip, const byte aMod);
236 
237 bool alphaKeyBlitMap(byte *dst, const byte *src,
238  const uint dstPitch, const uint srcPitch,
239  const uint w, const uint h,
240  const Graphics::PixelFormat &dstFmt, const uint32 *map,
241  const uint32 key, const byte flip, const byte aMod);
242 
243 bool alphaMaskBlitMap(byte *dst, const byte *src, const byte *mask,
244  const uint dstPitch, const uint srcPitch, const uint maskPitch,
245  const uint w, const uint h,
246  const Graphics::PixelFormat &dstFmt, const uint32 *map,
247  const byte flip, const byte aMod);
248 
249 typedef void (*FastBlitFunc)(byte *, const byte *, const uint, const uint, const uint, const uint);
250 
251 #ifdef SCUMMVM_NEON
252 // Fast blit functions for ARM NEON
253 void fastBlitNEON_XRGB1555_RGB565(byte *, const byte *, const uint, const uint, const uint, const uint);
254 #endif
255 
275 FastBlitFunc getFastBlitFunc(const PixelFormat &dstFmt, const PixelFormat &srcFmt);
276 
277 bool scaleBlit(byte *dst, const byte *src,
278  const uint dstPitch, const uint srcPitch,
279  const uint dstW, const uint dstH,
280  const uint srcW, const uint srcH,
281  const Graphics::PixelFormat &fmt,
282  const byte flip = 0);
283 
284 bool scaleBlitBilinear(byte *dst, const byte *src,
285  const uint dstPitch, const uint srcPitch,
286  const uint dstW, const uint dstH,
287  const uint srcW, const uint srcH,
288  const Graphics::PixelFormat &fmt,
289  const byte flip = 0);
290 
291 bool rotoscaleBlit(byte *dst, const byte *src,
292  const uint dstPitch, const uint srcPitch,
293  const uint dstW, const uint dstH,
294  const uint srcW, const uint srcH,
295  const Graphics::PixelFormat &fmt,
296  const TransformStruct &transform,
297  const Common::Point &newHotspot);
298 
299 bool rotoscaleBlitBilinear(byte *dst, const byte *src,
300  const uint dstPitch, const uint srcPitch,
301  const uint dstW, const uint dstH,
302  const uint srcW, const uint srcH,
303  const Graphics::PixelFormat &fmt,
304  const TransformStruct &transform,
305  const Common::Point &newHotspot);
306 
307 bool applyColorKey(byte *dst, const byte *src,
308  const uint dstPitch, const uint srcPitch,
309  const uint w, const uint h,
310  const Graphics::PixelFormat &format, const bool overwriteAlpha,
311  const uint8 rKey, const uint8 gKey, const uint8 bKey,
312  const uint8 rNew, const uint8 gNew, const uint8 bNew);
313 
314 bool setAlpha(byte *dst, const byte *src,
315  const uint dstPitch, const uint srcPitch,
316  const uint w, const uint h,
317  const Graphics::PixelFormat &format,
318  const bool skipTransparent, const uint8 alpha);
319 
320 // This is a class so that we can declare certain things as private
321 class BlendBlit {
322 private:
323  struct Args {
324  bool rgbmod, alphamod;
325  int xp, yp;
326  int inStep, inoStep;
327  const byte *ino;
328  byte *outo;
329 
330  int scaleX, scaleY, scaleXoff, scaleYoff;
331  uint dstPitch;
332  uint width, height;
333  uint32 color;
334  int flipping;
335 
336  Args(byte *dst, const byte *src,
337  const uint dstPitch, const uint srcPitch,
338  const int posX, const int posY,
339  const uint width, const uint height,
340  const int scaleX, const int scaleY,
341  const int scaleXsrcOff, const int scaleYsrcOff,
342  const uint32 colorMod, const uint flipping);
343  };
344 
345 #ifdef SCUMMVM_NEON
346  static void blitNEON(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
347 #endif
348 #ifdef SCUMMVM_SSE2
349  static void blitSSE2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
350 #endif
351 #ifdef SCUMMVM_AVX2
352  static void blitAVX2(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
353 #endif
354  static void blitGeneric(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
355  template<class T>
356  static void blitT(Args &args, const TSpriteBlendMode &blendMode, const AlphaType &alphaType);
357 
358  typedef void(*BlitFunc)(Args &, const TSpriteBlendMode &, const AlphaType &);
359  static BlitFunc blitFunc;
360 
361  static void fillGeneric(Args &args, const TSpriteBlendMode &blendMode);
362  template<class T>
363  static void fillT(Args &args, const TSpriteBlendMode &blendMode);
364 
365  typedef void(*FillFunc)(Args &, const TSpriteBlendMode &);
366  static FillFunc fillFunc;
367 
368  friend class ::BlendBlitUnfilteredTestSuite;
369  friend class BlendBlitImpl_Default;
370  friend class BlendBlitImpl_NEON;
371  friend class BlendBlitImpl_SSE2;
372  friend class BlendBlitImpl_AVX2;
373 
374 public:
375  static const int SCALE_THRESHOLD = 0x100;
376  static const int kBModShift = 8;
377  static const int kGModShift = 16;
378  static const int kRModShift = 24;
379  static const int kAModShift = 0;
380 
381  static const uint32 kBModMask = 0x0000ff00;
382  static const uint32 kGModMask = 0x00ff0000;
383  static const uint32 kRModMask = 0xff000000;
384  static const uint32 kAModMask = 0x000000ff;
385  static const uint32 kRGBModMask = (kRModMask | kGModMask | kBModMask);
386 
387 #ifdef SCUMM_LITTLE_ENDIAN
388  static const int kAIndex = 0;
389  static const int kBIndex = 1;
390  static const int kGIndex = 2;
391  static const int kRIndex = 3;
392 #else
393  static const int kAIndex = 3;
394  static const int kBIndex = 2;
395  static const int kGIndex = 1;
396  static const int kRIndex = 0;
397 #endif
398 
399  static inline int getScaleFactor(int srcSize, int dstSize) {
400  return SCALE_THRESHOLD * srcSize / dstSize;
401  }
402 
412  return PixelFormat(4, 8, 8, 8, 8, 24, 16, 8, 0);
413  }
414 
437  static void blit(byte *dst, const byte *src,
438  const uint dstPitch, const uint srcPitch,
439  const int posX, const int posY,
440  const uint width, const uint height,
441  const int scaleX, const int scaleY,
442  const int scaleXsrcOff, const int scaleYsrcOff,
443  const uint32 colorMod, const uint flipping,
444  const TSpriteBlendMode blendMode,
445  const AlphaType alphaType);
446 
457  static void fill(byte *dst, const uint dstPitch,
458  const uint width, const uint height,
459  const uint32 colorMod,
460  const TSpriteBlendMode blendMode);
461 
462 }; // End of class BlendBlit
463 
465 } // End of namespace Graphics
466 
467 #endif // GRAPHICS_BLIT_H
static PixelFormat getSupportedPixelFormat()
Definition: blit.h:411
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:321
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