diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-21 14:50:03 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2019-12-21 14:52:12 +0300 |
commit | 3304264990b96c09b174716ecb8da63d24457ae8 (patch) | |
tree | 9ec5711da75d4aa67587a8e39c24daaf6088c498 /aesxx/utils/helpers/bmp.hpp | |
parent | test: move data files to test/data (diff) | |
download | aes-tools-3304264990b96c09b174716ecb8da63d24457ae8.tar.gz aes-tools-3304264990b96c09b174716ecb8da63d24457ae8.zip |
utils/ -> aesxx/utils/
Diffstat (limited to 'aesxx/utils/helpers/bmp.hpp')
-rw-r--r-- | aesxx/utils/helpers/bmp.hpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/aesxx/utils/helpers/bmp.hpp b/aesxx/utils/helpers/bmp.hpp new file mode 100644 index 0000000..b4b283b --- /dev/null +++ b/aesxx/utils/helpers/bmp.hpp @@ -0,0 +1,57 @@ +// Copyright (c) 2016 Egor Tensin <Egor.Tensin@gmail.com> +// This file is part of the "AES tools" project. +// For details, see https://github.com/egor-tensin/aes-tools. +// Distributed under the MIT License. + +#include <windows.h> + +#include <cstddef> +#include <cstring> + +#include <string> +#include <utility> +#include <vector> + +namespace bmp +{ + class BmpFile + { + public: + BmpFile(std::vector<char>&& buffer) + : buffer{std::move(buffer)} + , header_size{extract_pixels_offset()} + { } + + const void* get_buffer() const { return buffer.data(); } + + std::size_t get_size() const { return buffer.size(); } + + std::size_t get_header_size() const { return header_size; } + + const void* get_pixels() const + { + return buffer.data() + get_header_size(); + } + + std::size_t get_pixels_size() const + { + return get_size() - get_header_size(); + } + + void replace_pixels(std::vector<unsigned char>&& pixels) + { + buffer.resize(get_header_size() + pixels.size()); + std::memcpy(buffer.data() + get_header_size(), pixels.data(), pixels.size()); + } + + private: + std::size_t extract_pixels_offset() const + { + const auto header = reinterpret_cast<const BITMAPFILEHEADER*>(get_buffer()); + return header->bfOffBits; + } + + std::vector<char> buffer; + std::size_t header_size; + }; +} |