//! Creates a software image from part of a texture. IImage* CNullDriver::createImage(ITexture* texture, const position2d<s32>& pos, const dimension2d<u32>& size) { if ((pos==position2di(0,0)) && (size == texture->getSize())) { IImage* image = new CImage(texture->getColorFormat(), size, texture->lock(ETLM_READ_ONLY), false); texture->unlock(); return image; } else { // make sure to avoid buffer overruns // make the vector a separate variable for g++ 3.x const vector2d<u32> leftUpper(clamp(static_cast<u32>(pos.X), 0u, texture->getSize().Width), clamp(static_cast<u32>(pos.Y), 0u, texture->getSize().Height)); const rectangle<u32> clamped(leftUpper, dimension2du(clamp(static_cast<u32>(size.Width), 0u, texture->getSize().Width), clamp(static_cast<u32>(size.Height), 0u, texture->getSize().Height))); if (!clamped.isValid()) return 0; u8* src = static_cast<u8*>(texture->lock(ETLM_READ_ONLY)); if (!src) return 0; IImage* image = new CImage(texture->getColorFormat(), clamped.getSize()); u8* dst = static_cast<u8*>(image->lock()); src += clamped.UpperLeftCorner.Y * texture->getPitch() + image->getBytesPerPixel() * clamped.UpperLeftCorner.X; for (u32 i=0; i<clamped.getHeight(); ++i) { CColorConverter::convert_viaFormat(src, texture->getColorFormat(), clamped.getWidth(), dst, image->getColorFormat()); src += texture->getPitch(); dst += image->getPitch(); } image->unlock(); texture->unlock(); return image; } }