libopenraw
dngfile.cpp
1 /*
2  * libopenraw - dngfile.cpp
3  *
4  * Copyright (C) 2006-2008 Hubert Figuiere
5  * Copyright (C) 2008 Novell, Inc.
6  *
7  * This library is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation, either version 3 of
10  * the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library. If not, see
19  * <http://www.gnu.org/licenses/>.
20  */
21 
22 
23 #include <libopenraw/libopenraw.h>
24 #include <libopenraw++/thumbnail.h>
25 #include <libopenraw++/rawdata.h>
26 
27 #include <boost/scoped_ptr.hpp>
28 
29 #include "trace.h"
30 #include "io/file.h"
31 #include "io/memstream.h"
32 #include "ifdfilecontainer.h"
33 #include "jfifcontainer.h"
34 #include "ljpegdecompressor.h"
35 #include "ifd.h"
36 #include "dngfile.h"
37 
38 using namespace Debug;
39 
40 namespace OpenRaw {
41 
42 
43  namespace Internals {
44  const IFDFile::camera_ids_t DNGFile::s_def[] = {
45  { "PENTAX K10D ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_PENTAX,
46  OR_TYPEID_PENTAX_K10D_DNG) },
47  { "R9 - Digital Back DMR", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA,
48  OR_TYPEID_LEICA_DMR) },
49  { "M8 Digital Camera", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA,
50  OR_TYPEID_LEICA_M8) },
51  { "LEICA X1 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_LEICA,
52  OR_TYPEID_LEICA_X1) },
53  { "GR DIGITAL 2 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_RICOH,
54  OR_TYPEID_RICOH_GR2) },
55  { "GXR ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_RICOH,
56  OR_TYPEID_RICOH_GXR) },
57  { "SAMSUNG GX10 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG,
58  OR_TYPEID_SAMSUNG_GX10) },
59  { "Pro 815 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_SAMSUNG,
60  OR_TYPEID_SAMSUNG_PRO815) },
61  { 0, OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_ADOBE,
62  OR_TYPEID_ADOBE_DNG_GENERIC) }
63  };
64 
65  RawFile *DNGFile::factory(IO::Stream *s)
66  {
67  return new DNGFile(s);
68  }
69 
70 
71  DNGFile::DNGFile(IO::Stream *s)
72  : TiffEpFile(s, OR_RAWFILE_TYPE_DNG)
73  {
74  _setIdMap(s_def);
75  }
76 
77  DNGFile::~DNGFile()
78  {
79  }
80 
81  ::or_error DNGFile::_getRawData(RawData & data, uint32_t options)
82  {
83  ::or_error ret = OR_ERROR_NONE;
84  if(!m_cfaIfd) {
85  m_cfaIfd = _locateCfaIfd();
86  }
87 
88  Trace(DEBUG1) << "_getRawData()\n";
89 
90  if (m_cfaIfd) {
91  ret = _getRawDataFromDir(data, m_cfaIfd);
92 
93  if(ret == OR_ERROR_NONE) {
94  uint16_t compression = 0;
95  if (m_cfaIfd->getValue(IFD::EXIF_TAG_COMPRESSION, compression) &&
96  compression == 7) {
97  // if the option is not set, decompress
98  if ((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) {
99  boost::scoped_ptr<IO::Stream> s(new IO::MemStream(data.data(),
100  data.size()));
101  s->open(); // TODO check success
102  boost::scoped_ptr<JFIFContainer> jfif(new JFIFContainer(s.get(), 0));
103  LJpegDecompressor decomp(s.get(), jfif.get());
104  RawData *dData = decomp.decompress();
105  if (dData != NULL) {
106  dData->setCfaPattern(data.cfaPattern());
107  data.swap(*dData);
108  delete dData;
109  }
110  }
111  }
112  else {
113  data.setDataType(OR_DATA_TYPE_CFA);
114  }
115  }
116  else {
117  Trace(ERROR) << "couldn't find raw data\n";
118  }
119  }
120  else {
121  ret = OR_ERROR_NOT_FOUND;
122  }
123  return ret;
124  }
125 
126  }
127 }