]> git.sesse.net Git - casparcg/blob - modules/psd/util/bigendian_file_input_stream.h
[streaming_consumer] Default to pcm_s24le for containers supporting it instead of...
[casparcg] / modules / psd / util / bigendian_file_input_stream.h
1 /*
2 * Copyright (c) 2011 Sveriges Television AB <info@casparcg.com>
3 *
4 * This file is part of CasparCG (www.casparcg.com).
5 *
6 * CasparCG is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CasparCG 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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CasparCG. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Author: Niklas P Andersson, niklas.p.andersson@svt.se
20 */
21
22 #pragma once
23
24 #include <common/except.h>
25
26 #include <boost/filesystem/fstream.hpp>
27
28 #include <string>
29 #include <fstream>
30 #include <cstdint>
31
32 namespace caspar { namespace psd {
33
34 struct unexpected_eof_exception : virtual io_error {};
35
36 class bigendian_file_input_stream
37 {
38 public:
39         explicit bigendian_file_input_stream();
40         virtual ~bigendian_file_input_stream();
41
42         void open(const std::wstring& filename);
43
44         void read(char*, std::streamsize);
45         std::uint8_t read_byte();
46         std::uint16_t read_short();
47         std::uint32_t read_long();
48         std::wstring read_pascal_string(int padding = 1);
49         std::wstring read_unicode_string();
50         std::wstring read_id_string();
51         double read_double();
52
53         void discard_bytes(std::streamoff);
54         void discard_to_next_word();
55         void discard_to_next_dword();
56
57         std::streamoff current_position();
58         void set_position(std::streamoff);
59
60         void close();
61 private:
62         boost::filesystem::ifstream     ifs_;
63         std::wstring                            filename_;
64 };
65
66 class StreamPositionBackup
67 {
68 public:
69         StreamPositionBackup(bigendian_file_input_stream& stream, std::streamoff newPos) : stream_(stream)
70         {
71                 oldPosition_ = stream.current_position();
72                 stream_.set_position(newPos);
73         }
74
75         ~StreamPositionBackup()
76         {
77                 stream_.set_position(oldPosition_);
78         }
79 private:
80         std::streamoff                                  oldPosition_;
81         bigendian_file_input_stream&    stream_;
82
83 };
84
85 }       //namespace psd
86 }       //namespace caspar