mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Merge branch 'nipixeldata' into 'master'
Clean up palettized NiPixelData loading See merge request OpenMW/openmw!374
This commit is contained in:
commit
a78aa6b22c
1 changed files with 8 additions and 24 deletions
|
@ -1401,32 +1401,16 @@ namespace NifOsg
|
|||
}
|
||||
// We're going to convert the indices that pixel data contains
|
||||
// into real colors using the palette.
|
||||
const std::vector<unsigned int>& palette = pixelData->palette->colors;
|
||||
if (pixelData->fmt == Nif::NiPixelData::NIPXFMT_PAL8)
|
||||
const auto& palette = pixelData->palette->colors;
|
||||
const int numChannels = pixelformat == GL_RGBA ? 4 : 3;
|
||||
unsigned char* data = new unsigned char[pixels.size() * numChannels];
|
||||
unsigned char* pixel = data;
|
||||
for (unsigned char index : pixels)
|
||||
{
|
||||
unsigned char* data = new unsigned char[pixels.size() * 3];
|
||||
for (size_t i = 0; i < pixels.size(); i++)
|
||||
{
|
||||
unsigned int color = palette[pixels[i]];
|
||||
data[i * 3 + 0] = (color >> 0) & 0xFF;
|
||||
data[i * 3 + 1] = (color >> 8) & 0xFF;
|
||||
data[i * 3 + 2] = (color >> 16) & 0xFF;
|
||||
}
|
||||
image->setImage(width, height, 1, pixelformat, pixelformat, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE);
|
||||
}
|
||||
else // if (fmt = NIPXFMT_PALA8)
|
||||
{
|
||||
unsigned char* data = new unsigned char[pixels.size() * 4];
|
||||
for (size_t i = 0; i < pixels.size(); i++)
|
||||
{
|
||||
unsigned int color = palette[pixels[i]];
|
||||
data[i * 4 + 0] = (color >> 0) & 0xFF;
|
||||
data[i * 4 + 1] = (color >> 8) & 0xFF;
|
||||
data[i * 4 + 2] = (color >> 16) & 0xFF;
|
||||
data[i * 4 + 3] = (color >> 24) & 0xFF;
|
||||
}
|
||||
image->setImage(width, height, 1, pixelformat, pixelformat, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE);
|
||||
memcpy(pixel, &palette[index], sizeof(unsigned char) * numChannels);
|
||||
pixel += numChannels;
|
||||
}
|
||||
image->setImage(width, height, 1, pixelformat, pixelformat, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue