Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / samples / common / format_reader / bmp.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * \brief BMP reader
7  * \file bmp.h
8  */
9 #pragma once
10
11 #include <memory>
12 #include <string>
13 #include <format_reader.h>
14
15 #include "register.h"
16
17 namespace FormatReader {
18 /**
19  * \class BitMap
20  * \brief Reader for bmp files
21  */
22 class BitMap : public Reader {
23 private:
24     static Register<BitMap> reg;
25
26     typedef struct {
27         unsigned short type   = 0u;              /* Magic identifier            */
28         unsigned int size     = 0u;              /* File size in bytes          */
29         unsigned int reserved = 0u;
30         unsigned int offset   = 0u;              /* Offset to image data, bytes */
31     } BmpHeader;
32
33     typedef struct {
34         unsigned int size = 0u;                  /* Header size in bytes      */
35         int width = 0, height = 0;               /* Width and height of image */
36         unsigned short planes = 0u;              /* Number of colour planes   */
37         unsigned short bits = 0u;                /* Bits per pixel            */
38         unsigned int compression = 0u;           /* Compression type          */
39         unsigned int imagesize = 0u;             /* Image size in bytes       */
40         int xresolution = 0, yresolution = 0;    /* Pixels per meter          */
41         unsigned int ncolours = 0u;              /* Number of colours         */
42         unsigned int importantcolours = 0u;      /* Important colours         */
43     } BmpInfoHeader;
44
45 public:
46     /**
47      * \brief Constructor of BMP reader
48      * @param filename - path to input data
49      * @return BitMap reader object
50      */
51     explicit BitMap(const std::string &filename);
52     virtual ~BitMap() {
53     }
54
55     /**
56      * \brief Get size
57      * @return size
58      */
59     size_t size() const override {
60         return _width * _height * 3;
61     }
62
63     void Release() noexcept override {
64         delete this;
65     }
66
67     std::shared_ptr<unsigned char> getData(size_t width, size_t height) override {
68         if ((width * height != 0) && (_width * _height != width * height)) {
69             std::cout << "[ WARNING ] Image won't be resized! Please use OpenCV.\n";
70             return nullptr;
71         }
72         return _data;
73     }
74 };
75 }  // namespace FormatReader