From cecd111869c82a1fc8e87d1075c7c373df42b0be Mon Sep 17 00:00:00 2001 From: spx Date: Wed, 2 Nov 2011 09:19:37 +0000 Subject: [PATCH] Improved performance on drawing image. (2-10 times faster in some cases) --- Library/TintedImage.cpp | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/Library/TintedImage.cpp b/Library/TintedImage.cpp index dfc6e073..c90ba129 100644 --- a/Library/TintedImage.cpp +++ b/Library/TintedImage.cpp @@ -225,25 +225,19 @@ Bitmap* CTintedImage::LoadImageFromFileHandle(HANDLE fileHandle, DWORD fileSize, if (Ok == bitmap->GetLastStatus()) { //////////////////////////////////////////// - // Workaround to avoid image corruption with JPEG in some cases - if (CSystem::GetOSPlatform() < OSPLATFORM_7) + // Convert loaded image to faster blittable bitmap (may increase memory usage slightly) { - GUID guid; - bitmap->GetRawFormat(&guid); - if (guid == ImageFormatJPEG) + Rect r(0, 0, bitmap->GetWidth(), bitmap->GetHeight()); + Bitmap* clone = new Bitmap(r.Width, r.Height, PixelFormat32bppPARGB); { - Rect r(0, 0, bitmap->GetWidth(), bitmap->GetHeight()); - Bitmap* clone = new Bitmap(r.Width, r.Height, PixelFormat24bppRGB); - { - Graphics graphics(clone); - graphics.DrawImage(bitmap, r, 0, 0, r.Width, r.Height, UnitPixel); - } - delete bitmap; - bitmap = clone; - - ::GlobalFree(hBuffer); - hBuffer = NULL; + Graphics graphics(clone); + graphics.DrawImage(bitmap, r, 0, 0, r.Width, r.Height, UnitPixel); } + delete bitmap; + bitmap = clone; + + ::GlobalFree(hBuffer); + hBuffer = NULL; } //////////////////////////////////////////// *ppCache = new ImageCache(bitmap, hBuffer);