Thanks for your reply

Yes the simple case was a jpeg image, LoadFromBuffer looks like what I need, thanks.

I have two more advanced case of Deflate/CCITT compressed images. In 0.9.x, deflate was implemented as follows, where buf holds the raw image data:

        PoDoFo::PdfMemoryInputStream is(buf.data(), buf.size());
        pdfImage.SetImageData(width, height, sampleSize, &is, {PoDoFo::ePdfFilter_FlateDecode});

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);

which however aborts here in PdfStreamedObjectStream::GetInputStream(PdfObject& obj) with

    PODOFO_RAISE_ERROR_INFO(PdfErrorCode::NotImplemented, "Unsupported reading from streamed object stream");

The CCITT code, implemented in 0.9.x as

        PoDoFo::PdfName faxFilterName(PoDoFo::PdfFilterFactory::FilterTypeToName(PoDoFo::ePdfFilter_CCITTFaxDecode));
        CCITTFax4Encoder encoder;
        uint8_t* encoded = /* image data */;
        uint32_t encodedLen = /* image data length */;
pdfImage.GetObject()->GetDictionary().AddKey(PoDoFo::PdfName::KeyFilter, faxFilterName);
        PoDoFo::PdfDictionary decodeParams;
        decodeParams.AddKey("Columns", PoDoFo::PdfObject(PoDoFo::pdf_int64(img.width())));         decodeParams.AddKey("Rows", PoDoFo::PdfObject(PoDoFo::pdf_int64(img.height())));         decodeParams.AddKey("K", PoDoFo::PdfObject(PoDoFo::pdf_int64(-1))); // K < 0 --- Pure two-dimensional encoding (Group 4) pdfImage.GetObject()->GetDictionary().AddKey("DecodeParms", PoDoFo::PdfObject(decodeParams));         PoDoFo::PdfMemoryInputStream is(reinterpret_cast<char*>(encoded), encodedLen);         pdfImage.SetImageDataRaw(img.width(), img.height(), pixelFormat, &is);

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);

also aborts with "Unsupported reading from streamed object stream". Could you give me a pointer how to translate these?

Many thanks
Sandro


On 14.07.23 17:15, Francesco Pretto wrote:
Are you trying to load a PdfImage from a jpeg image? If so, you should
use PdfImage::LoadFromBuffer(buffer), which will automatically fill the image
with the jpeg content. PdfImage::SetData(buffer, width, height, format)
is specialized to load an image from raw pixel data, as the PdfPixelFormat
enum parameter should have suggested. It's a new feature in 0.10.x.
Other input definitions are supported through
PdfImage::SetDataRaw(buffer, info), but not recommended for users that
don't know what they are doing.






On Fri, 14 Jul 2023 at 16:46, Sandro Mani <manisan...@gmail.com> wrote:
Hi

I'm migrating some podofo-0.9.x code to 0.10.x. I have code writing
encoded image streams like this:

          QByteArray data;
          QBuffer buffer(&data);
          img.save(&buffer, "jpg", settings.compressionQuality);
          PoDoFo::PdfName
dctFilterName(PoDoFo::PdfFilterFactory::FilterTypeToName(PoDoFo::ePdfFilter_DCTDecode));
pdfImage.GetObject()->GetDictionary().AddKey(PoDoFo::PdfName::KeyFilter,
dctFilterName);
          PoDoFo::SpanStreamDevice is(data.data(), data.size());
          pdfImage->SetData(is, width, height, pixelFormat);

which I'm having difficulties to adapt to 0.10.x as the API changed
substantially here. Can someone provide an example?

Thanks
Sandro



_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users


_______________________________________________
Podofo-users mailing list
Podofo-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/podofo-users

Reply via email to