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
 ~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 ()
 
 ~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)
 
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 89 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().

92  :
93  Image(image, false, nullptr),
95  mParent(parent)
96 {
97  if (mParent != nullptr)
98  {
99  mParent->incRef();
104  mSource = parent->mIdPath;
105 #ifdef DEBUG_IMAGES
106  logger->log("set name2 %p, %s", static_cast<void*>(this),
107  mSource.c_str());
108 #endif // DEBUG_IMAGES
109 #ifdef DEBUG_BIND_TEXTURE
110  mIdPath = parent->mIdPath;
111 #endif // DEBUG_BIND_TEXTURE
112  }
113  else
114  {
115  mHasAlphaChannel = false;
116  mIsAlphaVisible = false;
117  mAlphaChannel = nullptr;
118  }
119 
120  // Set up the rectangle.
121  mBounds.x = CAST_S16(x);
122  mBounds.y = CAST_S16(y);
123  mBounds.w = CAST_U16(width);
124  mBounds.h = CAST_U16(height);
125  if (mParent != nullptr)
126  {
131  }
132  else
133  {
134  mInternalBounds.x = 0;
135  mInternalBounds.y = 0;
136  mInternalBounds.w = 1;
137  mInternalBounds.h = 1;
138  }
139  mUseAlphaCache = false;
140 }
std::string mSource
Definition: resource.h:84
bool hasAlphaChannel() const
Definition: image.cpp:264
void SDLTerminateAlphaCache()
Definition: image.cpp:501
Image(SDL_Surface *const image, const bool hasAlphaChannel, uint8_t *const alphaChannel)
Definition: image.cpp:126
SDL_Rect mInternalBounds
Definition: subimage.h:78
uint8_t * SDLgetAlphaChannel() const
Definition: image.h:163
Logger * logger
Definition: logger.cpp:88
#define CAST_U16
Definition: cast.h:28
Image * mParent
Definition: subimage.h:81
bool mIsAlphaVisible
Definition: image.h:244
uint8_t * mAlphaChannel
Definition: image.h:237
bool mUseAlphaCache
Definition: image.h:243
bool mHasAlphaChannel
Definition: image.h:242
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:264
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 143 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.

147  :
148  Image(image, width, height, texWidth, texHeight),
149  mInternalBounds(),
150  mParent(parent)
151 {
152  if (mParent != nullptr)
153  mParent->incRef();
154 
155  // Set up the rectangle.
156  mBounds.x = CAST_S16(x);
157  mBounds.y = CAST_S16(y);
158  mBounds.w = CAST_U16(width);
159  mBounds.h = CAST_U16(height);
160  if (mParent != nullptr)
161  {
166  mSource = parent->mIdPath;
167 #ifdef DEBUG_IMAGES
168  logger->log("set name2 %p, %s", static_cast<void*>(this),
169  mSource.c_str());
170 #endif // DEBUG_IMAGES
171 #ifdef DEBUG_BIND_TEXTURE
172  mIdPath = parent->mIdPath;
173 #endif // DEBUG_BIND_TEXTURE
174  }
175  else
176  {
177  mInternalBounds.x = 0;
178  mInternalBounds.y = 0;
179  mInternalBounds.w = 1;
180  mInternalBounds.h = 1;
181  }
183 }
std::string mSource
Definition: resource.h:84
Image(SDL_Surface *const image, const bool hasAlphaChannel, uint8_t *const alphaChannel)
Definition: image.cpp:126
SDL_Rect mInternalBounds
Definition: subimage.h:78
Logger * logger
Definition: logger.cpp:88
#define CAST_U16
Definition: cast.h:28
Image * mParent
Definition: subimage.h:81
bool mIsAlphaVisible
Definition: image.h:244
bool mHasAlphaChannel
Definition: image.h:242
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:264
std::string mIdPath
Definition: resource.h:83

◆ ~SubImage()

SubImage::~SubImage ( )

Destructor.

Definition at line 186 of file subimage.cpp.

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

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

Member Function Documentation

◆ calcMemoryLocal()

int SubImage::calcMemoryLocal ( ) const
virtual

Reimplemented from Image.

Definition at line 230 of file subimage.cpp.

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

Referenced by getType().

231 {
232  return static_cast<int>(sizeof(SubImage) +
233  sizeof(std::map<float, SDL_Surface*>)) +
235 }
int calcMemoryLocal() const
Definition: image.cpp:507
SubImage(Image *const parent, SDL_Surface *const image, const int x, const int y, const int width, const int height)
Definition: subimage.cpp:89

◆ 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 224 of file subimage.cpp.

References Resource::decRef().

Referenced by getType().

225 {
227 }
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 215 of file subimage.cpp.

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

217 {
218  if (mParent != nullptr)
219  return mParent->getSubImage(mBounds.x + x, mBounds.y + y, w, h);
220  return nullptr;
221 }
Image * mParent
Definition: subimage.h:81
virtual Image * getSubImage(const int x, const int y, const int width, const int height)
Definition: image.cpp:466
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: