dngfile.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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 "debug.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 { "GR DIGITAL 2 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_RICOH,
00052 OR_TYPEID_RICOH_GR2) },
00053 { "SAMSUNG GX10 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG,
00054 OR_TYPEID_SAMSUNG_GX10) },
00055 { "Pro 815 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG,
00056 OR_TYPEID_SAMSUNG_PRO815) },
00057 { 0, OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_ADOBE,
00058 OR_TYPEID_ADOBE_DNG_GENERIC) }
00059 };
00060
00061 RawFile *DNGFile::factory(IO::Stream *s)
00062 {
00063 return new DNGFile(s);
00064 }
00065
00066
00067 DNGFile::DNGFile(IO::Stream *s)
00068 : TiffEpFile(s, OR_RAWFILE_TYPE_DNG)
00069 {
00070 _setIdMap(s_def);
00071 }
00072
00073 DNGFile::~DNGFile()
00074 {
00075 }
00076
00077 ::or_error DNGFile::_getRawData(RawData & data, uint32_t options)
00078 {
00079 ::or_error ret = OR_ERROR_NONE;
00080 if(!m_cfaIfd) {
00081 m_cfaIfd = _locateCfaIfd();
00082 }
00083
00084 Trace(DEBUG1) << "_getRawData()\n";
00085
00086 if (m_cfaIfd) {
00087 ret = _getRawDataFromDir(data, m_cfaIfd);
00088
00089 if(ret == OR_ERROR_NONE) {
00090 uint16_t compression = 0;
00091 if (m_cfaIfd->getValue(IFD::EXIF_TAG_COMPRESSION, compression) &&
00092 compression == 7) {
00093
00094 if ((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) {
00095 boost::scoped_ptr<IO::Stream> s(new IO::MemStream(data.data(),
00096 data.size()));
00097 s->open();
00098 boost::scoped_ptr<JFIFContainer> jfif(new JFIFContainer(s.get(), 0));
00099 LJpegDecompressor decomp(s.get(), jfif.get());
00100 RawData *dData = decomp.decompress();
00101 if (dData != NULL) {
00102 dData->setCfaPattern(data.cfaPattern());
00103 data.swap(*dData);
00104 delete dData;
00105 }
00106 }
00107 }
00108 else {
00109 data.setDataType(OR_DATA_TYPE_CFA);
00110 }
00111 }
00112 else {
00113 Trace(ERROR) << "couldn't find raw data\n";
00114 }
00115 }
00116 else {
00117 ret = OR_ERROR_NOT_FOUND;
00118 }
00119 return ret;
00120 }
00121
00122 }
00123 }