libopenraw  0.3.7
tiffepfile.cpp
1 /*
2  * libopenraw - tiffepfile.cpp
3  *
4  * Copyright (C) 2007-2020 Hubert Figuière
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 <vector>
22 
23 #include <algorithm>
24 #include <memory>
25 
26 #include <libopenraw/debug.h>
27 
28 #include "rawfile.hpp"
29 #include "trace.hpp"
30 #include "tiffepfile.hpp"
31 #include "ifddir.hpp"
32 #include "ifdfilecontainer.hpp"
33 
34 using namespace Debug;
35 
36 namespace OpenRaw {
37 namespace Internals {
38 
39 TiffEpFile::TiffEpFile(const IO::Stream::Ptr &s,
40  Type _type)
41  : IfdFile(s, _type)
42 {
43 }
44 
45 IfdDir::Ref TiffEpFile::_locateCfaIfd()
46 {
47  const IfdDir::Ref & _mainIfd = mainIfd();
48 
49  if (!_mainIfd) {
50  LOGDBG1("couldn't find main ifd\n");
51  return IfdDir::Ref();
52  }
53  if (_mainIfd->isPrimary()) {
54  return _mainIfd;
55  }
56  auto result = _mainIfd->getSubIFDs();
57  if (!result) {
58  // error
59  LOGDBG1("couldn't find main ifd nor subifds\n");
60  return IfdDir::Ref();
61  }
62 
63  std::vector<IfdDir::Ref> subdirs = result.value();
64  auto i = find_if(subdirs.cbegin(),
65  subdirs.cend(),
66  [] (const IfdDir::Ref& e) {
67  return e->isPrimary();
68  });
69  if (i != subdirs.cend()) {
70  return *i;
71  }
72  LOGDBG1("couldn't find a primary subifd\n");
73  return IfdDir::Ref();
74 }
75 
76 }
77 }
78 /*
79  Local Variables:
80  mode:c++
81  c-file-style:"stroustrup"
82  c-file-offsets:((innamespace . 0))
83  indent-tabs-mode:nil
84  fill-column:80
85  End:
86 */
std::shared_ptr< IfdDir > Ref
Shared ptr of an IfdDir.
Definition: ifddir.hpp:56
Global namespace for libopenraw.
Definition: arwfile.cpp:29