SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
ImageQuantize.cpp
Go to the documentation of this file.
2
3#include <vtfpp/ImagePixel.h>
4
5using namespace vtfpp;
6
7std::vector<std::byte> ImageQuantize::convertP8ImageDataToBGRA8888(std::span<const std::byte> paletteData, std::span<const std::byte> imageData) {
8 if (paletteData.size() != 256 * sizeof(ImagePixel::BGRA8888)) {
9 return {};
10 }
11
12 const std::span palettePixelData{reinterpret_cast<const ImagePixel::BGRA8888*>(paletteData.data()), 256};
13
14 std::vector<std::byte> out;
15 out.resize(imageData.size() * sizeof(ImagePixel::BGRA8888));
16 BufferStream stream{out};
17 for (const auto index : imageData) {
18 stream << palettePixelData[static_cast<uint8_t>(index)];
19 }
20 return out;
21}
std::vector< std::byte > convertP8ImageDataToBGRA8888(std::span< const std::byte > paletteData, std::span< const std::byte > imageData)
Converts a paletted image to something usable.
Definition HOT.h:11