libopenraw
|
00001 /* 00002 * libopenraw - dngfile.cpp 00003 * 00004 * Copyright (C) 2006-2008 Hubert Figuiere 00005 * Copyright (C) 2008 Novell, Inc. 00006 * 00007 * This library is free software: you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * as published by the Free Software Foundation, either version 3 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library. If not, see 00019 * <http://www.gnu.org/licenses/>. 00020 */ 00021 00022 00023 #include <libopenraw/libopenraw.h> 00024 #include <libopenraw++/thumbnail.h> 00025 #include <libopenraw++/rawdata.h> 00026 00027 #include <boost/scoped_ptr.hpp> 00028 00029 #include "trace.h" 00030 #include "io/file.h" 00031 #include "io/memstream.h" 00032 #include "ifdfilecontainer.h" 00033 #include "jfifcontainer.h" 00034 #include "ljpegdecompressor.h" 00035 #include "ifd.h" 00036 #include "dngfile.h" 00037 00038 using namespace Debug; 00039 00040 namespace OpenRaw { 00041 00042 00043 namespace Internals { 00044 const IFDFile::camera_ids_t DNGFile::s_def[] = { 00045 { "PENTAX K10D ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX, 00046 OR_TYPEID_PENTAX_K10D_DNG) }, 00047 { "R9 - Digital Back DMR", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA, 00048 OR_TYPEID_LEICA_DMR) }, 00049 { "M8 Digital Camera", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA, 00050 OR_TYPEID_LEICA_M8) }, 00051 { "LEICA X1 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA, 00052 OR_TYPEID_LEICA_X1) }, 00053 { "GR DIGITAL 2 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_RICOH, 00054 OR_TYPEID_RICOH_GR2) }, 00055 { "GXR ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_RICOH, 00056 OR_TYPEID_RICOH_GXR) }, 00057 { "SAMSUNG GX10 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG, 00058 OR_TYPEID_SAMSUNG_GX10) }, 00059 { "Pro 815 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG, 00060 OR_TYPEID_SAMSUNG_PRO815) }, 00061 { 0, OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_ADOBE, 00062 OR_TYPEID_ADOBE_DNG_GENERIC) } 00063 }; 00064 00065 RawFile *DNGFile::factory(IO::Stream *s) 00066 { 00067 return new DNGFile(s); 00068 } 00069 00070 00071 DNGFile::DNGFile(IO::Stream *s) 00072 : TiffEpFile(s, OR_RAWFILE_TYPE_DNG) 00073 { 00074 _setIdMap(s_def); 00075 } 00076 00077 DNGFile::~DNGFile() 00078 { 00079 } 00080 00081 ::or_error DNGFile::_getRawData(RawData & data, uint32_t options) 00082 { 00083 ::or_error ret = OR_ERROR_NONE; 00084 if(!m_cfaIfd) { 00085 m_cfaIfd = _locateCfaIfd(); 00086 } 00087 00088 Trace(DEBUG1) << "_getRawData()\n"; 00089 00090 if (m_cfaIfd) { 00091 ret = _getRawDataFromDir(data, m_cfaIfd); 00092 00093 if(ret == OR_ERROR_NONE) { 00094 uint16_t compression = 0; 00095 if (m_cfaIfd->getValue(IFD::EXIF_TAG_COMPRESSION, compression) && 00096 compression == 7) { 00097 // if the option is not set, decompress 00098 if ((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) { 00099 boost::scoped_ptr<IO::Stream> s(new IO::MemStream(data.data(), 00100 data.size())); 00101 s->open(); // TODO check success 00102 boost::scoped_ptr<JFIFContainer> jfif(new JFIFContainer(s.get(), 0)); 00103 LJpegDecompressor decomp(s.get(), jfif.get()); 00104 RawData *dData = decomp.decompress(); 00105 if (dData != NULL) { 00106 dData->setCfaPattern(data.cfaPattern()); 00107 data.swap(*dData); 00108 delete dData; 00109 } 00110 } 00111 } 00112 else { 00113 data.setDataType(OR_DATA_TYPE_CFA); 00114 } 00115 } 00116 else { 00117 Trace(ERROR) << "couldn't find raw data\n"; 00118 } 00119 } 00120 else { 00121 ret = OR_ERROR_NOT_FOUND; 00122 } 00123 return ret; 00124 } 00125 00126 } 00127 }