diff options
author | Campbell Barton <ideasman42@gmail.com> | 2020-11-10 14:16:29 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2020-11-10 14:25:05 +0300 |
commit | 23c71a5fab42e22266196a45f1f2ac77e815bcd3 (patch) | |
tree | 66dd61354a80166b99de0539b1f704ba3986f396 /source/blender/imbuf/intern/oiio | |
parent | d2ab9b568e854457414e779dcceb6f48968de4d0 (diff) |
ImBuf: support detecting the file format from in-memory images
Add `IMB_ispic_type_from_memory` so we can detect the file format
of in-memory images.
This removes `is_a_filepath` callback and uses a magic check for
photo-shop files that's compatible with OIIO.
Even though OIIO doesn't support packed images, we can still use the
file magic for detecting the format.
This change allows D9500 (a fix for unpacking images),
to be implemented without a significant performance penalty,
although the actual performance cost would depend heavily on the
blend file.
Reviewed By: dfelinto, sergey
Ref D9517
Diffstat (limited to 'source/blender/imbuf/intern/oiio')
-rw-r--r-- | source/blender/imbuf/intern/oiio/openimageio_api.cpp | 14 | ||||
-rw-r--r-- | source/blender/imbuf/intern/oiio/openimageio_api.h | 2 |
2 files changed, 5 insertions, 11 deletions
diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.cpp b/source/blender/imbuf/intern/oiio/openimageio_api.cpp index 9d8c5d50a89..0b787a7842f 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.cpp +++ b/source/blender/imbuf/intern/oiio/openimageio_api.cpp @@ -163,16 +163,10 @@ static ImBuf *imb_oiio_load_image_float( extern "C" { -int imb_is_a_filepath_photoshop(const char *filename) +int imb_is_a_photoshop(const unsigned char *mem) { - const char *photoshop_extension[] = { - ".psd", - ".pdd", - ".psb", - nullptr, - }; - - return BLI_path_extension_check_array(filename, photoshop_extension); + const unsigned char magic[4] = {'8', 'B', 'P', 'S'}; + return memcmp(magic, mem, sizeof(magic)) == 0; } int imb_save_photoshop(struct ImBuf *ibuf, const char * /*name*/, int flags) @@ -198,7 +192,7 @@ struct ImBuf *imb_load_photoshop(const char *filename, int flags, char colorspac const bool is_colorspace_manually_set = (colorspace[0] != '\0'); /* load image from file through OIIO */ - if (imb_is_a_filepath_photoshop(filename) == 0) { + if (IMB_ispic_type_matches(filename, IMB_FTYPE_PSD) == 0) { return nullptr; } diff --git a/source/blender/imbuf/intern/oiio/openimageio_api.h b/source/blender/imbuf/intern/oiio/openimageio_api.h index 135e3521f71..0ac6e560cfa 100644 --- a/source/blender/imbuf/intern/oiio/openimageio_api.h +++ b/source/blender/imbuf/intern/oiio/openimageio_api.h @@ -31,7 +31,7 @@ extern "C" { struct ImBuf; -int imb_is_a_filepath_photoshop(const char *name); +int imb_is_a_photoshop(const unsigned char *mem); int imb_save_photoshop(struct ImBuf *ibuf, const char *name, int flags); |