proper way to handle maker notes

Hubert Figuiere hub at
Tue Jun 10 08:40:15 PDT 2008

On Mon, 2008-06-09 at 23:09 +0100, Rafael Espíndola wrote:
> For decompressing NEF files I need to read the decompression curve. I
> am not sure I am using the API the best I way. What I currently have
> is:
> 		void NEFFile::_getCompressionCurve(std::vector<uint8_t>& v)
> 		{
> 			IFDDir::Ref dir = _locateExifIfd();
> 			assert(dir);
> 			IFDEntry::Ref maker_ent = dir->getEntry(IFD::EXIF_TAG_MAKER_NOTE);
> 			assert(maker_ent);
> 			uint32_t off = maker_ent->offset();
> 			uint32_t base = off + 10;
> 			IFDDir::Ref ref(new IFDDir(base + 8, *m_container));
> 			ref->load();
> 			IFDEntry::Ref curve = ref->getEntry(0x0096);
> 			assert(curve);
> 			size_t size = curve->count();
> 			std::vector<uint8_t> temp(size);
> 			size_t read = m_container->fetchData(&temp[0],
> 						base + curve->offset(),
> 						size);
> 			assert(read == size);
> 			v.swap(temp);
> 		}
> Other then proper error checking and not hard coding constants, is
> this the proper way to read something from the MakerNote?

There is not really any standard way to access MakerNote. One of the
reason is that some MakerNote may not even be an IFD. The other reason
is that I didn't have any need for that yet, although it is planned as
part of the meta data loading.

Now about the code, a couple of comments:

-Only use _locateExifIfd() if m_exifIfd is NULL
-Don't assert on conditions that occur at run time. assert() are only
for semantic checks, like passing NULL where it is forbidden, etc.
-Passing &temp[0] to something that expect a "raw" pointer is a
fundamental error. There is absolutely NO warranty that 
  &temp[n + 1] == &temp[n] when temp is a std::vector<>.
-There is a IFDEntry::getArray<>() to which you pass a vector that
should do that for you.


More information about the Libopenraw-dev mailing list