本文整理汇总了C++中SkTArray::push_back_n方法的典型用法代码示例。如果您正苦于以下问题:C++ SkTArray::push_back_n方法的具体用法?C++ SkTArray::push_back_n怎么用?C++ SkTArray::push_back_n使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SkTArray
的用法示例。
在下文中一共展示了SkTArray::push_back_n方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: similarBits
static int similarBits(const SkBitmap& gr, const SkBitmap& sk) {
const int kRowCount = 3;
const int kThreshold = 3;
int width = SkTMin(gr.width(), sk.width());
if (width < kRowCount) {
return true;
}
int height = SkTMin(gr.height(), sk.height());
if (height < kRowCount) {
return true;
}
int errorTotal = 0;
SkTArray<int, true> errorRows;
errorRows.push_back_n(width * kRowCount);
SkAutoLockPixels autoGr(gr);
SkAutoLockPixels autoSk(sk);
for (int y = 0; y < height; ++y) {
SkPMColor* grRow = gr.getAddr32(0, y);
SkPMColor* skRow = sk.getAddr32(0, y);
int* base = &errorRows[0];
int* cOut = &errorRows[y % kRowCount];
for (int x = 0; x < width; ++x) {
SkPMColor grColor = grRow[x];
SkPMColor skColor = skRow[x];
int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor);
int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor);
int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor);
int error = cOut[x] = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db)));
if (error < kThreshold || x < 2) {
continue;
}
if (base[x - 2] < kThreshold
|| base[width + x - 2] < kThreshold
|| base[width * 2 + x - 2] < kThreshold
|| base[x - 1] < kThreshold
|| base[width + x - 1] < kThreshold
|| base[width * 2 + x - 1] < kThreshold
|| base[x] < kThreshold
|| base[width + x] < kThreshold
|| base[width * 2 + x] < kThreshold) {
continue;
}
errorTotal += error;
}
}
return errorTotal;
}
示例2: onDrawPosText
void GrDistanceFieldTextContext::onDrawPosText(GrRenderTarget* rt, const GrClip& clip,
const GrPaint& paint,
const SkPaint& skPaint, const SkMatrix& viewMatrix,
const char text[], size_t byteLength,
const SkScalar pos[], int scalarsPerPosition,
const SkPoint& offset,
const SkIRect& regionClipBounds) {
SkASSERT(byteLength == 0 || text != NULL);
SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
// nothing to draw
if (text == NULL || byteLength == 0 /* no raster clip? || fRC->isEmpty()*/) {
return;
}
fViewMatrix = viewMatrix;
this->init(rt, clip, paint, skPaint, regionClipBounds);
SkDrawCacheProc glyphCacheProc = fSkPaint.getDrawCacheProc();
SkAutoGlyphCacheNoGamma autoCache(fSkPaint, &fDeviceProperties, NULL);
SkGlyphCache* cache = autoCache.getCache();
GrFontScaler* fontScaler = GetGrFontScaler(cache);
int numGlyphs = fSkPaint.textToGlyphs(text, byteLength, NULL);
fTotalVertexCount = kVerticesPerGlyph*numGlyphs;
const char* stop = text + byteLength;
SkTArray<char> fallbackTxt;
SkTArray<SkScalar> fallbackPos;
if (SkPaint::kLeft_Align == fSkPaint.getTextAlign()) {
while (text < stop) {
const char* lastText = text;
// the last 2 parameters are ignored
const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) {
SkScalar x = offset.x() + pos[0];
SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
glyph.getSubYFixed(),
GrGlyph::kDistance_MaskStyle),
x, y, fontScaler)) {
// couldn't append, send to fallback
fallbackTxt.push_back_n(SkToInt(text-lastText), lastText);
fallbackPos.push_back(pos[0]);
if (2 == scalarsPerPosition) {
fallbackPos.push_back(pos[1]);
}
}
}
pos += scalarsPerPosition;
}
} else {
SkScalar alignMul = SkPaint::kCenter_Align == fSkPaint.getTextAlign() ? SK_ScalarHalf
: SK_Scalar1;
while (text < stop) {
const char* lastText = text;
// the last 2 parameters are ignored
const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
if (glyph.fWidth) {
SkScalar x = offset.x() + pos[0];
SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0);
SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX)*alignMul*fTextRatio;
SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY)*alignMul*fTextRatio;
if (!this->appendGlyph(GrGlyph::Pack(glyph.getGlyphID(),
glyph.getSubXFixed(),
glyph.getSubYFixed(),
GrGlyph::kDistance_MaskStyle),
x - advanceX, y - advanceY, fontScaler)) {
// couldn't append, send to fallback
fallbackTxt.push_back_n(SkToInt(text-lastText), lastText);
fallbackPos.push_back(pos[0]);
if (2 == scalarsPerPosition) {
fallbackPos.push_back(pos[1]);
}
}
}
pos += scalarsPerPosition;
}
}
this->finish();
if (fallbackTxt.count() > 0) {
fFallbackTextContext->drawPosText(rt, clip, paint, skPaint, viewMatrix,
fallbackTxt.begin(), fallbackTxt.count(),
fallbackPos.begin(), scalarsPerPosition, offset,
regionClipBounds);
}
}
示例3: Assemble
/*
check start and end of each contour
if not the same, record them
match them up
connect closest
reassemble contour pieces into new path
*/
void Assemble(const SkPathWriter& path, SkPathWriter* simple) {
#if DEBUG_PATH_CONSTRUCTION
SkDebugf("%s\n", __FUNCTION__);
#endif
SkTArray<SkOpContour> contours;
SkOpEdgeBuilder builder(path, contours);
builder.finish();
int count = contours.count();
int outer;
SkTArray<int, true> runs(count); // indices of partial contours
for (outer = 0; outer < count; ++outer) {
const SkOpContour& eContour = contours[outer];
const SkPoint& eStart = eContour.start();
const SkPoint& eEnd = eContour.end();
#if DEBUG_ASSEMBLE
SkDebugf("%s contour", __FUNCTION__);
if (!SkDPoint::ApproximatelyEqual(eStart, eEnd)) {
SkDebugf("[%d]", runs.count());
} else {
SkDebugf(" ");
}
SkDebugf(" start=(%1.9g,%1.9g) end=(%1.9g,%1.9g)\n",
eStart.fX, eStart.fY, eEnd.fX, eEnd.fY);
#endif
if (SkDPoint::ApproximatelyEqual(eStart, eEnd)) {
eContour.toPath(simple);
continue;
}
runs.push_back(outer);
}
count = runs.count();
if (count == 0) {
return;
}
SkTArray<int, true> sLink, eLink;
sLink.push_back_n(count);
eLink.push_back_n(count);
int rIndex, iIndex;
for (rIndex = 0; rIndex < count; ++rIndex) {
sLink[rIndex] = eLink[rIndex] = SK_MaxS32;
}
const int ends = count * 2; // all starts and ends
const int entries = (ends - 1) * count; // folded triangle : n * (n - 1) / 2
SkTArray<double, true> distances;
distances.push_back_n(entries);
for (rIndex = 0; rIndex < ends - 1; ++rIndex) {
outer = runs[rIndex >> 1];
const SkOpContour& oContour = contours[outer];
const SkPoint& oPt = rIndex & 1 ? oContour.end() : oContour.start();
const int row = rIndex < count - 1 ? rIndex * ends : (ends - rIndex - 2)
* ends - rIndex - 1;
for (iIndex = rIndex + 1; iIndex < ends; ++iIndex) {
int inner = runs[iIndex >> 1];
const SkOpContour& iContour = contours[inner];
const SkPoint& iPt = iIndex & 1 ? iContour.end() : iContour.start();
double dx = iPt.fX - oPt.fX;
double dy = iPt.fY - oPt.fY;
double dist = dx * dx + dy * dy;
distances[row + iIndex] = dist; // oStart distance from iStart
}
}
SkTArray<int, true> sortedDist;
sortedDist.push_back_n(entries);
for (rIndex = 0; rIndex < entries; ++rIndex) {
sortedDist[rIndex] = rIndex;
}
SkTQSort<int>(sortedDist.begin(), sortedDist.end() - 1, DistanceLessThan(distances.begin()));
int remaining = count; // number of start/end pairs
for (rIndex = 0; rIndex < entries; ++rIndex) {
int pair = sortedDist[rIndex];
int row = pair / ends;
int col = pair - row * ends;
int thingOne = row < col ? row : ends - row - 2;
int ndxOne = thingOne >> 1;
bool endOne = thingOne & 1;
int* linkOne = endOne ? eLink.begin() : sLink.begin();
if (linkOne[ndxOne] != SK_MaxS32) {
continue;
}
int thingTwo = row < col ? col : ends - row + col - 1;
int ndxTwo = thingTwo >> 1;
bool endTwo = thingTwo & 1;
int* linkTwo = endTwo ? eLink.begin() : sLink.begin();
if (linkTwo[ndxTwo] != SK_MaxS32) {
continue;
}
SkASSERT(&linkOne[ndxOne] != &linkTwo[ndxTwo]);
bool flip = endOne == endTwo;
linkOne[ndxOne] = flip ? ~ndxTwo : ndxTwo;
linkTwo[ndxTwo] = flip ? ~ndxOne : ndxOne;
if (!--remaining) {
break;
}
//.........这里部分代码省略.........
示例4: testOne
void TestResult::testOne() {
sk_sp<SkPicture> pic;
{
SkString d;
d.printf(" {%d, \"%s\"},", fDirNo, fFilename);
SkString path = make_filepath(fDirNo, IN_DIR, fFilename);
SkFILEStream stream(path.c_str());
if (!stream.isValid()) {
SkDebugf("invalid stream %s\n", path.c_str());
goto finish;
}
if (fTestStep == kEncodeFiles) {
size_t length = stream.getLength();
SkTArray<char, true> bytes;
bytes.push_back_n(length);
stream.read(&bytes[0], length);
stream.rewind();
SkString wPath = make_filepath(0, outSkpDir, fFilename);
SkFILEWStream wStream(wPath.c_str());
wStream.write(&bytes[0], length);
wStream.flush();
}
pic = SkPicture::MakeFromStream(&stream);
if (!pic) {
SkDebugf("unable to decode %s\n", fFilename);
goto finish;
}
int pWidth = pic->width();
int pHeight = pic->height();
int pLargerWH = SkTMax(pWidth, pHeight);
GrContextFactory contextFactory;
#ifdef SK_BUILD_FOR_WIN
GrContext* context = contextFactory.get(kAngle);
#else
GrContext* context = contextFactory.get(kNative);
#endif
if (nullptr == context) {
SkDebugf("unable to allocate context for %s\n", fFilename);
goto finish;
}
int maxWH = context->getMaxRenderTargetSize();
int scale = 1;
while (pLargerWH / scale > maxWH) {
scale *= 2;
}
SkBitmap bitmap;
SkIPoint dim;
do {
dim.fX = (pWidth + scale - 1) / scale;
dim.fY = (pHeight + scale - 1) / scale;
bool success = bitmap.allocN32Pixels(dim.fX, dim.fY);
if (success) {
break;
}
SkDebugf("-%d-", scale);
} while ((scale *= 2) < 256);
if (scale >= 256) {
SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n",
fFilename, pWidth, pHeight, dim.fX, dim.fY);
return;
}
SkCanvas skCanvas(bitmap);
drawPict(pic, &skCanvas, fScaleOversized ? scale : 1);
GrTextureDesc desc;
desc.fConfig = kRGBA_8888_GrPixelConfig;
desc.fFlags = kRenderTarget_GrTextureFlagBit;
desc.fWidth = dim.fX;
desc.fHeight = dim.fY;
desc.fSampleCnt = 0;
sk_sp<GrTexture> texture(context->createUncachedTexture(desc, nullptr, 0));
if (!texture) {
SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename,
dim.fX, dim.fY);
return;
}
SkGpuDevice grDevice(context, texture.get());
SkCanvas grCanvas(&grDevice);
drawPict(pic.get(), &grCanvas, fScaleOversized ? scale : 1);
SkBitmap grBitmap;
grBitmap.allocPixels(grCanvas.imageInfo());
grCanvas.readPixels(&grBitmap, 0, 0);
if (fTestStep == kCompareBits) {
fPixelError = similarBits(grBitmap, bitmap);
SkMSec skTime = timePict(pic, &skCanvas);
SkMSec grTime = timePict(pic, &grCanvas);
fTime = skTime - grTime;
} else if (fTestStep == kEncodeFiles) {
SkString pngStr = make_png_name(fFilename);
const char* pngName = pngStr.c_str();
writePict(grBitmap, outGrDir, pngName);
writePict(bitmap, outSkDir, pngName);
}
}
}