本文整理汇总了C++中GfxSurface::create方法的典型用法代码示例。如果您正苦于以下问题:C++ GfxSurface::create方法的具体用法?C++ GfxSurface::create怎么用?C++ GfxSurface::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GfxSurface
的用法示例。
在下文中一共展示了GfxSurface::create方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: surfaceFromRes
/**
* Translates a raw image resource into a graphics surface. The caller is then responsible
* for managing and destroying the surface when done with it
*
* @imgData Raw image resource
* @size Size of the resource
*/
GfxSurface surfaceFromRes(const byte *imgData) {
Rect r(0, 0, READ_LE_UINT16(imgData), READ_LE_UINT16(imgData + 2));
GfxSurface s;
s.create(r.width(), r.height());
s._centroid.x = READ_LE_UINT16(imgData + 4);
s._centroid.y = READ_LE_UINT16(imgData + 6);
s._transColor = *(imgData + 8);
bool rleEncoded = (imgData[9] & 2) != 0;
const byte *srcP = imgData + 10;
Graphics::Surface destSurface = s.lockSurface();
byte *destP = (byte *)destSurface.getBasePtr(0, 0);
if (!rleEncoded) {
Common::copy(srcP, srcP + (r.width() * r.height()), destP);
} else {
Common::set_to(destP, destP + (r.width() * r.height()), s._transColor);
for (int yp = 0; yp < r.height(); ++yp) {
int width = r.width();
destP = (byte *)destSurface.getBasePtr(0, yp);
while (width > 0) {
uint8 controlVal = *srcP++;
if ((controlVal & 0x80) == 0) {
// Copy specified number of bytes
Common::copy(srcP, srcP + controlVal, destP);
width -= controlVal;
srcP += controlVal;
destP += controlVal;
} else if ((controlVal & 0x40) == 0) {
// Skip a specified number of output pixels
destP += controlVal & 0x3f;
width -= controlVal & 0x3f;
} else {
// Copy a specified pixel a given number of times
controlVal &= 0x3f;
int pixel = *srcP++;
Common::set_to(destP, destP + controlVal, pixel);
destP += controlVal;
width -= controlVal;
}
}
assert(width == 0);
}
}
s.unlockSurface();
return s;
}
示例2: ResizeSurface
/**
* Scales a passed surface, creating a new surface with the result
* @param srcImage Source image to scale
* @param NewWidth New width for scaled image
* @param NewHeight New height for scaled image
* @remarks Caller is responsible for freeing the returned surface
*/
static GfxSurface ResizeSurface(GfxSurface &src, int xSize, int ySize, int transIndex) {
GfxSurface s;
s.create(xSize, ySize);
Graphics::Surface srcImage = src.lockSurface();
Graphics::Surface destImage = s.lockSurface();
int *horizUsage = scaleLine(xSize, srcImage.w);
int *vertUsage = scaleLine(ySize, srcImage.h);
// Loop to create scaled version
for (int yp = 0; yp < ySize; ++yp) {
byte *destP = (byte *)destImage.getBasePtr(0, yp);
if (vertUsage[yp] == -1) {
Common::set_to(destP, destP + xSize, transIndex);
} else {
const byte *srcP = (const byte *)srcImage.getBasePtr(0, vertUsage[yp]);
for (int xp = 0; xp < xSize; ++xp) {
if (horizUsage[xp] != -1) {
const byte *tempSrcP = srcP + horizUsage[xp];
*destP++ = *tempSrcP++;
} else {
// Pixel overrun at the end of the line
*destP++ = transIndex;
}
}
}
}
// Unlock surfaces
src.unlockSurface();
s.unlockSurface();
// Delete arrays and return surface
delete[] horizUsage;
delete[] vertUsage;
return s;
}
示例3: copyFrom
/**
* Copys an area from one GfxSurface to another
*/
void GfxSurface::copyFrom(GfxSurface &src, Rect srcBounds, Rect destBounds, Region *priorityRegion) {
GfxSurface srcImage;
if (srcBounds.isEmpty())
return;
if (srcBounds == src.getBounds())
srcImage = src;
else {
// Set the source image to be the subset specified by the source bounds
Graphics::Surface srcSurface = src.lockSurface();
srcImage.create(srcBounds.width(), srcBounds.height());
Graphics::Surface destSurface = srcImage.lockSurface();
const byte *srcP = (const byte *)srcSurface.getBasePtr(srcBounds.left, srcBounds.top);
byte *destP = (byte *)destSurface.pixels;
for (int yp = srcBounds.top; yp < srcBounds.bottom; ++yp, srcP += srcSurface.pitch, destP += destSurface.pitch) {
Common::copy(srcP, srcP + srcBounds.width(), destP);
}
srcImage.unlockSurface();
src.unlockSurface();
}
if ((destBounds.width() != srcBounds.width()) || (destBounds.height() != srcBounds.height()))
srcImage = ResizeSurface(srcImage, destBounds.width(), destBounds.height(), src._transColor);
Graphics::Surface srcSurface = srcImage.lockSurface();
Graphics::Surface destSurface = lockSurface();
// Adjust bounds to ensure destination will be on-screen
int srcX = 0, srcY = 0;
if (destBounds.left < 0) {
srcX = -destBounds.left;
destBounds.left = 0;
}
if (destBounds.top < 0) {
srcY = -destBounds.top;
destBounds.top = 0;
}
if (destBounds.right > destSurface.w)
destBounds.right = destSurface.w;
if (destBounds.bottom > destSurface.h)
destBounds.bottom = destSurface.h;
if (destBounds.isValidRect()) {
const byte *pSrc = (const byte *)srcSurface.getBasePtr(srcX, srcY);
byte *pDest = (byte *)destSurface.getBasePtr(destBounds.left, destBounds.top);
for (int y = 0; y < destBounds.height(); ++y, pSrc += srcSurface.pitch, pDest += destSurface.pitch) {
if (!priorityRegion && (src._transColor == -1))
Common::copy(pSrc, pSrc + destBounds.width(), pDest);
else {
const byte *tempSrc = pSrc;
byte *tempDest = pDest;
int xp = destBounds.left;
while (tempSrc < (pSrc + destBounds.width())) {
if (!priorityRegion || !priorityRegion->contains(Common::Point(
xp + _globals->_sceneManager._scene->_sceneBounds.left,
destBounds.top + y + _globals->_sceneManager._scene->_sceneBounds.top))) {
if (*tempSrc != src._transColor)
*tempDest = *tempSrc;
}
++tempSrc;
++tempDest;
++xp;
}
}
}
}
unlockSurface();
srcImage.unlockSurface();
}