本文整理汇总了C++中SkScalarRound函数的典型用法代码示例。如果您正苦于以下问题:C++ SkScalarRound函数的具体用法?C++ SkScalarRound怎么用?C++ SkScalarRound使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SkScalarRound函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HSV_to_RGB
static SkColor HSV_to_RGB(SkColor color, HSV_Choice choice, SkScalar hsv) {
SkScalar hue = choice == kGetHue ? hsv : RGB_to_HSV(color, kGetHue);
SkScalar saturation = choice == kGetSaturation ? hsv : RGB_to_HSV(color, kGetSaturation);
SkScalar value = choice == kGetValue ? hsv : RGB_to_HSV(color, kGetValue);
value *= 255;
SkScalar red SK_INIT_TO_AVOID_WARNING;
SkScalar green SK_INIT_TO_AVOID_WARNING;
SkScalar blue SK_INIT_TO_AVOID_WARNING;
if (saturation == 0) // color is on black-and-white center line
red = green = blue = value;
else {
//SkScalar fraction = SkScalarMod(hue, 60 * SK_Scalar1);
int sextant = SkScalarFloor(hue / 60);
SkScalar fraction = hue / 60 - SkIntToScalar(sextant);
SkScalar p = SkScalarMul(value , SK_Scalar1 - saturation);
SkScalar q = SkScalarMul(value, SK_Scalar1 - SkScalarMul(saturation, fraction));
SkScalar t = SkScalarMul(value, SK_Scalar1 -
SkScalarMul(saturation, SK_Scalar1 - fraction));
switch (sextant % 6) {
case 0: red = value; green = t; blue = p; break;
case 1: red = q; green = value; blue = p; break;
case 2: red = p; green = value; blue = t; break;
case 3: red = p; green = q; blue = value; break;
case 4: red = t; green = p; blue = value; break;
case 5: red = value; green = p; blue = q; break;
}
}
//used to say SkToU8((U8CPU) red) etc
return SkColorSetARGB(SkColorGetA(color), SkScalarRound(red),
SkScalarRound(green), SkScalarRound(blue));
}
示例2: count_path_runtype_values
static int count_path_runtype_values(const SkPath& path, int* itop, int* ibot) {
SkPath::Iter iter(path, true);
SkPoint pts[4];
SkPath::Verb verb;
int maxEdges = 0;
SkScalar top = SkIntToScalar(SK_MaxS16);
SkScalar bot = SkIntToScalar(SK_MinS16);
while ((verb = iter.next(pts, false)) != SkPath::kDone_Verb) {
maxEdges += verb_to_max_edges(verb);
int lastIndex = verb_to_initial_last_index(verb);
if (lastIndex > 0) {
for (int i = 1; i <= lastIndex; i++) {
if (top > pts[i].fY) {
top = pts[i].fY;
} else if (bot < pts[i].fY) {
bot = pts[i].fY;
}
}
} else if (SkPath::kMove_Verb == verb) {
if (top > pts[0].fY) {
top = pts[0].fY;
} else if (bot < pts[0].fY) {
bot = pts[0].fY;
}
}
}
SkASSERT(top <= bot);
*itop = SkScalarRound(top);
*ibot = SkScalarRound(bot);
return maxEdges;
}
示例3: SkASSERT
bool SkOSWindow::attach(SkBackEndTypes /* attachType */, int msaaSampleCount) {
this->initWindow(msaaSampleCount);
if (NULL == fUnixWindow.fDisplay) {
return false;
}
if (NULL == fUnixWindow.fGLContext) {
SkASSERT(NULL != fVi);
fUnixWindow.fGLContext = glXCreateContext(fUnixWindow.fDisplay,
fVi,
NULL,
GL_TRUE);
if (NULL == fUnixWindow.fGLContext) {
return false;
}
}
glXMakeCurrent(fUnixWindow.fDisplay,
fUnixWindow.fWin,
fUnixWindow.fGLContext);
glViewport(0, 0,
SkScalarRound(this->width()), SkScalarRound(this->height()));
glClearColor(0, 0, 0, 0);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
return true;
}
示例4: drawMask
void drawMask(SkCanvas* canvas, const SkRect& r) {
SkPaint paint;
paint.setAntiAlias(true);
if (true) {
SkBitmap mask;
int w = SkScalarRound(r.width());
int h = SkScalarRound(r.height());
mask.setConfig(SkBitmap::kARGB_8888_Config, w, h);
mask.allocPixels();
mask.eraseColor(0);
SkCanvas c(mask);
SkRect bounds = r;
bounds.offset(-bounds.fLeft, -bounds.fTop);
c.drawOval(bounds, paint);
paint.setXfermodeMode(SkXfermode::kDstIn_Mode);
canvas->drawBitmap(mask, r.fLeft, r.fTop, &paint);
} else {
SkPath p;
p.addOval(r);
p.setFillType(SkPath::kInverseWinding_FillType);
paint.setXfermodeMode(SkXfermode::kDstOut_Mode);
canvas->drawPath(p, paint);
}
}
示例5: addCornerArc
void addCornerArc(SkPath* path, const SkRect& rect, const IntSize& size, int startAngle)
{
SkIRect ir;
int rx = SkMin32(SkScalarRound(rect.width()), size.width());
int ry = SkMin32(SkScalarRound(rect.height()), size.height());
ir.set(-rx, -ry, rx, ry);
switch (startAngle) {
case 0:
ir.offset(rect.fRight - ir.fRight, rect.fBottom - ir.fBottom);
break;
case 90:
ir.offset(rect.fLeft - ir.fLeft, rect.fBottom - ir.fBottom);
break;
case 180:
ir.offset(rect.fLeft - ir.fLeft, rect.fTop - ir.fTop);
break;
case 270:
ir.offset(rect.fRight - ir.fRight, rect.fTop - ir.fTop);
break;
default:
ASSERT(0);
}
SkRect r;
r.set(ir);
path->arcTo(r, SkIntToScalar(startAngle), SkIntToScalar(90), false);
}
示例6: round
static void round(SkIRect* dst, const WebCore::FloatRect& src)
{
dst->set(SkScalarRound(SkFloatToScalar(src.x())),
SkScalarRound(SkFloatToScalar(src.y())),
SkScalarRound(SkFloatToScalar((src.x() + src.width()))),
SkScalarRound(SkFloatToScalar((src.y() + src.height()))));
}
示例7: lettersToBitmap2
static void lettersToBitmap2(SkBitmap* dst, const char chars[],
const SkPaint& original, SkBitmap::Config config) {
SkPath path;
SkScalar x = 0;
SkScalar width;
SkPath p;
for (size_t i = 0; i < strlen(chars); i++) {
original.getTextPath(&chars[i], 1, x, 0, &p);
path.addPath(p);
original.getTextWidths(&chars[i], 1, &width);
x += width;
}
SkRect bounds = path.getBounds();
SkScalar sw = -original.getStrokeWidth();
bounds.inset(sw, sw);
path.offset(-bounds.fLeft, -bounds.fTop);
bounds.offset(-bounds.fLeft, -bounds.fTop);
int w = SkScalarRound(bounds.width());
int h = SkScalarRound(bounds.height());
SkPaint paint(original);
paint.setAntiAlias(true);
paint.setXfermodeMode(SkXfermode::kDstATop_Mode);
paint.setColor(original.getColor());
paint.setStyle(SkPaint::kStroke_Style);
dst->setConfig(config, w, h);
dst->allocPixels();
dst->eraseColor(SK_ColorWHITE);
SkCanvas canvas(*dst);
canvas.drawPath(path, paint);
}
示例8: count_path_runtype_values
static int count_path_runtype_values(const SkPath& path, int* itop, int* ibot) {
static const uint8_t gPathVerbToInitialLastIndex[] = {
0, // kMove_Verb
1, // kLine_Verb
2, // kQuad_Verb
3, // kCubic_Verb
0, // kClose_Verb
0 // kDone_Verb
};
static const uint8_t gPathVerbToMaxEdges[] = {
0, // kMove_Verb
1, // kLine_Verb
2, // kQuad_VerbB
3, // kCubic_Verb
0, // kClose_Verb
0 // kDone_Verb
};
SkPath::Iter iter(path, true);
SkPoint pts[4];
SkPath::Verb verb;
int maxEdges = 0;
SkScalar top = SkIntToScalar(SK_MaxS16);
SkScalar bot = SkIntToScalar(SK_MinS16);
while ((verb = iter.next(pts)) != SkPath::kDone_Verb) {
maxEdges += gPathVerbToMaxEdges[verb];
int lastIndex = gPathVerbToInitialLastIndex[verb];
if (lastIndex > 0) {
for (int i = 1; i <= lastIndex; i++) {
if (top > pts[i].fY) {
top = pts[i].fY;
} else if (bot < pts[i].fY) {
bot = pts[i].fY;
}
}
} else if (SkPath::kMove_Verb == verb) {
if (top > pts[0].fY) {
top = pts[0].fY;
} else if (bot < pts[0].fY) {
bot = pts[0].fY;
}
}
}
SkASSERT(top <= bot);
*itop = SkScalarRound(top);
*ibot = SkScalarRound(bot);
return maxEdges;
}
示例9: onDrawContent
virtual void onDrawContent(SkCanvas* canvas)
{
canvas->translate(SkIntToScalar(10), SkIntToScalar(50));
const SkScalar W = SkIntToScalar(fBitmaps[0].width() + 1);
const SkScalar H = SkIntToScalar(fBitmaps[0].height() + 1);
SkPaint paint;
const SkScalar scale = SkFloatToScalar(0.897917f);
canvas->scale(SK_Scalar1, scale);
for (int k = 0; k < 2; k++)
{
paint.setFilterBitmap(k == 1);
for (int j = 0; j < 2; j++)
{
paint.setDither(j == 1);
for (int i = 0; i < fBitmapCount; i++)
{
SkScalar x = (k * fBitmapCount + j) * W;
SkScalar y = i * H;
x = SkIntToScalar(SkScalarRound(x));
y = SkIntToScalar(SkScalarRound(y));
canvas->drawBitmap(fBitmaps[i], x, y, &paint);
if (i == 0)
{
SkPaint p;
p.setAntiAlias(true);
p.setTextAlign(SkPaint::kCenter_Align);
p.setTextSize(SkIntToScalar(18));
SkString s("dither=");
s.appendS32(paint.isDither());
s.append(" filter=");
s.appendS32(paint.isFilterBitmap());
canvas->drawText(s.c_str(), s.size(), x + W/2,
y - p.getTextSize(), p);
}
if (k+j == 2)
{
SkPaint p;
p.setAntiAlias(true);
p.setTextSize(SkIntToScalar(18));
SkString s;
s.append(" depth=");
s.appendS32(fBitmaps[i].config() == SkBitmap::kRGB_565_Config ? 16 : 32);
canvas->drawText(s.c_str(), s.size(), x + W + SkIntToScalar(4),
y + H/2, p);
}
}
}
}
}
示例10: SkScalerContext
SkScalerContext_Ascender::SkScalerContext_Ascender(const SkDescriptor* desc)
: SkScalerContext(desc)
{
int size = aca_Get_FontHandleRec_Size();
fHandle = (aca_FontHandle)sk_malloc_throw(size);
// get the pointer to the font
fFontStream = new SkMMAPStream("/UcsGB2312-Hei-H.FDL");
fHintStream = new SkMMAPStream("/genv6-23.bin");
void* hints = sk_malloc_throw(fHintStream->getLength());
memcpy(hints, fHintStream->getMemoryBase(), fHintStream->getLength());
aca_Create_Font_Handle(fHandle,
(void*)fFontStream->getMemoryBase(), fFontStream->getLength(),
"fred",
hints, fHintStream->getLength());
// compute our factors from the record
SkMatrix m;
fRec.getSingleMatrix(&m);
// now compute our scale factors
SkScalar sx = m.getScaleX();
SkScalar sy = m.getScaleY();
int ppemX = SkScalarRound(sx);
int ppemY = SkScalarRound(sy);
size = aca_Find_Font_Memory_Required(fHandle, ppemX, ppemY);
size *= 8; // Jeff suggests this :)
fWorkspace = sk_malloc_throw(size);
aca_Set_Font_Memory(fHandle, (uint8_t*)fWorkspace, size);
aca_GlyphAttribsRec rec;
memset(&rec, 0, sizeof(rec));
rec.xSize = ppemX;
rec.ySize = ppemY;
rec.doAdjust = true;
rec.doExceptions = true;
rec.doGlyphHints = true;
rec.doInterpolate = true;
rec.grayMode = 2;
aca_Set_Font_Attributes(fHandle, &rec, &size);
fGlyphWorkspace = sk_malloc_throw(size);
aca_Set_Glyph_Memory(fHandle, fGlyphWorkspace);
}
示例11: getPoints
HRGN Path::CreateNativeRegion() const
{
int point_count = getPoints(NULL, 0);
scoped_array<SkPoint> points(new SkPoint[point_count]);
getPoints(points.get(), point_count);
scoped_array<POINT> windows_points(new POINT[point_count]);
for(int i=0; i<point_count; ++i)
{
windows_points[i].x = SkScalarRound(points[i].fX);
windows_points[i].y = SkScalarRound(points[i].fY);
}
return ::CreatePolygonRgn(windows_points.get(), point_count, ALTERNATE);
}
示例12: storage
int Font::offsetForPositionForComplexText(const TextRun& run, int x,
bool includePartialGlyphs) const
{
SkPaint paint;
int count = run.length();
SkAutoSTMalloc<64, SkScalar> storage(count);
SkScalar* widths = storage.get();
SkAutoSTMalloc<64, int> storageClusterIndex(count);
int* clusterIndex = storageClusterIndex.get();
primaryFont()->platformData().setupPaint(&paint);
//count = paint.getTextWidths(run.characters(), count << 1, widths);
count = paint.getComplexTextWidths(run.characters(), count << 1, widths, clusterIndex);
if (count > 0)
{
SkScalar pos = 0;
for (int i = 0; i < count; i++)
{
if (x < SkScalarRound(pos + SkScalarHalf(widths[i])))
return clusterIndex[i];
pos += widths[i];
}
}
return run.length();
}
示例13: timeToT
SkInterpolatorBase::Result SkOperandInterpolator::timeToValues(SkMSec time, SkOperand values[]) const
{
SkScalar T;
int index;
SkBool exact;
Result result = timeToT(time, &T, &index, &exact);
if (values)
{
const SkOperand* nextSrc = &fValues[index * fElemCount];
if (exact)
memcpy(values, nextSrc, fElemCount * sizeof(SkScalar));
else
{
SkASSERT(index > 0);
const SkOperand* prevSrc = nextSrc - fElemCount;
if (fType == SkType_Float || fType == SkType_3D_Point) {
for (int i = fElemCount - 1; i >= 0; --i)
values[i].fScalar = SkScalarInterp(prevSrc[i].fScalar, nextSrc[i].fScalar, T);
} else if (fType == SkType_Int || fType == SkType_MSec) {
for (int i = fElemCount - 1; i >= 0; --i) {
int32_t a = prevSrc[i].fS32;
int32_t b = nextSrc[i].fS32;
values[i].fS32 = a + SkScalarRound((b - a) * T);
}
} else
memcpy(values, prevSrc, sizeof(SkOperand) * fElemCount);
}
}
return result;
}
示例14: just_trans_clamp
/**
* For the purposes of drawing bitmaps, if a matrix is "almost" translate
* go ahead and treat it as if it were, so that subsequent code can go fast.
*/
static bool just_trans_clamp(const SkMatrix& matrix, const SkBitmap& bitmap) {
SkMatrix::TypeMask mask = matrix.getType();
if (mask & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
return false;
}
if (mask & SkMatrix::kScale_Mask) {
SkScalar sx = matrix[SkMatrix::kMScaleX];
SkScalar sy = matrix[SkMatrix::kMScaleY];
int w = bitmap.width();
int h = bitmap.height();
int sw = SkScalarRound(SkScalarMul(sx, SkIntToScalar(w)));
int sh = SkScalarRound(SkScalarMul(sy, SkIntToScalar(h)));
return sw == w && sh == h;
}
// if we got here, we're either kTranslate_Mask or identity
return true;
}
示例15: getFontMetricsInt
static jint getFontMetricsInt(JNIEnv* env, jobject paint, jobject metricsObj) {
NPE_CHECK_RETURN_ZERO(env, paint);
SkPaint::FontMetrics metrics;
GraphicsJNI::getNativePaint(env, paint)->getFontMetrics(&metrics);
int ascent = SkScalarRound(metrics.fAscent);
int descent = SkScalarRound(metrics.fDescent);
int leading = SkScalarRound(metrics.fLeading);
if (metricsObj) {
SkASSERT(env->IsInstanceOf(metricsObj, gFontMetricsInt_class));
env->SetIntField(metricsObj, gFontMetricsInt_fieldID.top, SkScalarFloor(metrics.fTop));
env->SetIntField(metricsObj, gFontMetricsInt_fieldID.ascent, ascent);
env->SetIntField(metricsObj, gFontMetricsInt_fieldID.descent, descent);
env->SetIntField(metricsObj, gFontMetricsInt_fieldID.bottom, SkScalarCeil(metrics.fBottom));
env->SetIntField(metricsObj, gFontMetricsInt_fieldID.leading, leading);
}
return descent - ascent + leading;
}