parent
b243d15c74
commit
f55cf96713
|
|
@ -38,9 +38,6 @@ NzImage::~NzImage()
|
||||||
|
|
||||||
bool NzImage::Convert(nzPixelFormat format)
|
bool NzImage::Convert(nzPixelFormat format)
|
||||||
{
|
{
|
||||||
if (format == m_sharedImage->format)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
#if NAZARA_UTILITY_SAFE
|
#if NAZARA_UTILITY_SAFE
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
{
|
{
|
||||||
|
|
@ -55,56 +52,37 @@ bool NzImage::Convert(nzPixelFormat format)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
EnsureOwnership();
|
if (format == m_sharedImage->format)
|
||||||
|
return true;
|
||||||
|
|
||||||
unsigned int depth = (IsCubemap()) ? 6 : m_sharedImage->depth;
|
// Les images 3D et cubemaps sont stockés de la même façon
|
||||||
|
unsigned int depth = (m_sharedImage->type == nzImageType_Cubemap) ? 6 : m_sharedImage->depth;
|
||||||
unsigned int pixelsPerFace = m_sharedImage->width*m_sharedImage->height;
|
unsigned int pixelsPerFace = m_sharedImage->width*m_sharedImage->height;
|
||||||
|
|
||||||
nzUInt8* buffer;
|
nzUInt8* buffer = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)];
|
||||||
if (depth > 1)
|
nzUInt8* ptr = buffer;
|
||||||
|
nzUInt8* pixels = m_sharedImage->pixels;
|
||||||
|
unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format);
|
||||||
|
unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < depth; ++i)
|
||||||
{
|
{
|
||||||
// Les images 3D sont un empilement d'images 2D
|
if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr))
|
||||||
// Quant aux cubemaps, ils sont stockés côte à côte, ce qui revient au même
|
|
||||||
buffer = new nzUInt8[pixelsPerFace*depth*NzPixelFormat::GetBPP(format)];
|
|
||||||
|
|
||||||
nzUInt8* ptr = buffer;
|
|
||||||
nzUInt8* pixels = m_sharedImage->pixels;
|
|
||||||
unsigned int srcStride = pixelsPerFace * NzPixelFormat::GetBPP(m_sharedImage->format);
|
|
||||||
unsigned int dstStride = pixelsPerFace * NzPixelFormat::GetBPP(format);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < depth; ++i)
|
|
||||||
{
|
|
||||||
if (!NzPixelFormat::Convert(m_sharedImage->format, format, pixels, &pixels[srcStride], ptr))
|
|
||||||
{
|
|
||||||
NazaraError("Failed to convert image");
|
|
||||||
delete[] buffer;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pixels += srcStride;
|
|
||||||
ptr += dstStride;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete[] buffer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buffer = new nzUInt8[pixelsPerFace*NzPixelFormat::GetBPP(format)];
|
|
||||||
|
|
||||||
if (!NzPixelFormat::Convert(m_sharedImage->format, format, m_sharedImage->pixels, &m_sharedImage->pixels[pixelsPerFace*NzPixelFormat::GetBPP(m_sharedImage->format)], buffer))
|
|
||||||
{
|
{
|
||||||
NazaraError("Failed to convert image");
|
NazaraError("Failed to convert image");
|
||||||
delete[] buffer;
|
delete[] buffer;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pixels += srcStride;
|
||||||
|
ptr += dstStride;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] m_sharedImage->pixels;
|
SharedImage* newImage = new SharedImage(1, m_sharedImage->type, format, buffer, m_sharedImage->width, m_sharedImage->height, m_sharedImage->depth);
|
||||||
|
|
||||||
m_sharedImage->format = format;
|
ReleaseImage();
|
||||||
m_sharedImage->pixels = buffer;
|
m_sharedImage = newImage;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -800,8 +800,6 @@ namespace
|
||||||
nzUInt16* ptr = reinterpret_cast<nzUInt16*>(dst);
|
nzUInt16* ptr = reinterpret_cast<nzUInt16*>(dst);
|
||||||
while (start < end)
|
while (start < end)
|
||||||
{
|
{
|
||||||
NazaraWarning("r: " + NzString::Number(c8to5(start[0])));
|
|
||||||
|
|
||||||
*ptr++ = (static_cast<nzUInt16>(c8to5(start[0])) << 11) |
|
*ptr++ = (static_cast<nzUInt16>(c8to5(start[0])) << 11) |
|
||||||
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
|
(static_cast<nzUInt16>(c8to5(start[1])) << 6) |
|
||||||
(static_cast<nzUInt16>(c8to5(start[2])) << 1) |
|
(static_cast<nzUInt16>(c8to5(start[2])) << 1) |
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue