ScummVM API documentation
managed_surface.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_MANAGED_SURFACE_H
23 #define GRAPHICS_MANAGED_SURFACE_H
24 
25 #include "graphics/pixelformat.h"
26 #include "graphics/surface.h"
27 #include "graphics/transform_struct.h"
28 #include "common/types.h"
29 #include "graphics/blit.h"
30 
31 #define MS_RGB(R,G,B) (uint32)(((R) << 24) | ((G) << 16) | ((B) << 8) | 0xff)
32 #define MS_ARGB(A,R,G,B) (uint32)(((R) << 24) | ((G) << 16) | ((B) << 8) | (A))
33 
34 namespace Graphics {
35 
36 class Palette;
37 
52 private:
56  Surface _innerSurface;
57 
62  DisposeAfterUse::Flag _disposeAfterUse;
63 
68  ManagedSurface *_owner;
69 
74  Common::Point _offsetFromOwner;
75 
80  uint _transparentColor;
81  bool _transparentColorSet;
82 
86  Palette *_palette;
87 protected:
91  void simpleBlitFromInner(const Surface &src, const Common::Rect &srcRect,
92  const Common::Point &destPos, const Palette *srcPalette,
93  bool transparentColorSet, uint transparentColor);
94 
98  void blitFromInner(const Surface &src, const Common::Rect &srcRect,
99  const Common::Rect &destRect, const Palette *srcPalette);
100 
104  void transBlitFromInner(const Surface &src, const Common::Rect &srcRect,
105  const Common::Rect &destRect, uint32 transColor, bool flipped, uint32 overrideColor,
106  uint32 srcAlpha, const Palette *srcPalette, const Palette *dstPalette,
107  const Surface *mask, bool maskOnly);
108 public:
112  bool clip(Common::Rect& srcBounds, Common::Rect& destBounds) const {
113  return _innerSurface.clip(srcBounds, destBounds);
114  }
115 
116 public:
117  int16 &w;
118  int16 &h;
119  int32 &pitch;
121 public:
125  ManagedSurface();
126 
134  WARN_DEPRECATED("Use copyFrom(), a move constructor or supply bounds")
135  ManagedSurface(const ManagedSurface &surf);
136 
141 
145  ManagedSurface(int width, int height);
146 
150  ManagedSurface(int width, int height, const Graphics::PixelFormat &pixelFormat);
151 
155  ManagedSurface(ManagedSurface &surf, const Common::Rect &bounds);
156 
163  WARN_DEPRECATED("Use copyFrom() instead")
165 
169  WARN_DEPRECATED("Use copyFrom() instead")
170  ManagedSurface(const Surface *surf);
171 
175  virtual ~ManagedSurface();
176 
184  operator const Surface &() const { return _innerSurface; }
185 
193  const Surface &rawSurface() const { return _innerSurface; }
194  Surface *surfacePtr() { return &_innerSurface; }
195 
201  WARN_DEPRECATED("Use copyFrom() or a move constructor instead")
203 
208 
212  bool empty() const { return w == 0 || h == 0 || _innerSurface.getPixels() == nullptr; }
213 
217  DisposeAfterUse::Flag disposeAfterUse() const { return _disposeAfterUse; }
218 
227  inline uint32 getPixel(int x, int y) const {
228  return _innerSurface.getPixel(x, y);
229  }
230 
238  inline void setPixel(int x, int y, uint32 pixel) {
239  return _innerSurface.setPixel(x, y, pixel);
240  }
241 
250  inline const void *getBasePtr(int x, int y) const {
251  return _innerSurface.getBasePtr(x, y);
252  }
253 
262  inline void *getBasePtr(int x, int y) {
263  return _innerSurface.getBasePtr(x, y);
264  }
265 
269  inline void *getPixels() { return _innerSurface.getPixels(); }
271  inline const void *getPixels() const { return _innerSurface.getPixels(); }
272 
276  virtual void setPixels(void *newPixels);
277 
281  virtual void create(int16 width, int16 height);
282 
286  virtual void create(int16 width, int16 height, const PixelFormat &pixelFormat);
287 
297  virtual void create(ManagedSurface &surf, const Common::Rect &bounds);
298 
304  virtual void free();
305 
309  virtual void clearDirtyRects() {}
310 
315  virtual void addDirtyRect(const Common::Rect &r);
316 
321  const Common::Point getOffsetFromOwner() const { return _offsetFromOwner; }
322 
326  const Common::Rect getBounds() const {
327  return Common::Rect(0, 0, this->w, this->h);
328  }
329 
333  void simpleBlitFrom(const Surface &src, const Palette *srcPalette = nullptr);
334 
338  void simpleBlitFrom(const Surface &src, const Common::Point &destPos, const Palette *srcPalette = nullptr);
339 
343  void simpleBlitFrom(const Surface &src, const Common::Rect &srcRect,
344  const Common::Point &destPos, const Palette *srcPalette = nullptr);
345 
349  void simpleBlitFrom(const ManagedSurface &src);
350 
354  void simpleBlitFrom(const ManagedSurface &src, const Common::Point &destPos);
355 
359  void simpleBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
360  const Common::Point &destPos);
361 
365  void blitFrom(const Surface &src, const Palette *srcPalette = nullptr);
366 
370  void blitFrom(const Surface &src, const Common::Point &destPos, const Palette *srcPalette = nullptr);
371 
375  void blitFrom(const Surface &src, const Common::Rect &srcRect,
376  const Common::Point &destPos, const Palette *srcPalette = nullptr);
377 
381  void blitFrom(const Surface &src, const Common::Rect &srcRect,
382  const Common::Rect &destRect, const Palette *srcPalette = nullptr);
383 
387  void blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
388  const Common::Rect &destRect);
389 
393  void blitFrom(const ManagedSurface &src);
394 
398  void blitFrom(const ManagedSurface &src, const Common::Point &destPos);
399 
403  void blitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
404  const Common::Point &destPos);
405 
417  void transBlitFrom(const Surface &src, uint32 transColor = 0, bool flipped = false,
418  uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);
419 
432  void transBlitFrom(const Surface &src, const Common::Point &destPos,
433  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);
434 
443  void transBlitFrom(const Surface &src, const Common::Point &destPos,
444  const ManagedSurface &mask, const Palette *srcPalette = nullptr);
445 
454  void transBlitFrom(const Surface &src, const Common::Point &destPos,
455  const Surface &mask, const Palette *srcPalette = nullptr);
456 
470  void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Point &destPos,
471  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff, const Palette *srcPalette = nullptr);
472 
482  void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect, const Palette *srcPalette);
483 
500  void transBlitFrom(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
501  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff,
502  const Surface *mask = nullptr, bool maskOnly = false, const Palette *srcPalette = nullptr);
503 
514  void transBlitFrom(const ManagedSurface &src, uint32 transColor = 0, bool flipped = false,
515  uint32 overrideColor = 0, uint32 srcAlpha = 0xff);
516 
528  void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
529  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff);
530 
538  void transBlitFrom(const ManagedSurface &src, const Common::Point &destPos,
539  const ManagedSurface &mask);
540 
553  void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos,
554  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff);
555 
571  void transBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Rect &destRect,
572  uint32 transColor = 0, bool flipped = false, uint32 overrideColor = 0, uint32 srcAlpha = 0xff,
573  const Surface *mask = nullptr, bool maskOnly = false);
574 
578  void rawBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect,
579  const Common::Point &destPos) {
580  blitFromInner(src._innerSurface, srcRect, Common::Rect(destPos.x, destPos.y, destPos.x + srcRect.width(),
581  destPos.y + srcRect.height()), src._palette);
582  }
583 
589  static inline bool isBlendBlitPixelFormatSupported(const PixelFormat &src, const PixelFormat &dst) {
591  }
592 
608  const int posX = 0, const int posY = 0,
609  const int flipping = FLIP_NONE,
610  const Common::Rect *srcRect = nullptr,
611  const uint colorMod = MS_ARGB(255, 255, 255, 255),
612  const int width = -1, const int height = -1,
613  const TSpriteBlendMode blend = BLEND_NORMAL,
614  const AlphaType alphaType = ALPHA_FULL);
616  const int posX = 0, const int posY = 0,
617  const int flipping = FLIP_NONE,
618  const Common::Rect *srcRect = nullptr,
619  const uint colorMod = MS_ARGB(255, 255, 255, 255),
620  const int width = -1, const int height = -1,
621  const TSpriteBlendMode blend = BLEND_NORMAL,
622  const AlphaType alphaType = ALPHA_FULL);
623 
627  void clear(uint32 color = 0);
628 
632  void markAllDirty();
633 
639  void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height) {
640  _innerSurface.copyRectToSurface(buffer, srcPitch, destX, destY, width, height);
641  addDirtyRect(Common::Rect(destX, destY, destX + width, destY + height));
642  }
643 
649  void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect) {
650  _innerSurface.copyRectToSurface(srcSurface, destX, destY, subRect);
651  addDirtyRect(Common::Rect(destX, destY, destX + subRect.width(), destY + subRect.height()));
652  }
653 
659  void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key) {
660  _innerSurface.copyRectToSurfaceWithKey(buffer, srcPitch, destX, destY, width, height, key);
661  addDirtyRect(Common::Rect(destX, destY, destX + width, destY + height));
662  }
663 
669  void copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key) {
670  _innerSurface.copyRectToSurfaceWithKey(srcSurface, destX, destY, subRect, key);
671  addDirtyRect(Common::Rect(destX, destY, destX + subRect.width(), destY + subRect.height()));
672  }
673 
678  void copyFrom(const ManagedSurface &surf);
679 
684  void copyFrom(const Surface &surf);
685 
691  void convertFrom(const ManagedSurface &surf, const PixelFormat &fmt);
692 
698  void convertFrom(const Surface &surf, const PixelFormat &fmt);
699 
707  ManagedSurface *scale(int16 newWidth, int16 newHeight, bool filtering = false) const;
708 
717  ManagedSurface *rotoscale(const TransformStruct &transform, bool filtering = false) const;
718 
722  void drawLine(int x0, int y0, int x1, int y1, uint32 color) {
723  _innerSurface.drawLine(x0, y0, x1, y1, color);
724  addDirtyRect(Common::Rect(MIN(x0, x1), MIN(y0, y1), MAX(x0, x1 + 1), MAX(y0, y1 + 1)));
725  }
726 
730  void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color) {
731  _innerSurface.drawThickLine(x0, y0, x1, y1, penX, penY, color);
732  addDirtyRect(Common::Rect(MIN(x0, x1 + penX), MIN(y0, y1 + penY), MAX(x0, x1 + penX), MAX(y0, y1 + penY)));
733  }
734 
738  void hLine(int x, int y, int x2, uint32 color) {
739  _innerSurface.hLine(x, y, x2, color);
740  addDirtyRect(Common::Rect(x, y, x2 + 1, y + 1));
741  }
742 
746  void vLine(int x, int y, int y2, uint32 color) {
747  _innerSurface.vLine(x, y, y2, color);
748  addDirtyRect(Common::Rect(x, y, x + 1, y2 + 1));
749  }
750 
754  void fillRect(Common::Rect r, uint32 color) {
755  _innerSurface.fillRect(r, color);
756  addDirtyRect(r);
757  }
758 
762  void frameRect(const Common::Rect &r, uint32 color) {
763  _innerSurface.frameRect(r, color);
764  addDirtyRect(r);
765  }
766 
770  AlphaType detectAlpha() const {
771  return _innerSurface.detectAlpha();
772  }
773 
779  addDirtyRect(area);
780  return _innerSurface.getSubArea(area);
781  }
782 
792  void convertToInPlace(const PixelFormat &dstFormat) {
793  _innerSurface.convertToInPlace(dstFormat);
794  }
795 
807  void convertToInPlace(const PixelFormat &dstFormat, const byte *palette, uint16 paletteCount) {
808  _innerSurface.convertToInPlace(dstFormat, palette, paletteCount);
809  }
810 
814  uint getTransparentColor() const { return _transparentColor; }
815 
819  void setTransparentColor(uint32 color) {
820  _transparentColor = color;
821  _transparentColorSet = true;
822  }
823 
828  _transparentColorSet = false;
829  }
830 
834  bool hasTransparentColor() const {
835  return _transparentColorSet;
836  }
837 
841  void clearPalette();
842 
846  bool hasPalette() const;
847 
851  void grabPalette(byte *colors, uint start, uint num) const;
852 
856  void setPalette(const byte *colors, uint start, uint num);
857 };
859 } // End of namespace Graphics
860 
861 #endif
void clear(uint32 color=0)
Definition: managed_surface.h:51
void convertFrom(const ManagedSurface &surf, const PixelFormat &fmt)
void convertToInPlace(const PixelFormat &dstFormat)
Definition: managed_surface.h:792
const Common::Rect getBounds() const
Definition: managed_surface.h:326
static PixelFormat getSupportedPixelFormat()
Definition: blit.h:337
int16 & w
Definition: managed_surface.h:117
uint getTransparentColor() const
Definition: managed_surface.h:814
Definition: surface.h:67
Common::Rect blendBlitTo(ManagedSurface &target, const int posX=0, const int posY=0, const int flipping=FLIP_NONE, const Common::Rect *srcRect=nullptr, const uint colorMod=(uint32)(((255)<< 24)|((255)<< 16)|((255)<< 8)|(255)), const int width=-1, const int height=-1, const TSpriteBlendMode blend=BLEND_NORMAL, const AlphaType alphaType=ALPHA_FULL)
Renders this surface onto target.
virtual void addDirtyRect(const Common::Rect &r)
bool clip(Common::Rect &srcBounds, Common::Rect &destBounds) const
Definition: managed_surface.h:112
Surface getSubArea(const Common::Rect &area)
void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key)
Definition: managed_surface.h:659
virtual void create(int16 width, int16 height)
void rawBlitFrom(const ManagedSurface &src, const Common::Rect &srcRect, const Common::Point &destPos)
Definition: managed_surface.h:578
void simpleBlitFrom(const Surface &src, const Palette *srcPalette=nullptr)
Definition: types.h:27
Definition: pixelformat.h:138
void convertToInPlace(const PixelFormat &dstFormat)
Definition: surface.h:359
Surface getSubArea(const Common::Rect &area)
Definition: managed_surface.h:778
static bool isBlendBlitPixelFormatSupported(const PixelFormat &src, const PixelFormat &dst)
Definition: managed_surface.h:589
virtual void clearDirtyRects()
Definition: managed_surface.h:309
int32 & pitch
Definition: managed_surface.h:119
void * getBasePtr(int x, int y)
Definition: managed_surface.h:262
DisposeAfterUse::Flag disposeAfterUse() const
Definition: managed_surface.h:217
void setTransparentColor(uint32 color)
Definition: managed_surface.h:819
void clearTransparentColor()
Definition: managed_surface.h:827
const void * getBasePtr(int x, int y) const
Definition: managed_surface.h:250
void transBlitFromInner(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect, uint32 transColor, bool flipped, uint32 overrideColor, uint32 srcAlpha, const Palette *srcPalette, const Palette *dstPalette, const Surface *mask, bool maskOnly)
AlphaType detectAlpha() const
Definition: managed_surface.h:770
void drawLine(int x0, int y0, int x1, int y1, uint32 color)
Definition: managed_surface.h:722
Definition: rect.h:144
void copyRectToSurfaceWithKey(const void *buffer, int srcPitch, int destX, int destY, int width, int height, uint32 key)
void transBlitFrom(const Surface &src, uint32 transColor=0, bool flipped=false, uint32 overrideColor=0, uint32 srcAlpha=0xff, const Palette *srcPalette=nullptr)
bool empty() const
Definition: managed_surface.h:212
void vLine(int x, int y, int y2, uint32 color)
Definition: managed_surface.h:746
void copyFrom(const ManagedSurface &surf)
void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color)
Definition: managed_surface.h:730
bool hasTransparentColor() const
Definition: managed_surface.h:834
bool clip(Common::Rect &srcBounds, Common::Rect &destBounds) const
void blitFrom(const Surface &src, const Palette *srcPalette=nullptr)
int16 & h
Definition: managed_surface.h:118
const void * getBasePtr(int x, int y) const
Definition: surface.h:138
int16 width() const
Definition: rect.h:191
void hLine(int x, int y, int x2, uint32 color)
void copyRectToSurface(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect)
Definition: managed_surface.h:649
void * getPixels()
Definition: managed_surface.h:269
Definition: algorithm.h:29
void drawThickLine(int x0, int y0, int x1, int y1, int penX, int penY, uint32 color)
Definition: formatinfo.h:28
Definition: rect.h:45
const Surface & rawSurface() const
Definition: managed_surface.h:193
ManagedSurface * scale(int16 newWidth, int16 newHeight, bool filtering=false) const
void drawLine(int x0, int y0, int x1, int y1, uint32 color)
void frameRect(const Common::Rect &r, uint32 color)
ManagedSurface * rotoscale(const TransformStruct &transform, bool filtering=false) const
Rotoscale function; this returns a transformed version of this surface after rotation and scaling...
const Common::Point getOffsetFromOwner() const
Definition: managed_surface.h:321
void setPixel(int x, int y, int pixel)
Definition: surface.h:183
AlphaType detectAlpha() const
int16 x
Definition: rect.h:46
void fillRect(Common::Rect r, uint32 color)
Definition: managed_surface.h:754
void frameRect(const Common::Rect &r, uint32 color)
Definition: managed_surface.h:762
int16 y
Definition: rect.h:47
void blitFromInner(const Surface &src, const Common::Rect &srcRect, const Common::Rect &destRect, const Palette *srcPalette)
T MIN(T a, T b)
Definition: util.h:59
void grabPalette(byte *colors, uint start, uint num) const
void simpleBlitFromInner(const Surface &src, const Common::Rect &srcRect, const Common::Point &destPos, const Palette *srcPalette, bool transparentColorSet, uint transparentColor)
ManagedSurface & operator=(const ManagedSurface &surf)
PixelFormat & format
Definition: managed_surface.h:120
T MAX(T a, T b)
Definition: util.h:62
void vLine(int x, int y, int y2, uint32 color)
Definition: transform_struct.h:75
void hLine(int x, int y, int x2, uint32 color)
Definition: managed_surface.h:738
uint32 getPixel(int x, int y) const
Definition: managed_surface.h:227
Simple class for handling a palette data.
Definition: palette.h:45
void copyRectToSurfaceWithKey(const Graphics::Surface &srcSurface, int destX, int destY, const Common::Rect subRect, uint32 key)
Definition: managed_surface.h:669
void fillRect(Common::Rect r, uint32 color)
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height)
void setPalette(const byte *colors, uint start, uint num)
const void * getPixels() const
Definition: managed_surface.h:271
uint32 getPixel(int x, int y) const
Definition: surface.h:162
void setPixel(int x, int y, uint32 pixel)
Definition: managed_surface.h:238
void convertToInPlace(const PixelFormat &dstFormat, const byte *palette, uint16 paletteCount)
Definition: managed_surface.h:807
virtual void setPixels(void *newPixels)
const void * getPixels() const
Definition: surface.h:108
int16 height() const
Definition: rect.h:192
void copyRectToSurface(const void *buffer, int srcPitch, int destX, int destY, int width, int height)
Definition: managed_surface.h:639
Definition: atari-screen.h:44