1 /*
2 This file is part of darktable,
3 Copyright (C) 2012-2020 darktable developers.
4
5 darktable is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 darktable is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with darktable. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #pragma once
20
21 #include "common/image.h"
22 #include "common/mipmap_cache.h"
23
24 #include <ciso646>
25
26 #if defined(_LIBCPP_VERSION)
27 #include <memory>
28 #else
29 #include <tr1/memory>
30 #endif
31
32 #include <OpenEXR/ImfChannelList.h>
33 #include <OpenEXR/ImfFrameBuffer.h>
34 #include <OpenEXR/ImfInputFile.h>
35 #include <OpenEXR/ImfStandardAttributes.h>
36 #include <OpenEXR/ImfTestFile.h>
37 #include <OpenEXR/ImfTiledInputFile.h>
38
39 #ifdef OPENEXR_IMF_INTERNAL_NAMESPACE
40 #define IMF_NS OPENEXR_IMF_INTERNAL_NAMESPACE
41 #else
42 #define IMF_NS Imf
43 #endif
44
45 // this stores our exif data as a blob.
46
47 template <typename T> struct array_deleter
48 {
operator ()array_deleter49 void operator()(T const *p)
50 {
51 delete[] p;
52 }
53 };
54
55 namespace IMF_NS
56 {
57 class Blob
58 {
59 public:
Blob()60 Blob() : size(0), data((uint8_t *)NULL)
61 {
62 }
63
Blob(uint32_t _size,uint8_t * _data)64 Blob(uint32_t _size, uint8_t *_data) : size(_size)
65 {
66 uint8_t *tmp_ptr = new uint8_t[_size];
67 memcpy(tmp_ptr, _data, _size);
68 data.reset(tmp_ptr, array_deleter<uint8_t>());
69 }
70
71 uint32_t size;
72 #if defined(_LIBCPP_VERSION)
73 std::shared_ptr<uint8_t> data;
74 #else
75 std::tr1::shared_ptr<uint8_t> data;
76 #endif
77 };
78
79
80 typedef IMF_NS::TypedAttribute<IMF_NS::Blob> BlobAttribute;
staticTypeName()81 template <> const char *BlobAttribute::staticTypeName()
82 {
83 return "blob";
84 }
writeValueTo(OStream & os,int version) const85 template <> void BlobAttribute::writeValueTo(OStream &os, int version) const
86 {
87 Xdr::write<StreamIO>(os, _value.size);
88 Xdr::write<StreamIO>(os, (char *)(_value.data.get()), _value.size);
89 }
90
readValueFrom(IStream & is,int size,int version)91 template <> void BlobAttribute::readValueFrom(IStream &is, int size, int version)
92 {
93 Xdr::read<StreamIO>(is, _value.size);
94 _value.data.reset(new uint8_t[_value.size], array_deleter<uint8_t>());
95 Xdr::read<StreamIO>(is, (char *)(_value.data.get()), _value.size);
96 }
97 }
98
99 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
100 // vim: shiftwidth=2 expandtab tabstop=2 cindent
101 // kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-space on;
102