libopenraw  0.3.7
rawfile.hpp
1 /* -*- Mode: C++ -*- */
2 /*
3  * libopenraw - rawfile.hpp
4  *
5  * Copyright (C) 2005-2020 Hubert Figuière
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 #pragma once
23 
24 #include <string>
25 #include <vector>
26 
27 #include <libopenraw/rawfile.h>
28 
29 #include "ifddir.hpp"
30 #include "makernotedir.hpp"
31 
43 namespace OpenRaw {
44 
45 class Thumbnail;
46 class RawData;
47 class BitmapData;
48 class MetaValue;
49 class MetadataIterator;
50 
52 namespace Internals {
53 class RawContainer;
54 class ThumbDesc;
56 typedef std::map<uint32_t, ::or_rawfile_typeid> ModelIdMap;
57 struct BuiltinColourMatrix;
58 template<typename T>
59 void audit_coefficients();
60 }
61 
62 void init();
63 
65 class RawFile
66 {
67  template<typename T>
68  friend void Internals::audit_coefficients();
69 
70 public:
73 
74  RawFile(const RawFile&) = delete;
75  RawFile & operator=(const RawFile &) = delete;
76 
84  static const char **fileExtensions();
85 
91  static RawFile *newRawFile(const char*_filename,
92  Type typeHint = OR_RAWFILE_TYPE_UNKNOWN);
100  static RawFile *newRawFileFromMemory(const uint8_t *buffer, uint32_t len,
101  Type typeHint = OR_RAWFILE_TYPE_UNKNOWN);
102 
104  virtual ~RawFile();
106  Type type() const;
107 
111  TypeId typeId();
112  TypeId vendorId();
113 
114  // standard api, like get thumbnail
115  // and get exif.
116 
119  const std::vector<uint32_t> & listThumbnailSizes(void);
125  ::or_error getThumbnail(uint32_t size, Thumbnail & thumbnail);
126 
132  ::or_error getRawData(RawData & rawdata, uint32_t options);
133 
139  ::or_error getRenderedImage(BitmapData & bitmapdata, uint32_t options);
140 
143  uint32_t getOrientation();
144 
148  uint32_t colourMatrixSize();
149 
157  ::or_error getColourMatrix1(double* matrix, uint32_t& size);
158  ::or_error getColourMatrix2(double* matrix, uint32_t& size);
159 
163  ExifLightsourceValue getCalibrationIlluminant1();
164  ExifLightsourceValue getCalibrationIlluminant2();
165 
171 
179  Internals::MakerNoteDir::Ref makerNoteIfd();
180 
185  const MetaValue *getMetaValue(int32_t meta_index);
186 
187  MetadataIterator* getMetadataIterator();
188 protected:
217  virtual Internals::MakerNoteDir::Ref _locateMakerNoteIfd();
218 
219  struct camera_ids_t {
220  const char * model;
221  const uint32_t type_id;
222  };
227  RawFile(Type _type);
228 
232  static RawFile::TypeId modelid_to_typeid(const std::map<uint32_t, RawFile::TypeId>& model_map,
233  uint32_t model_id);
240  virtual bool vendorCameraIdLocation(Internals::IfdDir::Ref& ifd, uint16_t& index,
241  const Internals::ModelIdMap*& model_map);
243  void _setTypeId(TypeId _type_id);
247  TypeId _typeId() const;
248 
250  virtual Internals::RawContainer* getContainer() const = 0;
251 
256  virtual ::or_error _enumThumbnailSizes(std::vector<uint32_t> &list) = 0;
257 
265  virtual ::or_error _getThumbnail(uint32_t size, Thumbnail & thumbnail);
266  void _addThumbnail(uint32_t size, Internals::ThumbDesc&& desc);
267 
274  virtual ::or_error _getRawData(RawData & data, uint32_t options) = 0;
275 
279  virtual ::or_error _getColourMatrix(uint32_t index, double* matrix, uint32_t & size);
280  virtual ExifLightsourceValue _getCalibrationIlluminant(uint16_t index);
282  virtual MetaValue *_getMetaValue(int32_t /*meta_index*/) = 0;
283 
284  TypeId _typeIdFromModel(const std::string& make, const std::string & model);
285  TypeId _typeIdFromMake(const std::string& make, const std::string& model);
286  void _setIdMap(const camera_ids_t *map);
287  void _setMatrices(const Internals::BuiltinColourMatrix* matrices);
288  const Internals::BuiltinColourMatrix* _getMatrices() const;
289 
291  virtual void _identifyId() = 0;
292 
293  static ::or_error _getBuiltinLevels(const Internals::BuiltinColourMatrix* m,
294  TypeId type_id,
295  uint16_t & black,
296  uint16_t & white);
297  static ::or_error _getBuiltinColourMatrix(const Internals::BuiltinColourMatrix* m,
298  TypeId type_id,
299  double* matrix,
300  uint32_t & size);
301 
302 private:
303  static Type identify(const char*_filename);
304  static ::or_error identifyBuffer(const uint8_t* buff, size_t len,
305  Type &_type);
306  static ::or_error identifyIOBuffer(IO::Stream::Ptr& stream,
307  RawFile::Type& _type);
308  static const camera_ids_t s_make[];
309  static const camera_ids_t* _lookupCameraId(const camera_ids_t * map,
310  const std::string& value);
311  static const camera_ids_t* lookupVendorId(const camera_ids_t * map,
312  const std::string& value);
313 
314  class Private;
315 
316  Private *d;
317 };
318 
319 }
320 
323 /*
324  Local Variables:
325  mode:c++
326  c-file-style:"stroustrup"
327  c-file-offsets:((innamespace . 0))
328  c-basic-offset: 4
329  tab-width: 4
330  indent-tabs-mode:nil
331  fill-column:80
332  End:
333 */
Represent some bitmap data.
Definition: bitmapdata.hpp:30
std::shared_ptr< Stream > Ptr
Definition: stream.hpp:47
std::shared_ptr< IfdDir > Ref
Shared ptr of an IfdDir.
Definition: ifddir.hpp:56
Generic interface for the RAW file container.
Metadata value.
Definition: metavalue.hpp:35
Iterator for the metadata.
Definition: metadata.hpp:34
Represent camera raw data.
Definition: rawdata.hpp:38
RAW file.
Definition: rawfile.hpp:66
virtual ::or_error _getRawData(RawData &data, uint32_t options)=0
Get the RAW data.
virtual ::or_error _getThumbnail(uint32_t size, Thumbnail &thumbnail)
Get the thumbnail of exact size.
Definition: rawfile.cpp:495
virtual Internals::MakerNoteDir::Ref _locateMakerNoteIfd()
Locate the MakerNote IFD.
Definition: rawfile.cpp:686
::or_error getThumbnail(uint32_t size, Thumbnail &thumbnail)
Get the thumbnail from the raw file.
Definition: rawfile.cpp:445
virtual Internals::IfdDir::Ref _locateCfaIfd()=0
Locate the IFD for the raw data.
TypeId typeId()
The RAW file type ID. Identify it if needed.
Definition: rawfile.cpp:380
virtual bool vendorCameraIdLocation(Internals::IfdDir::Ref &ifd, uint16_t &index, const Internals::ModelIdMap *&model_map)
Get the vendor camera ID location.
Definition: rawfile.cpp:416
void _setTypeId(TypeId _type_id)
Set the file type id.
Definition: rawfile.cpp:428
Internals::IfdDir::Ref exifIfd()
Get the Exif IFD.
Definition: rawfile.cpp:715
virtual Internals::IfdDir::Ref _locateExifIfd()
Locate the Exif IFD.
Definition: rawfile.cpp:676
::or_error getRawData(RawData &rawdata, uint32_t options)
Get the RAW data.
Definition: rawfile.cpp:536
uint32_t colourMatrixSize()
Definition: rawfile.cpp:584
virtual ::or_error _getColourMatrix(uint32_t index, double *matrix, uint32_t &size)
Get the colour matrix.
Definition: rawfile.cpp:599
static RawFile * newRawFile(const char *_filename, Type typeHint=OR_RAWFILE_TYPE_UNKNOWN)
Factory method to create the proper RawFile instance.
Definition: rawfile.cpp:187
virtual Internals::IfdDir::Ref _locateMainIfd()=0
Locate the main IFD.
virtual ::or_error _enumThumbnailSizes(std::vector< uint32_t > &list)=0
Enumerate the thumbnail sizes.
uint32_t getOrientation()
Get the orientation of the image, using Exif enums.
Definition: rawfile.cpp:568
Internals::MakerNoteDir::Ref makerNoteIfd()
Get the MakerNote IFD.
Definition: rawfile.cpp:724
::or_error getColourMatrix1(double *matrix, uint32_t &size)
Get colour matrix.
Definition: rawfile.cpp:589
virtual Internals::RawContainer * getContainer() const =0
Get the container.
static RawFile * newRawFileFromMemory(const uint8_t *buffer, uint32_t len, Type typeHint=OR_RAWFILE_TYPE_UNKNOWN)
Factory method to create the proper RawFile instance from content.
Definition: rawfile.cpp:221
virtual ~RawFile()
Destructor.
Definition: rawfile.cpp:370
virtual MetaValue * _getMetaValue(int32_t)=0
Implementation for getMetaValue()
virtual void _identifyId()=0
Identify the file and set the ID internally.
const std::vector< uint32_t > & listThumbnailSizes(void)
List the available thumbnail sizes.
Definition: rawfile.cpp:433
::or_error getRenderedImage(BitmapData &bitmapdata, uint32_t options)
Get the rendered image.
Definition: rawfile.cpp:557
Internals::IfdDir::Ref mainIfd()
Get the main IFD.
Definition: rawfile.cpp:706
ExifLightsourceValue getCalibrationIlluminant1()
Get the calibration illuminant that match the colour matrix.
Definition: rawfile.cpp:638
Internals::IfdDir::Ref cfaIfd()
Get the IFD containing the CFA.
Definition: rawfile.cpp:696
static const char ** fileExtensions()
Return a NULL terminated list of file extensions that the library handle.
Definition: rawfile.cpp:180
TypeId _typeId() const
Just get the type id value. No identification. You might want to use typeId() in the general case.
Definition: rawfile.cpp:423
const MetaValue * getMetaValue(int32_t meta_index)
Get a metadata value.
Definition: rawfile.cpp:733
static RawFile::TypeId modelid_to_typeid(const std::map< uint32_t, RawFile::TypeId > &model_map, uint32_t model_id)
Helper to get the TypeId from the map.
Definition: rawfile.cpp:406
virtual or_colour_matrix_origin getColourMatrixOrigin() const
Get the origin of the colour matrix for the RAW file.
Definition: rawfile.cpp:648
Type type() const
Accessor for the type.
Definition: rawfile.cpp:375
Represent a thumbnail.
Definition: thumbnail.hpp:32
uint32_t or_rawfile_typeid
This is the type ID, a combination of vendor model It maps a specific camera. Only for the NATIVE fil...
Definition: consts.h:130
or_rawfile_type
Types of RAW files.
Definition: consts.h:59
or_colour_matrix_origin
Where the colour matrix comes from. Typically DNG is provided. The others are built-in.
Definition: consts.h:121
or_error
Error codes returned by libopenraw.
Definition: consts.h:42
@ OR_RAWFILE_TYPE_UNKNOWN
Definition: consts.h:60
std::map< uint32_t, ::or_rawfile_typeid > ModelIdMap
Definition: rawfile.hpp:54
Global namespace for libopenraw.
Definition: arwfile.cpp:29