libopenraw
bitmapdata.cpp
1/*
2 * libopenraw - bitmapdata.cpp
3 *
4 * Copyright (C) 2007-2017 Hubert Figuière
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
21#include <stddef.h>
22#include <stdint.h>
23#include <algorithm>
24#include <cstdlib>
25
26#include <libopenraw/consts.h>
27#include <libopenraw/debug.h>
28
29#include "trace.hpp"
30#include "bitmapdata.hpp"
31
32using namespace Debug;
33
34namespace OpenRaw {
35
37public:
39 void *data;
41 size_t data_size;
43 DataType data_type;
45 uint32_t width;
47 uint32_t height;
49 uint32_t bpc;
51 uint32_t roi_x;
52 uint32_t roi_y;
53 uint32_t roi_w;
54 uint32_t roi_h;
55
56 Private()
57 : data(nullptr)
58 , data_size(0)
59 , data_type(OR_DATA_TYPE_NONE)
60 , width(0)
61 , height(0)
62 , bpc(0)
63 , roi_x(0)
64 , roi_y(0)
65 , roi_w(0)
66 , roi_h(0)
67 {
68 }
69
70 ~Private()
71 {
72 if (data) {
73 free(data);
74 }
75 }
76
77 Private(const Private &) = delete;
78 Private &operator=(const Private &) = delete;
79};
80
81BitmapData::BitmapData() : d(new BitmapData::Private())
82{
83}
84
85BitmapData::~BitmapData()
86{
87 delete d;
88}
89
90void BitmapData::swap(BitmapData &with)
91{
92 std::swap(this->d, with.d);
93}
94
95BitmapData::DataType BitmapData::dataType() const
96{
97 return d->data_type;
98}
99
100void BitmapData::setDataType(BitmapData::DataType _type)
101{
102 d->data_type = _type;
103 if (d->bpc == 0) {
104 switch (_type) {
105 case OR_DATA_TYPE_NONE:
106 d->bpc = 0;
107 break;
108 case OR_DATA_TYPE_COMPRESSED_RAW:
109 case OR_DATA_TYPE_RAW:
110 d->bpc = 16;
111 break;
112 case OR_DATA_TYPE_PIXMAP_8RGB:
113 case OR_DATA_TYPE_JPEG:
114 default:
115 d->bpc = 8;
116 }
117 }
118}
119
120void *BitmapData::allocData(const size_t s)
121{
122 LOGDBG1("allocate s=%lu data =%p\n", s, d->data);
123 d->data = calloc(s, 1);
124 LOGDBG1(" data =%p\n", d->data);
125 d->data_size = s;
126 return d->data;
127}
128
129size_t BitmapData::size() const
130{
131 return d->data_size;
132}
133
134void *BitmapData::data() const
135{
136 return d->data;
137}
138
139uint32_t BitmapData::x() const
140{
141 return d->width;
142}
143
144uint32_t BitmapData::width() const
145{
146 return d->width;
147}
148
149uint32_t BitmapData::y() const
150{
151 return d->height;
152}
153
154uint32_t BitmapData::height() const
155{
156 return d->height;
157}
158
159uint32_t BitmapData::bpc() const
160{
161 return d->bpc;
162}
163
164void BitmapData::setBpc(uint32_t _bpc)
165{
166 d->bpc = _bpc;
167}
168
169void BitmapData::setDimensions(uint32_t _width, uint32_t _height)
170{
171 d->width = _width;
172 d->height = _height;
173 if (d->roi_w == 0) {
174 d->roi_w = _width;
175 }
176 if (d->roi_h == 0) {
177 d->roi_h = _height;
178 }
179}
180
181uint32_t BitmapData::roi_x() const
182{
183 return d->roi_x;
184}
185
186uint32_t BitmapData::roi_y() const
187{
188 return d->roi_y;
189}
190
191uint32_t BitmapData::roi_width() const
192{
193 return d->roi_w;
194}
195
196uint32_t BitmapData::roi_height() const
197{
198 return d->roi_h;
199}
200
201void BitmapData::setRoi(uint32_t _x, uint32_t _y, uint32_t w, uint32_t h)
202{
203 d->roi_x = _x;
204 d->roi_y = _y;
205 d->roi_w = w;
206 d->roi_h = h;
207}
208}
void setDataType(DataType _type)
uint32_t roi_x() const
void swap(BitmapData &with)
void setBpc(uint32_t _bpc)
size_t size() const
virtual void setDimensions(uint32_t x, uint32_t y)
OR_DEPRECATED uint32_t x() const
DataType dataType() const
OR_DEPRECATED uint32_t y() const
uint32_t bpc() const
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard....
Definition arwfile.cpp:30