libopenraw  0.3.7
bitmapdata.cpp
1 /*
2  * libopenraw - bitmapdata.cpp
3  *
4  * Copyright (C) 2007-2020 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 
32 using namespace Debug;
33 
34 namespace OpenRaw {
35 
37 public:
39  void *data;
41  size_t data_size;
45  uint32_t width;
47  uint32_t height;
49  uint32_t bpc;
50 
51  Private()
52  : data(nullptr)
53  , data_size(0)
54  , data_type(OR_DATA_TYPE_NONE)
55  , width(0)
56  , height(0)
57  , bpc(0)
58  {
59  }
60 
61  ~Private()
62  {
63  if (data) {
64  free(data);
65  }
66  }
67 
68  Private(const Private &) = delete;
69  Private &operator=(const Private &) = delete;
70 };
71 
72 BitmapData::BitmapData() : d(new BitmapData::Private())
73 {
74 }
75 
76 BitmapData::~BitmapData()
77 {
78  delete d;
79 }
80 
82 {
83  std::swap(this->d, with.d);
84 }
85 
87 {
88  return d->data_type;
89 }
90 
92 {
93  d->data_type = _type;
94  if (d->bpc == 0) {
95  switch (_type) {
96  case OR_DATA_TYPE_NONE:
97  d->bpc = 0;
98  break;
100  case OR_DATA_TYPE_RAW:
101  d->bpc = 16;
102  break;
104  case OR_DATA_TYPE_JPEG:
105  default:
106  d->bpc = 8;
107  }
108  }
109 }
110 
111 void *BitmapData::allocData(const size_t s)
112 {
113  LOGDBG1("allocate s=%lu data =%p\n", (LSIZE)s, d->data);
114  d->data = calloc(s, 1);
115  LOGDBG1(" data =%p\n", d->data);
116  d->data_size = s;
117  return d->data;
118 }
119 
120 size_t BitmapData::size() const
121 {
122  return d->data_size;
123 }
124 
126 {
127  if (size < d->data_size) {
128  d->data_size = size;
129  }
130 }
131 
132 void *BitmapData::data() const
133 {
134  return d->data;
135 }
136 
137 uint32_t BitmapData::width() const
138 {
139  return d->width;
140 }
141 
142 uint32_t BitmapData::height() const
143 {
144  return d->height;
145 }
146 
147 uint32_t BitmapData::bpc() const
148 {
149  return d->bpc;
150 }
151 
152 void BitmapData::setBpc(uint32_t _bpc)
153 {
154  d->bpc = _bpc;
155 }
156 
157 void BitmapData::setDimensions(uint32_t _width, uint32_t _height)
158 {
159  d->width = _width;
160  d->height = _height;
161 }
162 
163 }
Represent some bitmap data.
Definition: bitmapdata.hpp:30
void setDataType(DataType _type)
Set the data type.
Definition: bitmapdata.cpp:91
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
void swap(BitmapData &with)
Swap the two objects data.
Definition: bitmapdata.cpp:81
void setBpc(uint32_t _bpc)
Set bit per channel.
Definition: bitmapdata.cpp:152
size_t size() const
Get the size of the data.
Definition: bitmapdata.cpp:120
virtual void setDimensions(uint32_t x, uint32_t y)
Set the pixel dimensions of the bitmap.
Definition: bitmapdata.cpp:157
DataType dataType() const
Get the data type.
Definition: bitmapdata.cpp:86
uint32_t bpc() const
Bit per channel.
Definition: bitmapdata.cpp:147
void adjustSize(size_t size)
Definition: bitmapdata.cpp:125
or_data_type
Data types.
Definition: consts.h:80
@ OR_DATA_TYPE_JPEG
Definition: consts.h:84
@ OR_DATA_TYPE_COMPRESSED_RAW
Definition: consts.h:88
@ OR_DATA_TYPE_RAW
Definition: consts.h:87
@ OR_DATA_TYPE_PIXMAP_8RGB
Definition: consts.h:82
Global namespace for libopenraw.
Definition: arwfile.cpp:29