Commit 7f8e942d authored by Ilya Kirillov's avatar Ilya Kirillov

Fixed bug #32822. Fixed an issue with saving grayscale jpeg images in pdf.

parent a9509852
......@@ -1470,7 +1470,7 @@ PdfWriter::CImageDict* CPdfRenderer::LoadImage(Aggplus::CImage* pImage, const BY
pPdfImage->LoadSMask(pData, nImageW, nImageH, nAlpha, (pImage->GetStride() >= 0) ? false : true);
if (bJpeg)
pPdfImage->LoadJpeg(pBuffer, nBufferSize, nImageW, nImageH);
pPdfImage->LoadJpeg(pBuffer, nBufferSize, nImageW, nImageH);
else
pPdfImage->LoadJpx(pBuffer, nBufferSize, nImageW, nImageH);
......@@ -1663,7 +1663,7 @@ void CPdfRenderer::UpdateBrush()
if (pImage)
{
if (_CXIMAGE_FORMAT_JPG == oImageFormat.eFileType)
pImage->LoadJpeg(wsTexturePath.c_str(), nImageW, nImageH);
pImage->LoadJpeg(wsTexturePath.c_str(), nImageW, nImageH, oFrame.IsGrayScale());
else
pImage->LoadJpx(wsTexturePath.c_str(), nImageW, nImageH);
}
......
......@@ -46,7 +46,7 @@ namespace PdfWriter
m_pXref = pXref;
m_pDocument = pDocument;
}
void CImageDict::LoadJpeg(const wchar_t* wsFilePath, unsigned int unWidth, unsigned int unHeight)
void CImageDict::LoadJpeg(const wchar_t* wsFilePath, unsigned int unWidth, unsigned int unHeight, bool bGrayScale)
{
CImageFileStream* pStream = new CImageFileStream();
if (!pStream)
......@@ -58,11 +58,16 @@ namespace PdfWriter
Add("Subtype", "Image");
Add("Height", unHeight);
Add("Width", unWidth);
Add("ColorSpace", "DeviceRGB");
if (bGrayScale)
Add("ColorSpace", "DeviceGray");
else
Add("ColorSpace", "DeviceRGB");
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_DCT_DECODE);
}
void CImageDict::LoadJpeg(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight)
void CImageDict::LoadJpeg(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight, bool bGrayScale)
{
CMemoryStream* pStream = new CMemoryStream();
if (!pStream)
......@@ -74,8 +79,13 @@ namespace PdfWriter
Add("Subtype", "Image");
Add("Height", unHeight);
Add("Width", unWidth);
Add("ColorSpace", "DeviceRGB");
Add("BitsPerComponent", 8);
if (bGrayScale)
Add("ColorSpace", "DeviceGray");
else
Add("ColorSpace", "DeviceRGB");
Add("BitsPerComponent", 8);
SetFilter(STREAM_FILTER_DCT_DECODE);
}
void CImageDict::LoadJpx(const wchar_t* wsFilePath, unsigned int unWidth, unsigned int unHeight)
......@@ -437,4 +447,4 @@ namespace PdfWriter
{
return m_vImages.size();
}
}
\ No newline at end of file
}
......@@ -57,8 +57,8 @@ namespace PdfWriter
CImageDict(CXref* pXref, CDocument* pDocument);
void LoadJpeg(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadJpeg(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight);
void LoadJpeg(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight, bool bGrayScale = false);
void LoadJpeg(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight, bool bGrayScale = false);
void LoadJpx(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
void LoadJpx(BYTE* pBuffer, int nBufferSize, unsigned int unWidth, unsigned int unHeight);
void LoadJb2(const wchar_t* wsTempFile, unsigned int unWidth, unsigned int unHeight);
......@@ -98,4 +98,4 @@ namespace PdfWriter
};
}
#endif // _PDF_WRITER_SRC_IMAGE_H
\ No newline at end of file
#endif // _PDF_WRITER_SRC_IMAGE_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment