diff options
| author | Carl Hetherington <cth@carlh.net> | 2024-03-26 22:43:10 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2024-04-21 23:18:23 +0200 |
| commit | f7518583f90a866a07d8069a78bebcea82b2b248 (patch) | |
| tree | 92af4f01ff048248fcf7eeb6e65d7d8408d89807 /src/lib/frame_info.cc | |
| parent | fa15dc1a375e13d2047a857e5aef202179eec0d4 (diff) | |
Extract frame info read/write to new class.
Diffstat (limited to 'src/lib/frame_info.cc')
| -rw-r--r-- | src/lib/frame_info.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/lib/frame_info.cc b/src/lib/frame_info.cc new file mode 100644 index 000000000..f348bca6a --- /dev/null +++ b/src/lib/frame_info.cc @@ -0,0 +1,84 @@ +/* + Copyright (C) 2024 Carl Hetherington <cth@carlh.net> + + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DCP-o-matic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>. + +*/ + + +#include "frame_info.h" +#include <string> + + +using std::shared_ptr; +using std::string; + + +J2KFrameInfo::J2KFrameInfo(uint64_t offset_, uint64_t size_, string hash_) + : dcp::J2KFrameInfo(offset_, size_, hash_) +{ + +} + + +J2KFrameInfo::J2KFrameInfo(dcp::J2KFrameInfo const& info) + : dcp::J2KFrameInfo(info) +{ + +} + + +J2KFrameInfo::J2KFrameInfo(shared_ptr<InfoFileHandle> info_file, Frame frame, Eyes eyes) +{ + info_file->get().seek(position(frame, eyes), SEEK_SET); + info_file->get().checked_read(&offset, sizeof(offset)); + info_file->get().checked_read(&size, sizeof(size)); + + char hash_buffer[33]; + info_file->get().checked_read(hash_buffer, 32); + hash_buffer[32] = '\0'; + hash = hash_buffer; +} + + +long +J2KFrameInfo::position(Frame frame, Eyes eyes) const +{ + switch (eyes) { + case Eyes::BOTH: + return frame * _size_on_disk; + case Eyes::LEFT: + return frame * _size_on_disk * 2; + case Eyes::RIGHT: + return frame * _size_on_disk * 2 + _size_on_disk; + default: + DCPOMATIC_ASSERT(false); + } + + DCPOMATIC_ASSERT(false); +} + + +/** @param frame reel-relative frame */ +void +J2KFrameInfo::write(shared_ptr<InfoFileHandle> info_file, Frame frame, Eyes eyes) const +{ + info_file->get().seek(position(frame, eyes), SEEK_SET); + info_file->get().checked_write(&offset, sizeof(offset)); + info_file->get().checked_write(&size, sizeof(size)); + info_file->get().checked_write(hash.c_str(), hash.size()); +} + |
