2
This file is part of darktable,
3
copyright (c) 2010 Henrik Andersson.
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.
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.
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/>.
22
#include <OpenEXR/ImfFrameBuffer.h>
23
#include <OpenEXR/ImfTiledOutputFile.h>
24
#include <OpenEXR/ImfChannelList.h>
25
#include <OpenEXR/ImfStandardAttributes.h>
26
#include "common/darktable.h"
27
#include "common/exif.h"
28
#include "common/colorspaces.h"
29
#include "common/imageio_module.h"
35
/** Special BLOB attribute implementation.*/
43
typedef Imf::TypedAttribute<Imf::Blob> BlobAttribute;
44
template <> const char *BlobAttribute::staticTypeName()
48
template <> void BlobAttribute::writeValueTo (OStream &os, int version) const
50
Xdr::write <StreamIO> (os, _value.size);
51
Xdr::write <StreamIO> (os, (char *)_value.data,_value.size);
54
template <> void BlobAttribute::readValueFrom (IStream &is, int size, int version)
56
Xdr::read <StreamIO> (is, _value.size);
57
Xdr::read <StreamIO> (is, (char *)_value.data, _value.size);
68
typedef struct dt_imageio_exr_t
70
int max_width, max_height;
75
int write_image (dt_imageio_exr_t *exr, const char *filename, const float *in, void *exif, int exif_len, int imgid)
77
Imf::BlobAttribute::registerAttributeType();
78
Imf::Blob exif_blob= {0};
79
exif_blob.size=exif_len;
80
exif_blob.data=(uint8_t *)exif;
81
Imf::Header header(exr->width,exr->height,1,Imath::V2f (0, 0),1,Imf::INCREASING_Y,Imf::PIZ_COMPRESSION);
82
header.insert("comment",Imf::StringAttribute("Developed using Darktable "PACKAGE_VERSION));
83
header.insert("exif", Imf::BlobAttribute(exif_blob));
84
header.channels().insert("R",Imf::Channel(Imf::FLOAT));
85
header.channels().insert("B",Imf::Channel(Imf::FLOAT));
86
header.channels().insert("G",Imf::Channel(Imf::FLOAT));
87
header.setTileDescription(Imf::TileDescription(100, 100, Imf::ONE_LEVEL));
88
Imf::TiledOutputFile file(filename, header);
89
Imf::FrameBuffer data;
91
uint32_t channelsize=(exr->width*exr->height);
92
float *red=(float *)malloc(channelsize*sizeof(float));
93
float *green=(float *)malloc(channelsize*sizeof(float));
94
float *blue=(float *)malloc(channelsize*sizeof(float));
96
for(uint32_t j=0; j<channelsize; j++)
100
data.insert("R",Imf::Slice(Imf::FLOAT,(char *)red,sizeof(float)*1,sizeof(float)*exr->width));
102
for(uint32_t j=0; j<channelsize; j++)
106
data.insert("B",Imf::Slice(Imf::FLOAT,(char *)blue,sizeof(float)*1,sizeof(float)*exr->width));
108
for(uint32_t j=0; j<channelsize; j++)
112
data.insert("G",Imf::Slice(Imf::FLOAT,(char *)green,sizeof(float)*1,sizeof(float)*exr->width));
114
file.setFrameBuffer(data);
115
file.writeTiles (0, file.numXTiles() - 1, 0, file.numYTiles() - 1);
123
get_params(dt_imageio_module_format_t *self, int *size)
125
*size = sizeof(dt_imageio_module_data_t);
126
dt_imageio_exr_t *d = (dt_imageio_exr_t *)malloc(sizeof(dt_imageio_exr_t));
131
free_params(dt_imageio_module_format_t *self, void *params)
137
set_params(dt_imageio_module_format_t *self, void *params, int size)
139
if(size != sizeof(dt_imageio_module_data_t)) return 1;
143
int bpp(dt_imageio_module_data_t *p)
149
mime(dt_imageio_module_data_t *data)
151
return "image/openexr";
155
extension(dt_imageio_module_data_t *data)
166
// TODO: some quality/compression stuff?
167
void gui_init (dt_imageio_module_format_t *self) {}
168
void gui_cleanup (dt_imageio_module_format_t *self) {}
169
void gui_reset (dt_imageio_module_format_t *self) {}