libopenraw
|
00001 /* 00002 * libopenraw - bitmapdata.cpp 00003 * 00004 * Copyright (C) 2007 Hubert Figuiere 00005 * 00006 * This library is free software: you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #include <cstdlib> 00022 #include <cstring> 00023 #include <iostream> 00024 #include <assert.h> 00025 00026 #include "trace.h" 00027 00028 #include <libopenraw/libopenraw.h> 00029 #include <libopenraw++/rawfile.h> 00030 #include <libopenraw++/bitmapdata.h> 00031 00032 using namespace Debug; 00033 00034 namespace OpenRaw { 00035 00036 class BitmapData::Private { 00037 public: 00039 void *data; 00041 size_t data_size; 00043 DataType data_type; 00045 uint32_t x; 00047 uint32_t y; 00049 uint32_t bpc; 00050 00051 00052 Private() 00053 : data(NULL), 00054 data_size(0), 00055 data_type(OR_DATA_TYPE_NONE), 00056 x(0), y(0), bpc(0) 00057 { 00058 } 00059 00060 ~Private() 00061 { 00062 if (NULL != data) { 00063 free(data); 00064 } 00065 } 00066 private: 00067 Private(const Private &); 00068 Private & operator=(const Private &); 00069 }; 00070 00071 00072 BitmapData::BitmapData() 00073 : d(new BitmapData::Private()) 00074 { 00075 } 00076 00077 BitmapData::~BitmapData() 00078 { 00079 delete d; 00080 } 00081 00082 void BitmapData::swap(BitmapData & with) 00083 { 00084 std::swap(this->d, with.d); 00085 } 00086 00087 BitmapData::DataType BitmapData::dataType() const 00088 { 00089 return d->data_type; 00090 } 00091 00092 void BitmapData::setDataType(BitmapData::DataType _type) 00093 { 00094 d->data_type = _type; 00095 if(d->bpc == 0) { 00096 switch(_type) { 00097 case OR_DATA_TYPE_NONE: 00098 d->bpc = 0; 00099 break; 00100 case OR_DATA_TYPE_COMPRESSED_CFA: 00101 case OR_DATA_TYPE_CFA: 00102 d->bpc = 16; 00103 break; 00104 case OR_DATA_TYPE_PIXMAP_8RGB: 00105 case OR_DATA_TYPE_JPEG: 00106 default: 00107 d->bpc = 8; 00108 } 00109 } 00110 } 00111 00112 void * BitmapData::allocData(const size_t s) 00113 { 00114 Trace(DEBUG1) << "allocate s=" << s << " data =" 00115 << d->data << "\n"; 00116 d->data = calloc(s, 1); 00117 Trace(DEBUG1) << " data =" << d->data << "\n"; 00118 d->data_size = s; 00119 return d->data; 00120 } 00121 00122 size_t BitmapData::size() const 00123 { 00124 return d->data_size; 00125 } 00126 00127 void * BitmapData::data() const 00128 { 00129 return d->data; 00130 } 00131 00132 uint32_t BitmapData::x() const 00133 { 00134 return d->x; 00135 } 00136 00137 uint32_t BitmapData::y() const 00138 { 00139 return d->y; 00140 } 00141 00142 uint32_t BitmapData::bpc() const 00143 { 00144 return d->bpc; 00145 } 00146 00147 00148 void BitmapData::setDimensions(uint32_t _x, uint32_t _y) 00149 { 00150 d->x = _x; 00151 d->y = _y; 00152 } 00153 00154 void BitmapData::setBpc(uint32_t _bpc) 00155 { 00156 d->bpc = _bpc; 00157 } 00158 00159 00160 }