23 #include <com/sun/star/beans/PropertyValue.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
33 #include <osl/endian.h>
37 #define PNG_DEF_COMPRESSION 6
39 #define PNGCHUNK_IHDR 0x49484452
40 #define PNGCHUNK_PLTE 0x504c5445
41 #define PNGCHUNK_IDAT 0x49444154
42 #define PNGCHUNK_IEND 0x49454e44
43 #define PNGCHUNK_pHYs 0x70485973
51 const css::uno::Sequence<css::beans::PropertyValue>* pFilterData);
69 std::unique_ptr<sal_uInt8[]>
91 void ImplWriteChunk(
unsigned char const* pSource, sal_uInt32 nDatSize);
95 const css::uno::Sequence<css::beans::PropertyValue>* pFilterData)
100 , mpMaskAccess(nullptr)
121 aBitmapEx = rBitmapEx;
127 bool bTranslucent =
true;
131 for (
const auto& rPropVal : *pFilterData)
133 if (rPropVal.Name ==
"Compression")
135 else if (rPropVal.Name ==
"Interlaced")
137 else if (rPropVal.Name ==
"Translucent")
140 rPropVal.Value >>= nTmp;
142 bTranslucent =
false;
144 else if (rPropVal.Name ==
"MaxChunkSize")
147 if (rPropVal.Value >>= nVal)
148 mnMaxChunkSize =
static_cast<sal_uInt32
>(nVal);
154 if (aBitmapEx.
IsAlpha() && bTranslucent)
175 aMask.ReleaseAccess(mpMaskAccess);
176 mpMaskAccess =
nullptr;
226 sal_uInt32
nType = chunk.nType;
227 #if defined(__LITTLEENDIAN) || defined(OSL_LITENDIAN)
228 nType = OSL_SWAPDWORD(nType);
230 sal_uInt32 nCRC = rtl_crc32(0, &nType, 4);
231 sal_uInt32 nDataSize = chunk.aData.size();
233 nCRC = rtl_crc32(nCRC, chunk.aData.data(), nDataSize);
237 rOStm.
WriteBytes(chunk.aData.data(), nDataSize);
287 std::unique_ptr<sal_uInt8[]> pTempBuf(
new sal_uInt8[nCount * 3]);
295 *pTmp++ = rColor.
GetRed();
312 sal_uInt32 nPrefSizeX =
static_cast<sal_uInt32
>(
313 100000.0 / (
static_cast<double>(aPrefSize.Width()) /
mnWidth) + 0.5);
314 sal_uInt32 nPrefSizeY =
static_cast<sal_uInt32
>(
315 100000.0 / (
static_cast<double>(aPrefSize.Height()) /
mnHeight) + 0.5);
354 for (nY = 0; nY <
mnHeight; nY += 8)
360 for (nY = 0; nY <
mnHeight; nY += 8)
368 for (nY = 4; nY <
mnHeight; nY += 8)
375 for (nY = 0; nY <
mnHeight; nY += 4)
383 for (nY = 2; nY <
mnHeight; nY += 4)
390 for (nY = 0; nY <
mnHeight; nY += 2)
398 for (nY = 1; nY <
mnHeight; nY += 2)
413 sal_uInt32 nIDATSize = aOStm.
Tell();
414 sal_uInt32 nBytes, nBytesToWrite = nIDATSize;
415 while (nBytesToWrite)
420 const_cast<unsigned char*>(static_cast<unsigned char const*>(aOStm.
GetData()))
421 + (nIDATSize - nBytesToWrite),
423 nBytesToWrite -= nBytes;
453 for (nX = nXStart, nXIndex = 0; nX <
mnWidth; nX += nXAdd, nXIndex++)
458 else if (nShift == 0)
463 if ((nXIndex & 7) != 0)
472 for (nX = nXStart, nXIndex = 0; nX <
mnWidth; nX += nXAdd, nXIndex++)
510 *pDest++ = rColor.
GetRed();
525 *pDest++ = rColor.
GetRed();
542 *pDest++ = rColor.
GetRed();
587 if (npa <= npb && npa <= npc)
588 *pDest++ = *p1++ -
static_cast<sal_uInt8>(na);
590 *pDest++ = *p1++ -
static_cast<sal_uInt8>(nb);
592 *pDest++ = *p1++ -
static_cast<sal_uInt8>(nc);
629 rChunkData.
aData.push_back(static_cast<sal_uInt8>(nSource >> 24));
630 rChunkData.
aData.push_back(static_cast<sal_uInt8>(nSource >> 16));
631 rChunkData.
aData.push_back(static_cast<sal_uInt8>(nSource >> 8));
632 rChunkData.
aData.push_back(static_cast<sal_uInt8>(nSource));
640 sal_uInt32 nSize = rChunkData.
aData.size();
641 rChunkData.
aData.resize(nSize + nDatSize);
642 memcpy(&rChunkData.
aData[nSize], pSource, nDatSize);
647 const css::uno::Sequence<css::beans::PropertyValue>* pFilterData)
sal_uInt8 GetIndexFromData(const sal_uInt8 *pData, tools::Long nX) const
Bitmap::ScopedReadAccess mpAccess
tools::Long Height() const
bool Write(SvStream &rOutStream)
void ImplWritepHYs(const BitmapEx &rBitmapEx)
const MapMode & GetPrefMapMode() const
std::vector< vcl::PNGWriter::ChunkData > maChunkSeq
void ImplWriteChunk(sal_uInt8 nNumb)
const std::unique_ptr< PNGWriterImpl > mpImpl
std::unique_ptr< sal_uInt8[]> mpDeflateInBuf
sal_uLong ImplGetFilter(sal_uLong nY, sal_uLong nXStart=0, sal_uLong nXAdd=1)
Scanline GetScanline(tools::Long nY) const
const Size & GetPrefSize() const
sal_uLong mnDeflateInSize
SvStream & WriteUInt32(sal_uInt32 nUInt32)
BitmapColor GetBestMatchingColor(const BitmapColor &rBitmapColor) const
sal_uInt8 GetBlue() const
PNGWriter(const BitmapEx &, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData=nullptr)
vcl::ScopedBitmapAccess< BitmapReadAccess, Bitmap,&Bitmap::AcquireReadAccess > ScopedReadAccess
vcl::PixelFormat getPixelFormat() const
std::vector< vcl::PNGWriter::ChunkData > & GetChunks()
PNGWriterImpl(const BitmapEx &BmpEx, const css::uno::Sequence< css::beans::PropertyValue > *pFilterData)
void ImplClearFirstScanline()
std::vector< vcl::PNGWriter::ChunkData > & GetChunks()
tools::Long Width() const
std::size_t WriteBytes(const void *pData, std::size_t nSize)
void BeginCompression(int nCompressLevel=ZCODEC_DEFAULT_COMPRESSION, bool gzLib=false)
tools::Long EndCompression()
bool Write(SvStream &rStream)
MapUnit GetMapUnit() const
sal_uInt32 mnMaxChunkSize
sal_uInt16 GetPaletteEntryCount() const
BitmapReadAccess * mpMaskAccess
Bitmap GetBitmap(Color aTransparentReplaceColor) const
sal_uInt8 GetGreen() const
SvStreamEndian GetEndian() const
AlphaMask GetAlpha() const
#define PNG_DEF_COMPRESSION
void SetEndian(SvStreamEndian SvStreamEndian)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
bool convertBitmap32To24Plus8(BitmapEx const &rInput, BitmapEx &rResult)
constexpr sal_uInt16 pixelFormatBitCount(PixelFormat ePixelFormat)
BitmapColor GetPixelFromData(const sal_uInt8 *pData, tools::Long nX) const
const BitmapColor & GetPaletteColor(sal_uInt16 nColor) const
std::unique_ptr< sal_uInt8[]> mpPreviousScan
void ImplOpenChunk(sal_uLong nChunkType)
std::unique_ptr< sal_uInt8[]> mpCurrentScan
std::vector< sal_uInt8 > aData
void Write(SvStream &rOStm, const sal_uInt8 *pData, sal_uInt32 nSize)
bool m_bDetectedRangeSegmentation false