switch Image copy methods to use x,y,width,height instead of left,top,right,bottom style arguments
This commit is contained in:
parent
c9cfceec39
commit
0480bf5fea
|
@ -22,12 +22,6 @@ Image::Image()
|
||||||
m_pitch = 0;
|
m_pitch = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Image::~Image()
|
|
||||||
{
|
|
||||||
STACK_TRACE;
|
|
||||||
Release();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Image::Release()
|
void Image::Release()
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
|
@ -84,32 +78,34 @@ BOOL Image::Create(const Image *source)
|
||||||
if (source == NULL)
|
if (source == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
else
|
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;
|
STACK_TRACE;
|
||||||
ASSERT(m_pixels == NULL);
|
ASSERT(m_pixels == NULL);
|
||||||
if (m_pixels != NULL)
|
if (m_pixels != NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
ASSERT(source != NULL);
|
||||||
|
if (source == NULL)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
ASSERT(source->GetPixels() != NULL);
|
ASSERT(source->GetPixels() != NULL);
|
||||||
if (source->GetPixels() == NULL)
|
if (source->GetPixels() == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
ASSERT(right > left);
|
ASSERT(x < source->GetWidth());
|
||||||
ASSERT(bottom > top);
|
ASSERT(y < source->GetHeight());
|
||||||
ASSERT(left < source->GetWidth());
|
ASSERT((x + width) <= source->GetWidth());
|
||||||
ASSERT(right < source->GetWidth());
|
ASSERT((y + height) <= source->GetHeight());
|
||||||
ASSERT(top < source->GetHeight());
|
|
||||||
ASSERT(bottom < source->GetHeight());
|
|
||||||
|
|
||||||
BOOL baseCreateSuccess = Create((right - left) + 1, (bottom - top) + 1, source->GetFormat());
|
BOOL baseCreateSuccess = Create(width, height, source->GetFormat());
|
||||||
if (!baseCreateSuccess)
|
if (!baseCreateSuccess)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
Copy(source, left, top, right, bottom, 0, 0);
|
Copy(source, x, y, width, height, 0, 0);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -236,32 +232,27 @@ void Image::Copy(const Image *source, uint16_t destX, uint16_t destY)
|
||||||
{
|
{
|
||||||
STACK_TRACE;
|
STACK_TRACE;
|
||||||
ASSERT(source != NULL);
|
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;
|
STACK_TRACE;
|
||||||
ASSERT(source != NULL);
|
ASSERT(source != NULL);
|
||||||
ASSERT(source->GetBpp() == m_bpp);
|
if (source == NULL)
|
||||||
ASSERT(right > left);
|
return;
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
uint8_t *destPixels = m_pixels + GetOffsetFor(destX, destY);
|
||||||
|
|
||||||
size_t lineWidthInBytes = ((right - left) + 1) * (m_bpp / 8);
|
size_t lineWidthInBytes = width * (m_bpp / 8);
|
||||||
uint16_t numLinesToCopy = (bottom - top) + 1;
|
uint16_t numLinesToCopy = height;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < numLinesToCopy; ++i)
|
for (uint16_t i = 0; i < numLinesToCopy; ++i)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,7 +23,7 @@ public:
|
||||||
CONTENT_TYPE GetTypeOf() const { return GetType(); }
|
CONTENT_TYPE GetTypeOf() const { return GetType(); }
|
||||||
|
|
||||||
Image();
|
Image();
|
||||||
virtual ~Image();
|
virtual ~Image() { Release(); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a empty new image.
|
* Creates a empty new image.
|
||||||
|
@ -44,13 +44,13 @@ public:
|
||||||
/**
|
/**
|
||||||
* Creates a copy of a subsection of an image.
|
* Creates a copy of a subsection of an image.
|
||||||
* @param source the source image object to copy
|
* @param source the source image object to copy
|
||||||
* @param left left X coordinate of the source region to copy
|
* @param x left X coordinate of the source region to copy
|
||||||
* @param top top Y coordinate of the source region to copy
|
* @param y top Y coordinate of the source region to copy
|
||||||
* @param right right X coordinate of the source region to copy
|
* @param width the width of the source region to copy
|
||||||
* @param bottom bottom Y coordinate of the source region to copy
|
* @param height the height of the source region to copy
|
||||||
* @return TRUE if successful
|
* @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.
|
* Creates an image from an image file.
|
||||||
|
@ -124,14 +124,14 @@ public:
|
||||||
* given. The source image must fit entirely in this image. No clipping
|
* given. The source image must fit entirely in this image. No clipping
|
||||||
* is performed.
|
* is performed.
|
||||||
* @param source the source image to copy
|
* @param source the source image to copy
|
||||||
* @param left the left X 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 top the top Y 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 right the right X coordinate of the region to copy from the source image
|
* @param width the width 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 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 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
|
* @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
|
* @return the width of this image
|
||||||
|
|
Reference in a new issue