libopenraw
rawdata.cpp
1 /*
2  * libopenraw - rawdata.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 rawdata
21  */
22 
23 #include <stddef.h>
24 #include <stdint.h>
25 #include <stdlib.h>
26 
27 #include <libopenraw/consts.h>
28 #include <libopenraw/types.h>
29 
30 #include "rawdata.hpp"
31 #include "cfapattern.hpp"
32 
33 namespace OpenRaw {
34 class BitmapData;
35 }
36 
37 using OpenRaw::RawData;
39 
40 extern "C" {
41 
43 #define CHECK_PTR(p, r) \
44  if (p == NULL) { \
45  return r; \
46  }
47 
48 or_error or_get_extract_rawdata(const char *filename, uint32_t options,
49  ORRawDataRef *rawdata)
50 {
51  or_error ret = OR_ERROR_NONE;
52 
53  RawData **pRawData = reinterpret_cast<RawData **>(rawdata);
54  *pRawData = RawData::getAndExtractRawData(filename, options, ret);
55  return ret;
56 }
57 
58 ORRawDataRef or_rawdata_new(void)
59 {
60  RawData *rawdata = new RawData();
61  return reinterpret_cast<ORRawDataRef>(rawdata);
62 }
63 
64 or_error or_rawdata_release(ORRawDataRef rawdata)
65 {
66  if (rawdata == NULL) {
67  return OR_ERROR_NOTAREF;
68  }
69  delete reinterpret_cast<RawData *>(rawdata);
70  return OR_ERROR_NONE;
71 }
72 
73 or_data_type or_rawdata_format(ORRawDataRef rawdata)
74 {
75  return reinterpret_cast<RawData *>(rawdata)->dataType();
76 }
77 
78 void *or_rawdata_data(ORRawDataRef rawdata)
79 {
80  return reinterpret_cast<RawData *>(rawdata)->data();
81 }
82 
83 size_t or_rawdata_data_size(ORRawDataRef rawdata)
84 {
85  return reinterpret_cast<RawData *>(rawdata)->size();
86 }
87 
88 void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width,
89  uint32_t *height)
90 {
91  RawData *t = reinterpret_cast<RawData *>(rawdata);
92  if (width != NULL) {
93  *width = t->width();
94  }
95  if (height != NULL) {
96  *height = t->height();
97  }
98 }
99 
100 void or_rawdata_get_roi(ORRawDataRef rawdata, uint32_t *x, uint32_t *y,
101  uint32_t *width, uint32_t *height)
102 {
103  RawData *t = reinterpret_cast<RawData *>(rawdata);
104  if (x != NULL) {
105  *x = t->roi_x();
106  }
107  if (y != NULL) {
108  *y = t->roi_y();
109  }
110  if (width != NULL) {
111  *width = t->roi_width();
112  }
113  if (height != NULL) {
114  *height = t->roi_height();
115  }
116 }
117 
118 uint32_t or_rawdata_bpc(ORRawDataRef rawdata)
119 {
120  return reinterpret_cast<RawData *>(rawdata)->bpc();
121 }
122 
123 or_cfa_pattern or_rawdata_get_cfa_pattern_type(ORRawDataRef rawdata)
124 {
125  return reinterpret_cast<RawData *>(rawdata)->cfaPattern()->patternType();
126 }
127 
128 ORCfaPatternRef or_rawdata_get_cfa_pattern(ORRawDataRef rawdata)
129 {
130  return reinterpret_cast<ORCfaPatternRef>(reinterpret_cast<RawData *>(rawdata)->cfaPattern());
131 }
132 
133 uint32_t or_rawdata_get_compression(ORRawDataRef rawdata)
134 {
135  return reinterpret_cast<RawData *>(rawdata)->compression();
136 }
137 
138 or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black,
139  uint16_t *white)
140 {
141  RawData *t = reinterpret_cast<RawData *>(rawdata);
142  if (black) {
143  *black = t->blackLevel();
144  }
145  if (white) {
146  *white = t->whiteLevel();
147  }
148  return OR_ERROR_NONE;
149 }
150 
151 const double *or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index,
152  uint32_t *size)
153 {
154  uint32_t matrix_size = 0;
155  RawData *t = reinterpret_cast<RawData *>(rawdata);
156  const double *matrix = nullptr;
157 
158  switch (index) {
159  case 0:
160  matrix = t->getColourMatrix1(matrix_size);
161  break;
162  case 1:
163  matrix = t->getColourMatrix2(matrix_size);
164  break;
165  default:
166  break;
167  }
168 
169  if (!matrix_size) {
170  // a valid pointer might always be returned with size 0.
171  // force a return of nullptr.
172  // XXX change the C++ API instead?
173  matrix = nullptr;
174  }
175  if (size) {
176  *size = matrix_size;
177  }
178 
179  return matrix;
180 }
181 
182 or_error or_rawdata_get_rendered_image(ORRawDataRef rawdata,
183  ORBitmapDataRef bitmapdata,
184  uint32_t options)
185 {
186  RawData *prawdata = reinterpret_cast<RawData *>(rawdata);
187  CHECK_PTR(rawdata, OR_ERROR_NOTAREF);
188  return prawdata->getRenderedImage(
189  *reinterpret_cast<BitmapData *>(bitmapdata), options);
190 }
191 }
192 
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 getRenderedImage(BitmapData &bitmapdata, uint32_t options)
Definition: rawdata.cpp:125
const double * getColourMatrix2(uint32_t &size) const
Definition: rawdata.cpp:228
uint32_t roi_x() const
Definition: bitmapdata.cpp:181
const double * getColourMatrix1(uint32_t &size) const
Definition: rawdata.cpp:211