Commit Graph
714 Commits
Author SHA1 Message Date
Andrew Champion eadec8f0b9 Remove most unchecked size/index casts
Convert most unchecked size/index `as` casts to checked casts with
`TryFrom`, included another top-level error variant.

This has several motivations:
- Making the library as robust as possible, including to platform
differences.
- Unchecked casts are susceptible to breakage during refactorings.
- Preparing for BigTIFF support, which will require the introduction of
generics and associated types for some parts of the de/encoders.
Unchecked primitive casts cannot be bound, while TryFrom can, and
overflowing conversions become more likely.
- Remaining u16 casts may be prone in failure in existing practice and
not just in theory during future changes.
2019-12-21 15:57:24 +00:00
Andrew Champion 462697e373 Add support for CMYK(16|32|64) decoding 2019-12-21 15:57:24 +00:00
Andrew Champion c537f5cc64 Add decode test for CMYK(8) 2019-12-21 15:57:24 +00:00
Andrew Champion 8f61196d70 Note 32 and 64 bit support in README 2019-12-21 15:57:24 +00:00
Andrew Champion 298dc8841d Remove unchecked casts and magic values for some tags 2019-12-21 15:57:24 +00:00
Andrew Champion f92be13f6c Factor tags into own module
Tag representations are not decoder- or encoder-specific, so should live
in their own module accessible to both for reuse. The decoder::ifd
module remains since this module is mainly dedicated to decoding the
IFD.
2019-12-21 15:57:24 +00:00
Andrew Champion f9cace84da Deduplicate primitive conversions for tag enum 2019-12-21 15:57:24 +00:00
Andrew Champion d510a9f4ab Strictly handle expected tag value types
Resolve several TODOs where tag values were cast from u32 without checks
by providing generic methods that error when the value fails casting to
the desired type. In addition to being more correct, this simplifies and
shortens decoding logic.

Remove `find_tag_u32` and `find_tag_u32_vec` as they are now redundant
and a GitHub code search found no usages outside copies of
`image-tiff`.
2019-12-21 15:57:24 +00:00
Andrew Champion 1fafcccb36 Remove needless cast (minor) 2019-12-21 15:57:24 +00:00
Andrew Champion 8b96793671 Simplify expression (minor) 2019-12-21 15:57:24 +00:00
Andrew Champion 27ae65160d Deduplicate decoding buffer construction 2019-12-21 15:57:24 +00:00
Andrew Champion 29bb8c2dfe Summarize supported features in README 2019-12-21 15:57:24 +00:00
Andrew Champion c5fcba45a0 Fix typo in error display message 2019-12-21 15:57:24 +00:00
HeroicKatora cbaa9dbc5b Merge pull request #68 from aschampion/refactors/test-dedup
Deduplicate tests and remove tempfile dev-dependency
2019-12-21 16:47:42 +01:00
Andrew Champion 959254aee9 Deduplicate encoding tests
Also removes dev dependency on tempfile.
2019-12-21 15:12:25 +00:00
Andrew Champion 3f14098060 Deduplicate decoding tests 2019-12-21 15:11:47 +00:00
Andrew Champion 57783ba43f Merge pull request #66 from aschampion/features/32-bit
Support 32- and 64-bit integer sample grayscale and RGB(A) images
2019-12-19 13:19:35 +00:00
Andrew Champion abd6aee19f Remove outdate and ambiguous TODO (minor) 2019-12-16 22:10:57 +00:00
Andrew Champion c72a8d364d Add tests for exotic 12-bit sample images
These images should correctly report their color depths, but fail to
decode as they are unsupported.
2019-12-16 18:53:44 +00:00
Andrew Champion e5d2e7862c Parse all homogeneous bit depth RGB(A) color types
Make the behavior of RGB and RGBA like Gray in returning ColorTypes for
all homogeneous bit depths, even if those depths are not 8, 16, 32 or
64. Note that this does not change which color types can actually be
decoded.
2019-12-11 15:03:05 +00:00
Andrew Champion 6e61de81b6 Simplify color type matching 2019-12-11 12:56:11 +00:00
Andrew Champion 8c4cea5d97 Support 64-bit encoding
Note that this adds the LONG8 data type from BigTIFF because of bounds
requiring TiffValue. However, this datatype should not actually be
written to tags.
2019-12-10 20:18:53 +00:00
Andrew Champion 0c53e1066a Support 64-bit rgb and rgba decoding 2019-12-10 20:18:53 +00:00
Andrew Champion f4e985e0bd Support 64-bit grayscale decoding 2019-12-10 20:18:53 +00:00
Andrew Champion af010edcfd Support 32-bit encoding 2019-12-10 20:18:53 +00:00
Andrew Champion f32b3b9d10 Fix warnings in encoding test 2019-12-10 20:18:53 +00:00
Andrew Champion 1f92c562bc Support 32-bit rgb and rgba decoding 2019-12-10 20:18:51 +00:00
Andrew Champion fca4e1f88a Support 32-bit grayscale decoding 2019-12-10 20:18:23 +00:00
HeroicKatora ff574b4ca2 Merge pull request #64 from image-rs/release-0.4
Document changes for release 0.4
v0.4,0
2019-11-23 19:43:33 +01:00
HeroicKatora 6f87228458 Merge pull request #65 from image-rs/error-type
Improve the error types
2019-11-21 19:36:38 +01:00
Andreas Molzer 15929f8b8e Document changes for release 0.4
Fixes: #60
2019-11-21 19:23:03 +01:00
Andreas Molzer f13492e41d Fix a doc typo found in PR review 2019-11-21 18:46:55 +01:00
Andreas Molzer 1d9944c5c5 Mark both detailed error types as non-exhaustive
This makes it cheaper to introduce new features that might require
amending the list of variants by allowing us to introduce previously
uncovered causes or more specialized representations.
2019-11-20 20:58:45 +01:00
Andreas Molzer a14b23473b Export the inflate error publicly
It encapsulates the implementation detail of holding a miniz_oxide
status within. The derived traits are not too extensive for other
possible representations as well.
2019-11-20 20:02:55 +01:00
Andreas Molzer 101940335c Fix public constructor from miniz_oxide status
Avoids leaking the dependency on `miniz_oxide` into the public interface
by making a constructor taking a status argument crate internal. It
would otherwise not be possible to replace the deflate decoder without
breaking that interface.
2019-11-20 19:56:13 +01:00
HeroicKatora 8e1c67ee53 Merge pull request #63 from image-rs/tagged
Replace FromPrimitive with our own tag macro
2019-11-12 20:14:25 +01:00
Andreas Molzer 7b672998db Get rid of num-traits crate
Turns out the only use was as a private bound which was unused within
that method.
2019-11-12 20:06:02 +01:00
HeroicKatora 62fee106a7 Merge pull request #62 from onnotechno/multipage_image_patch
Multipage image patch
2019-11-12 13:13:57 +01:00
Onno Kammeraad fd789dc420 Cursor::new(Vec::new()) requires a &mut instead of just & 2019-11-12 13:09:09 +01:00
Andreas Molzer 07e8501ad6 Prefer matching over if-else-chain in tags macro
Thanks to the review comment for pointing this style issue out.
2019-11-12 10:53:38 +01:00
OnnoandHeroicKatora f70447325e Update tests/encode_images.rs
Co-Authored-By: HeroicKatora <HeroicKatora@users.noreply.github.com>
2019-11-12 10:40:19 +01:00
Onno Kammeraad b2eb480c44 add multipage testcase, to validate the multipage image handling 2019-11-12 09:44:27 +01:00
Onno Kammeraad 686e9b2648 added a missing offset increase while adding padding 2019-11-11 16:15:01 +01:00
Andreas Molzer 517638a38f Prefer explicit conversion over as
The discriminant of some enum types can be retrieved with the `as`
operator and in C style enums it is also possible to set a specific
discriminant. However, that may silently change—breaking the value
written to the file. It is better to use that technique mostly for ffi
purposes.
2019-11-10 23:20:19 +01:00
Andreas Molzer a6696ab02f fixup! Move everything to the tags macro 2019-11-10 19:24:22 +01:00
Andreas Molzer 258edf4a46 Remove the num-derive dependency 2019-11-10 18:02:43 +01:00
Andreas Molzer f88c9f00c3 Move everything to the tags macro 2019-11-10 18:02:42 +01:00
Andreas Molzer f80f4a06d5 Make the Unknown field optional
Several other uses that currently rely on num-traits for conversion have
no Unknown representation. Thus, the converter now outputs only known
variants or an error and the exposing function then can put the error
value into an Unknown variant instead.
2019-11-10 18:02:08 +01:00
Onno Kammeraad cbae42ea94 fixed support for multipage images, the IDF offset is added during the new and also at the end of the internal_finish. This should only be done once 2019-11-06 14:04:18 +01:00
Onno Kammeraad 80b8ec5cdb Somehow the current offset was invalid when using multipage images. Now using the seek function to get the current offset 2019-11-06 13:58:29 +01:00