libopenraw
rawfile.cpp
1 /*
2  * libopenraw - rawfile.cpp
3  *
4  * Copyright (C) 2007-2016 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 /* @brief C api for rawfile
21  */
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 
26 #include <boost/checked_delete.hpp>
27 
28 #include <libopenraw/consts.h>
29 #include <libopenraw/thumbnails.h>
30 #include <libopenraw/types.h>
31 
32 #include "rawfile.hpp"
33 
34 namespace OpenRaw {
35 class BitmapData;
36 class RawData;
37 class Thumbnail;
38 }
39 
40 using OpenRaw::RawFile;
41 using OpenRaw::RawData;
43 using OpenRaw::Thumbnail;
44 
45 extern "C" {
46 
48 #define CHECK_PTR(p, r) \
49  if (p == nullptr) { \
50  return r; \
51  }
52 
53 const char **or_get_file_extensions()
54 {
55  return RawFile::fileExtensions();
56 }
57 
58 ORRawFileRef or_rawfile_new(const char *filename, or_rawfile_type type)
59 {
60  CHECK_PTR(filename, NULL);
61  RawFile *rawfile = RawFile::newRawFile(filename, type);
62  return reinterpret_cast<ORRawFileRef>(rawfile);
63 }
64 
65 ORRawFileRef or_rawfile_new_from_memory(const uint8_t *buffer, uint32_t len,
66  or_rawfile_type type)
67 {
68  CHECK_PTR(buffer, NULL);
69  RawFile *rawfile = RawFile::newRawFileFromMemory(buffer, len, type);
70  return reinterpret_cast<ORRawFileRef>(rawfile);
71 }
72 
73 or_error or_rawfile_release(ORRawFileRef rawfile)
74 {
75  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
76  boost::checked_delete(reinterpret_cast<RawFile *>(rawfile));
77  return OR_ERROR_NONE;
78 }
79 
80 or_rawfile_type or_rawfile_get_type(ORRawFileRef rawfile)
81 {
82  CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN);
83  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
84  return prawfile->type();
85 }
86 
87 or_rawfile_typeid or_rawfile_get_typeid(ORRawFileRef rawfile)
88 {
89  CHECK_PTR(rawfile, OR_RAWFILE_TYPE_UNKNOWN);
90  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
91  return prawfile->typeId();
92 }
93 
94 const uint32_t *
95 or_rawfile_get_thumbnail_sizes(ORRawFileRef rawfile,
96  size_t *size)
97 {
98  CHECK_PTR(rawfile, nullptr);
99  CHECK_PTR(size, nullptr);
100  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
101  const auto & v = prawfile->listThumbnailSizes();
102  if (v.empty()) {
103  *size = 0;
104  return nullptr;
105  }
106  *size = v.size();
107  // we return a pointer to the storage
108  // C++11 spec says it has to be contiguous.
109  return &(*v.begin());
110 }
111 
112 or_error or_rawfile_get_thumbnail(ORRawFileRef rawfile,
113  uint32_t _preferred_size,
114  ORThumbnailRef thumb)
115 {
116  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
117  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
118  return prawfile->getThumbnail(_preferred_size,
119  *reinterpret_cast<Thumbnail *>(thumb));
120 }
121 
122 or_error or_rawfile_get_rawdata(ORRawFileRef rawfile, ORRawDataRef rawdata,
123  uint32_t options)
124 {
125  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
126  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
127  return prawfile->getRawData(*reinterpret_cast<RawData *>(rawdata), options);
128 }
129 
130 or_error or_rawfile_get_rendered_image(ORRawFileRef rawfile,
131  ORBitmapDataRef bitmapdata,
132  uint32_t options)
133 {
134  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
135  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
136  return prawfile->getRenderedImage(
137  *reinterpret_cast<BitmapData *>(bitmapdata), options);
138 }
139 
140 int32_t or_rawfile_get_orientation(ORRawFileRef rawfile)
141 {
142  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
143  CHECK_PTR(rawfile, 0);
144  return prawfile->getOrientation();
145 }
146 
147 or_error or_rawfile_get_colourmatrix1(ORRawFileRef rawfile, double *matrix,
148  uint32_t *size)
149 {
150  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
151  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
152  CHECK_PTR(size, OR_ERROR_INVALID_PARAM);
153  return prawfile->getColourMatrix1(matrix, *size);
154 }
155 
156 or_error or_rawfile_get_colourmatrix2(ORRawFileRef rawfile, double *matrix,
157  uint32_t *size)
158 {
159  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
160  CHECK_PTR(rawfile, OR_ERROR_NOTAREF);
161  CHECK_PTR(size, OR_ERROR_INVALID_PARAM);
162  return prawfile->getColourMatrix2(matrix, *size);
163 }
164 
165 ExifLightsourceValue or_rawfile_get_calibration_illuminant1(ORRawFileRef rawfile)
166 {
167  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
168  CHECK_PTR(rawfile, (ExifLightsourceValue)0);
169  return prawfile->getCalibrationIlluminant1();
170 }
171 
172 ExifLightsourceValue or_rawfile_get_calibration_illuminant2(ORRawFileRef rawfile)
173 {
174  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
175  CHECK_PTR(rawfile, (ExifLightsourceValue)0);
176  return prawfile->getCalibrationIlluminant2();
177 }
178 
179 ORConstMetaValueRef
180 or_rawfile_get_metavalue(ORRawFileRef rawfile, int32_t meta_index)
181 {
182  RawFile *prawfile = reinterpret_cast<RawFile *>(rawfile);
183  CHECK_PTR(rawfile, nullptr);
184  return reinterpret_cast<ORConstMetaValueRef>(prawfile->getMetaValue(meta_index));
185 }
186 
187 }
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard. I guess it failed.
Definition: arwfile.cpp:30
::or_error getThumbnail(uint32_t size, Thumbnail &thumbnail)
Definition: rawfile.cpp:363
::or_error getRawData(RawData &rawdata, uint32_t options)
Definition: rawfile.cpp:448
::or_error getRenderedImage(BitmapData &bitmapdata, uint32_t options)
Definition: rawfile.cpp:470
ExifLightsourceValue getCalibrationIlluminant1()
Definition: rawfile.cpp:552
static RawFile * newRawFileFromMemory(const uint8_t *buffer, uint32_t len, Type _typeHint=OR_RAWFILE_TYPE_UNKNOWN)
Definition: rawfile.cpp:189
Type type() const
Definition: rawfile.cpp:327
static const char ** fileExtensions()
Definition: rawfile.cpp:156
::or_error getColourMatrix1(double *matrix, uint32_t &size)
Definition: rawfile.cpp:504
TypeId typeId()
Definition: rawfile.cpp:332
const std::vector< uint32_t > & listThumbnailSizes(void)
Definition: rawfile.cpp:350
int32_t getOrientation()
Definition: rawfile.cpp:482
static RawFile * newRawFile(const char *_filename, Type _typeHint=OR_RAWFILE_TYPE_UNKNOWN)
Definition: rawfile.cpp:164