1/*
2---------------------------------------------------------------------------
3Open Asset Import Library (assimp)
4---------------------------------------------------------------------------
5
6Copyright (c) 2006-2017, assimp team
7
8
9All rights reserved.
10
11Redistribution and use of this software in source and binary forms,
12with or without modification, are permitted provided that the following
13conditions are met:
14
15* Redistributions of source code must retain the above
16 copyright notice, this list of conditions and the
17 following disclaimer.
18
19* Redistributions in binary form must reproduce the above
20 copyright notice, this list of conditions and the
21 following disclaimer in the documentation and/or other
22 materials provided with the distribution.
23
24* Neither the name of the assimp team, nor the names of its
25 contributors may be used to endorse or promote products
26 derived from this software without specific prior
27 written permission of the assimp team.
28
29THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40---------------------------------------------------------------------------
41*/
42
43/** @file Bitmap.h
44 * @brief Defines bitmap format helper for textures
45 *
46 * Used for file formats which embed their textures into the model file.
47 */
48
49#ifndef AI_BITMAP_H_INC
50#define AI_BITMAP_H_INC
51
52#include <stdint.h>
53#include <cstddef>
54
55struct aiTexture;
56
57namespace Assimp {
58
59class IOStream;
60
61class Bitmap {
62protected:
63
64 struct Header {
65 uint16_t type;
66 uint32_t size;
67 uint16_t reserved1;
68 uint16_t reserved2;
69 uint32_t offset;
70
71 // We define the struct size because sizeof(Header) might return a wrong result because of structure padding.
72 // Moreover, we must use this ugly and error prone syntax because Visual Studio neither support constexpr or sizeof(name_of_field).
73 static const std::size_t header_size =
74 sizeof(uint16_t) + // type
75 sizeof(uint32_t) + // size
76 sizeof(uint16_t) + // reserved1
77 sizeof(uint16_t) + // reserved2
78 sizeof(uint32_t); // offset
79 };
80
81 struct DIB {
82 uint32_t size;
83 int32_t width;
84 int32_t height;
85 uint16_t planes;
86 uint16_t bits_per_pixel;
87 uint32_t compression;
88 uint32_t image_size;
89 int32_t x_resolution;
90 int32_t y_resolution;
91 uint32_t nb_colors;
92 uint32_t nb_important_colors;
93
94 // We define the struct size because sizeof(DIB) might return a wrong result because of structure padding.
95 // Moreover, we must use this ugly and error prone syntax because Visual Studio neither support constexpr or sizeof(name_of_field).
96 static const std::size_t dib_size =
97 sizeof(uint32_t) + // size
98 sizeof(int32_t) + // width
99 sizeof(int32_t) + // height
100 sizeof(uint16_t) + // planes
101 sizeof(uint16_t) + // bits_per_pixel
102 sizeof(uint32_t) + // compression
103 sizeof(uint32_t) + // image_size
104 sizeof(int32_t) + // x_resolution
105 sizeof(int32_t) + // y_resolution
106 sizeof(uint32_t) + // nb_colors
107 sizeof(uint32_t); // nb_important_colors
108 };
109
110 static const std::size_t mBytesPerPixel = 4;
111
112public:
113 static void Save(aiTexture* texture, IOStream* file);
114
115protected:
116 static void WriteHeader(Header& header, IOStream* file);
117 static void WriteDIB(DIB& dib, IOStream* file);
118 static void WriteData(aiTexture* texture, IOStream* file);
119};
120
121}
122
123#endif // AI_BITMAP_H_INC
124