Permalink
Browse files

Added initShape, initSubShape, exitShape, exitSubShape in IBackend. S…

…mall fix to prevent array overflow.
  • Loading branch information...
1 parent 892f082 commit 098f74a2bd5b43dd9c070ac6b01fae6a8dbdb78d Claus Wahlers committed May 21, 2011
View
Binary file not shown.
@@ -91,12 +91,6 @@
this.bmWidth = bitmapDataCopy.width;
this.bmHeight = bitmapDataCopy.height;
- if(backend == null) {
- backend = new NullBackend();
- }
-
- backend.init(bmWidth, bmHeight);
-
var i:int;
var j:int;
var k:int;
@@ -120,36 +114,46 @@
var shapes:Array = pathlist_to_curvearrayslist(plist);
- for (i = 0; i < shapes.length; i++) {
- var shape:Array = shapes[i] as Array;
- for (j = 0; j < shape.length; j++) {
- var curves:Array = shape[j] as Array;
- if(curves.length > 0) {
- var curve:Curve = curves[0] as Curve;
- backend.moveTo(curve.a.clone());
- for (k = 0; k < curves.length; k++) {
- curve = curves[k] as Curve;
- switch(curve.kind) {
- case CurveKind.BEZIER:
- backend.addBezier(
- curve.a.clone(),
- curve.cpa.clone(),
- curve.cpb.clone(),
- curve.b.clone()
- );
- break;
- case CurveKind.LINE:
- backend.addLine(
- curve.a.clone(),
- curve.b.clone()
- );
- break;
+ if(backend != null)
+ {
+ backend.init(bmWidth, bmHeight);
+
+ for (i = 0; i < shapes.length; i++) {
+ backend.initShape();
+ var shape:Array = shapes[i] as Array;
+ for (j = 0; j < shape.length; j++) {
+ backend.initSubShape((j % 2) == 0);
+ var curves:Array = shape[j] as Array;
+ if(curves.length > 0) {
+ var curve:Curve = curves[0] as Curve;
+ backend.moveTo(curve.a.clone());
+ for (k = 0; k < curves.length; k++) {
+ curve = curves[k] as Curve;
+ switch(curve.kind) {
+ case CurveKind.BEZIER:
+ backend.addBezier(
+ curve.a.clone(),
+ curve.cpa.clone(),
+ curve.cpb.clone(),
+ curve.b.clone()
+ );
+ break;
+ case CurveKind.LINE:
+ backend.addLine(
+ curve.a.clone(),
+ curve.b.clone()
+ );
+ break;
+ }
}
}
+ backend.exitSubShape();
}
+ backend.exitShape();
}
+
+ backend.exit();
}
- backend.exit();
return shapes;
}
@@ -673,7 +677,7 @@
// Keep track of "directions" that have occurred
dir = (3 + 3 * (pt[mod(i + 1, n)].x - pt[i].x) + (pt[mod(i + 1, n)].y - pt[i].y)) / 2;
- ct[dir]++;
+ ct[dir % 4]++;
constraint[0].x = 0;
constraint[0].y = 0;
@@ -17,9 +17,9 @@ package com.powerflasher.as3potrace.backend
this.gp = new GraphicsPath();
}
- public function init(width:int, height:int):void
- {
- }
+ public function init(width:int, height:int):void {}
+ public function initShape():void {}
+ public function initSubShape(positive:Boolean):void {}
public function moveTo(a:Point):void
{
@@ -41,6 +41,9 @@ package com.powerflasher.as3potrace.backend
gp.lineTo(b.x, b.y);
}
+ public function exitSubShape():void {}
+ public function exitShape():void {}
+
public function exit():void
{
gd.push(gp);
@@ -5,9 +5,13 @@ package com.powerflasher.as3potrace.backend
public interface IBackend
{
function init(width:int, height:int):void;
+ function initShape():void;
+ function initSubShape(positive:Boolean):void;
function moveTo(a:Point):void;
function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void;
function addLine(a:Point, b:Point):void;
+ function exitSubShape():void;
+ function exitShape():void;
function exit():void;
}
}
@@ -8,6 +8,14 @@ package com.powerflasher.as3potrace.backend
{
}
+ public function initShape():void
+ {
+ }
+
+ public function initSubShape(positive:Boolean):void
+ {
+ }
+
public function moveTo(a:Point):void
{
}
@@ -20,6 +28,14 @@ package com.powerflasher.as3potrace.backend
{
}
+ public function exitSubShape():void
+ {
+ }
+
+ public function exitShape():void
+ {
+ }
+
public function exit():void
{
}
@@ -8,24 +8,42 @@ package com.powerflasher.as3potrace.backend
{
public function init(width:int, height:int):void
{
- trace("Segment w:" + width + ", h:" + height);
+ trace("Canvas width:" + width + ", height:" + height);
}
+ public function initShape():void
+ {
+ trace(" Shape");
+ }
+
+ public function initSubShape(positive:Boolean):void
+ {
+ trace(" SubShape positive:" + positive);
+ }
+
public function moveTo(a:Point):void
{
- trace(" MoveTo a:" + a);
+ trace(" MoveTo a:" + a);
}
public function addBezier(a:Point, cpa:Point, cpb:Point, b:Point):void
{
- trace(" Bezier a:" + a + ", cpa:" + cpa + ", cpb:" + cpb + ", b:" + b);
+ trace(" Bezier a:" + a + ", cpa:" + cpa + ", cpb:" + cpb + ", b:" + b);
}
public function addLine(a:Point, b:Point):void
{
- trace(" Line a:" + a + ", b:" + b);
+ trace(" Line a:" + a + ", b:" + b);
}
+ public function exitSubShape():void
+ {
+ }
+
+ public function exitShape():void
+ {
+ }
+
public function exit():void
{
}

0 comments on commit 098f74a

Please sign in to comment.