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)); }
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; }
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; }
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); } }
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); }
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())))); }
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); }
int main (int argc, char * const argv[]) { SkAutoGraphics ag; SkString path("skhello.png"); SkString text("Hello"); for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "--help")) { show_help(); return 0; } if (!strcmp(argv[i], "-o")) { if (i == argc-1) { SkDebugf("ERROR: -o needs a following filename\n"); return -1; } path.set(argv[i+1]); i += 1; // skip the out dir name } else if (!strcmp(argv[i], "-t")) { if (i == argc-1) { SkDebugf("ERROR: -t needs a following string\n"); return -1; } text.set(argv[i+1]); i += 1; // skip the text string } } SkPaint paint; paint.setAntiAlias(true); paint.setTextSize(SkIntToScalar(30)); SkScalar width = paint.measureText(text.c_str(), text.size()); SkScalar spacing = paint.getFontSpacing(); int w = SkScalarRound(width) + 30; int h = SkScalarRound(spacing) + 30; SkBitmap bitmap; bitmap.setConfig(SkBitmap::kARGB_8888_Config, w, h); bitmap.allocPixels(); SkCanvas canvas(bitmap); canvas.drawColor(SK_ColorWHITE); paint.setTextAlign(SkPaint::kCenter_Align); canvas.drawText(text.c_str(), text.size(), SkIntToScalar(w)/2, SkIntToScalar(h)*2/3, paint); bool success = SkImageEncoder::EncodeFile(path.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100); if (!success) { SkDebugf("--- failed to write %s\n", path.c_str()); } return !success; }
Rect Transform::makeBounds(int w, int h) const { Rect r; SkRect d, s; s.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); mTransform.mapRect(&d, s); r.left = SkScalarRound( d.fLeft ); r.top = SkScalarRound( d.fTop ); r.right = SkScalarRound( d.fRight ); r.bottom = SkScalarRound( d.fBottom ); return r; }
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; }
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); } } } } }
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); }
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); }
Rect Transform::transform(const Rect& bounds) const { Rect r; SkRect d, s; s.set( SkIntToScalar( bounds.left ), SkIntToScalar( bounds.top ), SkIntToScalar( bounds.right ), SkIntToScalar( bounds.bottom )); mTransform.mapRect(&d, s); r.left = SkScalarRound( d.fLeft ); r.top = SkScalarRound( d.fTop ); r.right = SkScalarRound( d.fRight ); r.bottom = SkScalarRound( d.fBottom ); return r; }
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(); }
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; }
void LayerAndroid::onDraw(SkCanvas* canvas, SkScalar opacity, android::DrawExtra* extra, PaintStyle style) { if (m_haveClip) { SkRect r; r.set(0, 0, getSize().width(), getSize().height()); canvas->clipRect(r); return; } // only continue drawing if layer is drawable if (!m_content && !m_imageCRC) return; // we just have this save/restore for opacity... SkAutoCanvasRestore restore(canvas, true); int canvasOpacity = SkScalarRound(opacity * 255); if (canvasOpacity < 255) canvas->setDrawFilter(new OpacityDrawFilter(canvasOpacity)); if (m_imageCRC) { ImageTexture* imageTexture = ImagesManager::instance()->retainImage(m_imageCRC); m_dirtyRegion.setEmpty(); if (imageTexture) { SkRect dest; dest.set(0, 0, getSize().width(), getSize().height()); imageTexture->drawCanvas(canvas, dest); } ImagesManager::instance()->releaseImage(m_imageCRC); } contentDraw(canvas, style); if (extra) extra->draw(canvas, this); }
static SkIPoint* getpts(const SkPath& path, int* count) { SkPoint pts[4]; int n = 1; SkIPoint* array; { SkPath::Iter iter(path, false); for (;;) switch (iter.next(pts)) { case SkPath::kLine_Verb: n += 1; break; case SkPath::kDone_Verb: goto FINISHED; default: break; } } FINISHED: array = new SkIPoint[n]; n = 0; { SkPath::Iter iter(path, false); for (;;) switch (iter.next(pts)) { case SkPath::kMove_Verb: array[n++].set(SkScalarRound(pts[0].fX), SkScalarRound(pts[0].fY)); break; case SkPath::kLine_Verb: array[n++].set(SkScalarRound(pts[1].fX), SkScalarRound(pts[1].fY)); break; case SkPath::kDone_Verb: goto FINISHED2; default: break; } } FINISHED2: *count = n; return array; }
/** * 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; }
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; }
BlurBench(void* param, SkScalar rad, SkBlurMaskFilter::BlurStyle bs) : INHERITED(param) { fRadius = rad; fStyle = bs; const char* name = rad > 0 ? gStyleName[bs] : "none"; if (SkScalarFraction(rad) != 0) { fName.printf("blur_%.2f_%s", SkScalarToFloat(rad), name); } else { fName.printf("blur_%d_%s", SkScalarRound(rad), name); } }
virtual void onDraw(SkCanvas* canvas, SkScalar opacity) { SkRect r; r.set(0, 0, this->getWidth(), this->getHeight()); SkPaint paint; paint.setColor(fColor); paint.setAlpha(SkScalarRound(opacity * 255)); canvas->drawRect(r, paint); }
MorphologyBench(void* param, SkScalar rad, MorphologyType style) : INHERITED(param) { fRadius = rad; fStyle = style; const char* name = rad > 0 ? gStyleName[style] : "none"; if (SkScalarFraction(rad) != 0) { fName.printf("morph_%.2f_%s", SkScalarToFloat(rad), name); } else { fName.printf("morph_%d_%s", SkScalarRound(rad), name); } }
bool SkSliderView::onClick(Click* click) { if (fMax) { SkScalar percent = SkScalarDiv(click->fCurr.fX + SK_Scalar1, this->width() - SK_Scalar1*2); percent = SkMaxScalar(0, SkMinScalar(percent, SK_Scalar1)); this->setValue(SkScalarRound(percent * fMax)); return true; } return false; }
static void build_power_table(uint8_t table[], float ee) { // SkDebugf("------ build_power_table %g\n", ee); for (int i = 0; i < 256; i++) { float x = i / 255.f; // printf(" %d %g", i, x); x = powf(x, ee); // printf(" %g", x); int xx = SkScalarRound(SkFloatToScalar(x * 255)); // printf(" %d\n", xx); table[i] = SkToU8(xx); } }
// This is only used to draw borders. void GraphicsContext::drawLine(const IntPoint& point1, const IntPoint& point2) { if (paintingDisabled()) return; StrokeStyle penStyle = strokeStyle(); if (penStyle == NoStroke) return; SkPaint paint; if (!isPointSkiaSafe(getCTM(), point1) || !isPointSkiaSafe(getCTM(), point2)) return; platformContext()->prepareForSoftwareDraw(); FloatPoint p1 = point1; FloatPoint p2 = point2; bool isVerticalLine = (p1.x() == p2.x()); int width = roundf(strokeThickness()); // We know these are vertical or horizontal lines, so the length will just // be the sum of the displacement component vectors give or take 1 - // probably worth the speed up of no square root, which also won't be exact. FloatSize disp = p2 - p1; int length = SkScalarRound(disp.width() + disp.height()); platformContext()->setupPaintForStroking(&paint, 0, length); if (strokeStyle() == DottedStroke || strokeStyle() == DashedStroke) { // Do a rect fill of our endpoints. This ensures we always have the // appearance of being a border. We then draw the actual dotted/dashed line. SkRect r1, r2; r1.set(p1.x(), p1.y(), p1.x() + width, p1.y() + width); r2.set(p2.x(), p2.y(), p2.x() + width, p2.y() + width); if (isVerticalLine) { r1.offset(-width / 2, 0); r2.offset(-width / 2, -width); } else { r1.offset(0, -width / 2); r2.offset(-width, -width / 2); } SkPaint fillPaint; fillPaint.setColor(paint.getColor()); platformContext()->canvas()->drawRect(r1, fillPaint); platformContext()->canvas()->drawRect(r2, fillPaint); } adjustLineToPixelBoundaries(p1, p2, width, penStyle); SkPoint pts[2] = { (SkPoint)p1, (SkPoint)p2 }; platformContext()->canvas()->drawPoints(SkCanvas::kLines_PointMode, 2, pts, paint); }
// static void SkPDFScalar::Append(SkScalar value, SkWStream* stream) { // The range of reals in PDF/A is the same as SkFixed: +/- 32,767 and // +/- 1/65,536 (though integers can range from 2^31 - 1 to -2^31). // When using floats that are outside the whole value range, we can use // integers instead. #if defined(SK_SCALAR_IS_FIXED) stream->writeScalarAsText(value); return; #endif // SK_SCALAR_IS_FIXED #if !defined(SK_ALLOW_LARGE_PDF_SCALARS) if (value > 32767 || value < -32767) { stream->writeDecAsText(SkScalarRound(value)); return; } char buffer[SkStrAppendScalar_MaxSize]; char* end = SkStrAppendFixed(buffer, SkScalarToFixed(value)); stream->write(buffer, end - buffer); return; #endif // !SK_ALLOW_LARGE_PDF_SCALARS #if defined(SK_SCALAR_IS_FLOAT) && defined(SK_ALLOW_LARGE_PDF_SCALARS) // Floats have 24bits of significance, so anything outside that range is // no more precise than an int. (Plus PDF doesn't support scientific // notation, so this clamps to SK_Max/MinS32). if (value > (1 << 24) || value < -(1 << 24)) { stream->writeDecAsText(value); return; } // Continue to enforce the PDF limits for small floats. if (value < 1.0f/65536 && value > -1.0f/65536) { stream->writeDecAsText(0); return; } // SkStrAppendFloat might still use scientific notation, so use snprintf // directly.. static const int kFloat_MaxSize = 19; char buffer[kFloat_MaxSize]; int len = SNPRINTF(buffer, kFloat_MaxSize, "%#.8f", value); // %f always prints trailing 0s, so strip them. for (; buffer[len - 1] == '0' && len > 0; len--) { buffer[len - 1] = '\0'; } if (buffer[len - 1] == '.') { buffer[len - 1] = '\0'; } stream->writeText(buffer); return; #endif // SK_SCALAR_IS_FLOAT && SK_ALLOW_LARGE_PDF_SCALARS }
bool SkWindow::handleInval(const SkRect* localR) { SkIRect ir; if (localR) { SkRect devR; SkMatrix inverse; if (!fMatrix.invert(&inverse)) { return false; } fMatrix.mapRect(&devR, *localR); devR.round(&ir); } else { ir.set(0, 0, SkScalarRound(this->width()), SkScalarRound(this->height())); } fDirtyRgn.op(ir, SkRegion::kUnion_Op); this->onHandleInval(ir); return true; }
void SkPowerMode::init(SkScalar e) { fExp = e; float ee = SkScalarToFloat(e); printf("------ %g\n", ee); for (int i = 0; i < 256; i++) { float x = i / 255.f; // printf(" %d %g", i, x); x = powf(x, ee); // printf(" %g", x); int xx = SkScalarRound(SkFloatToScalar(x * 255)); // printf(" %d\n", xx); fTable[i] = SkToU8(xx); } }
static cairo_status_t _cairo_skia_context_paint_with_alpha (void *abstract_cr, double alpha) { cairo_skia_context_t *cr = (cairo_skia_context_t *) abstract_cr; cairo_status_t status; if (CAIRO_ALPHA_IS_OPAQUE (alpha)) return _cairo_skia_context_paint (cr); cr->paint->setAlpha(SkScalarRound(255*alpha)); status = _cairo_skia_context_paint (cr); cr->paint->setAlpha(255); return status; }