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
00045 RawFile *DNGFile::factory(const char* _filename)
00046 {
00047 return new DNGFile(_filename);
00048 }
00049
00050
00051 DNGFile::DNGFile(const char* _filename)
00052 : TiffEpFile(_filename, OR_RAWFILE_TYPE_DNG)
00053 {
00054
00055 }
00056
00057 DNGFile::~DNGFile()
00058 {
00059 }
00060
00061 ::or_error DNGFile::_getRawData(RawData & data, uint32_t options)
00062 {
00063 ::or_error ret = OR_ERROR_NONE;
00064 if(!m_cfaIfd) {
00065 m_cfaIfd = _locateCfaIfd();
00066 }
00067
00068 Trace(DEBUG1) << "_getRawData()\n";
00069
00070 if (m_cfaIfd) {
00071 ret = _getRawDataFromDir(data, m_cfaIfd);
00072
00073 if(ret == OR_ERROR_NONE) {
00074 uint16_t compression = 0;
00075 if (m_cfaIfd->getValue(IFD::EXIF_TAG_COMPRESSION, compression) &&
00076 compression == 7) {
00077
00078 if ((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) {
00079 boost::scoped_ptr<IO::Stream> s(new IO::MemStream(data.data(),
00080 data.size()));
00081 s->open();
00082 boost::scoped_ptr<JFIFContainer> jfif(new JFIFContainer(s.get(), 0));
00083 LJpegDecompressor decomp(s.get(), jfif.get());
00084 RawData *dData = decomp.decompress();
00085 if (dData != NULL) {
00086 dData->setCfaPattern(data.cfaPattern());
00087 data.swap(*dData);
00088 delete dData;
00089 }
00090 }
00091 }
00092 else {
00093 data.setDataType(OR_DATA_TYPE_CFA);
00094 }
00095 }
00096 else {
00097 Trace(ERROR) << "couldn't find raw data\n";
00098 }
00099 }
00100 else {
00101 ret = OR_ERROR_NOT_FOUND;
00102 }
00103 return ret;
00104 }
00105
00106 }
00107 }