dngfile.cpp

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
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of 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, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
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                         // if the option is not set, decompress
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(); // TODO check success
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 }

Generated on Sun Mar 23 09:28:21 2008 for libopenraw by  doxygen 1.5.5