libopenraw
bitmapdata.cpp
1 /*
2  * libopenraw - bitmapdata.cpp
3  *
4  * Copyright (C) 2007 Hubert Figuiere
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 <cstdlib>
22 #include <cstring>
23 #include <iostream>
24 #include <assert.h>
25 
26 #include "trace.h"
27 
28 #include <libopenraw/libopenraw.h>
29 #include <libopenraw++/rawfile.h>
30 #include <libopenraw++/bitmapdata.h>
31 
32 using namespace Debug;
33 
34 namespace OpenRaw {
35 
37  public:
39  void *data;
41  size_t data_size;
43  DataType data_type;
45  uint32_t x;
47  uint32_t y;
49  uint32_t bpc;
50 
51 
52  Private()
53  : data(NULL),
54  data_size(0),
55  data_type(OR_DATA_TYPE_NONE),
56  x(0), y(0), bpc(0)
57  {
58  }
59 
60  ~Private()
61  {
62  if (NULL != data) {
63  free(data);
64  }
65  }
66  private:
67  Private(const Private &);
68  Private & operator=(const Private &);
69  };
70 
71 
72  BitmapData::BitmapData()
73  : d(new BitmapData::Private())
74  {
75  }
76 
77  BitmapData::~BitmapData()
78  {
79  delete d;
80  }
81 
83  {
84  std::swap(this->d, with.d);
85  }
86 
87  BitmapData::DataType BitmapData::dataType() const
88  {
89  return d->data_type;
90  }
91 
92  void BitmapData::setDataType(BitmapData::DataType _type)
93  {
94  d->data_type = _type;
95  if(d->bpc == 0) {
96  switch(_type) {
97  case OR_DATA_TYPE_NONE:
98  d->bpc = 0;
99  break;
100  case OR_DATA_TYPE_COMPRESSED_CFA:
101  case OR_DATA_TYPE_CFA:
102  d->bpc = 16;
103  break;
104  case OR_DATA_TYPE_PIXMAP_8RGB:
105  case OR_DATA_TYPE_JPEG:
106  default:
107  d->bpc = 8;
108  }
109  }
110  }
111 
112  void * BitmapData::allocData(const size_t s)
113  {
114  Trace(DEBUG1) << "allocate s=" << s << " data ="
115  << d->data << "\n";
116  d->data = calloc(s, 1);
117  Trace(DEBUG1) << " data =" << d->data << "\n";
118  d->data_size = s;
119  return d->data;
120  }
121 
122  size_t BitmapData::size() const
123  {
124  return d->data_size;
125  }
126 
127  void * BitmapData::data() const
128  {
129  return d->data;
130  }
131 
132  uint32_t BitmapData::x() const
133  {
134  return d->x;
135  }
136 
137  uint32_t BitmapData::y() const
138  {
139  return d->y;
140  }
141 
142  uint32_t BitmapData::bpc() const
143  {
144  return d->bpc;
145  }
146 
147 
148  void BitmapData::setDimensions(uint32_t _x, uint32_t _y)
149  {
150  d->x = _x;
151  d->y = _y;
152  }
153 
154  void BitmapData::setBpc(uint32_t _bpc)
155  {
156  d->bpc = _bpc;
157  }
158 
159 
160 }