libopenraw  0.3.7
rawdata.cpp
1 /* -*- mode:c++; indent-tabs-mode:nil; c-basic-offset:4; tab-width:4; -*- */
2 /*
3  * libopenraw - rawdata.cpp
4  *
5  * Copyright (C) 2007-2019 Hubert Figuiere
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 /* @brief C api for rawdata
22  */
23 
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <stdlib.h>
27 
28 #include <libopenraw/consts.h>
29 #include <libopenraw/types.h>
30 
31 #include "capi.h"
32 #include "rawdata.hpp"
33 #include "mosaicinfo.hpp"
34 
35 namespace OpenRaw {
36 class BitmapData;
37 }
38 
39 using OpenRaw::RawData;
41 
42 extern "C" {
43 
45 #define CHECK_PTR(p, r) \
46  if (p == NULL) { \
47  return r; \
48  }
49 
50 API_EXPORT
51 or_error or_get_extract_rawdata(const char *filename, uint32_t options,
52  ORRawDataRef *rawdata)
53 {
54  or_error ret = OR_ERROR_NONE;
55 
56  RawData **pRawData = reinterpret_cast<RawData **>(rawdata);
57  *pRawData = RawData::getAndExtractRawData(filename, options, ret);
58  return ret;
59 }
60 
61 API_EXPORT
63 {
64  RawData *rawdata = new RawData();
65  return reinterpret_cast<ORRawDataRef>(rawdata);
66 }
67 
68 API_EXPORT
70 {
71  if (rawdata == NULL) {
72  return OR_ERROR_NOTAREF;
73  }
74  delete reinterpret_cast<RawData *>(rawdata);
75  return OR_ERROR_NONE;
76 }
77 
78 API_EXPORT
80 {
81  return reinterpret_cast<RawData *>(rawdata)->dataType();
82 }
83 
84 API_EXPORT
86 {
87  return reinterpret_cast<RawData *>(rawdata)->data();
88 }
89 
90 API_EXPORT
92 {
93  return reinterpret_cast<RawData *>(rawdata)->size();
94 }
95 
96 API_EXPORT
97 void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width,
98  uint32_t *height)
99 {
100  RawData *t = reinterpret_cast<RawData *>(rawdata);
101  if (width != NULL) {
102  *width = t->width();
103  }
104  if (height != NULL) {
105  *height = t->height();
106  }
107 }
108 
109 API_EXPORT
110 or_error or_rawdata_get_active_area(ORRawDataRef rawdata, uint32_t *x, uint32_t *y,
111  uint32_t *width, uint32_t *height)
112 {
113  RawData *t = reinterpret_cast<RawData *>(rawdata);
114  if (x != NULL) {
115  *x = t->activeAreaX();
116  }
117  if (y != NULL) {
118  *y = t->activeAreaY();
119  }
120  if (width != NULL) {
121  *width = t->activeAreaWidth();
122  }
123  if (height != NULL) {
124  *height = t->activeAreaHeight();
125  }
126  return OR_ERROR_NONE;
127 }
128 
129 API_EXPORT
130 uint32_t or_rawdata_bpc(ORRawDataRef rawdata)
131 {
132  return reinterpret_cast<RawData *>(rawdata)->bpc();
133 }
134 
135 API_EXPORT
137 {
138  return reinterpret_cast<RawData *>(rawdata)->mosaicInfo()->patternType();
139 }
140 
141 API_EXPORT
143 {
144  return reinterpret_cast<ORMosaicInfoRef>(reinterpret_cast<RawData *>(rawdata)->mosaicInfo());
145 }
146 
147 API_EXPORT
149 {
150  return reinterpret_cast<RawData *>(rawdata)->compression();
151 }
152 
153 API_EXPORT
154 or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black,
155  uint16_t *white)
156 {
157  RawData *t = reinterpret_cast<RawData *>(rawdata);
158  if (black) {
159  *black = t->blackLevel();
160  }
161  if (white) {
162  *white = t->whiteLevel();
163  }
164  return OR_ERROR_NONE;
165 }
166 
167 API_EXPORT
168 const double *or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index,
169  uint32_t *size)
170 {
171  uint32_t matrix_size = 0;
172  RawData *t = reinterpret_cast<RawData *>(rawdata);
173  const double *matrix = nullptr;
174 
175  switch (index) {
176  case 0:
177  matrix = t->getColourMatrix1(matrix_size);
178  break;
179  case 1:
180  matrix = t->getColourMatrix2(matrix_size);
181  break;
182  default:
183  break;
184  }
185 
186  if (!matrix_size) {
187  // a valid pointer might always be returned with size 0.
188  // force a return of nullptr.
189  // XXX change the C++ API instead?
190  matrix = nullptr;
191  }
192  if (size) {
193  *size = matrix_size;
194  }
195 
196  return matrix;
197 }
198 
199 API_EXPORT
201  ORBitmapDataRef bitmapdata,
202  uint32_t options)
203 {
204  RawData *prawdata = reinterpret_cast<RawData *>(rawdata);
205  CHECK_PTR(rawdata, OR_ERROR_NOTAREF);
206  return prawdata->getRenderedImage(
207  *reinterpret_cast<BitmapData *>(bitmapdata), options);
208 }
209 }
210 
Represent some bitmap data.
Definition: bitmapdata.hpp:30
uint32_t width() const
Width of the image data.
Definition: bitmapdata.cpp:137
uint32_t height() const
Height of the image data.
Definition: bitmapdata.cpp:142
Represent camera raw data.
Definition: rawdata.hpp:38
const double * getColourMatrix1(uint32_t &size) const
Definition: rawdata.cpp:248
uint32_t activeAreaX() const
Definition: rawdata.cpp:209
::or_error getRenderedImage(BitmapData &bitmapdata, uint32_t options)
Definition: rawdata.cpp:131
const double * getColourMatrix2(uint32_t &size) const
Definition: rawdata.cpp:265
const struct _MosaicInfo * ORMosaicInfoRef
A MosaicInfo object.
Definition: mosaicinfo.h:40
struct _RawData * ORRawDataRef
RawData reference.
Definition: types.h:31
or_cfa_pattern
CFA pattern types.
Definition: consts.h:94
or_data_type
Data types.
Definition: consts.h:80
or_error
Error codes returned by libopenraw.
Definition: consts.h:42
struct _BitmapData * ORBitmapDataRef
BitmapData reference.
Definition: types.h:32
@ OR_ERROR_NONE
Definition: consts.h:43
@ OR_ERROR_NOTAREF
Definition: consts.h:45
API_EXPORT void or_rawdata_dimensions(ORRawDataRef rawdata, uint32_t *width, uint32_t *height)
Get the RAW data dimensions in pixels.
Definition: rawdata.cpp:97
API_EXPORT ORRawDataRef or_rawdata_new(void)
Allocate a new RawData.
Definition: rawdata.cpp:62
API_EXPORT const double * or_rawdata_get_colour_matrix(ORRawDataRef rawdata, uint32_t index, uint32_t *size)
Get the colour matrix.
Definition: rawdata.cpp:168
API_EXPORT or_error or_rawdata_get_rendered_image(ORRawDataRef rawdata, ORBitmapDataRef bitmapdata, uint32_t options)
Get the rendered image from the raw data.
Definition: rawdata.cpp:200
API_EXPORT or_error or_rawdata_get_levels(ORRawDataRef rawdata, uint16_t *black, uint16_t *white)
Return the levels values for the raw data.
Definition: rawdata.cpp:154
API_EXPORT uint32_t or_rawdata_bpc(ORRawDataRef rawdata)
Return the bits per component.
Definition: rawdata.cpp:130
API_EXPORT or_error or_rawdata_get_active_area(ORRawDataRef rawdata, uint32_t *x, uint32_t *y, uint32_t *width, uint32_t *height)
Get the active area for the raw data.
Definition: rawdata.cpp:110
API_EXPORT size_t or_rawdata_data_size(ORRawDataRef rawdata)
Get the size of the RAW data in bytes.
Definition: rawdata.cpp:91
API_EXPORT uint32_t or_rawdata_get_compression(ORRawDataRef rawdata)
Return the compression type for the RawData.
Definition: rawdata.cpp:148
API_EXPORT ORMosaicInfoRef or_rawdata_get_mosaicinfo(ORRawDataRef rawdata)
Return the mosaic info.
Definition: rawdata.cpp:142
API_EXPORT or_cfa_pattern or_rawdata_get_cfa_pattern_type(ORRawDataRef rawdata)
Return the bayer type for the raw data.
Definition: rawdata.cpp:136
API_EXPORT or_data_type or_rawdata_format(ORRawDataRef rawdata)
Get the format of the RAW data.
Definition: rawdata.cpp:79
API_EXPORT or_error or_get_extract_rawdata(const char *filename, uint32_t options, ORRawDataRef *rawdata)
Extract the RAW data from the raw file.
Definition: rawdata.cpp:51
API_EXPORT void * or_rawdata_data(ORRawDataRef rawdata)
Get a pointer to the RAW data.
Definition: rawdata.cpp:85
API_EXPORT or_error or_rawdata_release(ORRawDataRef rawdata)
Release the rawdata.
Definition: rawdata.cpp:69
Global namespace for libopenraw.
Definition: arwfile.cpp:29