差分発生行の前後
無視リスト:
コミット日時:
2007/10/15 09:02:14 (5 年前)
コミッタ:
nitoyon
ログメッセージ:

高速化した
mx 名前空間を使わないようにした

ファイル:

凡例:

変更無し
追加
削除
更新
コピー
移動
  • nitoyon/as3/src/com/nitoyon/potras/PathList.as

    r85 r91  
    3232                        var param:Object = {turdSize : 3}; 
    3333 
    34                         var point:Point; 
    35                         while(point = findNext(bmdCopy, y)) 
     34                        // XOR 
     35                        var filter:ColorMatrixFilter = new ColorMatrixFilter([ 
     36                                -1, 0, 0, 0, 255,  
     37                                -1, 0, 0, 0, 255,  
     38                                -1, 0, 0, 0, 255, 
     39                                 0, 0, 0, 1, 0 
     40                        ]); 
     41 
     42                        var point:Point = new Point(); 
     43                        while(findNext(bmdCopy, point)) 
    3644                        { 
    3745                                // calculate the sign by looking at the original 
     
    4250                                if(!p) 
    4351                                { 
    44                                         bitmapData.dispose()
    45                                         return null
     52                                        pathList = null
     53                                        break
    4654                                } 
    4755 
    4856                                // update buffered image 
    49                                 xorPath(bmdCopy, p); 
     57                                xorPath(bmdCopy, p, filter); 
    5058 
    5159                                // if it's a turd, eliminate it, else append it to the list 
     
    6775                 * <p>If found, return Point object. Else return null.</p> 
    6876                 */ 
    69                 private static function findNext(bmd:BitmapData, startY:int):Point 
    70                 { 
    71                         for(var y:int = startY; y < bmd.height; y++) 
     77                private static function findNext(bmd:BitmapData, pt:Point):Boolean 
     78                { 
     79                        for(var y:int = pt.y; y < bmd.height; y++) 
    7280                        { 
    7381                                for(var x:int = 0; x < bmd.width; x++) 
     
    7583                                        if(bmd.getPixel(x, y) == 0x000000) 
    7684                                        { 
    77                                                 return new Point(x, y); 
     85                                                pt.x = x; 
     86                                                pt.y = y; 
     87                                                return true; 
    7888                                        } 
    7989                                } 
    8090                        } 
    8191 
    82                         return null
     92                        return false
    8393                } 
    8494 
     
    160170                 *  Note: the path must be within the dimensions of the pixmap. 
    161171                 */ 
    162                 private static function xorPath(bm:BitmapData, p:Object):void 
    163                 { 
    164                         if(p.priv.length <= 0)  // a path of length 0 is silly, but legal 
    165                         { 
    166                                 return; 
    167                         } 
    168  
    169                         var y1:int = p.priv[p.priv.length - 1].y; 
    170  
    171                         var xa:int = p.priv[0].x; 
    172                         for(var k:int = 0; k < p.priv.length; k++) 
    173                         { 
    174                                 var x:int = p.priv[k].x; 
    175                                 var y:int = p.priv[k].y; 
     172                private static function xorPath(bm:BitmapData, p:Object, filter:ColorMatrixFilter):void 
     173                { 
     174                        var priv:Array = p.priv as Array; 
     175                        var len:int = priv.length; 
     176 
     177                        // get minimum x 
     178                        var minX:int = 99999; 
     179                        for(var i:int = 0; i < len; i++) 
     180                        { 
     181                                minX = Math.min(minX, priv[i].x); 
     182                        } 
     183 
     184                        var y1:int = priv[len - 1].y; 
     185                        var pt:Point = new Point(); 
     186                        var rect:Rectangle = new Rectangle; 
     187                        for(i = 0; i < len; i++) 
     188                        { 
     189                                var x:int = priv[i].x; 
     190                                var y:int = priv[i].y; 
    176191 
    177192                                if(y != y1) 
    178193                                { 
    179                                         // efficiently invert the rectangle [x,xa] x [y,y1] 
    180                                         xorToRef(bm, x, Math.max(y, y1), xa); 
     194                                        // efficiently invert the rectangle [minX, x] x [y,y1] 
     195                                        var y2:int = Math.max(y, y1); 
     196                                        pt.x = minX; pt.y = y2; 
     197                                        rect.x = minX; rect.y = y2; rect.width = x - minX; rect.height = 1; 
     198                                        bm.applyFilter(bm, rect, pt, filter); 
    181199                                        y1 = y; 
    182200                                } 
    183201                        } 
    184                 } 
    185  
    186                 /** 
    187                  *  decompose image into paths efficiently invert bits [x,infty) and [xa,infty) in line y. 
    188                  * 
    189                  *  Here xa must be a multiple of BM_WORDBITS. 
    190                  */ 
    191                 private static function xorToRef(bm:BitmapData, x:int, y:int, xa:int):void 
    192                 { 
    193                         // XOR 
    194                         var filter:ColorMatrixFilter = new ColorMatrixFilter([ 
    195                                 -1, 0, 0, 0, 255,  
    196                                 -1, 0, 0, 0, 255,  
    197                                 -1, 0, 0, 0, 255, 
    198                                  0, 0, 0, 1, 0 
    199                         ]); 
    200  
    201                         bm.applyFilter(bm, new Rectangle(0, y, x, 1), new Point(0, y), filter); 
    202202                } 
    203203        }