switch Image copy methods to use x,y,width,height instead of left,top,right,bottom style arguments

This commit is contained in:
Gered 2013-04-02 12:02:18 -04:00
parent c9cfceec39
commit 0480bf5fea
2 changed files with 42 additions and 51 deletions

View file

@ -22,12 +22,6 @@ Image::Image()
m_pitch = 0;
}
Image::~Image()
{
STACK_TRACE;
Release();
}
void Image::Release()
{
STACK_TRACE;
@ -84,32 +78,34 @@ BOOL Image::Create(const Image *source)
if (source == NULL)
return FALSE;
else
return Create(source, 0, 0, source->GetWidth() - 1, source->GetHeight() - 1);
return Create(source, 0, 0, source->GetWidth(), source->GetHeight());
}
BOOL Image::Create(const Image *source, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom)
BOOL Image::Create(const Image *source, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
STACK_TRACE;
ASSERT(m_pixels == NULL);
if (m_pixels != NULL)
return FALSE;
ASSERT(source != NULL);
if (source == NULL)
return FALSE;
ASSERT(source->GetPixels() != NULL);
if (source->GetPixels() == NULL)
return FALSE;
ASSERT(right > left);
ASSERT(bottom > top);
ASSERT(left < source->GetWidth());
ASSERT(right < source->GetWidth());
ASSERT(top < source->GetHeight());
ASSERT(bottom < source->GetHeight());
ASSERT(x < source->GetWidth());
ASSERT(y < source->GetHeight());
ASSERT((x + width) <= source->GetWidth());
ASSERT((y + height) <= source->GetHeight());
BOOL baseCreateSuccess = Create((right - left) + 1, (bottom - top) + 1, source->GetFormat());
BOOL baseCreateSuccess = Create(width, height, source->GetFormat());
if (!baseCreateSuccess)
return FALSE;
Copy(source, left, top, right, bottom, 0, 0);
Copy(source, x, y, width, height, 0, 0);
return TRUE;
}
@ -236,32 +232,27 @@ void Image::Copy(const Image *source, uint16_t destX, uint16_t destY)
{
STACK_TRACE;
ASSERT(source != NULL);
Copy(source, 0, 0, source->GetWidth() - 1, source->GetHeight() - 1, destX, destY);
Copy(source, 0, 0, source->GetWidth(), source->GetHeight(), destX, destY);
}
void Image::Copy(const Image *source, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t destX, uint16_t destY)
void Image::Copy(const Image *source, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t destX, uint16_t destY)
{
STACK_TRACE;
ASSERT(source != NULL);
ASSERT(source->GetBpp() == m_bpp);
ASSERT(right > left);
ASSERT(bottom > top);
ASSERT(left < source->GetWidth());
ASSERT(right < source->GetWidth());
ASSERT(top < source->GetHeight());
ASSERT(bottom < source->GetHeight());
ASSERT(destX < m_width);
ASSERT(destY < m_height);
ASSERT((right - left) < m_width);
ASSERT((bottom - top) < m_height);
ASSERT(destX + (right - left) < m_width);
ASSERT(destY + (bottom - top) < m_height);
if (source == NULL)
return;
uint8_t *sourcePixels = source->GetPixels() + source->GetOffsetFor(left, top);
ASSERT(source->GetBpp() == m_bpp);
ASSERT((x + width) <= source->GetWidth());
ASSERT((y + height) <= source->GetHeight());
ASSERT((destX + width) <= m_width);
ASSERT((destY + height) <= m_height);
uint8_t *sourcePixels = source->GetPixels() + source->GetOffsetFor(x, y);
uint8_t *destPixels = m_pixels + GetOffsetFor(destX, destY);
size_t lineWidthInBytes = ((right - left) + 1) * (m_bpp / 8);
uint16_t numLinesToCopy = (bottom - top) + 1;
size_t lineWidthInBytes = width * (m_bpp / 8);
uint16_t numLinesToCopy = height;
for (uint16_t i = 0; i < numLinesToCopy; ++i)
{

View file

@ -23,7 +23,7 @@ public:
CONTENT_TYPE GetTypeOf() const { return GetType(); }
Image();
virtual ~Image();
virtual ~Image() { Release(); }
/**
* Creates a empty new image.
@ -44,13 +44,13 @@ public:
/**
* Creates a copy of a subsection of an image.
* @param source the source image object to copy
* @param left left X coordinate of the source region to copy
* @param top top Y coordinate of the source region to copy
* @param right right X coordinate of the source region to copy
* @param bottom bottom Y coordinate of the source region to copy
* @param x left X coordinate of the source region to copy
* @param y top Y coordinate of the source region to copy
* @param width the width of the source region to copy
* @param height the height of the source region to copy
* @return TRUE if successful
*/
BOOL Create(const Image *source, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom);
BOOL Create(const Image *source, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
/**
* Creates an image from an image file.
@ -124,14 +124,14 @@ public:
* given. The source image must fit entirely in this image. No clipping
* is performed.
* @param source the source image to copy
* @param left the left X coordinate of the region to copy from the source image
* @param top the top Y coordinate of the region to copy from the source image
* @param right the right X coordinate of the region to copy from the source image
* @param bottom the bottom Y coordinate of the region to copy from the source image
* @param x the left X coordinate of the region to copy from the source image
* @param y the top Y coordinate of the region to copy from the source image
* @param width the width of the region to copy from the source image
* @param height the height of the region to copy from the source image
* @param destX the X coordinate to copy the source image to on this image
* @param destY the Y coordinate to copy the source image to on this image
*/
void Copy(const Image *source, uint16_t left, uint16_t top, uint16_t right, uint16_t bottom, uint16_t destX, uint16_t destY);
void Copy(const Image *source, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t destX, uint16_t destY);
/**
* @return the width of this image