libopenraw
orffile.cpp
1 /*
2  * libopenraw - orffile.cpp
3  *
4  * Copyright (C) 2006, 2008, 2010 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #include <libopenraw++/thumbnail.h>
22 #include <libopenraw++/rawdata.h>
23 
24 #include "trace.h"
25 #include "orffile.h"
26 #include "ifd.h"
27 #include "ifddir.h"
28 #include "ifdentry.h"
29 #include "orfcontainer.h"
30 #include "io/file.h"
31 
32 using namespace Debug;
33 
34 namespace OpenRaw {
35 namespace Internals {
36 
37  const struct IFDFile::camera_ids_t OrfFile::s_def[] = {
38  { "E-1 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
39  OR_TYPEID_OLYMPUS_E1) },
40  { "E-10 " , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
41  OR_TYPEID_OLYMPUS_E10) },
42  { "E-3 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
43  OR_TYPEID_OLYMPUS_E3) },
44  { "E-300 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
45  OR_TYPEID_OLYMPUS_E300) },
46  { "E-330 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
47  OR_TYPEID_OLYMPUS_E330) },
48  { "E-400 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
49  OR_TYPEID_OLYMPUS_E400) },
50  { "E-410 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
51  OR_TYPEID_OLYMPUS_E410) },
52  { "E-500 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
53  OR_TYPEID_OLYMPUS_E500) },
54  { "E-510 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
55  OR_TYPEID_OLYMPUS_E510) },
56  { "SP350" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
57  OR_TYPEID_OLYMPUS_SP350) },
58  { "SP500UZ" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
59  OR_TYPEID_OLYMPUS_SP500) },
60  { "SP510UZ" , OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
61  OR_TYPEID_OLYMPUS_SP510) },
62  { "SP550UZ ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
63  OR_TYPEID_OLYMPUS_SP550) },
64  { "E-P1 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
65  OR_TYPEID_OLYMPUS_EP1) },
66  { "E-620 ", OR_MAKE_FILE_TYPEID(OR_TYPEID_VENDOR_OLYMPUS,
67  OR_TYPEID_OLYMPUS_E620) },
68  { 0, 0 }
69  };
70 
71  RawFile *OrfFile::factory(IO::Stream *s)
72  {
73  return new OrfFile(s);
74  }
75 
76 
77  OrfFile::OrfFile(IO::Stream *s)
78  : IFDFile(s, OR_RAWFILE_TYPE_ORF, false)
79  {
80  _setIdMap(s_def);
81  m_container = new OrfContainer(m_io, 0);
82  }
83 
84  OrfFile::~OrfFile()
85  {
86  }
87 
88  IFDDir::Ref OrfFile::_locateCfaIfd()
89  {
90  // in ORF the CFA IFD is the main IFD
91  if(!m_mainIfd) {
92  m_mainIfd = _locateMainIfd();
93  }
94  return m_mainIfd;
95  }
96 
97 
98  IFDDir::Ref OrfFile::_locateMainIfd()
99  {
100  return m_container->setDirectory(0);
101  }
102 
103 
104 
105  ::or_error OrfFile::_getRawData(RawData & data, uint32_t options)
106  {
107  ::or_error err;
108  if(!m_cfaIfd) {
109  m_cfaIfd = _locateCfaIfd();
110  }
111  err = _getRawDataFromDir(data, m_cfaIfd);
112  if(err == OR_ERROR_NONE) {
113  // ORF files seems to be marked as uncompressed even if they are.
114  uint32_t x = data.x();
115  uint32_t y = data.y();
116  uint16_t compression = 0;
117  if(data.size() < x * y * 2) {
118  compression = 65535;
119  data.setCompression(65535);
120  data.setDataType(OR_DATA_TYPE_COMPRESSED_CFA);
121  }
122  else {
123  compression = data.compression();
124  }
125  switch(compression) {
126  case 65535:
127  if((options & OR_OPTIONS_DONT_DECOMPRESS) == 0) {
128  // TODO decompress
129  }
130  break;
131  default:
132  break;
133  }
134  }
135  return err;
136  }
137 
138 }
139 }
140 
IFDFileContainer * m_container
Definition: ifdfile.h:95
virtual ::or_error _getRawData(RawData &data, uint32_t options)
Definition: orffile.cpp:105
void setDataType(DataType _type)
Definition: bitmapdata.cpp:92
base virtual class for IO
Definition: stream.h:40
size_t size() const
Definition: bitmapdata.cpp:122
::or_error _getRawDataFromDir(RawData &data, IFDDir::Ref &dir)
Definition: ifdfile.cpp:477