-
Notifications
You must be signed in to change notification settings - Fork 11
Add support for the decoding of jpeg2000 #7
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
base: master
Are you sure you want to change the base?
Changes from all commits
c344d0f
7ddeddd
9256e9a
49bba27
8c2f2cd
8f66899
a881a57
7a10a82
0bb7207
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ | |
| *.rs.bk | ||
| /Cargo.lock | ||
| /target/ | ||
| .DS_Store | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -111,14 +111,41 @@ impl IconElement { | |
| let width = icon_type.pixel_width(); | ||
| let height = icon_type.pixel_width(); | ||
| match icon_type.encoding() { | ||
| #[cfg(feature = "pngio")] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line needs to be restored so that the crate can still build with the |
||
| Encoding::JP2PNG => { | ||
| let image: Image; | ||
| if self.data.starts_with(&JPEG_2000_FILE_MAGIC_NUMBER) { | ||
| let msg = "element to be decoded contains JPEG 2000 \ | ||
| data, which is not yet supported"; | ||
| return Err(Error::new(ErrorKind::InvalidInput, msg)); | ||
| let j2k_image = match jpeg2k::Image::from_bytes(&self.data) { | ||
| Ok(image) => image, | ||
| Err(e) => { | ||
| return Err(io::Error::new( | ||
| io::ErrorKind::InvalidData, | ||
| e, | ||
| )) | ||
| } | ||
| }; | ||
| let alpha_default = 255u8; // Full opacity | ||
| let pixels = | ||
| j2k_image.get_pixels(Some(alpha_default)).map_err( | ||
| |e| io::Error::new(io::ErrorKind::InvalidData, e), | ||
| )?; | ||
|
|
||
| let pixel_format = match pixels.format { | ||
| jpeg2k::ImageFormat::L8 => PixelFormat::Gray, | ||
| jpeg2k::ImageFormat::La8 => PixelFormat::GrayAlpha, | ||
| jpeg2k::ImageFormat::Rgb8 => PixelFormat::RGB, | ||
| jpeg2k::ImageFormat::Rgba8 => PixelFormat::RGBA, | ||
| }; | ||
|
|
||
| image = Image::from_data( | ||
| pixel_format, | ||
| pixels.width, | ||
| pixels.height, | ||
| pixels.data, | ||
| )?; | ||
| } else { | ||
| image = Image::read_png(io::Cursor::new(&self.data))?; | ||
| } | ||
| let image = Image::read_png(io::Cursor::new(&self.data))?; | ||
|
|
||
| if image.width() != width || image.height() != height { | ||
| let msg = format!("decoded PNG has wrong dimensions \ | ||
| ({}x{} instead of {}x{})", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,24 @@ fn encode_ic11() { | |
| encoder_test("32x32.png", IconType::RGBA32_16x16_2x, "ic11.icns"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn decode_ic13() { | ||
| decoder_test("ic13.icns", IconType::RGBA32_128x128_2x, "256x256.png"); | ||
CharlieS1103 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #[test] | ||
| fn decode_ic08(){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test seems to be failing for me when I run it locally. (Hmm, looks like I need to set up CI for this repo.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not totally sure why, given the JP2000 decoding is working (which I'm not totally sure of as I tested it with a jp2000 file which I created of type ic10 and it didn't seem to function) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just now enabled CI testing for this repo. If you rebase, we should be able to see the results of that. |
||
| decoder_test("ic08.icns", IconType::RGBA32_256x256, "256x256.png"); | ||
| } | ||
|
|
||
| #[test] | ||
| fn decode_jpeg2000_256x256() { | ||
| decoder_test("loom.icns", IconType::RGBA32_512x512, "loom-512x512.png"); | ||
| } | ||
|
|
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor style nitpick: Please remove the extra lines here (just one blank line between functions). |
||
|
|
||
|
|
||
| fn decoder_test(icns_name: &str, icon_type: IconType, png_name: &str) { | ||
| let family = load_icns_file(icns_name).unwrap(); | ||
| let image = family.get_icon_with_type(icon_type).unwrap(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.