本文整理汇总了C++中PixelBox类的典型用法代码示例。如果您正苦于以下问题:C++ PixelBox类的具体用法?C++ PixelBox怎么用?C++ PixelBox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PixelBox类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: naiveBulkPixelConversion
// Pure 32 bit float precision brute force pixel conversion; for comparison
void naiveBulkPixelConversion(const PixelBox &src, const PixelBox &dst)
{
uint8 *srcptr = static_cast<uint8*>(src.data);
uint8 *dstptr = static_cast<uint8*>(dst.data);
unsigned int srcPixelSize = PixelUtil::getNumElemBytes(src.format);
unsigned int dstPixelSize = PixelUtil::getNumElemBytes(dst.format);
// Calculate pitches+skips in bytes
int srcRowSkipBytes = src.getRowSkip()*srcPixelSize;
int srcSliceSkipBytes = src.getSliceSkip()*srcPixelSize;
int dstRowSkipBytes = dst.getRowSkip()*dstPixelSize;
int dstSliceSkipBytes = dst.getSliceSkip()*dstPixelSize;
// The brute force fallback
float r,g,b,a;
for(size_t z=src.front; z<src.back; z++)
{
for(size_t y=src.top; y<src.bottom; y++)
{
for(size_t x=src.left; x<src.right; x++)
{
PixelUtil::unpackColour(&r, &g, &b, &a, src.format, srcptr);
PixelUtil::packColour(r, g, b, a, dst.format, dstptr);
srcptr += srcPixelSize;
dstptr += dstPixelSize;
}
srcptr += srcRowSkipBytes;
dstptr += dstRowSkipBytes;
}
srcptr += srcSliceSkipBytes;
dstptr += dstSliceSkipBytes;
}
}
示例2: copyContentsToMemory
void SDLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer)
{
if ((dst.left < 0) || (dst.right > mWidth) ||
(dst.top < 0) || (dst.bottom > mHeight) ||
(dst.front != 0) || (dst.back != 1))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Invalid box.",
"SDLWindow::copyContentsToMemory" );
}
if (buffer == FB_AUTO)
{
buffer = mIsFullScreen? FB_FRONT : FB_BACK;
}
GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format);
GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format);
if ((format == GL_NONE) || (type == 0))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Unsupported format.",
"SDLWindow::copyContentsToMemory" );
}
// Switch context if different from current one
RenderSystem* rsys = Root::getSingleton().getRenderSystem();
rsys->_setViewport(this->getViewport(0));
// Must change the packing to ensure no overruns!
glPixelStorei(GL_PACK_ALIGNMENT, 1);
glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
glReadPixels((GLint)dst.left, (GLint)dst.top,
(GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
format, type, dst.data);
// restore default alignment
glPixelStorei(GL_PACK_ALIGNMENT, 4);
//vertical flip
{
size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
size_t height = dst.getHeight();
uchar *tmpData = new uchar[rowSpan * height];
uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan;
while (tmpRow >= tmpData)
{
memcpy(tmpRow, srcRow, rowSpan);
srcRow += rowSpan;
tmpRow -= rowSpan;
}
memcpy(dst.data, tmpData, rowSpan * height);
delete [] tmpData;
}
}
示例3: copyContentsToMemory
//-------------------------------------------------------------------------------------------------//
void OSXWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer)
{
if ((dst.left < 0) || (dst.right > mWidth) ||
(dst.top < 0) || (dst.bottom > mHeight) ||
(dst.front != 0) || (dst.back != 1))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Invalid box.",
"OSXWindow::copyContentsToMemory" );
}
if (buffer == FB_AUTO)
{
buffer = mIsFullScreen? FB_FRONT : FB_BACK;
}
GLenum format = Ogre::GLPixelUtil::getGLOriginFormat(dst.format);
GLenum type = Ogre::GLPixelUtil::getGLOriginDataType(dst.format);
if ((format == GL_NONE) || (type == 0))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Unsupported format.",
"OSXWindow::copyContentsToMemory" );
}
if((dst.getWidth()*Ogre::PixelUtil::getNumElemBytes(dst.format)) & 3)
{
// Standard alignment of 4 is not right
glPixelStorei(GL_PACK_ALIGNMENT, 1);
}
glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
glReadPixels((GLint)dst.left, (GLint)dst.top,
(GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
format, type, dst.data);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
//vertical flip
{
size_t rowSpan = dst.getWidth() * PixelUtil::getNumElemBytes(dst.format);
size_t height = dst.getHeight();
uchar *tmpData = new uchar[rowSpan * height];
uchar *srcRow = (uchar *)dst.data, *tmpRow = tmpData + (height - 1) * rowSpan;
while (tmpRow >= tmpData)
{
memcpy(tmpRow, srcRow, rowSpan);
srcRow += rowSpan;
tmpRow -= rowSpan;
}
memcpy(dst.data, tmpData, rowSpan * height);
delete [] tmpData;
}
}
示例4: OGRE_EXCEPT
void GLES2HardwarePixelBuffer::blitFromMemory(const PixelBox &src, const Image::Box &dstBox)
{
if (!mBuffer.contains(dstBox))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Destination box out of range",
"GLES2HardwarePixelBuffer::blitFromMemory");
}
PixelBox scaled;
if (src.getWidth() != dstBox.getWidth() ||
src.getHeight() != dstBox.getHeight() ||
src.getDepth() != dstBox.getDepth())
{
// Scale to destination size.
// This also does pixel format conversion if needed
allocateBuffer();
scaled = mBuffer.getSubVolume(dstBox);
Image::scale(src, scaled, Image::FILTER_BILINEAR);
}
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
else if ((src.format != mFormat) ||
((GLES2PixelUtil::getGLOriginFormat(src.format) == 0) && (src.format != PF_R8G8B8)))
#else
else if (GLES2PixelUtil::getGLOriginFormat(src.format) == 0)
#endif
{
// Extents match, but format is not accepted as valid source format for GL
// do conversion in temporary buffer
allocateBuffer();
scaled = mBuffer.getSubVolume(dstBox);
PixelUtil::bulkPixelConversion(src, scaled);
}
else
{
allocateBuffer();
// No scaling or conversion needed
scaled = src;
if (src.format == PF_R8G8B8)
{
scaled.format = PF_B8G8R8;
PixelUtil::bulkPixelConversion(src, scaled);
}
#if OGRE_PLATFORM == OGRE_PLATFORM_NACL
if (src.format == PF_A8R8G8B8)
{
scaled.format = PF_A8B8G8R8;
PixelUtil::bulkPixelConversion(src, scaled);
}
#endif
}
upload(scaled, dstBox);
freeBuffer();
}
示例5: toD3DRECTExtent
// Convert Ogre pixelbox extent to D3D rectangle
RECT toD3DRECTExtent(const PixelBox &lockBox)
{
RECT prect;
assert(lockBox.getDepth() == 1);
prect.left = 0;
prect.right = static_cast<LONG>(lockBox.getWidth());
prect.top = 0;
prect.bottom = static_cast<LONG>(lockBox.getHeight());
return prect;
}
示例6: toD3DBOXExtent
// Convert Ogre pixelbox extent to D3D box
D3DBOX toD3DBOXExtent(const PixelBox &lockBox)
{
D3DBOX pbox;
pbox.Left = 0;
pbox.Right = static_cast<UINT>(lockBox.getWidth());
pbox.Top = 0;
pbox.Bottom = static_cast<UINT>(lockBox.getHeight());
pbox.Front = 0;
pbox.Back = static_cast<UINT>(lockBox.getDepth());
return pbox;
}
示例7: assert
//-----------------------------------------------------------------------------
void D3D11HardwarePixelBuffer::blitToMemory(const Image::Box &srcBox, const PixelBox &dst)
{
// Decide on pixel format of temp surface
PixelFormat tmpFormat = mFormat;
if(D3D11Mappings::_getPF(dst.format) != DXGI_FORMAT_UNKNOWN)
{
tmpFormat = dst.format;
}
assert(srcBox.getDepth() == 1 && dst.getDepth() == 1);
//This is a pointer to the texture we're trying to copy
//Only implemented for 2D at the moment...
ID3D11Texture2D *textureResource = mParentTexture->GetTex2D();
// get the description of the texture
D3D11_TEXTURE2D_DESC desc = {0};
textureResource->GetDesc( &desc );
//Alter the description to set up a staging texture
desc.Usage = D3D11_USAGE_STAGING;
//This texture is not bound to any part of the pipeline
desc.BindFlags = 0;
//Allow CPU Access
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
//No Misc Flags
desc.MiscFlags = 0;
//Create the staging texture
ID3D11Texture2D* pStagingTexture = NULL;
mDevice->CreateTexture2D( &desc, NULL, &pStagingTexture );
//Copy our texture into the staging texture
mDevice.GetImmediateContext()->CopyResource( pStagingTexture, textureResource );
//Create a mapped resource and map the staging texture to the resource
D3D11_MAPPED_SUBRESOURCE mapped = {0};
mDevice.GetImmediateContext()->Map( pStagingTexture, 0, D3D11_MAP_READ , 0, &mapped );
// read the data out of the texture.
unsigned int rPitch = mapped.RowPitch;
BYTE *data = ((BYTE *)mapped.pData);
//Using existing OGRE functions
DXGI_MAPPED_RECT lrect;
lrect.pBits = data;
lrect.Pitch = rPitch;
PixelBox locked(dst.getWidth(), dst.getHeight(), dst.getDepth(), tmpFormat);
fromD3DLock(locked, lrect);
PixelUtil::bulkPixelConversion(locked, dst);
//Release the staging texture
mDevice.GetImmediateContext()->Unmap( pStagingTexture, 0 );
pStagingTexture->Release();
}
示例8: copyContentsToMemory
void EGLWindow::copyContentsToMemory(const PixelBox &dst, FrameBuffer buffer)
{
if ((dst.left < 0) || (dst.right > mWidth) ||
(dst.top < 0) || (dst.bottom > mHeight) ||
(dst.front != 0) || (dst.back != 1))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Invalid box.",
"Win32Window::copyContentsToMemory" );
}
if (buffer == FB_AUTO)
{
buffer = mIsFullScreen? FB_FRONT : FB_BACK;
}
GLenum format = GLESPixelUtil::getGLOriginFormat(dst.format);
GLenum type = GLESPixelUtil::getGLOriginDataType(dst.format);
if ((format == 0) || (type == 0))
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS,
"Unsupported format.",
"GtkEGLWindow::copyContentsToMemory" );
}
// Switch context if different from current one
RenderSystem* rsys = Root::getSingleton().getRenderSystem();
rsys->_setViewport(this->getViewport(0));
#if OGRE_NO_GLES3_SUPPORT == 0
if(dst.getWidth() != dst.rowPitch)
glPixelStorei(GL_PACK_ROW_LENGTH, dst.rowPitch);
#endif
// Must change the packing to ensure no overruns!
glPixelStorei(GL_PACK_ALIGNMENT, 1);
//glReadBuffer((buffer == FB_FRONT)? GL_FRONT : GL_BACK);
glReadPixels((GLint)0, (GLint)(mHeight - dst.getHeight()),
(GLsizei)dst.getWidth(), (GLsizei)dst.getHeight(),
format, type, dst.getTopLeftFrontPixelPtr());
// restore default alignment
glPixelStorei(GL_PACK_ALIGNMENT, 4);
#if OGRE_NO_GLES3_SUPPORT == 0
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
#endif
PixelUtil::bulkPixelVerticalFlip(dst);
}
示例9: pixelBox
void pixelBox(const PixelBox& box, isab::MapPlotter* plotter)
{
std::vector<MC2Point> points;
points.push_back(box.getTopLeft());
points.push_back(box.getTopRight());
points.push_back(box.getBottomRight());
points.push_back(box.getBottomLeft());
points.push_back(box.getTopLeft());
plotter->setPenColor(255, 0, 0);
plotter->setLineWidth(3);
plotter->drawPolyLine(points.begin(), points.end());
}
示例10:
//-----------------------------------------------------------------------------
// Util functions to convert a D3D locked box to a pixel box
void D3D10HardwarePixelBuffer::fromD3DLock(PixelBox &rval, const DXGI_MAPPED_RECT &lrect)
{
rval.rowPitch = lrect.Pitch / PixelUtil::getNumElemBytes(rval.format);
rval.slicePitch = rval.rowPitch * rval.getHeight();
assert((lrect.Pitch % PixelUtil::getNumElemBytes(rval.format))==0);
rval.data = lrect.pBits;
}
示例11: ToolTexAlpha
/// _Tool_ tex ..........................
// (remove alpha channel for ter tex prv img)
void App::ToolTexAlpha()
{
Ogre::Image im;
im.load("jungle_5d.png", "General");
PixelBox pb = im.getPixelBox();
int w = pb.getWidth(), h = pb.getHeight();
for(int j=0; j < h; ++j)
for(int i=0; i < w; ++i)
{
ColourValue c = pb.getColourAt(i,j,0);
c.a = 1.f;
pb.setColourAt(c,i,j,0);
}
im.save(PATHMANAGER::Data()+"/prv.png");
}
示例12: copyContentsToMemory
void EGLWindow::copyContentsToMemory(const Box& src, const PixelBox &dst, FrameBuffer buffer)
{
if(src.right > mWidth || src.bottom > mHeight || src.front != 0 || src.back != 1
|| dst.getWidth() != src.getWidth() || dst.getHeight() != src.getHeight() || dst.getDepth() != 1)
{
OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid box.", "EGLWindow::copyContentsToMemory");
}
if (buffer == FB_AUTO)
{
buffer = mIsFullScreen? FB_FRONT : FB_BACK;
}
static_cast<GLRenderSystemCommon*>(Root::getSingleton().getRenderSystem())
->_copyContentsToMemory(getViewport(0), src, dst, buffer);
}
示例13: getPixelBoxPointer
void ShVarItem::setCurrentValue(int key0, int key1)
{
if (key0 >= 0 && key1 >= 0 && data(DF_WATCHED).toBool()) {
if (data(DF_DATA_PIXELBOX).value<void*>() != NULL) {
PixelBox *fb = getPixelBoxPointer();
if (fb) {
QVariant value;
bool validValue = fb->getDataValue(key0, key1, &value);
if (validValue) {
setData(DF_DEBUG_SELECTED_VALUE, value.toString());
return;
}
}
}
setData(DF_DEBUG_SELECTED_VALUE, "?");
return;
}
setData(DF_DEBUG_SELECTED_VALUE, QVariant());
}
示例14: OGRE_EXCEPT
//-----------------------------------------------------------------------
void ILUtil::toOgre(const PixelBox &dst)
{
if(!dst.isConsecutive())
OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
"Destination must currently be consecutive",
"ILUtil::ilToOgre" ) ;
if(dst.getWidth() != static_cast<size_t>(ilGetInteger( IL_IMAGE_WIDTH )) ||
dst.getHeight() != static_cast<size_t>(ilGetInteger( IL_IMAGE_HEIGHT )) ||
dst.getDepth() != static_cast<size_t>(ilGetInteger( IL_IMAGE_DEPTH )))
OGRE_EXCEPT( Exception::ERR_INVALIDPARAMS,
"Destination dimensions must equal IL dimension",
"ILUtil::ilToOgre" ) ;
int ilfmt = ilGetInteger( IL_IMAGE_FORMAT );
int iltp = ilGetInteger( IL_IMAGE_TYPE );
// Check if in-memory format just matches
// If yes, we can just copy it and save conversion
ILFormat ifmt = OgreFormat2ilFormat( dst.format );
if(ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp)) {
memcpy(dst.data, ilGetData(), ilGetInteger( IL_IMAGE_SIZE_OF_DATA ));
return;
}
// Try if buffer is in a known OGRE format so we can use OGRE its
// conversion routines
PixelFormat bufFmt = ilFormat2OgreFormat((int)ilfmt, (int)iltp);
ifmt = OgreFormat2ilFormat( bufFmt );
if(ifmt.format == ilfmt && ILabs(ifmt.type) == ILabs(iltp))
{
// IL format matches another OGRE format
PixelBox src(dst.getWidth(), dst.getHeight(), dst.getDepth(), bufFmt, ilGetData());
PixelUtil::bulkPixelConversion(src, dst);
return;
}
// Thee extremely slow method
if(iltp == IL_UNSIGNED_BYTE || iltp == IL_BYTE)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format, (uint8)0x00,(uint8)0x00,(uint8)0x00,(uint8)0xFF);
}
else if(iltp == IL_FLOAT)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format, 0.0f,0.0f,0.0f,1.0f);
}
else if(iltp == IL_SHORT || iltp == IL_UNSIGNED_SHORT)
{
ilToOgreInternal(static_cast<uint8*>(dst.data), dst.format,
(uint16)0x0000,(uint16)0x0000,(uint16)0x0000,(uint16)0xFFFF);
}
else
{
OGRE_EXCEPT( Exception::ERR_NOT_IMPLEMENTED,
"Cannot convert this DevIL type",
"ILUtil::ilToOgre" ) ;
}
}
示例15: ReadPixels
void TextureViewGL::ReadPixels(RenderContext_Base_GL* gl, TextureBase::ReadPixelUpdateParams& params) {
if (params.lock.test_and_set(std::memory_order_release))
return;
PixelBox* pixels = params.box;
gl->ActivateTexture(target, texture);
Size dim = gl->GetTextureParams(target);
pixels->data = static_cast<uint8*>(
NEX_ALLOC(dim.dx * dim.dy * pixelFormat.pixelSize, MEMCAT_GENERAL));
pixels->left = 0;
pixels->right = dim.dx;
pixels->top = 0;
pixels->bottom = dim.dy;
pixels->front = 0;
pixels->back = 1;
pixels->format = pixelFormat.textureFormat;
pixels->deleteData = true;
gl->GetTextureData(target, pixelFormat.internalFormat, pixelFormat.dataType, pixels->data);
pixels->CalculatePitches();
}