-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zero copy rendering #83
Comments
Hi @DorianRudolph , yes, Pdfium does support rendering into an external buffer. We would need to add a new constructor to (This approach is fundamentally incompatible with WASM because Pdfium and |
Under the assumption that you will be providing a |
Thanks, this is what I had in mind. I should be able to test it sometime this week. Eventually I would like to get my project running in the web. Why would this not work in WASM? I guess your concern is that pdfium and pdfium-render are compiled to two different .wasm modules? I'm just learning about WASM, but could something like this work to establish a shared memory between WASM modules? |
Because Pdfium and So long as the WASM memory address spaces are separate, it will never be possible to share a buffer between Pdfium and Because Javascript does have access to all memory irrespective of WASM modules, it is possible to work around this to a certain degree. The WASM-specific My suggestion is that you have two code paths: one using You are welcome to try getting Pdfium and I will rename the |
Renamed |
Added unit test for |
Yes thank you it works for me. Btw, this is how I render into a skia image: let w: f32 = page.width().value;
let h = page.height().value;
let scale = (2_000_000.0 / (w * h)).sqrt();
let width = (w * scale) as i32;
let height = (h * scale) as i32;
let data = unsafe { Data::new_uninitialized((width * height * 4) as usize) };
assert!(data.inner()._base.fRefCnt == 1);
let mut bitmap = unsafe {
let mut_data = std::slice::from_raw_parts_mut(data.inner().fPtr as _, data.size());
PdfBitmap::from_bytes(width, height, PdfBitmapFormat::BGRA, mut_data, pdfium.bindings())
.expect("Could not create bitmap")
};
page
.render_into_bitmap(&mut bitmap, width, height, None)
.expect("Could not render page");
let size = ISize::new(width, height);
let info = ImageInfo::new(size, ColorType::RGBA8888, AlphaType::Premul, None); // need RGB and not BGR, not sure why
let image = Image::from_raster_data(&info, data, (width * 4) as usize).unwrap(); |
I would like to render a PdfPage into an external buffer via a raw pointer. My use case is to render directly into a skia bitmap. This way I don't have to copy the data from the PdfBitmap to the skia bitmap, saving one copy.
Right now there does not appear to be a way to give pdfium-render a pointer or slice to render into.
The text was updated successfully, but these errors were encountered: