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 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
* libopenraw - bitmapdata.cpp
*
* Copyright (C) 2007-2017 Hubert Figuière
*
* 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 <stddef.h>
#include <stdint.h>
#include <algorithm>
#include <cstdlib>
#include <libopenraw/consts.h>
#include <libopenraw/debug.h>
#include "trace.hpp"
#include "bitmapdata.hpp"
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;
/** width dimension in pixels of image data */
uint32_t width;
/** height dimension in pixels of image data */
uint32_t height;
/** bpc bit per channel. 0 is not a valid value */
uint32_t bpc;
/** region of interest */
uint32_t roi_x;
uint32_t roi_y;
uint32_t roi_w;
uint32_t roi_h;
Private()
: data(nullptr)
, data_size(0)
, data_type(OR_DATA_TYPE_NONE)
, width(0)
, height(0)
, bpc(0)
, roi_x(0)
, roi_y(0)
, roi_w(0)
, roi_h(0)
{
}
~Private()
{
if (data) {
free(data);
}
}
Private(const Private &) = delete;
Private &operator=(const Private &) = delete;
};
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_RAW:
case OR_DATA_TYPE_RAW:
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)
{
LOGDBG1("allocate s=%lu data =%p\n", s, d->data);
d->data = calloc(s, 1);
LOGDBG1(" data =%p\n", d->data);
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->width;
}
uint32_t BitmapData::width() const
{
return d->width;
}
uint32_t BitmapData::y() const
{
return d->height;
}
uint32_t BitmapData::height() const
{
return d->height;
}
uint32_t BitmapData::bpc() const
{
return d->bpc;
}
void BitmapData::setBpc(uint32_t _bpc)
{
d->bpc = _bpc;
}
void BitmapData::setDimensions(uint32_t _width, uint32_t _height)
{
d->width = _width;
d->height = _height;
if (d->roi_w == 0) {
d->roi_w = _width;
}
if (d->roi_h == 0) {
d->roi_h = _height;
}
}
uint32_t BitmapData::roi_x() const
{
return d->roi_x;
}
uint32_t BitmapData::roi_y() const
{
return d->roi_y;
}
uint32_t BitmapData::roi_width() const
{
return d->roi_w;
}
uint32_t BitmapData::roi_height() const
{
return d->roi_h;
}
void BitmapData::setRoi(uint32_t _x, uint32_t _y, uint32_t w, uint32_t h)
{
d->roi_x = _x;
d->roi_y = _y;
d->roi_w = w;
d->roi_h = h;
}
}
|