Files
openvino/samples/cpp/common/format_reader/bmp.cpp
Vladimir Dudnik 5b25dbee22 ov2.0 IE samples modification (#8340)
* ov2.0 IE samples modification

apply code style

turn off clang style check for headers order

unify samples a bit

add yuv nv12 reader to format_reader, helloe_nv112 sample

hello_reshape_ssd ov2.0

* sync with PR 8629 preprocessing api changes

* fix for slog << vector<int>

* add operator<< for ov::Version from PR-8687

* Update samples/cpp/hello_nv12_input_classification/main.cpp

Co-authored-by: Mikhail Nosov <mikhail.nosov@intel.com>

* apply code style

* change according to review comments

* add const qualifier

* apply code style

* std::ostream for old inference engine version to make VPU plugin tests happy

* apply code style

* revert changes in print version for old api samples

* keep inference_engine.hpp for not ov2.0 yet samples

* fix merge artifacts

* fix compilation

* apply code style

* Fixed classification sample test

* Revert changes in hello_reshape_ssd sample

* rebase to master, sync with PR-9054

* fix issues found by C++ tests

* rebased and sync with PR-9051

* fix test result parsers for classification tests (except unicode one)

* fix mismatches after merge

* rebase and sync with PR-9144

Co-authored-by: Mikhail Nosov <mikhail.nosov@intel.com>
Co-authored-by: antonrom23 <anton.romanov@intel.com>
2021-12-13 11:30:58 +03:00

65 lines
1.7 KiB
C++

// Copyright (C) 2018-2021 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);
}
}