Cleanup: Use new OIIO valid_file API
Now that OIIO has proper `valid_file` APIs for the formats we care
about, and which take MemReaders, we can remove the code added to TIFF,
PSD, and PNG as part of 5cc8fea7e9
.
Additionally, this change eliminates the recent console spew on startup
where the TIFF loader is asked to load non-TIFF files (it is based on
the ordering of the filetype array)[1]. We now make a `valid_file` check
during open to address this.
[1] `: Not a TIFF or MDI file, bad magic number 12150 (0x2f76).`
Pull Request: https://projects.blender.org/blender/blender/pulls/116826
This commit is contained in:
parent
1254fee589
commit
75c71b78ba
|
@ -19,11 +19,7 @@ extern "C" {
|
|||
|
||||
bool imb_is_a_png(const uchar *mem, size_t size)
|
||||
{
|
||||
const char signature[] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A};
|
||||
if (size < sizeof(signature)) {
|
||||
return false;
|
||||
}
|
||||
return memcmp(signature, mem, sizeof(signature)) == 0;
|
||||
return imb_oiio_check(mem, size, "png");
|
||||
}
|
||||
|
||||
ImBuf *imb_load_png(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
||||
|
|
|
@ -19,11 +19,7 @@ extern "C" {
|
|||
|
||||
bool imb_is_a_psd(const uchar *mem, size_t size)
|
||||
{
|
||||
const uchar magic[4] = {'8', 'B', 'P', 'S'};
|
||||
if (size < sizeof(magic)) {
|
||||
return false;
|
||||
}
|
||||
return memcmp(magic, mem, sizeof(magic)) == 0;
|
||||
return imb_oiio_check(mem, size, "psd");
|
||||
}
|
||||
|
||||
ImBuf *imb_load_psd(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
||||
|
|
|
@ -19,15 +19,7 @@ extern "C" {
|
|||
|
||||
bool imb_is_a_tiff(const uchar *mem, size_t size)
|
||||
{
|
||||
constexpr int MAGIC_SIZE = 4;
|
||||
if (size < MAGIC_SIZE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char big_endian[MAGIC_SIZE] = {0x4d, 0x4d, 0x00, 0x2a};
|
||||
const char lil_endian[MAGIC_SIZE] = {0x49, 0x49, 0x2a, 0x00};
|
||||
return ((memcmp(big_endian, mem, MAGIC_SIZE) == 0) ||
|
||||
(memcmp(lil_endian, mem, MAGIC_SIZE) == 0));
|
||||
return imb_oiio_check(mem, size, "tif");
|
||||
}
|
||||
|
||||
ImBuf *imb_load_tiff(const uchar *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
|
||||
|
|
|
@ -250,7 +250,7 @@ static unique_ptr<ImageInput> get_oiio_reader(const char *format,
|
|||
{
|
||||
/* Attempt to create a reader based on the passed in format. */
|
||||
unique_ptr<ImageInput> in = ImageInput::create(format);
|
||||
if (!in) {
|
||||
if (!(in && in->valid_file(&mem_reader))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ static unique_ptr<ImageInput> get_oiio_reader(const char *format,
|
|||
in->set_ioproxy(&mem_reader);
|
||||
bool ok = in->open("", r_newspec, config);
|
||||
if (!ok) {
|
||||
in.reset();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return in;
|
||||
|
@ -270,8 +270,8 @@ bool imb_oiio_check(const uchar *mem, size_t mem_size, const char *file_format)
|
|||
|
||||
/* This memory proxy must remain alive for the full duration of the read. */
|
||||
Filesystem::IOMemReader mem_reader(cspan<uchar>(mem, mem_size));
|
||||
unique_ptr<ImageInput> in = get_oiio_reader(file_format, config, mem_reader, spec);
|
||||
return in ? true : false;
|
||||
unique_ptr<ImageInput> in = ImageInput::create(file_format);
|
||||
return in && in->valid_file(&mem_reader);
|
||||
}
|
||||
|
||||
ImBuf *imb_oiio_read(const ReadContext &ctx,
|
||||
|
|
Loading…
Reference in New Issue