aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--bench/PathUtilsBench.cpp72
-rw-r--r--gyp/SampleApp.gyp1
-rw-r--r--gyp/bench.gypi1
-rw-r--r--gyp/tests.gypi1
-rw-r--r--gyp/utils.gypi1
-rw-r--r--include/utils/SkPathUtils.h40
-rw-r--r--samplecode/SamplePathUtils.cpp108
-rw-r--r--src/utils/SkPathUtils.cpp152
-rw-r--r--tests/PathUtilsTest.cpp152
9 files changed, 0 insertions, 528 deletions
diff --git a/bench/PathUtilsBench.cpp b/bench/PathUtilsBench.cpp
deleted file mode 100644
index 6c8086fb9d..0000000000
--- a/bench/PathUtilsBench.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-#include "Benchmark.h"
-#include "SkCanvas.h"
-#include "SkPathUtils.h"
-#include "SkRandom.h"
-#include "SkString.h"
-#include "SkTime.h"
-
-#define H 16
-#define W 16
-#define STRIDE 2
-
-//this function is redefined for sample, test, and bench. is there anywhere
-// I can put it to avoid code duplcation?
-static void fillRandomBits( int chars, char* bits ){
- SkRandom rand(SkTime::GetMSecs());
-
- for (int i = 0; i < chars; ++i){
- bits[i] = rand.nextU();
- }
-}
-
-static void path_proc(char* bits, SkPath* path) {
- SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE);
-}
-
-static void region_proc(char* bits, SkPath* path) {
- SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE);
-}
-
-/// Emulates the mix of rects blitted by gmail during scrolling
-class PathUtilsBench : public Benchmark {
- typedef void (*Proc)(char*, SkPath*);
-
- Proc fProc;
- SkString fName;
- char* bits[H * STRIDE];
-
-public:
- PathUtilsBench(Proc proc, const char name[]) {
- fProc = proc;
- fName.printf("pathUtils_%s", name);
-
-
- }
-
-protected:
- virtual const char* onGetName() { return fName.c_str(); }
-
- virtual void onDraw(const int loops, SkCanvas* canvas) {
-
- for (int i = 0; i < loops; ++i){
- //create a random 16x16 bitmap
- fillRandomBits(H * STRIDE, (char*) &bits);
-
- //use passed function pointer to handle it
- SkPath path;
- fProc( (char*) &bits, &path);
- }
- }
-
-private:
- typedef Benchmark INHERITED;
-};
-
-DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); )
-DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); )
diff --git a/gyp/SampleApp.gyp b/gyp/SampleApp.gyp
index 402c4247ab..b9b8eff811 100644
--- a/gyp/SampleApp.gyp
+++ b/gyp/SampleApp.gyp
@@ -91,7 +91,6 @@
'../samplecode/SamplePath.cpp',
'../samplecode/SamplePathClip.cpp',
'../samplecode/SamplePathFuzz.cpp',
- '../samplecode/SamplePathUtils.cpp',
'../samplecode/SamplePathEffects.cpp',
'../samplecode/SamplePicture.cpp',
'../samplecode/SamplePictFile.cpp',
diff --git a/gyp/bench.gypi b/gyp/bench.gypi
index d89222a090..3d041f6314 100644
--- a/gyp/bench.gypi
+++ b/gyp/bench.gypi
@@ -83,7 +83,6 @@
'../bench/PatchGridBench.cpp',
'../bench/PathBench.cpp',
'../bench/PathIterBench.cpp',
- '../bench/PathUtilsBench.cpp',
'../bench/PerlinNoiseBench.cpp',
'../bench/PictureNestingBench.cpp',
'../bench/PictureOverheadBench.cpp',
diff --git a/gyp/tests.gypi b/gyp/tests.gypi
index bcf8d56108..acbcc354e2 100644
--- a/gyp/tests.gypi
+++ b/gyp/tests.gypi
@@ -169,7 +169,6 @@
'../tests/PathCoverageTest.cpp',
'../tests/PathMeasureTest.cpp',
'../tests/PathTest.cpp',
- '../tests/PathUtilsTest.cpp',
'../tests/PictureBBHTest.cpp',
'../tests/PictureShaderTest.cpp',
'../tests/PictureTest.cpp',
diff --git a/gyp/utils.gypi b/gyp/utils.gypi
index 68876cbdfe..f382e1028f 100644
--- a/gyp/utils.gypi
+++ b/gyp/utils.gypi
@@ -84,7 +84,6 @@
'<(skia_src_path)/utils/SkPatchGrid.h',
'<(skia_src_path)/utils/SkPatchUtils.cpp',
'<(skia_src_path)/utils/SkPatchUtils.h',
- '<(skia_src_path)/utils/SkPathUtils.cpp',
'<(skia_src_path)/utils/SkSHA1.cpp',
'<(skia_src_path)/utils/SkSHA1.h',
'<(skia_src_path)/utils/SkRTConf.cpp',
diff --git a/include/utils/SkPathUtils.h b/include/utils/SkPathUtils.h
deleted file mode 100644
index a27cbb8f0f..0000000000
--- a/include/utils/SkPathUtils.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * CAUTION: EXPERIMENTAL CODE
- *
- * This code is not to be used and will not be supported
- * if it fails on you. DO NOT USE!
- *
- */
-
-#ifndef SkPathUtils_DEFINED
-#define SkPathUtils_DEFINED
-
-#include "SkPath.h"
-
-/*
- * The following methods return the boundary path given a 1-bit bitmap, specified
- * by width/height and stride. The bits are interpreted as 1 being "in" the path,
- * and 0 being "out". The bits are interpreted as MSB on the left, and LSB on the right.
- */
-
-class SK_API SkPathUtils {
-public:
- /**
- This variation iterates the binary data sequentially (as in scanline fashion)
- and will add each run of 1's to the path as a rectangular path. Upon parsing
- all binary data the path is simplified using the PathOps::Simplify() method.
- */
- static void BitsToPath_Path(SkPath* path, const char* bitmap,
- int w, int h, int rowBytes);
-
- /**
- This variation utilizes the SkRegion class to generate paths, adding
- each run of 1's to the SkRegion as an SkIRect. Upon parsing the entirety
- of the binary the SkRegion is converted to a Path via getBoundaryPath().
- */
- static void BitsToPath_Region(SkPath* path, const char* bitmap,
- int w, int h, int rowBytes);
-
-};
-
-#endif
diff --git a/samplecode/SamplePathUtils.cpp b/samplecode/SamplePathUtils.cpp
deleted file mode 100644
index 503a6eaa25..0000000000
--- a/samplecode/SamplePathUtils.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SampleCode.h"
-
-#include "SkCanvas.h"
-#include "SkCornerPathEffect.h"
-#include "SkDashPathEffect.h"
-#include "SkPathUtils.h"
-#include "SkRandom.h"
-#include "SkView.h"
-
-typedef void (*BitsToPath)(SkPath*, const char*, int, int, int);
-
-static const BitsToPath gBitsToPath_fns[] = {
- SkPathUtils::BitsToPath_Path,
- SkPathUtils::BitsToPath_Region,
-};
-
-// hardcoded bitmap patterns
-static const uint8_t gBits[][16] = {
- { 0x18, 0x00, 0x3c, 0x00, 0x7e, 0x00, 0xdb, 0x00,
- 0xff, 0x00, 0x24, 0x00, 0x5a, 0x00, 0xa5, 0x00 },
-
- { 0x20, 0x80, 0x91, 0x20, 0xbf, 0xa0, 0xee, 0xe0,
- 0xff, 0xe0, 0x7f, 0xc0, 0x20, 0x80, 0x40, 0x40 },
-
- { 0x0f, 0x00, 0x7f, 0xe0, 0xff, 0xf0, 0xe6, 0x70,
- 0xff, 0xf0, 0x19, 0x80, 0x36, 0xc0, 0xc0, 0x30 }
-};
-
-
-class SamplePathUtils : public SampleView {
-public:
- static const int fNumBits = 3;
- static const int fH = 8, fW = 12;
- static const size_t fRowBytes = 2;
- static const int fNumChars = fH * fRowBytes;
-
- SkPaint fBmpPaint;
- SkScalar fPhase;
-
- SamplePathUtils() {
- fBmpPaint.setAntiAlias(true); // Black paint for bitmap
- fBmpPaint.setStyle(SkPaint::kFill_Style);
-
- fPhase = 0.0f; // to animate the dashed path
- }
-
-protected:
- // overrides from SkEventSink
- virtual bool onQuery(SkEvent* evt) {
- if (SampleCode::TitleQ(*evt)) {
- SampleCode::TitleR(evt, "PathUtils");
- return true;
- }
- return this->INHERITED::onQuery(evt);
- }
-
- /////////////////////////////////////////////////////////////
-
- virtual void onDrawContent(SkCanvas* canvas) {
- SkScalar intervals[8] = { .5f, .3f, .5f, .3f, .5f, .3f, .5f, .3f };
- SkAutoTUnref<SkDashPathEffect> dash(SkDashPathEffect::Create(intervals, 2, fPhase));
- SkAutoTUnref<SkCornerPathEffect> corner(SkCornerPathEffect::Create(.25f));
- SkAutoTUnref<SkComposePathEffect> compose(SkComposePathEffect::Create(dash, corner));
-
- SkPaint outlinePaint;
- outlinePaint.setAntiAlias(true); // dashed paint for bitmap
- outlinePaint.setStyle(SkPaint::kStroke_Style);
- outlinePaint.setPathEffect(compose);
-
- canvas->scale(10.0f, 10.0f); // scales up
-
- for (int i = 0; i < fNumBits; ++i) {
- canvas->save();
- for (size_t j = 0; j < SK_ARRAY_COUNT(gBitsToPath_fns); ++j) {
- SkPath path;
- gBitsToPath_fns[j](&path, (char*) &gBits[i], fW, fH, fRowBytes);
-
- //draw skPath and outline
- canvas->drawPath(path, fBmpPaint);
- canvas->translate(1.5f * fW, 0); // translates past previous bitmap
- canvas->drawPath(path, outlinePaint);
- canvas->translate(1.5f * fW, 0); // translates past previous bitmap
- }
- canvas->restore();
- canvas->translate(0, 1.5f * fH); //translate to next row
- }
-
- // for animated pathEffect
- fPhase += .01f;
- this->inval(NULL);
- }
-
-private:
- typedef SkView INHERITED;
-};
-
-//////////////////////////////////////////////////////////////////////////////
-
-static SkView* MyFactory() { return new SamplePathUtils; }
-static SkViewRegister reg(MyFactory)
-;
diff --git a/src/utils/SkPathUtils.cpp b/src/utils/SkPathUtils.cpp
deleted file mode 100644
index fdca09aa63..0000000000
--- a/src/utils/SkPathUtils.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * CAUTION: EXPERIMENTAL CODE
- *
- * This code is not to be used and will not be supported
- * if it fails on you. DO NOT USE!
- *
- */
-
-#include "SkPathUtils.h"
-
-#include "SkPath.h"
-#include "SkPathOps.h" // this can't be found, how do I link it?
-#include "SkRegion.h"
-
-typedef void (*line2path)(SkPath*, const char*, int, int);
-#define SQRT_2 1.41421356237f
-#define ON 0xFF000000 // black pixel
-#define OFF 0x00000000 // transparent pixel
-
-// assumes stride is in bytes
-/*
-static void FillRandomBits( int chars, char* bits ){
- SkTime time;
- SkRandom rand = SkRandom( time.GetMSecs() );
-
- for (int i = 0; i < chars; ++i){
- bits[i] = rand.nextU();
- }
-}OA
-*/
-
-static int GetBit( const char* buffer, int x ) {
- int byte = x >> 3;
- int bit = x & 7;
-
- return buffer[byte] & (128 >> bit);
-}
-
-/*
-static void Line2path_pixel(SkPath* path, const char* line,
- int lineIdx, int width) {
- for (int i = 0; i < width; ++i) {
- // simply makes every ON pixel into a rect path
- if (GetBit(line,i)) {
- path->addRect(SkRect::MakeXYWH(i, lineIdx, 1, 1),
- SkPath::kCW_Direction);
- }
- }
-}
-
-static void Line2path_pixelCircle(SkPath* path, const char* line,
- int lineIdx, int width) {
- for (int i = 0; i < width; ++i) {
- // simply makes every ON pixel into a circle path
- if (GetBit(line,i)) {
- path->addCircle(i + SK_ScalarHalf,
- lineIdx + SK_ScalarHalf,
- SQRT_2 / 2.0f);
- }
- }
-}
-*/
-
-static void Line2path_span(SkPath* path, const char* line,
- int lineIdx, int width) {
- bool inRun = 0;
- int start = 1;
-
- for (int i = 0; i < width; ++i) {
- int curPixel = GetBit(line,i);
-
- if ( (curPixel!=0) != inRun ) { // if transition
- if (curPixel) { // if transition on
- inRun = 1;
- start = i; // mark beginning of span
- }else { // if transition off add the span as a path
- inRun = 0;
- path->addRect(SkRect::MakeXYWH(SkIntToScalar(start), SkIntToScalar(lineIdx),
- SkIntToScalar(i-start), SK_Scalar1),
- SkPath::kCW_Direction);
- }
- }
- }
-
- if (inRun==1) { // close any open spans
- int end = 0;
- if ( GetBit(line,width-1) ) ++end;
- path->addRect(SkRect::MakeXYWH(SkIntToScalar(start), SkIntToScalar(lineIdx),
- SkIntToScalar(width - 1 + end - start), SK_Scalar1),
- SkPath::kCW_Direction);
- } else if ( GetBit(line, width - 1) ) { // if last pixel on add
- path->addRect(SkRect::MakeXYWH(width - SK_Scalar1, SkIntToScalar(lineIdx),
- SK_Scalar1, SK_Scalar1),
- SkPath::kCW_Direction);
- }
-}
-
-void SkPathUtils::BitsToPath_Path(SkPath* path,
- const char* bitmap,
- int w, int h, int stride) {
- // loop for every line in bitmap
- for (int i = 0; i < h; ++i) {
- // fn ptr handles each line separately
- //l2p_fn(path, &bitmap[i*stride], i, w);
- Line2path_span(path, &bitmap[i*stride], i, w);
- }
- Simplify(*path, path); // simplify resulting path.
-}
-
-void SkPathUtils::BitsToPath_Region(SkPath* path,
- const char* bitmap,
- int w, int h, int stride) {
- SkRegion region;
-
- // loop for each line
- for (int y = 0; y < h; ++y){
- bool inRun = 0;
- int start = 1;
- const char* line = &bitmap[y * stride];
-
- // loop for each pixel
- for (int i = 0; i < w; ++i) {
- int curPixel = GetBit(line,i);
-
- if ( (curPixel!=0) != inRun ) { // if transition
- if (curPixel) { // if transition on
- inRun = 1;
- start = i; // mark beginning of span
- }else { // if transition off add the span as a path
- inRun = 0;
- //add here
- region.op(SkIRect::MakeXYWH(start, y, i-start, 1),
- SkRegion::kUnion_Op );
- }
- }
- }
- if (inRun==1) { // close any open spans
- int end = 0;
- if ( GetBit(line,w-1) ) ++end;
- // add the thing here
- region.op(SkIRect::MakeXYWH(start, y, w-1-start+end, 1),
- SkRegion::kUnion_Op );
-
- } else if ( GetBit(line,w-1) ) { // if last pixel on add rect
- // add the thing here
- region.op(SkIRect::MakeXYWH(w-1, y, 1, 1),
- SkRegion::kUnion_Op );
- }
- }
- // convert region to path
- region.getBoundaryPath(path);
-}
diff --git a/tests/PathUtilsTest.cpp b/tests/PathUtilsTest.cpp
deleted file mode 100644
index 4dfeda467c..0000000000
--- a/tests/PathUtilsTest.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * Copyright 2013 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#include "SkBitmap.h"
-#include "SkCanvas.h"
-#include "SkPathUtils.h"
-#include "SkRandom.h"
-#include "SkTime.h"
-#include "Test.h"
-
-const int kNumIt = 100;
-
-static void fill_random_bits(int chars, char* bits){
- SkRandom rand(SkTime::GetMSecs());
-
- for (int i = 0; i < chars; ++i){
- bits[i] = rand.nextU();
- }
-}
-
-static int get_bit(const char* buffer, int x) {
- int byte = x >> 3;
- int bit = x & 7;
-
- return buffer[byte] & (128 >> bit);
-}
-
-/* // useful for debugging errors
- #include <iostream>
-static void print_bits( const char* bits, int w, int h) {
-
- for (int y = 0; y < h; ++y) {
- for (int x = 0; x < w; ++x){
- bool bit = get_bit(&bits[y], x)!=0;
- std::cout << bit;
- }
- std::cout << std::endl;
- }
-}
-
-static void print_bmp( SkBitmap* bmp, int w, int h){
-
- for (int y = 0; y < h; ++y) {
- for (int x = 0; x < w; ++x) {
- int d = *bmp->getAddr32(x,y);
- if (d == -1)
- std::cout << 0;
- else
- std::cout << 1;
- }
- std::cout << std::endl;
- }
-}
-*/
-
-static void binary_to_skbitmap(const char* bin_bmp, SkBitmap* sk_bmp,
- int w, int h, int rowBytes){
- //init the SkBitmap
- sk_bmp->allocN32Pixels(w, h);
-
- for (int y = 0; y < h; ++y) { // for every row
-
- const char* curLine = &bin_bmp[y * rowBytes];
- for (int x = 0; x < w; ++x) {// for every pixel
- if (get_bit(curLine, x)) {
- *sk_bmp->getAddr32(x,y) = SK_ColorBLACK;
- }
- else {
- *sk_bmp->getAddr32(x,y) = SK_ColorWHITE;
- }
- }
- }
-}
-
-static bool test_bmp(skiatest::Reporter* reporter,
- const SkBitmap* bmp1, const SkBitmap* bmp2,
- int w, int h) {
- for (int y = 0; y < h; ++y) { // loop through all pixels
- for (int x = 0; x < w; ++x) {
- REPORTER_ASSERT( reporter, *bmp1->getAddr32(x,y) == *bmp2->getAddr32(x,y) );
- }
- }
- return true;
-}
-
-static void test_path_eq(skiatest::Reporter* reporter, const SkPath* path,
- const SkBitmap* truth, int w, int h){
- // make paint
- SkPaint bmpPaint;
- bmpPaint.setAntiAlias(true); // Black paint for bitmap
- bmpPaint.setStyle(SkPaint::kFill_Style);
- bmpPaint.setColor(SK_ColorBLACK);
-
- // make bmp
- SkBitmap bmp;
- bmp.allocN32Pixels(w, h);
- SkCanvas canvas(bmp);
- canvas.clear(SK_ColorWHITE);
- canvas.drawPath(*path, bmpPaint);
-
- // test bmp
- test_bmp(reporter, truth, &bmp, w, h);
-}
-
-static void test_path(skiatest::Reporter* reporter, const SkBitmap* truth,
- const char* bin_bmp, int w, int h, int rowBytes){
- // make path
- SkPath path;
- SkPathUtils::BitsToPath_Path(&path, bin_bmp, w, h, rowBytes);
-
- //test for correctness
- test_path_eq(reporter, &path, truth, w, h);
-}
-
-static void test_region(skiatest::Reporter* reporter, const SkBitmap* truth,
- const char* bin_bmp, int w, int h, int rowBytes){
- //generate bitmap
- SkPath path;
- SkPathUtils::BitsToPath_Region(&path, bin_bmp, w, h, rowBytes);
-
- //test for correctness
- test_path_eq(reporter, &path, truth, w, h);
-}
-
-DEF_TEST(PathUtils, reporter) {
- const int w[] = {4, 8, 12, 16};
- const int h = 8, rowBytes = 4;
-
- char bits[ h * rowBytes ];
- static char* binBmp = &bits[0];
-
- //loop to run randomized test lots of times
- for (int it = 0; it < kNumIt; ++it)
- {
- // generate a random binary bitmap
- fill_random_bits( h * rowBytes, binBmp); // generate random bitmap
-
- // for each bitmap width, use subset of binary bitmap
- for (unsigned int i = 0; i < SK_ARRAY_COUNT(w); ++i) {
- // generate truth bitmap
- SkBitmap bmpTruth;
- binary_to_skbitmap(binBmp, &bmpTruth, w[i], h, rowBytes);
-
- test_path(reporter, &bmpTruth, binBmp, w[i], h, rowBytes);
- test_region(reporter, &bmpTruth, binBmp, w[i], h, rowBytes);
- }
- }
-}