2 Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /** @file src/tiff_encoder.h
21 * @brief An encoder that writes TIFF files (and does nothing with audio).
29 #include <boost/filesystem.hpp>
31 #include "tiff_encoder.h"
33 #include "film_state.h"
35 #include "exceptions.h"
39 using namespace boost;
41 /** @param s FilmState of the film that we are encoding.
45 TIFFEncoder::TIFFEncoder (shared_ptr<const FilmState> s, shared_ptr<const Options> o, Log* l)
52 TIFFEncoder::process_video (shared_ptr<Image> image, int frame)
54 shared_ptr<Image> scaled = image->scale_and_convert_to_rgb (_opt->out_size, _opt->padding, _fs->scaler);
55 string tmp_file = _opt->frame_out_path (frame, true);
56 TIFF* output = TIFFOpen (tmp_file.c_str (), "w");
58 throw CreateFileError (tmp_file);
61 TIFFSetField (output, TIFFTAG_IMAGEWIDTH, _opt->out_size.width);
62 TIFFSetField (output, TIFFTAG_IMAGELENGTH, _opt->out_size.height);
63 TIFFSetField (output, TIFFTAG_COMPRESSION, COMPRESSION_NONE);
64 TIFFSetField (output, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
65 TIFFSetField (output, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
66 TIFFSetField (output, TIFFTAG_BITSPERSAMPLE, 8);
67 TIFFSetField (output, TIFFTAG_SAMPLESPERPIXEL, 3);
69 if (TIFFWriteEncodedStrip (output, 0, scaled->data()[0], _opt->out_size.width * _opt->out_size.height * 3) == 0) {
70 throw WriteFileError (tmp_file, 0);
75 boost::filesystem::rename (tmp_file, _opt->frame_out_path (frame, false));