29 #include <libopenraw/consts.h>
30 #include <libopenraw/debug.h>
32 #include "bitmapdata.hpp"
33 #include "rawdata.hpp"
34 #include "mosaicinfo.hpp"
35 #include "rawfile.hpp"
36 #include "render/bimedian_demosaic.hpp"
37 #include "render/grayscale.hpp"
42 static const int MAX_MATRIX_SIZE = 12;
47 uint16_t blackLevel, whiteLevel;
53 ExifPhotometricInterpretation photometricInterpretation;
63 std::vector<uint16_t> slices;
66 uint32_t colourMatrixCount;
67 double colourMatrix2[MAX_MATRIX_SIZE];
68 uint32_t colourMatrix2Count;
72 , blackLevel(0), whiteLevel(0)
73 ,
activeAreaX(0), activeAreaY(0), activeAreaW(0), activeAreaH(0)
74 , photometricInterpretation(EV_PI_CFA)
77 , pos(NULL), offset(0)
81 , colourMatrixCount(0)
82 , colourMatrix2Count(0)
85 memset(colourMatrix2, 0,
sizeof(colourMatrix2));
87 void advance(
size_t s);
97 RawData::getAndExtractRawData(
const char* filename, uint32_t options,
118 d(new RawData::Private(this))
133 uint32_t _x, _y, out_x, out_y;
137 LOGDBG1(
"wrong data type\n");
140 if(d->photometricInterpretation != EV_PI_CFA &&
141 d->photometricInterpretation != EV_PI_LINEAR_RAW) {
142 LOGDBG1(
"only CFA or LinearRaw are supported.\n");
155 src = (uint16_t*)data();
159 if (d->photometricInterpretation == EV_PI_CFA) {
163 pattern = mosaic_info->patternType();
168 uint16_t *dst = (uint16_t *)bitmapdata.allocData(
sizeof(uint16_t) * 3 * _x * _y);
169 err = bimedian_demosaic(src, _x, _y, pattern, dst, out_x, out_y);
177 uint16_t *dst = (uint16_t *)bitmapdata.allocData(
sizeof(uint16_t)
180 err = grayscale_to_rgb(src, _x, _y, dst);
189 uint16_t RawData::blackLevel()
const
191 return d->blackLevel;
194 uint16_t RawData::whiteLevel()
const
196 return d->whiteLevel;
199 void RawData::setBlackLevel(uint16_t m)
204 void RawData::setWhiteLevel(uint16_t m)
214 uint32_t RawData::activeAreaY()
const
216 return d->activeAreaY;
219 uint32_t RawData::activeAreaWidth()
const
221 return d->activeAreaW;
224 uint32_t RawData::activeAreaHeight()
const
226 return d->activeAreaH;
229 void RawData::setActiveArea(uint32_t x, uint32_t y, uint32_t w, uint32_t h)
237 void RawData::setPhotometricInterpretation(ExifPhotometricInterpretation pi)
239 d->photometricInterpretation = pi;
242 ExifPhotometricInterpretation RawData::getPhotometricInterpretation()
const
244 return d->photometricInterpretation;
250 matrixSize = d->colourMatrixCount;
254 void RawData::setColourMatrix1(
const double* matrix, uint32_t matrixSize)
256 if(matrixSize > MAX_MATRIX_SIZE) {
257 matrixSize = MAX_MATRIX_SIZE;
259 for(uint32_t i = 0; i < matrixSize; i++) {
262 d->colourMatrixCount = matrixSize;
267 matrixSize = d->colourMatrix2Count;
268 return d->colourMatrix2;
271 void RawData::setColourMatrix2(
const double* matrix, uint32_t matrixSize)
273 if(matrixSize > MAX_MATRIX_SIZE) {
274 matrixSize = MAX_MATRIX_SIZE;
276 for(uint32_t i = 0; i < matrixSize; i++) {
277 d->colourMatrix2[i] = matrix[i];
279 d->colourMatrix2Count = matrixSize;
285 std::swap(this->d, with.d);
288 void * RawData::allocData(
const size_t s)
290 void * p = BitmapData::allocData(s);
291 d->pos = (uint8_t*)p;
301 if (d->activeAreaW == 0) {
306 if (d->activeAreaH == 0) {
308 }
else if (d->activeAreaH + d->activeAreaY > y) {
309 d->activeAreaH = y - d->activeAreaY;
311 if (d->slices.size()) {
319 void RawData::setSlices(
const std::vector<uint16_t> & slices)
337 return d->mosaic_info;
340 void RawData::setMosaicInfo(
const MosaicInfo* mosaic_info)
342 d->mosaic_info = mosaic_info;
345 void RawData::setCompression(uint32_t t)
350 uint32_t RawData::compression()
const
352 return d->compression;
358 assert(d->offset <
size());
359 *(d->pos) = c & 0xff;
360 *(d->pos + 1) = (c >> 8) & 0xff;
361 d->advance(
sizeof(c));
365 void RawData::Private::nextRow()
367 uint32_t w =
self->width() * 2;
368 uint32_t row = offset / w;
370 if (row == self->height()) {
375 offset = row * w + sliceOffset * 2;
376 pos = (uint8_t*)(self->data()) + offset;
380 void RawData::Private::nextSlice()
382 if(slices.size() > slice) {
383 sliceOffset += slices[slice];
386 if(slices.size() > slice) {
387 sliceWidth = slices[slice];
394 void RawData::Private::advance(
size_t s)
396 if(offset + s - row_offset >= sliceWidth * 2) {
Represent some bitmap data.
void setDataType(DataType _type)
Set the data type.
uint32_t width() const
Width of the image data.
uint32_t height() const
Height of the image data.
void swap(BitmapData &with)
Swap the two objects data.
size_t size() const
Get the size of the data.
virtual void setDimensions(uint32_t x, uint32_t y)
Set the pixel dimensions of the bitmap.
DataType dataType() const
Get the data type.
Info on the mosaic for the Colour Filter Array.
static const MosaicInfo * twoByTwoPattern(::or_cfa_pattern)
Factory to return a singleton instance of the right pattern.
double colourMatrix[MAX_MATRIX_SIZE]
Represent camera raw data.
const double * getColourMatrix1(uint32_t &size) const
uint32_t activeAreaX() const
RawData & append(uint16_t c)
const MosaicInfo * mosaicInfo() const
::or_error getRenderedImage(BitmapData &bitmapdata, uint32_t options)
const double * getColourMatrix2(uint32_t &size) const
virtual void setDimensions(uint32_t x, uint32_t y) override
Set the pixel dimensions of the bitmap.
::or_error getRawData(RawData &rawdata, uint32_t options)
Get the RAW data.
static RawFile * newRawFile(const char *_filename, Type typeHint=OR_RAWFILE_TYPE_UNKNOWN)
Factory method to create the proper RawFile instance.
or_cfa_pattern
CFA pattern types.
or_error
Error codes returned by libopenraw.
@ OR_DATA_TYPE_PIXMAP_16RGB
@ OR_ERROR_INVALID_FORMAT
Global namespace for libopenraw.