Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pdf::Image::Image(PoDoFo::PdfObject *pObject) :
- width((const l_int32) pObject->GetDictionary().GetKeyAsLong(PoDoFo::PdfName::FromEscaped("Width"))),
- height((const l_int32) pObject->GetDictionary().GetKeyAsLong(PoDoFo::PdfName::FromEscaped("Height"))),
- bpp((const int8_t) pObject->GetDictionary().GetKeyAsLong(PoDoFo::PdfName::FromEscaped("BitsPerComponent"))) {
- char *tmp;
- long len;
- dynamic_cast<PoDoFo::PdfMemStream *>(pObject->GetStream())->GetFilteredCopy(&tmp, &len);
- Magick::Blob blob;
- blob.updateNoCopy(tmp, (size_t) len, Magick::Blob::MallocAllocator);
- Magick::Image im(blob, Magick::Geometry(width, height), 2, "gray");
- std::string pnm_header = "P5\n" + std::to_string(width) + " " + std::to_string(height) + "\n255\n";
- unsigned char *buffer = (unsigned char *) malloc(width * height + pnm_header.size());
- memcpy(buffer, pnm_header.c_str(), pnm_header.size());
- im.write(0, 0, width, height, "I", MagickCore::StorageType::CharPixel, buffer + pnm_header.size());
- pix_image = pixReadMemPnm(buffer, width * height + pnm_header.size());
- free(buffer);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement