mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 12:35:46 +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
@ -1401,32 +1401,16 @@ namespace NifOsg
|
|||||||
}
|
}
|
||||||
// We're going to convert the indices that pixel data contains
|
// We're going to convert the indices that pixel data contains
|
||||||
// into real colors using the palette.
|
// into real colors using the palette.
|
||||||
const std::vector<unsigned int>& palette = pixelData->palette->colors;
|
const auto& palette = pixelData->palette->colors;
|
||||||
if (pixelData->fmt == Nif::NiPixelData::NIPXFMT_PAL8)
|
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];
|
memcpy(pixel, &palette[index], sizeof(unsigned char) * numChannels);
|
||||||
for (size_t i = 0; i < pixels.size(); i++)
|
pixel += numChannels;
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
image->setImage(width, height, 1, pixelformat, pixelformat, GL_UNSIGNED_BYTE, data, osg::Image::USE_NEW_DELETE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user