1 /* 2 mkvmerge -- utility for splicing together matroska files 3 from component media subtypes 4 5 Distributed under the GPL v2 6 see the file COPYING for details 7 or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 8 9 image handling 10 11 Written by Moritz Bunkus <moritz@bunkus.org>. 12 */ 13 14 #include "common/common_pch.h" 15 16 #include "common/image/jpeg.h" 17 #include "common/image/png.h" 18 #include "common/mm_file_io.h" 19 #include "common/mm_io_x.h" 20 21 namespace mtx::image { 22 23 std::optional<std::pair<unsigned int, unsigned int>> get_size(std::filesystem::path const & file_name)24get_size(std::filesystem::path const &file_name) { 25 try { 26 mm_file_io_c file{file_name.u8string(), MODE_READ}; 27 28 auto marker = file.read_uint64_be(); 29 30 if ((marker & 0xffff'0000'0000'0000ull) == 0xffd8'0000'0000'0000ull) 31 return mtx::image::jpeg::get_size(file); 32 33 if (marker == 0x8950'4e47'0d0a'1a0aull) 34 return mtx::image::png::get_size(file); 35 36 } catch (mtx::mm_io::exception &) { 37 } 38 39 return {}; 40 } 41 42 } // namespace mtx::image 43