Generally speaking, you can read JUST THE HEADER with the following sequence:
ImageInput *in = ImageInput::open(filename);
ImageSpec spec = in->spec();
// Note: NO read_scanline* or read_tile* calls here!
I would like to tell you that this will always work in a high-performance way,
but it depends on the format reader, which in some cases may be dependent on a
3rd party library that doesn't really have any easy way to read just the header
without reading the whole file (libraw, I'm looking at you!), in which case the
whole thing may be read when you open(). In those cases, you're mostly stuck,
unless there is a header-only-read API call in the dependent library that we
didn't know about or neglected to use properly.
It just so happens that NEF is a variant of TIFF (at least for the header
info), so you *can* force the TIFF reader to be used, like this:
ImageInput *in = ImageInput::create ("tiff"); // note: use format name
rather than filename
in->open (filename, spec);
This is a trick that happens to work with NEF, but I think it only works for
reading the header, because the TIFF reader certainly doesn't know how to
de-bayerize the image data or perform any other transformations that libraw is
expected to do with true raw data. The header-only-reading trick might work
with other RAW formats that happen to use the TIFF header conventions, but I
don't know exactly which those are. You certainly shouldn't assume it's the
case for all RAW formats.
> On Aug 6, 2017, at 12:59 PM, Kenny Carruthers <kennycarruth...@gmail.com>
> This is in C++ and using ImageInput.
> I did notice after sending my original email that in rawinput.cpp, the method
> read_tiff_metadata() shows how to create a new ImageInput of type ‘TIFF’ and
> then load data into that directly from a filename. That method completely
> bypasses all of the libraw code. Not sure how I overlooked that earlier.
> But that would appear to be working because of the (reasonably sound)
> assumption that most RAW files have a TIFF formatted header. Can this
> technique be extended to all image formats that contain embedded metadata?
>> On Aug 7, 2017, at 2:54 AM, Larry Gritz <l...@larrygritz.com> wrote:
>> Before I give a full answer...
>> C++ or Python? Or command line?
>> ImageInput or ImageBuf or ImageCache/TextureSystem?
>> On August 6, 2017 11:34:12 AM PDT, Kenny Carruthers
>> <kennycarruth...@gmail.com> wrote:
>> I’m using OpenImage IO and extracting the metadata from an image using the
>> extra_attribs() method on ImageSpec. Is there a way to tell OpenImage IO
>> that I’m only going to be accessing the metadata and that no image loading
>> or decoding needs to occur?
>> In particular, the RawInput class, which uses libraw, calls unpack() which
>> is a very slow method because of the RAW decoding that needs to take place.
>> However, that call to unpack() is being made at the start of the
>> ImageInput::open() method and there doesn’t appear to be any flag one can
>> set to disable that. Further down that method, it calls through to
>> read_tiff_metadata() which is really all that one needs if they are only
>> interested in the metadata.
>> If I disable libraw support in OpenImageIO, then OIIO defaults to opening a
>> Nikon NEF file with another plugin that only loads the metadata since it
>> can’t load the raw data. That code path is very fast but I don’t know how to
>> trigger it if raw support is built-in (or how to tell the raw plugin
>> Thank you.
>> Kenny Carruthers
>> macOS Developer
>> Corduroy Code Inc,
>> Oiio-dev mailing list
>> Larry Gritz
> Oiio-dev mailing list
Oiio-dev mailing list