ManaPlus
Public Member Functions | Data Fields | Private Attributes
SubImage Class Reference

#include <subimage.h>

Inheritance diagram for SubImage:
Image Resource MemoryCounter

Public Member Functions

 SubImage (Image *const parent, SDL_Surface *const image, const int x, const int y, const int width, const int height)
 
 SubImage (Image *const parent, const GLuint image, const int x, const int y, const int width, const int height, const int texWidth, const int textHeight)
 
 ~SubImage ()
 
ImagegetSubImage (const int x, const int y, const int width, const int height)
 
ImageTypeT getType () const
 
int calcMemoryLocal () const
 
void decRef ()
 
- Public Member Functions inherited from Image
virtual ~Image ()
 
void unload ()
 
bool isLoaded () const
 
int getWidth () const A_INLINE
 
int getHeight () const A_INLINE
 
bool hasAlphaChannel () const
 
virtual void setAlpha (const float alpha)
 
ImageSDLgetScaledImage (const int width, const int height) const
 
uint8_t * SDLgetAlphaChannel () const
 
void SDLCleanCache ()
 
void SDLTerminateAlphaCache ()
 
int getTextureWidth () const
 
int getTextureHeight () const
 
GLuint getGLImage () const
 
bool isHasAlphaChannel () const
 
bool isAlphaVisible () const
 
void setAlphaVisible (const bool b)
 
bool isAlphaCalculated () const
 
void setAlphaCalculated (const bool b)
 
SDL_Surface * getSDLSurface ()
 
- Public Member Functions inherited from Resource
 Resource ()
 
virtual ~Resource ()
 
virtual void incRef ()
 
int calcMemoryLocal () const
 
std::string getCounterName () const
 
- Public Member Functions inherited from MemoryCounter
 MemoryCounter ()
 
virtual ~MemoryCounter ()
 
int calcMemory (const int level) const
 
virtual int calcMemoryChilds (const int level) const
 

Data Fields

SDL_Rect mInternalBounds
 
- Data Fields inherited from Image
GLuint mGLImage
 
int mTexWidth
 
int mTexHeight
 
SDL_Rect mBounds
 
float mAlpha
 
- Data Fields inherited from Resource
time_t mTimeStamp
 
std::string mIdPath
 
std::string mSource
 
unsigned int mRefCount
 
bool mProtected
 
bool mNotCount
 

Private Attributes

ImagemParent
 

Additional Inherited Members

- Protected Member Functions inherited from Image
 Image (SDL_Surface *const image, const bool hasAlphaChannel, uint8_t *const alphaChannel=0)
 
SDL_Surface * getByAlpha (const float alpha)
 
 Image (const GLuint glimage, const int width, const int height, const int texWidth, const int texHeight)
 
- Protected Attributes inherited from Image
SDL_Surface * mSDLSurface
 
uint8_t * mAlphaChannel
 
std::map< float, SDL_Surface * > mAlphaCache
 
bool mLoaded
 
bool mHasAlphaChannel
 
bool mUseAlphaCache
 
bool mIsAlphaVisible
 
bool mIsAlphaCalculated
 

Detailed Description

A clipped version of a larger image.

Definition at line 33 of file subimage.h.

Constructor & Destructor Documentation

◆ SubImage() [1/2]

SubImage::SubImage ( Image *const  parent,
SDL_Surface *const  image,
const int  x,
const int  y,
const int  width,
const int  height 
)

Constructor.

Definition at line 87 of file subimage.cpp.

References CAST_S16, CAST_U16, Image::hasAlphaChannel(), Resource::incRef(), Logger::log(), logger, Image::mAlphaChannel, Image::mBounds, Image::mHasAlphaChannel, Resource::mIdPath, mInternalBounds, Image::mIsAlphaVisible, mParent, Resource::mSource, Image::mUseAlphaCache, Image::SDLgetAlphaChannel(), and Image::SDLTerminateAlphaCache().

Referenced by calcMemoryLocal().

90  :
91  Image(image, false),
93  mParent(parent)
94 {
95  if (mParent != nullptr)
96  {
97  mParent->incRef();
102  mSource = parent->mIdPath;
103 #ifdef DEBUG_IMAGES
104  logger->log("set name2 %p, %s", static_cast<void*>(this),
105  mSource.c_str());
106 #endif // DEBUG_IMAGES
107 #ifdef DEBUG_BIND_TEXTURE
108  mIdPath = parent->mIdPath;
109 #endif // DEBUG_BIND_TEXTURE
110  }
111  else
112  {
113  mHasAlphaChannel = false;
114  mIsAlphaVisible = false;
115  mAlphaChannel = nullptr;
116  }
117 
118  // Set up the rectangle.
119  mBounds.x = CAST_S16(x);
120  mBounds.y = CAST_S16(y);
121  mBounds.w = CAST_U16(width);
122  mBounds.h = CAST_U16(height);
123  if (mParent != nullptr)
124  {
129  }
130  else
131  {
132  mInternalBounds.x = 0;
133  mInternalBounds.y = 0;
134  mInternalBounds.w = 1;
135  mInternalBounds.h = 1;
136  }
137  mUseAlphaCache = false;
138 }
std::string mSource
Definition: resource.h:84
bool hasAlphaChannel() const
Definition: image.cpp:263
void SDLTerminateAlphaCache()
Definition: image.cpp:500
SDL_Rect mInternalBounds
Definition: subimage.h:78
uint8_t * SDLgetAlphaChannel() const
Definition: image.h:163
Logger * logger
Definition: logger.cpp:95
#define CAST_U16
Definition: cast.h:28
Image * mParent
Definition: subimage.h:81
bool mIsAlphaVisible
Definition: image.h:243
uint8_t * mAlphaChannel
Definition: image.h:236
bool mUseAlphaCache
Definition: image.h:242
bool mHasAlphaChannel
Definition: image.h:241
Image(SDL_Surface *const image, const bool hasAlphaChannel, uint8_t *const alphaChannel=0)
Definition: image.cpp:125
virtual void incRef()
Definition: resource.cpp:37
SDL_Rect mBounds
Definition: image.h:210
#define CAST_S16
Definition: cast.h:27
void log(const char *const log_text,...)
Definition: logger.cpp:243
std::string mIdPath
Definition: resource.h:83

◆ SubImage() [2/2]

SubImage::SubImage ( Image *const  parent,
const GLuint  image,
const int  x,
const int  y,
const int  width,
const int  height,
const int  texWidth,
const int  textHeight 
)

Definition at line 141 of file subimage.cpp.

References CAST_S16, CAST_U16, Resource::incRef(), Logger::log(), logger, Image::mBounds, Image::mHasAlphaChannel, Resource::mIdPath, mInternalBounds, Image::mIsAlphaVisible, mParent, and Resource::mSource.

145  :
146  Image(image, width, height, texWidth, texHeight),
147  mInternalBounds(),
148  mParent(parent)
149 {
150  if (mParent != nullptr)
151  mParent->incRef();
152 
153  // Set up the rectangle.
154  mBounds.x = CAST_S16(x);
155  mBounds.y = CAST_S16(y);
156  mBounds.w = CAST_U16(width);
157  mBounds.h = CAST_U16(height);
158  if (mParent != nullptr)
159  {
164  mSource = parent->mIdPath;
165 #ifdef DEBUG_IMAGES
166  logger->log("set name2 %p, %s", static_cast<void*>(this),
167  mSource.c_str());
168 #endif // DEBUG_IMAGES
169 #ifdef DEBUG_BIND_TEXTURE
170  mIdPath = parent->mIdPath;
171 #endif // DEBUG_BIND_TEXTURE
172  }
173  else
174  {
175  mInternalBounds.x = 0;
176  mInternalBounds.y = 0;
177  mInternalBounds.w = 1;
178  mInternalBounds.h = 1;
179  }
181 }
std::string mSource
Definition: resource.h:84
SDL_Rect mInternalBounds
Definition: subimage.h:78
Logger * logger
Definition: logger.cpp:95
#define CAST_U16
Definition: cast.h:28
Image * mParent
Definition: subimage.h:81
bool mIsAlphaVisible
Definition: image.h:243
bool mHasAlphaChannel
Definition: image.h:241
Image(SDL_Surface *const image, const bool hasAlphaChannel, uint8_t *const alphaChannel=0)
Definition: image.cpp:125
virtual void incRef()
Definition: resource.cpp:37
SDL_Rect mBounds
Definition: image.h:210
#define CAST_S16
Definition: cast.h:27
void log(const char *const log_text,...)
Definition: logger.cpp:243
std::string mIdPath
Definition: resource.h:83

◆ ~SubImage()

SubImage::~SubImage ( )

Destructor.

Definition at line 184 of file subimage.cpp.

References Image::decRef(), Logger::log(), logger, Image::mAlphaChannel, Image::mGLImage, Resource::mIdPath, mParent, Image::mSDLSurface, and Resource::mSource.

185 {
186 #ifdef DEBUG_IMAGES
187  logger->log("delete subimage: %p", static_cast<void*>(this));
188  logger->log(" %s, %s", mIdPath.c_str(), mSource.c_str());
189 #endif // DEBUG_IMAGES
190  // Avoid destruction of the image
191  mSDLSurface = nullptr;
192  // Avoid possible destruction of its alpha channel
193  mAlphaChannel = nullptr;
194 #ifdef USE_SDL2
195  // Avoid destruction of texture
196  mTexture = nullptr;
197 #endif // USE_SDL2
198 #ifdef USE_OPENGL
199  mGLImage = 0;
200 #endif // USE_OPENGL
201  if (mParent != nullptr)
202  {
203 #ifdef DEBUG_IMAGES
204  logger->log("decref from subminage: %p, parent: %p",
205  static_cast<void*>(this), static_cast<void*>(mParent));
206 #endif // DEBUG_IMAGES
207 
208  mParent->decRef();
209  mParent = nullptr;
210  }
211 }
std::string mSource
Definition: resource.h:84
Logger * logger
Definition: logger.cpp:95
SDL_Surface * mSDLSurface
Definition: image.h:230
Image * mParent
Definition: subimage.h:81
uint8_t * mAlphaChannel
Definition: image.h:236
GLuint mGLImage
Definition: image.h:182
void log(const char *const log_text,...)
Definition: logger.cpp:243
std::string mIdPath
Definition: resource.h:83
void decRef()
Definition: image.cpp:521

Member Function Documentation

◆ calcMemoryLocal()

int SubImage::calcMemoryLocal ( ) const
virtual

Reimplemented from Image.

Definition at line 228 of file subimage.cpp.

References Resource::calcMemoryLocal(), and SubImage().

Referenced by getType().

229 {
230  return static_cast<int>(sizeof(SubImage) +
231  sizeof(std::map<float, SDL_Surface*>)) +
233 }
int calcMemoryLocal() const
Definition: resource.cpp:75
SubImage(Image *const parent, SDL_Surface *const image, const int x, const int y, const int width, const int height)
Definition: subimage.cpp:87

◆ decRef()

void SubImage::decRef ( )
virtual

Decrements the reference count and deletes the object if no references are left.

Returns
true if the object was deleted false otherwise.

Reimplemented from Image.

Definition at line 222 of file subimage.cpp.

References Resource::decRef().

Referenced by getType().

223 {
225 }
virtual void decRef()
Definition: resource.cpp:49

◆ getSubImage()

Image * SubImage::getSubImage ( const int  x,
const int  y,
const int  width,
const int  height 
)
virtual

Creates a new image with the desired clipping rectangle.

Returns
NULL if creation failed and a valid image otherwise.

Reimplemented from Image.

Definition at line 213 of file subimage.cpp.

References Image::getSubImage(), Image::mBounds, and mParent.

215 {
216  if (mParent != nullptr)
217  return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h);
218  return nullptr;
219 }
Image * mParent
Definition: subimage.h:81
virtual Image * getSubImage(const int x, const int y, const int width, const int height)
Definition: image.cpp:465
SDL_Rect mBounds
Definition: image.h:210

◆ getType()

ImageTypeT SubImage::getType ( ) const
inlinevirtual

Reimplemented from Image.

Definition at line 69 of file subimage.h.

References calcMemoryLocal(), decRef(), and ImageType::SubImage.

Field Documentation

◆ mInternalBounds

SDL_Rect SubImage::mInternalBounds

Definition at line 78 of file subimage.h.

Referenced by Map::reduce(), and SubImage().

◆ mParent

Image* SubImage::mParent
private

Definition at line 81 of file subimage.h.

Referenced by getSubImage(), SubImage(), and ~SubImage().


The documentation for this class was generated from the following files: