On Tue Feb 19 11:43:58 2019, DCANTRELL wrote:
Show quoted text> > Please try Imager::File::HEIF from github
> >
> >
https://github.com/tonycoz/imager-file-heif
> >
> > when tested with foo.png, Imager::File::HEIF and heif-enc now produce
> > the exact same file (with the defaults.)
>
> OK, so starting with my original input file, read it, scale it, and
> spit out foo.png:
>
> $ perl -Mblib -MImager -e '$foo=Imager->new(file => "IMG_2781.HEIC",
> type => "heif"); $thumb = $foo->scale(scalefactor => 0.3); $thumb-
> >write(file => "foo.png")'
>
> use Imager to convert that to foo.heif:
>
> $ perl -Mblib -MImager -e '$foo=Imager->new(file =>
> "foo.png",type=>"png");$foo->write(file=>"foo.heif",type=>"heif")'
>
> and use heif-enc to convert foo.png to foo.png.heif:
>
> $ heif-enc -o foo.png.heif foo.png
>
> I now have two *.heif files of the same size, visually
> indistinguishable, both readable by Preview.app, but with different
> MD5 sums:
>
> $ md5 *heif
> MD5 (foo.heif) = be3492ecaa260a73f63dd5b360ef3afc
> MD5 (foo.png.heif) = a3a1a9bd644b143c686cea8b495daac0
>
> The difference is:
>
> $ diff <(hexdump -C foo.heif) <(hexdump -C foo.png.heif)
> 4,5c4,5
> < 00000030 00 00 00 00 70 69 63 74 6f 23 eb 38 00 00 55 e8
> |....picto#.8..U.|
> < 00000040 6f 23 ed 78 00 00 00 00 0e 70 69 74 6d 00 00 00
> |o#.x.....pitm...|
> ---
> > 00000030 00 00 00 00 70 69 63 74 00 00 00 00 00 00 00 00
> > |....pict........|
> > 00000040 00 00 00 00 00 00 00 00 0e 70 69 74 6d 00 00 00
> > |.........pitm...|
>
> However, if I read the original, scale, and write back out as heif all
> in Imager without an intermediate file:
>
> $ perl -Mblib -MImager -e '$foo=Imager-
> >new("IMG_2781.HEIC",type=>"heif");$thumb=$foo-
> >scale(scalefactor=>0.3);$thumb->write(file=>"foo.heif")'
>
> The resulting file has yet another MD5 sum and can't be read by
> Preview.app.
The difference there is in the reserved fields of the hdlr box:
aligned(8) class HandlerBox extends FullBox(‘hdlr’, version = 0, 0) {
unsigned int(32) pre_defined = 0;
unsigned int(32) handler_type;
const unsigned int(32)[3] reserved = 0;
string name;
}
handler_type is the "pict" you see in the dump, the 12 bytes following should be NULs, but they aren't.
Commit 0a03d6fc2b4e26c3fbb0b541f70f83e45a56bd5f added initializers to the reserved fields of the Box_hdlr class:
commit 0a03d6fc2b4e26c3fbb0b541f70f83e45a56bd5f
Author: seunghoon.baek <seunghoon.baek@linecorp.com>
Date: Wed Oct 10 14:35:41 2018 +0900
Initialize a member of hdlf box.
diff --git a/libheif/box.h b/libheif/box.h
index 1b20784..91e43fd 100644
--- a/libheif/box.h
+++ b/libheif/box.h
@@ -246,7 +246,7 @@ namespace heif {
private:
uint32_t m_pre_defined = 0;
uint32_t m_handler_type = fourcc("pict");
- uint32_t m_reserved[3];
+ uint32_t m_reserved[3] = {0, };
std::string m_name;
};
Zeroing these out in the failed file makes no difference.
But, I ran a comparison of the heic-info -d of a file Preview likes and your sample that it doesn't, one of the differences was:
@@ -41,7 +41,7 @@
| | version: 2
| | flags: 0
| | item_ID: 1
-| | item_protection_index: 32656
+| | item_protection_index: 0
| | item_type: hvc1
| | item_name:
| | content_type:
which is part of the infe box.
Box_infe was modified in 6f5658898e46cf51be5a80fa60cdd4503037615d (v1.3.2-93-g6f56588):
@@ -377,8 +378,8 @@ namespace heif {
Error parse(BitstreamRange& range) override;
private:
- heif_item_id m_item_ID;
- uint16_t m_item_protection_index;
+ heif_item_id m_item_ID = 0;
+ uint16_t m_item_protection_index = 0;
std::string m_item_type;
std::string m_item_name;
to initialize that field to zero.
If I zero *that* out as well in the failing .heic file, Preview manages to load the image.
Unfortunately this isn't something I have control over from Imager::File::HEIF - the only fix is to use the newer library.
Tony