Skip to content

Commit

Permalink
return FlateDecode filter for PNG images (#181)
Browse files Browse the repository at this point in the history
* return FlateDecode filter for PNG images

* add png example in read.rs

---------

Co-authored-by: Sebastian <s3bk@protonmail.com>
  • Loading branch information
omkar-mohanty and s3bk authored Nov 23, 2023
1 parent ce5806f commit adc85a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pdf/examples/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ fn main() -> Result<(), PdfError> {
Some(StreamFilter::DCTDecode(_)) => "jpeg",
Some(StreamFilter::JBIG2Decode(_)) => "jbig2",
Some(StreamFilter::JPXDecode) => "jp2k",
Some(StreamFilter::FlateDecode(_)) => "png",
_ => continue,
};

Expand All @@ -80,7 +81,6 @@ fn main() -> Result<(), PdfError> {
}
println!("Found {} image(s).", images.len());


for (name, font) in fonts.iter() {
let fname = format!("font_{}", name);
if let Some(Ok(data)) = font.embedded_data(&resolver) {
Expand Down
6 changes: 3 additions & 3 deletions pdf/src/object/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ pub enum ImageFormat {
Jp2k,
Jbig2,
CittFax,
Png
}

impl ImageXObject {
Expand All @@ -610,9 +611,7 @@ impl ImageXObject {
StreamFilter::ASCIIHexDecode => false,
StreamFilter::ASCII85Decode => false,
StreamFilter::LZWDecode(_) => false,
StreamFilter::FlateDecode(_) => false,
StreamFilter::RunLengthDecode => false,

StreamFilter::Crypt => true,
_ => true
}).unwrap_or(filters.len());
Expand All @@ -625,6 +624,7 @@ impl ImageXObject {
[StreamFilter::DCTDecode(_)] |
[StreamFilter::CCITTFaxDecode(_)] |
[StreamFilter::JPXDecode] |
[StreamFilter::FlateDecode(_)] |
[StreamFilter::JBIG2Decode(_)] => Ok((data, Some(&image_filters[0]))),
_ => bail!("??? filters={:?}", image_filters)
}
Expand All @@ -651,7 +651,7 @@ impl ImageXObject {
data
}
StreamFilter::DCTDecode(ref p) => dct_decode(&data, p)?,
StreamFilter::JPXDecode => jpx_decode(&data)?,
StreamFilter::JPXDecode => jpx_decode(&data)?, params)?,
StreamFilter::JBIG2Decode(ref p) => {
let global_data = p.globals.as_ref().map(|s| s.data(resolve)).transpose()?;
jbig2_decode(&data, global_data.as_deref().unwrap_or_default())?
Expand Down

0 comments on commit adc85a8

Please sign in to comment.