| 131 | } |
| 132 | |
| 133 | void Bitmap::WriteData(aiTexture *texture, IOStream *file) { |
| 134 | static const std::size_t padding_offset = 4; |
| 135 | static const uint8_t padding_data[padding_offset] = { 0x0, 0x0, 0x0, 0x0 }; |
| 136 | |
| 137 | unsigned int padding = (padding_offset - ((mBytesPerPixel * texture->mWidth) % padding_offset)) % padding_offset; |
| 138 | uint8_t pixel[mBytesPerPixel]; |
| 139 | |
| 140 | for (std::size_t i = 0; i < texture->mHeight; ++i) { |
| 141 | for (std::size_t j = 0; j < texture->mWidth; ++j) { |
| 142 | const aiTexel &texel = texture->pcData[(texture->mHeight - i - 1) * texture->mWidth + j]; // Bitmap files are stored in bottom-up format |
| 143 | |
| 144 | pixel[0] = texel.r; |
| 145 | pixel[1] = texel.g; |
| 146 | pixel[2] = texel.b; |
| 147 | pixel[3] = texel.a; |
| 148 | |
| 149 | file->Write(pixel, mBytesPerPixel, 1); |
| 150 | } |
| 151 | // When padding is 0, passing it as an argument will cause an assertion failure in DefaultIOStream::Write. |
| 152 | if (padding) { |
| 153 | file->Write(padding_data, padding, 1); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | } // namespace Assimp |
no test coverage detected