diff options
| author | Eric Dao <eric@erickhangdao.com> | 2025-03-10 17:54:31 -0400 |
|---|---|---|
| committer | Eric Dao <eric@erickhangdao.com> | 2025-03-10 17:54:31 -0400 |
| commit | ab224e2e6ba65f5a369ec392f99cd8845ad06c98 (patch) | |
| tree | a1e757e9341863ed52b8ad4c5a1c45933aab9da4 /python/openvino/runtime/common/format_reader/bmp.cpp | |
| parent | 40da1752f2c8639186b72f6838aa415e854d0b1d (diff) | |
| download | thesis-master.tar.gz thesis-master.tar.bz2 thesis-master.zip | |
Diffstat (limited to 'python/openvino/runtime/common/format_reader/bmp.cpp')
| -rw-r--r-- | python/openvino/runtime/common/format_reader/bmp.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/python/openvino/runtime/common/format_reader/bmp.cpp b/python/openvino/runtime/common/format_reader/bmp.cpp new file mode 100644 index 0000000..240d13f --- /dev/null +++ b/python/openvino/runtime/common/format_reader/bmp.cpp @@ -0,0 +1,64 @@ +// Copyright (C) 2018-2022 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +// clang-format off +#include <fstream> +#include <iostream> + +#include "bmp.h" +// clang-format on + +using namespace std; +using namespace FormatReader; + +BitMap::BitMap(const string& filename) { + BmpHeader header; + BmpInfoHeader infoHeader; + + ifstream input(filename, ios::binary); + if (!input) { + return; + } + + input.read(reinterpret_cast<char*>(&header.type), 2); + + if (header.type != 'M' * 256 + 'B') { + std::cerr << "[BMP] file is not bmp type\n"; + return; + } + + input.read(reinterpret_cast<char*>(&header.size), 4); + input.read(reinterpret_cast<char*>(&header.reserved), 4); + input.read(reinterpret_cast<char*>(&header.offset), 4); + + input.read(reinterpret_cast<char*>(&infoHeader), sizeof(BmpInfoHeader)); + + bool rowsReversed = infoHeader.height < 0; + _width = infoHeader.width; + _height = abs(infoHeader.height); + + if (infoHeader.bits != 24) { + cerr << "[BMP] 24bpp only supported. But input has:" << infoHeader.bits << "\n"; + return; + } + + if (infoHeader.compression != 0) { + cerr << "[BMP] compression not supported\n"; + } + + int padSize = _width & 3; + char pad[3]; + size_t size = _width * _height * 3; + + _data.reset(new unsigned char[size], std::default_delete<unsigned char[]>()); + + input.seekg(header.offset, ios::beg); + + // reading by rows in invert vertically + for (uint32_t i = 0; i < _height; i++) { + uint32_t storeAt = rowsReversed ? i : (uint32_t)_height - 1 - i; + input.read(reinterpret_cast<char*>(_data.get()) + _width * 3 * storeAt, _width * 3); + input.read(pad, padSize); + } +} |
