Fix bug with hatch brush (support saving RGBA data in CBgraFrame)

This commit is contained in:
Oleg Korshul
2021-02-02 21:23:02 +03:00
parent 904561d1da
commit 01bf276697
7 changed files with 35 additions and 12 deletions

View File

@ -443,7 +443,7 @@ void CxImage::Bitfield2RGB(uint8_t *src, uint32_t redmask, uint32_t greenmask, u
* \param bFlipImage: tune this parameter if the image is upsidedown
* \return true if everything is ok
*/
bool CxImage::CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage)
bool CxImage::CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage, bool isBGRA)
{
if (pArray==NULL) return false;
if (!((dwBitsperpixel==1)||(dwBitsperpixel==4)||(dwBitsperpixel==8)||
@ -459,14 +459,18 @@ bool CxImage::CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight
uint8_t *dst,*src;
unsigned char ShiftR = isBGRA ? 2 : 0;
unsigned char ShiftG = 1;
unsigned char ShiftB = isBGRA ? 0 : 2;
for (uint32_t y = 0; y<dwHeight; y++) {
dst = info.pImage + (bFlipImage?(dwHeight-1-y):y) * info.dwEffWidth;
src = pArray + y * dwBytesperline;
if (dwBitsperpixel==32){
for(uint32_t x=0;x<dwWidth;x++){
*dst++=src[0];
*dst++=src[1];
*dst++=src[2];
*dst++=src[ShiftB];
*dst++=src[ShiftG];
*dst++=src[ShiftR];
#if CXIMAGE_SUPPORT_ALPHA
AlphaSet(x,(bFlipImage?(dwHeight-1-y):y),src[3]);
#endif //CXIMAGE_SUPPORT_ALPHA

View File

@ -278,7 +278,7 @@ public:
void Clear(uint8_t bval=0);
void Copy(const CxImage &src, bool copypixels = true, bool copyselection = true, bool copyalpha = true);
bool Transfer(CxImage &from, bool bTransferFrames = true);
bool CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
bool CreateFromArray(uint8_t* pArray,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage, bool isBGRA = true);
bool CreateFromMatrix(uint8_t** ppMatrix,uint32_t dwWidth,uint32_t dwHeight,uint32_t dwBitsperpixel, uint32_t dwBytesperline, bool bFlipImage);
void FreeMemory(void* memblock);

View File

@ -343,6 +343,7 @@ void CBgraFrame::Clear()
m_lPaletteColors = 0;
m_bIsGrayScale = false;
m_dJpegSaveQuality = -1;
m_bIsRGBA = false;
}
void CBgraFrame::ClearNoAttack()
@ -392,6 +393,15 @@ void CBgraFrame::SetJpegQuality(const double& value)
m_dJpegSaveQuality = value;
}
void CBgraFrame::put_IsRGBA(const bool& bIsRGBA)
{
m_bIsRGBA = bIsRGBA;
}
bool CBgraFrame::get_IsRGBA()
{
return m_bIsRGBA;
}
void CBgraFrame::put_Palette(BYTE* pDataColors, const int& colors)
{
if (!pDataColors || colors < 1) return;
@ -449,7 +459,7 @@ bool CBgraFrame::SaveFile(const std::wstring& strFileName, unsigned int nFileTyp
if (21/*CXIMAGE_FORMAT_JBIG2*/ == nFileType)
{
CJBig2File jBig2File;
bool res = jBig2File.MemoryToJBig2(m_pData, m_lWidth * m_lHeight * 24, m_lWidth, m_lHeight, strFileName);
bool res = jBig2File.MemoryToJBig2(m_pData, m_lWidth * m_lHeight * 24, m_lWidth, m_lHeight, strFileName, !m_bIsRGBA);
return res;
}
@ -461,7 +471,7 @@ bool CBgraFrame::SaveFile(const std::wstring& strFileName, unsigned int nFileTyp
CxImage img;
if (!img.CreateFromArray(m_pData, m_lWidth, m_lHeight, lBitsPerPixel * 8, lStride, (m_lStride >= 0) ? true : false))
if (!img.CreateFromArray(m_pData, m_lWidth, m_lHeight, lBitsPerPixel * 8, lStride, (m_lStride >= 0) ? true : false, !m_bIsRGBA))
return false;
if (m_pPalette)

View File

@ -55,6 +55,8 @@ private:
bool m_bIsGrayScale;
double m_dJpegSaveQuality;
bool m_bIsRGBA;
public:
CBgraFrame();
~CBgraFrame();
@ -80,10 +82,13 @@ public:
bool IsGrayScale();
void put_IsRGBA(const bool& bIsRGBA);
bool get_IsRGBA();
void SetJpegQuality(const double& value);
bool OpenFile(const std::wstring& strFileName, unsigned int nFileType = 0); //0 - detect
bool SaveFile(const std::wstring& strFileName, unsigned int nFileType);
bool SaveFile(const std::wstring& strFileName, unsigned int nFileType);
bool Encode(BYTE*& pBuffer, int& nSize, unsigned int nFileType);
bool Resize(const long& nNewWidth, const long& nNewHeight, bool bDestroyData = true);

View File

@ -25,7 +25,7 @@ CJBig2File::CJBig2File()
m_nBwTreshold = 188;
}
bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName)
bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName, bool isBGRA)
{
// check for valid input parameters
@ -38,11 +38,14 @@ bool CJBig2File::MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int n
PIX *pSource = pixCreate( nWidth, nHeight, 32 );
if ( !pSource ) return false;
unsigned char ShiftR = isBGRA ? 2 : 0;
unsigned char ShiftG = 1;
unsigned char ShiftB = isBGRA ? 0 : 2;
for ( int nY = 0; nY < nHeight; nY++ )
{
for ( int nX = 0; nX < nWidth; nX++, pSourceBuffer += 3 )//todooo сделать 3 ? 4
{
pixSetRGBPixel( pSource, nX, nY, pSourceBuffer[ 2 ], pSourceBuffer[ 1 ], pSourceBuffer[ 0 ] );
pixSetRGBPixel( pSource, nX, nY, pSourceBuffer[ ShiftR ], pSourceBuffer[ ShiftG ], pSourceBuffer[ ShiftB ] );
}
}

View File

@ -8,7 +8,7 @@ class CJBig2File
public:
CJBig2File();
bool MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName);
bool MemoryToJBig2(unsigned char* pBufferBGRA ,int BufferSize, int nWidth, int nHeight, std::wstring sDstFileName, bool isBGRA = true);
bool m_bDuplicateLineRemoval;
bool m_bPDFMode;
@ -22,4 +22,4 @@ public:
std::wstring m_sBaseName;
std::string m_sOutputTreshold;
};
};

View File

@ -94,6 +94,7 @@ namespace NSOnlineOfficeBinToPdf
oFrame.put_Width(nSize);
oFrame.put_Height(nSize);
oFrame.put_Stride(4 * nSize);
oFrame.put_IsRGBA(true);
oFrame.SaveFile(wsBase64TempFile, 4); // PNG
wsTempString = wsBase64TempFile;
}