Crop stamp thumbnails that don't fit even when resized
This commit is contained in:
parent
23a368dbf0
commit
6ba5de6034
@ -32,6 +32,16 @@ bool ThumbnailRendererTask::doWork()
|
||||
int scale = scaleX > scaleY ? scaleX : scaleY;
|
||||
int newWidth = thumbnail->Width / scale, newHeight = thumbnail->Height / scale;
|
||||
thumbnail->Resize(newWidth, newHeight, true);
|
||||
newWidth = thumbnail->Width;
|
||||
newHeight = thumbnail->Height;
|
||||
if (newWidth > Width || newHeight > Height)
|
||||
{
|
||||
auto croppedWidth = newWidth > Width ? Width : newWidth;
|
||||
auto croppedHeight = newHeight > Height ? Height : newHeight;
|
||||
thumbnail->Crop(croppedWidth, croppedHeight, (newWidth - croppedWidth) / 2, (newHeight - croppedHeight) / 2);
|
||||
newWidth = thumbnail->Width;
|
||||
newHeight = thumbnail->Height;
|
||||
}
|
||||
Width = newWidth;
|
||||
Height = newHeight;
|
||||
}
|
||||
|
@ -36,12 +36,27 @@ VideoBuffer::VideoBuffer(VideoBuffer * old):
|
||||
std::copy(old->Buffer, old->Buffer+(old->Width*old->Height), Buffer);
|
||||
};
|
||||
|
||||
VideoBuffer::VideoBuffer(pixel * buffer, int width, int height):
|
||||
VideoBuffer::VideoBuffer(pixel * buffer, int width, int height, int pitch):
|
||||
Width(width),
|
||||
Height(height)
|
||||
{
|
||||
Buffer = new pixel[width*height];
|
||||
std::copy(buffer, buffer+(width*height), Buffer);
|
||||
CopyData(buffer, width, height, pitch ? pitch : width);
|
||||
}
|
||||
|
||||
void VideoBuffer::CopyData(pixel * buffer, int width, int height, int pitch)
|
||||
{
|
||||
for (auto y = 0; y < height; ++y)
|
||||
{
|
||||
std::copy(buffer + y * pitch, buffer + y * pitch + width, Buffer + y * width);
|
||||
}
|
||||
}
|
||||
|
||||
void VideoBuffer::Crop(int width, int height, int x, int y)
|
||||
{
|
||||
CopyData(Buffer + y * Width + x, width, height, Width);
|
||||
Width = width;
|
||||
Height = height;
|
||||
}
|
||||
|
||||
void VideoBuffer::Resize(float factor, bool resample)
|
||||
|
@ -19,10 +19,11 @@ public:
|
||||
|
||||
VideoBuffer(const VideoBuffer & old);
|
||||
VideoBuffer(VideoBuffer * old);
|
||||
VideoBuffer(pixel * buffer, int width, int height);
|
||||
VideoBuffer(pixel * buffer, int width, int height, int pitch = 0);
|
||||
VideoBuffer(int width, int height);
|
||||
void Resize(float factor, bool resample = false);
|
||||
void Resize(int width, int height, bool resample = false, bool fixedRatio = true);
|
||||
void Crop(int width, int height, int x, int y);
|
||||
TPT_INLINE void BlendPixel(int x, int y, int r, int g, int b, int a)
|
||||
{
|
||||
#ifdef PIX32OGL
|
||||
@ -85,6 +86,8 @@ public:
|
||||
int BlendCharacter(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
int AddCharacter(int x, int y, String::value_type c, int r, int g, int b, int a);
|
||||
~VideoBuffer();
|
||||
|
||||
void CopyData(pixel * buffer, int width, int height, int pitch);
|
||||
};
|
||||
|
||||
class Graphics
|
||||
|
Reference in New Issue
Block a user