本文整理汇总了C++中CImg::Alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ CImg::Alloc方法的具体用法?C++ CImg::Alloc怎么用?C++ CImg::Alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CImg
的用法示例。
在下文中一共展示了CImg::Alloc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetPreviewPosition
void PreviewRenderer::SetPreviewPosition(int iX, int iY, int iWidth, int iHeight)
{
ScaleArea(AlgorithmRemote::GetRequiredOverlapFactor(), iX, iY, iWidth, iHeight);
/* Clamp bounds. */
iX = clamp(iX, 0, Source.m_iWidth);
iY = clamp(iY, 0, Source.m_iHeight);
iWidth = clamp(iWidth, 0, Source.m_iWidth - iX);
iHeight = clamp(iHeight, 0, Source.m_iHeight - iY);
/* If there's an overlap between the old position and the new position, optimize by
* moving the old data to the new position and only blitting in the changed data. */
int iFromX = 0, iFromY = 0;
int iToX = 0, iToY = 0;
if(iX < Image.iX) iToX += Image.iX - iX;
if(iX > Image.iX) iFromX += iX - Image.iX;
if(iY < Image.iY) iToY += Image.iY - iY;
if(iY > Image.iY) iFromY += iY - Image.iY;
CImg temp;
temp.Alloc(iWidth, iHeight, 1, 4);
/* Copy the area within the image that's moved. This usually covers most of the image, and
* it's much faster since we don't need to do any conversions. */
int iMoveWidth = min(Image.PreviewImage.m_iWidth, iWidth) - iToX - iFromX;
int iMoveHeight = min(Image.PreviewImage.m_iHeight, iHeight) - iToY - iFromY;
iMoveWidth = max(0, iMoveWidth);
iMoveHeight = max(0, iMoveHeight);
for(int y = 0; y < iMoveHeight; ++y)
{
const uint8_t *pFrom = Image.PreviewImage.ptr(iFromX, iFromY+y);
uint8_t *pTo = temp.ptr(iToX, iToY+y);
memmove(pTo, pFrom, iMoveWidth * Image.PreviewImage.m_iBytesPerChannel * Image.PreviewImage.m_iChannels);
}
/* Copy the edges; this part needs to be converted. Top edge:*/
if(iToY > 0)
{
CImg SrcRegion;
SrcRegion.Hold(Source, iX, iY, iWidth, iToY);
CImg DestRegion;
DestRegion.Hold(temp, 0, 0, iWidth, iToY);
SetFromImage(gFilterRecord, SrcRegion, DestRegion);
}
/* Top edge: */
if(iMoveHeight + iToY < iHeight)
{
int iYToCopy = iMoveHeight + iToY;
CImg SrcRegion;
SrcRegion.Hold(Source, iX, iY + iYToCopy, iWidth, iHeight - iYToCopy);
CImg DestRegion;
DestRegion.Hold(temp, 0, iYToCopy, iWidth, iHeight - iYToCopy);
SetFromImage(gFilterRecord, SrcRegion, DestRegion);
}
/* Left edge: */
if(iToX > 0)
{
CImg SrcRegion;
SrcRegion.Hold(Source, iX, iY, iToX, iHeight);
CImg DestRegion;
DestRegion.Hold(temp, 0, 0, iToX, iHeight);
SetFromImage(gFilterRecord, SrcRegion, DestRegion);
}
/* Right edge: */
if(iMoveWidth + iToX < iWidth)
{
int iXToCopy = iMoveWidth + iToX;
CImg SrcRegion;
SrcRegion.Hold(Source, iX + iXToCopy, iY, iWidth - iXToCopy, iHeight);
CImg DestRegion;
DestRegion.Hold(temp, iXToCopy, 0, iWidth - iXToCopy, iHeight);
SetFromImage(gFilterRecord, SrcRegion, DestRegion);
}
temp.Swap(Image.PreviewImage);
Image.iX = iX;
Image.iY = iY;
}