static void writeFrames() { const int scale = 5; for (int index = 0; index < (int) SK_ARRAY_COUNT(frameSizes); ++index) { SkDRect bounds; bool boundsSet = false; int frameSize = frameSizes[index]; for (int fIndex = 0; fIndex < frameSize; ++fIndex) { const SkDConic& dC = frames[index][fIndex]; SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale }, {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale }, {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight }; SkDRect dBounds; dBounds.setBounds(dConic); if (!boundsSet) { bounds = dBounds; boundsSet = true; } else { bounds.add((SkDPoint&) dBounds.fLeft); bounds.add((SkDPoint&) dBounds.fRight); } } bounds.fLeft -= 10; bounds.fTop -= 10; bounds.fRight += 10; bounds.fBottom += 10; SkBitmap bitmap; bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul( SkScalarRoundToInt(SkDoubleToScalar(bounds.width())), SkScalarRoundToInt(SkDoubleToScalar(bounds.height())))); SkCanvas canvas(bitmap); SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop)); canvas.drawColor(SK_ColorWHITE); for (int fIndex = 0; fIndex < frameSize; ++fIndex) { const SkDConic& dC = frames[index][fIndex]; SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale }, {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale }, {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight }; SkPath path; path.moveTo(dConic.fPts[0].asSkPoint()); path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight); if (fIndex < 2) { paint.setARGB(0x80, 0xFF, 0, 0); } else { paint.setARGB(0x80, 0, 0, 0xFF); } canvas.drawPath(path, paint); } SkString filename("c:\\Users\\caryclark\\Documents\\"); filename.appendf("f%d.png", index); SkImageEncoder::EncodeFile(filename.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100); } }
static void writeDPng(const SkDConic& dC, const char* name) { const int scale = 5; SkDConic dConic = {{{ {dC.fPts[0].fX * scale, dC.fPts[0].fY * scale }, {dC.fPts[1].fX * scale, dC.fPts[1].fY * scale }, {dC.fPts[2].fX * scale, dC.fPts[2].fY * scale }}}, dC.fWeight }; SkBitmap bitmap; SkDRect bounds; bounds.setBounds(dConic); bounds.fLeft -= 10; bounds.fTop -= 10; bounds.fRight += 10; bounds.fBottom += 10; bitmap.tryAllocPixels(SkImageInfo::MakeN32Premul( SkScalarRoundToInt(SkDoubleToScalar(bounds.width())), SkScalarRoundToInt(SkDoubleToScalar(bounds.height())))); SkCanvas canvas(bitmap); SkPaint paint; paint.setAntiAlias(true); paint.setStyle(SkPaint::kStroke_Style); canvas.translate(SkDoubleToScalar(-bounds.fLeft), SkDoubleToScalar(-bounds.fTop)); canvas.drawColor(SK_ColorWHITE); SkPath path; path.moveTo(dConic.fPts[0].asSkPoint()); path.conicTo(dConic.fPts[1].asSkPoint(), dConic.fPts[2].asSkPoint(), dConic.fWeight); paint.setARGB(0x80, 0xFF, 0, 0); canvas.drawPath(path, paint); path.reset(); const int chops = 2; for (int tIndex = 0; tIndex < chops; ++tIndex) { SkDConic chopped = dConic.subDivide(tIndex / (double) chops, (tIndex + 1) / (double) chops); path.moveTo(chopped.fPts[0].asSkPoint()); path.conicTo(chopped.fPts[1].asSkPoint(), chopped.fPts[2].asSkPoint(), chopped.fWeight); } paint.setARGB(0x80, 0, 0, 0xFF); canvas.drawPath(path, paint); SkString filename("c:\\Users\\caryclark\\Documents\\"); filename.appendf("%s.png", name); SkImageEncoder::EncodeFile(filename.c_str(), bitmap, SkImageEncoder::kPNG_Type, 100); }