1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* libopenraw - bitmapdata.cpp
*
* Copyright (C) 2007 Hubert Figuiere
*
* This library is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <assert.h>
#include "debug.h"
#include <libopenraw/libopenraw.h>
#include <libopenraw++/rawfile.h>
#include <libopenraw++/bitmapdata.h>
using namespace Debug;
namespace OpenRaw {
class BitmapData::Private {
public:
/** raw data */
void *data;
/** size in bytes of raw data */
size_t data_size;
/** type of thumbnail data */
DataType data_type;
/** x dimension in pixels of thumbnail data */
uint32_t x;
/** y dimension in pixels of thumbnail data */
uint32_t y;
/** bpc bit per channel. 0 is not a valid value */
uint32_t bpc;
Private()
: data(NULL),
data_size(0),
data_type(OR_DATA_TYPE_NONE),
x(0), y(0), bpc(0)
{
}
~Private()
{
if (NULL != data) {
free(data);
}
}
private:
Private(const Private &);
Private & operator=(const Private &);
};
BitmapData::BitmapData()
: d(new BitmapData::Private())
{
}
BitmapData::~BitmapData()
{
delete d;
}
void BitmapData::swap(BitmapData & with)
{
std::swap(this->d, with.d);
}
BitmapData::DataType BitmapData::dataType() const
{
return d->data_type;
}
void BitmapData::setDataType(BitmapData::DataType _type)
{
d->data_type = _type;
if(d->bpc == 0) {
switch(_type) {
case OR_DATA_TYPE_NONE:
d->bpc = 0;
break;
case OR_DATA_TYPE_COMPRESSED_CFA:
case OR_DATA_TYPE_CFA:
d->bpc = 16;
break;
case OR_DATA_TYPE_PIXMAP_8RGB:
case OR_DATA_TYPE_JPEG:
default:
d->bpc = 8;
}
}
}
void * BitmapData::allocData(const size_t s)
{
Trace(DEBUG1) << "allocate s=" << s << " data ="
<< d->data << "\n";
d->data = calloc(s, 1);
Trace(DEBUG1) << " data =" << d->data << "\n";
d->data_size = s;
return d->data;
}
size_t BitmapData::size() const
{
return d->data_size;
}
void * BitmapData::data() const
{
return d->data;
}
uint32_t BitmapData::x() const
{
return d->x;
}
uint32_t BitmapData::y() const
{
return d->y;
}
uint32_t BitmapData::bpc() const
{
return d->bpc;
}
void BitmapData::setDimensions(uint32_t _x, uint32_t _y)
{
d->x = _x;
d->y = _y;
}
void BitmapData::setBpc(uint32_t _bpc)
{
d->bpc = _bpc;
}
}
|