From 1d155e35d2b293ae2c9581d6dd0edbf19636ed89 Mon Sep 17 00:00:00 2001 From: Oleg Korshul Date: Fri, 3 Nov 2023 23:11:58 +0300 Subject: [PATCH] For bug 46717 --- DesktopEditor/raster/BgraFrame.cpp | 67 +++++++++++++++++++++++++++++- DesktopEditor/raster/BgraFrame.h | 4 +- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/DesktopEditor/raster/BgraFrame.cpp b/DesktopEditor/raster/BgraFrame.cpp index ec9b7473a2..1b32860e9c 100644 --- a/DesktopEditor/raster/BgraFrame.cpp +++ b/DesktopEditor/raster/BgraFrame.cpp @@ -421,7 +421,7 @@ void CBgraFrame::put_Palette(BYTE* pDataColors, const int& colors) memcpy(m_pPalette, pDataColors, colors * 4); } -bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileType) +bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileType, const bool& bIsOrientationRemove) { m_nFileType = nFileType; @@ -448,6 +448,13 @@ bool CBgraFrame::OpenFile(const std::wstring& strFileName, unsigned int nFileTyp if (!img->Decode(oFile.GetFileNative(), m_nFileType)) return false; +#if CXIMAGE_SUPPORT_EXIF +#if CXIMAGE_SUPPORT_TRANSFORMATION + if (bIsOrientationRemove) + img->RotateExif(0); +#endif +#endif + CxImage* imgResample = NULL; if (false) @@ -653,3 +660,61 @@ void CBgraFrame::FromImage(IGrObject* pGrObject, bool bIsCopy) } } } + +bool CBgraFrame::RemoveOrientation(const std::wstring& strFileName) +{ + CImageFileFormatChecker checker(strFileName); + __ENUM_CXIMAGE_FORMATS imageType = checker.eFileType; + + switch (imageType) + { + case _CXIMAGE_FORMAT_JPG: + case _CXIMAGE_FORMAT_PNG: + { + NSFile::CFileBinary oFile; + if (!oFile.OpenFile(strFileName)) + return false; + + CxImage* img = new CxImage(); + if (!img->Decode(oFile.GetFileNative(), imageType)) + { + delete img; + return false; + } + +#if CXIMAGE_SUPPORT_EXIF +#if CXIMAGE_SUPPORT_TRANSFORMATION + int32_t orientation = img->GetExifInfo()->Orientation; + + switch (orientation) + { + case 3: + case 6: + case 8: + case 5: + { + delete img; + oFile.CloseFile(); + + CBgraFrame oFrame; + oFrame.OpenFile(strFileName, imageType, true); + + NSFile::CFileBinary::Remove(strFileName); + oFrame.SaveFile(strFileName, imageType); + + return true; + } + default: + return false; + } + +#endif +#endif + break; + } + default: + break; + } + + return false; +} diff --git a/DesktopEditor/raster/BgraFrame.h b/DesktopEditor/raster/BgraFrame.h index 560f59ebe0..98d7df9885 100644 --- a/DesktopEditor/raster/BgraFrame.h +++ b/DesktopEditor/raster/BgraFrame.h @@ -87,7 +87,7 @@ public: void SetJpegQuality(const double& value); - bool OpenFile(const std::wstring& strFileName, unsigned int nFileType = 0); //0 - detect + bool OpenFile(const std::wstring& strFileName, unsigned int nFileType = 0, const bool& bIsOrientationRemove = false); bool SaveFile(const std::wstring& strFileName, unsigned int nFileType); bool Decode(BYTE* pBuffer, int nSize, unsigned int nFileType = 0); @@ -99,6 +99,8 @@ public: bool ReColorPatternImage(const std::wstring& strFileName, unsigned int rgbColorBack, unsigned int rgbColorFore); void FromImage(IGrObject* pGraphics, bool bIsCopy = true); + + static bool RemoveOrientation(const std::wstring& sFile); }; #endif