diff --git a/src/client/ThumbnailRendererTask.cpp b/src/client/ThumbnailRendererTask.cpp index f44332863..7999b9021 100644 --- a/src/client/ThumbnailRendererTask.cpp +++ b/src/client/ThumbnailRendererTask.cpp @@ -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; } diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index 543e6e968..3c3fc87b5 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -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) diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 6bfe202fd..fda575535 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -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