diff --git a/src/nvimage/DirectDrawSurface.cpp b/src/nvimage/DirectDrawSurface.cpp index 9c48457..303d62b 100644 --- a/src/nvimage/DirectDrawSurface.cpp +++ b/src/nvimage/DirectDrawSurface.cpp @@ -1242,6 +1242,7 @@ void DirectDrawSurface::readLinearImage(Image * img) const uint w = img->width(); const uint h = img->height(); + const uint d = img->depth(); uint rshift, rsize; PixelFormat::maskShiftAndSize(header.pf.rmask, &rshift, &rsize); @@ -1260,20 +1261,23 @@ void DirectDrawSurface::readLinearImage(Image * img) #pragma NV_MESSAGE("TODO: Support floating point linear images and other FOURCC codes.") // Read linear RGB images. - for (uint y = 0; y < h; y++) + for (uint z = 0; z < d; z++) { - for (uint x = 0; x < w; x++) + for (uint y = 0; y < h; y++) { - uint c = 0; - stream->serialize(&c, byteCount); + for (uint x = 0; x < w; x++) + { + uint c = 0; + stream->serialize(&c, byteCount); - Color32 pixel(0, 0, 0, 0xFF); - pixel.r = PixelFormat::convert((c & header.pf.rmask) >> rshift, rsize, 8); - pixel.g = PixelFormat::convert((c & header.pf.gmask) >> gshift, gsize, 8); - pixel.b = PixelFormat::convert((c & header.pf.bmask) >> bshift, bsize, 8); - pixel.a = PixelFormat::convert((c & header.pf.amask) >> ashift, asize, 8); + Color32 pixel(0, 0, 0, 0xFF); + pixel.r = PixelFormat::convert((c & header.pf.rmask) >> rshift, rsize, 8); + pixel.g = PixelFormat::convert((c & header.pf.gmask) >> gshift, gsize, 8); + pixel.b = PixelFormat::convert((c & header.pf.bmask) >> bshift, bsize, 8); + pixel.a = PixelFormat::convert((c & header.pf.amask) >> ashift, asize, 8); - img->pixel(x, y) = pixel; + img->pixel(x, y, z) = pixel; + } } } } diff --git a/src/nvimage/FloatImage.cpp b/src/nvimage/FloatImage.cpp index 3b6c070..7f591e6 100644 --- a/src/nvimage/FloatImage.cpp +++ b/src/nvimage/FloatImage.cpp @@ -1443,7 +1443,7 @@ FloatImage* FloatImage::clone() const { FloatImage* copy = new FloatImage(); - copy->allocate(m_componentCount, m_width, m_height); + copy->allocate(m_componentCount, m_width, m_height, m_depth); memcpy(copy->m_mem, m_mem, m_floatCount * sizeof(float)); return copy; diff --git a/src/nvimage/Image.h b/src/nvimage/Image.h index 729ccd4..4ab00a9 100644 --- a/src/nvimage/Image.h +++ b/src/nvimage/Image.h @@ -48,8 +48,8 @@ namespace nv const Color32 & pixel(uint idx) const; Color32 & pixel(uint idx); - const Color32 & pixel(uint x, uint y) const; - Color32 & pixel(uint x, uint y); + const Color32 & pixel(uint x, uint y, uint z = 0) const; + Color32 & pixel(uint x, uint y, uint z = 0); Format format() const; void setFormat(Format f); @@ -68,16 +68,16 @@ namespace nv }; - inline const Color32 & Image::pixel(uint x, uint y) const + inline const Color32 & Image::pixel(uint x, uint y, uint z) const { - nvDebugCheck(x < m_width && y < m_height); - return pixel(y * m_width + x); + nvDebugCheck(x < m_width && y < m_height && z < m_depth); + return pixel((z * m_height + y) * m_width + x); } - inline Color32 & Image::pixel(uint x, uint y) + inline Color32 & Image::pixel(uint x, uint y, uint z) { - nvDebugCheck(x < m_width && y < m_height); - return pixel(y * m_width + x); + nvDebugCheck(x < m_width && y < m_height && z < m_depth); + return pixel((z * m_height + y) * m_width + x); } } // nv namespace