From 3dc0f482c8df6164a68d72f13c0cbb6271cf92c5 Mon Sep 17 00:00:00 2001 From: Svetlana Kulikova Date: Tue, 3 Mar 2026 16:21:20 +0300 Subject: [PATCH] Fix swap rgba for djvu --- DjVuFile/DjVuFileImplementation.cpp | 15 +++++++++------ DjVuFile/DjVuFileImplementation.h | 2 +- PdfFile/SrcWriter/RedactOutputDev.h | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/DjVuFile/DjVuFileImplementation.cpp b/DjVuFile/DjVuFileImplementation.cpp index 523c0ab9a9..d56754db6c 100644 --- a/DjVuFile/DjVuFileImplementation.cpp +++ b/DjVuFile/DjVuFileImplementation.cpp @@ -726,7 +726,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, int nRas GP pPage = m_pDoc->get_page(nPageIndex); //pPage->wait_for_complete_decode(); pPage->set_rotate(0); - return ConvertToPixels(pPage, nRasterW, nRasterH, bIsFlip); + return ConvertToPixels(pPage, nRasterW, nRasterH, bIsFlip, true); } catch (...) { @@ -734,11 +734,11 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(int nPageIndex, int nRas return NULL; } -unsigned char* CDjVuFileImplementation::ConvertToPixels(GP& pPage, int nImageW, int nImageH, bool bFlip) +unsigned char* CDjVuFileImplementation::ConvertToPixels(GP& pPage, int nImageW, int nImageH, bool bFlip, bool bIsSwapRGB) { BYTE* pBufferDst = NULL; - auto processPixmap = [&](GP pImage, bool bFlip = false) + auto processPixmap = [&](GP pImage, bool bFlip = false, bool bIsSwapRGB = false) { pBufferDst = new BYTE[4 * nImageW * nImageH]; @@ -749,7 +749,10 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP& pPage, in GPixel* pLine = pImage->operator[](nRow); for (int i = 0; i < nImageW; ++i) { - *pBuffer++ = 0xFF000000 | pLine->r << 16 | pLine->g << 8 | pLine->b; + if (bIsSwapRGB) + *pBuffer++ = 0xFF000000 | pLine->b << 16 | pLine->g << 8 | pLine->r; + else + *pBuffer++ = 0xFF000000 | pLine->r << 16 | pLine->g << 8 | pLine->b; ++pLine; } } @@ -790,7 +793,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP& pPage, in if (pPage->is_legal_photo() || pPage->is_legal_compound()) { GP pImage = pPage->get_pixmap(oRectAll, oRectAll); - processPixmap(pImage, bFlip); + processPixmap(pImage, bFlip, bIsSwapRGB); } else if (pPage->is_legal_bilevel()) { @@ -802,7 +805,7 @@ unsigned char* CDjVuFileImplementation::ConvertToPixels(GP& pPage, in GP pImage = pPage->get_pixmap(oRectAll, oRectAll); if (pImage) { - processPixmap(pImage, bFlip); + processPixmap(pImage, bFlip, bIsSwapRGB); } else { diff --git a/DjVuFile/DjVuFileImplementation.h b/DjVuFile/DjVuFileImplementation.h index 785fbf8183..740ef60d11 100644 --- a/DjVuFile/DjVuFileImplementation.h +++ b/DjVuFile/DjVuFileImplementation.h @@ -83,7 +83,7 @@ public: private: - unsigned char* ConvertToPixels(GP& pPage, int nRasterW, int nRasterH, bool bIsFlip = false); + unsigned char* ConvertToPixels(GP& pPage, int nRasterW, int nRasterH, bool bIsFlip = false, bool bIsSwapRGB = false); void CreateFrame(IRenderer* pRenderer, GP& pImage, int nPage, XmlUtils::CXmlNode& oText); void CreatePdfFrame(IRenderer* pRenderer, GP& pImage, int nPage, XmlUtils::CXmlNode& oText); diff --git a/PdfFile/SrcWriter/RedactOutputDev.h b/PdfFile/SrcWriter/RedactOutputDev.h index d5636beb34..2f5f64f595 100644 --- a/PdfFile/SrcWriter/RedactOutputDev.h +++ b/PdfFile/SrcWriter/RedactOutputDev.h @@ -201,7 +201,7 @@ namespace PdfWriter void DoStateOp(); void DrawXObject(const char* name); CObjectBase* CreateImage(Gfx *gfx, int nWidth, int nHeight, unsigned int nFilter, int nBPC, const char* sCS); - CResourcesDict* GetResources(Gfx *gfx, CDictObject* pNewForm); + CResourcesDict* GetResources(Gfx *gfx, CDictObject* pNewForm = NULL); XRef* m_pXref; std::vector m_arrQuadPoints;