Blame lib/ifdfilecontainer.hpp

rpm-build d2b433
/*
rpm-build d2b433
 * libopenraw - ifdfilecontainer.h
rpm-build d2b433
 *
rpm-build d2b433
 * Copyright (C) 2005-2016 Hubert Figuiere
rpm-build d2b433
 *
rpm-build d2b433
 * This library is free software: you can redistribute it and/or
rpm-build d2b433
 * modify it under the terms of the GNU Lesser General Public License
rpm-build d2b433
 * as published by the Free Software Foundation, either version 3 of
rpm-build d2b433
 * the License, or (at your option) any later version.
rpm-build d2b433
 *
rpm-build d2b433
 * This library is distributed in the hope that it will be useful,
rpm-build d2b433
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
rpm-build d2b433
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
rpm-build d2b433
 * Lesser General Public License for more details.
rpm-build d2b433
 *
rpm-build d2b433
 * You should have received a copy of the GNU Lesser General Public
rpm-build d2b433
 * License along with this library.  If not, see
rpm-build d2b433
 * <http://www.gnu.org/licenses/>.
rpm-build d2b433
 */
rpm-build d2b433
rpm-build d2b433
/**
rpm-build d2b433
 @brief Defines the class for reading TIFF-like file, including but not
rpm-build d2b433
 limited to TIFF, Exif, CR2, NEF, etc. It is designed to also address 
rpm-build d2b433
 issues like sone RAW file that do create veriation of TIFF just to confuse
rpm-build d2b433
 readers (like Olympus ORW).
rpm-build d2b433
*/
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
#ifndef OR_INTERNALS_IFDFILECONTAINER_H_
rpm-build d2b433
#define OR_INTERNALS_IFDFILECONTAINER_H_
rpm-build d2b433
rpm-build d2b433
#include <stddef.h>
rpm-build d2b433
#include <stdint.h>
rpm-build d2b433
#include <sys/types.h>
rpm-build d2b433
#include <vector>
rpm-build d2b433
rpm-build d2b433
#include <libopenraw/consts.h>
rpm-build d2b433
rpm-build d2b433
#include "rawcontainer.hpp"
rpm-build d2b433
#include "ifddir.hpp"
rpm-build d2b433
#include "io/stream.hpp"
rpm-build d2b433
rpm-build d2b433
namespace OpenRaw {
rpm-build d2b433
namespace Internals {
rpm-build d2b433
		
rpm-build d2b433
rpm-build d2b433
class IfdFileContainer
rpm-build d2b433
  : public RawContainer
rpm-build d2b433
{
rpm-build d2b433
public:
rpm-build d2b433
  /** 
rpm-build d2b433
      constructor
rpm-build d2b433
      @param file the file handle
rpm-build d2b433
      @param offset the offset from the start of the file
rpm-build d2b433
  */
rpm-build d2b433
  IfdFileContainer(const IO::Stream::Ptr &file,
rpm-build d2b433
                   off_t offset);
rpm-build d2b433
  /** destructor */
rpm-build d2b433
  virtual ~IfdFileContainer();
rpm-build d2b433
rpm-build d2b433
  /** 
rpm-build d2b433
      due to the way Exif works, we have to set specific index
rpm-build d2b433
      to address these IFD 
rpm-build d2b433
  */
rpm-build d2b433
  enum {
rpm-build d2b433
    IFD_NONE = -1, /**< invalid IFD. Means an error */
rpm-build d2b433
    IFD_EXIF = -2, /**< exif IFD: see field 0x6789 in IFD 0 */
rpm-build d2b433
    IFD_GPS = -3,  /**< GPS IFD: see field 0x8825 in IFD 0 */
rpm-build d2b433
    IFD_INTEROP = -4 /**< interoperability IFD: see field 0xa005 in exif IFD*/ 
rpm-build d2b433
  };
rpm-build d2b433
rpm-build d2b433
  /** 
rpm-build d2b433
      Check the IFD magic header
rpm-build d2b433
		
rpm-build d2b433
      @param p the pointer to check
rpm-build d2b433
      @param len the length of the block to check. Likely to be at least 4.
rpm-build d2b433
      @return the endian if it is the magic header 
rpm-build d2b433
		
rpm-build d2b433
      subclasses needs to override it for like Olympus RAW
rpm-build d2b433
  */
rpm-build d2b433
  virtual EndianType isMagicHeader(const char *p, int len);
rpm-build d2b433
	
rpm-build d2b433
  /**
rpm-build d2b433
     Set the current directory
rpm-build d2b433
     @param dir the index of the directory to read, or one of the specific
rpm-build d2b433
     IFD index values that are < -1
rpm-build d2b433
     @return NULL if no error, or return the reference to the current directory
rpm-build d2b433
  */
rpm-build d2b433
  IfdDir::Ref setDirectory(int dir);
rpm-build d2b433
  /**
rpm-build d2b433
     Count the number of image file directories, not including
rpm-build d2b433
     EXIF, GPS and INTEROP.
rpm-build d2b433
     @return the number of image file directories
rpm-build d2b433
  */
rpm-build d2b433
  int countDirectories(void);
rpm-build d2b433
  /** Get the directories, loading them if necessary
rpm-build d2b433
   * @return the directories
rpm-build d2b433
   */
rpm-build d2b433
  std::vector<IfdDir::Ref> & directories();
rpm-build d2b433
rpm-build d2b433
  /**
rpm-build d2b433
     Get the number of the current directory
rpm-build d2b433
     @return the index of the current directory. By default we
rpm-build d2b433
     are in directory 0. -1 indicates an initialized IFD file
rpm-build d2b433
  */
rpm-build d2b433
  int currentDirectory();
rpm-build d2b433
rpm-build d2b433
  /**
rpm-build d2b433
   * get the extra data size chunk associated to the current image directory
rpm-build d2b433
   * @return the size of the data chunk in bytes
rpm-build d2b433
   */
rpm-build d2b433
  size_t getDirectoryDataSize();
rpm-build d2b433
rpm-build d2b433
rpm-build d2b433
  /**
rpm-build d2b433
     Return the last error
rpm-build d2b433
     @return the error code
rpm-build d2b433
  */
rpm-build d2b433
  int lastError() const
rpm-build d2b433
    {
rpm-build d2b433
      return m_error;
rpm-build d2b433
    }
rpm-build d2b433
rpm-build d2b433
  /**
rpm-build d2b433
     Return the Exif offset from the container begining. By 
rpm-build d2b433
     default it is 0, but some format like MRW needs a different one.
rpm-build d2b433
     This is an adjustement for the offset in the Exif IFD tag.
rpm-build d2b433
  */
rpm-build d2b433
  int exifOffsetCorrection() const
rpm-build d2b433
    {
rpm-build d2b433
      return m_exif_offset_correction;
rpm-build d2b433
    }
rpm-build d2b433
rpm-build d2b433
  /** Set the exif offset if needed. */
rpm-build d2b433
  void setExifOffsetCorrection(int corr)
rpm-build d2b433
    {
rpm-build d2b433
      m_exif_offset_correction = corr;
rpm-build d2b433
    }
rpm-build d2b433
rpm-build d2b433
  /** locate image data in the ifd (excepted RAW)
rpm-build d2b433
   * @param dir the IFD dir to locate the image data in
rpm-build d2b433
   * @param t the type of the image data
rpm-build d2b433
   * @return an error code
rpm-build d2b433
   */
rpm-build d2b433
  ::or_error locateImageData(const IfdDir::Ref& dir, uint32_t& x, uint32_t& y, 
rpm-build d2b433
                              ::or_data_type& t);
rpm-build d2b433
  
rpm-build d2b433
protected:
rpm-build d2b433
  /** hook to be called at the start of _locateDirs() */
rpm-build d2b433
  virtual bool locateDirsPreHook();
rpm-build d2b433
private:
rpm-build d2b433
  int m_error;
rpm-build d2b433
  int m_exif_offset_correction;
rpm-build d2b433
rpm-build d2b433
  IfdDir::Ref m_current_dir;
rpm-build d2b433
  std::vector<IfdDir::Ref> m_dirs;
rpm-build d2b433
rpm-build d2b433
  bool _locateDirs();
rpm-build d2b433
};
rpm-build d2b433
rpm-build d2b433
}
rpm-build d2b433
}
rpm-build d2b433
rpm-build d2b433
#endif
rpm-build d2b433
/*
rpm-build d2b433
  Local Variables:
rpm-build d2b433
  mode:c++
rpm-build d2b433
  c-file-style:"stroustrup"
rpm-build d2b433
  c-file-offsets:((innamespace . 0))
rpm-build d2b433
  tab-width:2
rpm-build d2b433
  c-basic-offset:2
rpm-build d2b433
  indent-tabs-mode:nil
rpm-build d2b433
  fill-column:80
rpm-build d2b433
  End:
rpm-build d2b433
*/