void SurfaceT<T>::copyRawRgb( const SurfaceT<T> &srcSurface, const Area &srcArea, const Vec2i &absoluteOffset ) { const int32_t srcRowBytes = srcSurface.getRowBytes(); const int8_t srcPixelInc = srcSurface.getPixelInc(); const uint8_t srcRed = srcSurface.getChannelOrder().getRedOffset(); const uint8_t srcGreen = srcSurface.getChannelOrder().getGreenOffset(); const uint8_t srcBlue = srcSurface.getChannelOrder().getBlueOffset(); const uint8_t dstPixelInc = getPixelInc(); const uint8_t dstRed = getChannelOrder().getRedOffset(); const uint8_t dstGreen = getChannelOrder().getGreenOffset(); const uint8_t dstBlue = getChannelOrder().getBlueOffset(); int32_t width = srcArea.getWidth(); for( int32_t y = 0; y < srcArea.getHeight(); ++y ) { const T *src = reinterpret_cast<const T*>( reinterpret_cast<const uint8_t*>( srcSurface.getData() + srcArea.x1 * srcPixelInc ) + ( srcArea.y1 + y ) * srcRowBytes ); T *dst = reinterpret_cast<T*>( reinterpret_cast<uint8_t*>( getData() + absoluteOffset.x * dstPixelInc ) + ( y + absoluteOffset.y ) * getRowBytes() ); for( int x = 0; x < width; ++x ) { dst[dstRed] = src[srcRed]; dst[dstGreen] = src[srcGreen]; dst[dstBlue] = src[srcBlue]; src += srcPixelInc; dst += dstPixelInc; } } }
void thresholdImpl( const SurfaceT<T> &srcSurface, T value, const Area &srcArea, const ivec2 &dstLT, SurfaceT<T> *dstSurface ) { std::pair<Area,ivec2> srcDst = clippedSrcDst( srcSurface.getBounds(), srcArea, dstSurface->getBounds(), dstLT ); const Area &area( srcDst.first ); const ivec2 &dstOffset( srcDst.second ); ptrdiff_t srcRowBytes = srcSurface.getRowBytes(); uint8_t srcPixelInc = srcSurface.getPixelInc(); uint8_t srcRedOffset = srcSurface.getRedOffset(), srcGreenOffset = srcSurface.getGreenOffset(), srcBlueOffset = srcSurface.getBlueOffset(); ptrdiff_t dstRowBytes = dstSurface->getRowBytes(); uint8_t dstPixelInc = dstSurface->getPixelInc(); uint8_t dstRedOffset = dstSurface->getRedOffset(), dstGreenOffset = dstSurface->getGreenOffset(), dstBlueOffset = dstSurface->getBlueOffset(); const T maxValue = CHANTRAIT<T>::max(); for( int32_t y = 0; y < area.getHeight(); ++y ) { T *dstPtr = reinterpret_cast<T*>( reinterpret_cast<uint8_t*>( dstSurface->getData() + ( dstOffset.x + area.getX1() ) * dstPixelInc ) + ( y + dstOffset.y ) * dstRowBytes ); const T *srcPtr = reinterpret_cast<const T*>( reinterpret_cast<const uint8_t*>( srcSurface.getData() + area.getX1() * srcPixelInc ) + ( y + area.getY1() ) * srcRowBytes ); for( int32_t x = area.getX1(); x < area.getX2(); ++x ) { dstPtr[dstRedOffset] = ( srcPtr[srcRedOffset] > value ) ? maxValue : 0; dstPtr[dstGreenOffset] = ( srcPtr[srcGreenOffset] > value ) ? maxValue : 0; dstPtr[dstBlueOffset] = ( srcPtr[srcBlueOffset] > value ) ? maxValue : 0;; dstPtr += dstPixelInc; srcPtr += srcPixelInc; } } }
bool transparentVerticalScanline( const SurfaceT<T> &surface, int32_t column, int32_t y1, int32_t y2 ) { const T *dstPtr = surface.getDataAlpha( Vec2i( column, y1 ) ); int32_t rowBytes = surface.getRowBytes(); for( int32_t y = y1; y < y2; ++y ) { if( *dstPtr ) return false; dstPtr += rowBytes; } return true; }
void SurfaceT<T>::copyRawSameChannelOrder( const SurfaceT<T> &srcSurface, const Area &srcArea, const Vec2i &absoluteOffset ) { int32_t srcRowBytes = srcSurface.getRowBytes(); int32_t srcPixelInc = srcSurface.getPixelInc(); int32_t dstPixelInc = getPixelInc(); size_t copyBytes = srcArea.getWidth() * srcPixelInc * sizeof(T); for( int32_t y = 0; y < srcArea.getHeight(); ++y ) { const T *srcPtr = reinterpret_cast<const T*>( reinterpret_cast<const uint8_t*>( srcSurface.getData() + srcArea.x1 * srcPixelInc ) + ( srcArea.y1 + y ) * srcRowBytes ); T *dstPtr = reinterpret_cast<T*>( reinterpret_cast<uint8_t*>( getData() + absoluteOffset.x * dstPixelInc ) + ( y + absoluteOffset.y ) * getRowBytes() ); memcpy( dstPtr, srcPtr, copyBytes ); } }
ImageSourceSurface( const SurfaceT<T> &surface ) : ImageSource() { mWidth = surface.getWidth(); mHeight = surface.getHeight(); setColorModel( ImageIo::CM_RGB ); setChannelOrder( ImageIo::ChannelOrder( surface.getChannelOrder().getImageIoChannelOrder() ) ); if( boost::is_same<T,uint8_t>::value ) { setDataType( ImageIo::UINT8 ); mSurface8u = *reinterpret_cast<const Surface8u*>( &surface ); // register reference to 'surface' } else if( boost::is_same<T,float>::value ) { setDataType( ImageIo::FLOAT32 ); mSurface32f = *reinterpret_cast<const Surface32f*>( &surface ); // register reference to 'surface' } else throw; // this surface seems to be a type we've never met mRowBytes = surface.getRowBytes(); mData = reinterpret_cast<const uint8_t*>( surface.getData() ); }