Thanks, nearly everything working now. Only exception is attempting to
pass a monochrome image bit-buffer to PdfImage::SetData, which results
in a distorted image. I worked around this by using SetDataRaw as follows:
PoDoFo::PdfImageInfo info;
info.Width = width;
info.Height = height;
info.ColorSpace = PoDoFo::PdfColorSpace::DeviceGray;
info.BitsPerComponent = 1;
// info.Filters = {PoDoFo::PdfFilterType::FlateDecode};
pdfImage->SetDataRaw(PoDoFo::bufferview(buf.data(),
buf.size()), info);
Interestingly, I had to comment out info.Filters, or I would get a blank
image (I suppose because it would be "double" flate decoded, as
FlateDecode is already default as you wrote?).
Sandro
On 17.07.23 10:53, Francesco Pretto wrote:
On Sat, 15 Jul 2023 at 23:58, Sandro Mani <manisan...@gmail.com> wrote:
deflate was implemented as follows [...]
which I translated to 0.10.x as
PoDoFo::PdfImageInfo info;
info.Width = width;
info.Height = height;
info.ColorSpace = colorSpace; //
PoDoFo::PdfColorSpace::DeviceRGB or PoDoFo::PdfColorSpace::DeviceGray
info.BitsPerComponent = sampleSize; // 8 or 1
info.Filters = {PoDoFo::PdfFilterType::FlateDecode};
pdfImage->SetDataRaw(PoDoFo::bufferview(buf.data(),
buf.size()), info);
I don't recommend doing this way for simple RGB/Gray input.
FlateDecode is the default compression for streams so you really
should just use the PdfImage::SetData(buffer, width, height, format,
scanLineSize) supplying proper image buffer input (these concepts are
the same in all graphics libraries). The library will default flate
encode the buffer.
which however aborts here in
PdfStreamedObjectStream::GetInputStream(PdfObject& obj) with
PODOFO_RAISE_ERROR_INFO(PdfErrorCode::NotImplemented, "Unsupported
reading from streamed object stream");
Please, don't use PdfStreamedDocument for now, use PdfMemDocument (see [1]).
The CCITT code, [...]
which I attempted to port to 0.10.x as
PoDoFo::PdfDictionary decodeParams;
decodeParams.AddKey("Columns",
PoDoFo::PdfObject(int64_t(img.width())));
decodeParams.AddKey("Rows",
PoDoFo::PdfObject(int64_t(img.height())));
decodeParams.AddKey("K", PoDoFo::PdfObject(int64_t(-1))); // K
< 0 --- Pure two-dimensional encoding (Group 4)
pdfImage->GetDictionary().AddKey("DecodeParms",
PoDoFo::PdfObject(decodeParams));
PoDoFo::PdfImageInfo info;
info.Width = width;
info.Height = height;
info.ColorSpace = colorSpace;
info.BitsPerComponent = sampleSize;
info.Filters = {PoDoFo::PdfFilterType::CCITTFaxDecode};
pdfImage->SetDataRaw(PoDoFo::bufferview(reinterpret_cast<const
char*>(encoded), encodedLen), info);
Please, re-try with with PdfMemDocument. This is a valid use case for
PdfImage::SetDataRaw, maybe it could be improved so "DecodeParms" are
added along filters in PdfImageInfo structure.
[1] https://github.com/podofo/podofo/issues/88
_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users