| | 57 | if ( keepOriginal_ ) |
|---|
| | 58 | keep = keepOriginal_; |
|---|
| | 59 | } |
|---|
| | 60 | |
|---|
| | 61 | /** |
|---|
| | 62 | * |
|---|
| | 63 | * @param alphaSrcBitmapData |
|---|
| | 64 | * @param channel |
|---|
| | 65 | */ |
|---|
| | 66 | public function mask( alphaSrc:BitmapData, channel:uint=8 ):void |
|---|
| | 67 | { |
|---|
| | 68 | copyChannel( alphaSrc, rect, zeropoint, channel, BitmapDataChannel.ALPHA ); |
|---|
| | 69 | } |
|---|
| | 70 | |
|---|
| | 71 | /** |
|---|
| | 72 | * |
|---|
| | 73 | * @param shape |
|---|
| | 74 | * @param fit |
|---|
| | 75 | */ |
|---|
| | 76 | public function maskShape( alphaSrc:DisplayObject, fit:Boolean = false ):void |
|---|
| | 77 | { |
|---|
| | 78 | var scaleX:Number = 1; |
|---|
| | 79 | var scaleY:Number = 1; |
|---|
| | 80 | if ( fit ) |
|---|
| | 81 | { |
|---|
| | 82 | scaleX = width / alphaSrc.width; |
|---|
| | 83 | scaleY = height/alphaSrc.height; |
|---|
| | 84 | } |
|---|
| | 85 | var alphashape:BitmapData = BmpUtil.makeImage( alphaSrc, 0, scaleX, scaleY, false ); |
|---|
| | 86 | mask( alphashape ); |
|---|
| | 87 | alphashape.dispose(); |
|---|
| | 88 | alphashape = null; |
|---|
| | 89 | } |
|---|
| | 90 | |
|---|
| | 91 | /** |
|---|
| | 92 | * |
|---|
| | 93 | * @param c1 |
|---|
| | 94 | * @param c2 |
|---|
| | 95 | * @param c3 |
|---|
| | 96 | * @param c4 |
|---|
| | 97 | */ |
|---|
| | 98 | public function tint( c1:Number, c2:Number=NaN, c3:Number=NaN, c4:Number=NaN ):void |
|---|
| | 99 | { |
|---|
| | 100 | if ( isNaN( c2 ) ) |
|---|
| | 101 | { |
|---|
| | 102 | _colortransform.redMultiplier = c1; |
|---|
| | 103 | _colortransform.greenMultiplier = c1; |
|---|
| | 104 | _colortransform.blueMultiplier = c1; |
|---|
| | 105 | _colortransform.alphaMultiplier = 1.0; |
|---|
| | 106 | } |
|---|
| | 107 | else if ( isNaN( c3 ) ) |
|---|
| | 108 | { |
|---|
| | 109 | _colortransform.redMultiplier = c1; |
|---|
| | 110 | _colortransform.greenMultiplier = c1; |
|---|
| | 111 | _colortransform.blueMultiplier = c1; |
|---|
| | 112 | _colortransform.alphaMultiplier = c2; |
|---|
| | 113 | } |
|---|
| | 114 | else if ( isNaN( c4 ) ) |
|---|
| | 115 | { |
|---|
| | 116 | _colortransform.redMultiplier = c1; |
|---|
| | 117 | _colortransform.greenMultiplier = c2; |
|---|
| | 118 | _colortransform.blueMultiplier = c3; |
|---|
| | 119 | _colortransform.alphaMultiplier = 1.0; |
|---|
| | 120 | } |
|---|
| | 121 | else |
|---|
| | 122 | { |
|---|
| | 123 | _colortransform.redMultiplier = c1; |
|---|
| | 124 | _colortransform.greenMultiplier = c2; |
|---|
| | 125 | _colortransform.blueMultiplier = c3; |
|---|
| | 126 | _colortransform.alphaMultiplier = c4; |
|---|
| | 127 | } |
|---|
| | 128 | colorTransform( rect, _colortransform ); |
|---|
| 61 | | * @private |
|---|
| 62 | | */ |
|---|
| 63 | | /* |
|---|
| 64 | | private function _pixelblend( c1:uint, c2:uint, a2:uint ):uint |
|---|
| 65 | | { |
|---|
| 66 | | var a1:uint = c1 >>> 24; |
|---|
| 67 | | var a0:uint = a2^0xff; |
|---|
| 68 | | c1 &= 0x00ffffff; |
|---|
| 69 | | var _r:uint = ( a0*(c1>>16) + a2*(c2>>16) ) >> 8 ; |
|---|
| 70 | | var _g:uint = ( a0*(( c1&0x00ff00 )>>8) + a2*(( c2&0x00ff00 )>>8) ) & 0xff00; |
|---|
| 71 | | var _b:uint = ( a0*( c1 & 0xff ) + a2*( c2 & 0xff ) ) >> 8; |
|---|
| 72 | | return Math.min( a1 + a2, 0xff ) << 24 | _r << 16 | _g | _b; |
|---|
| 73 | | } |
|---|
| 74 | | */ |
|---|
| | 148 | * BitmapData 全体の alpha 値 を指定します. |
|---|
| | 149 | */ |
|---|
| | 150 | public function set alpha( value:Number ):void |
|---|
| | 151 | { |
|---|
| | 152 | if ( transparent ) |
|---|
| | 153 | { |
|---|
| | 154 | var a:uint = Math.floor( value * 0xff ) << 24 | 0x000000; |
|---|
| | 155 | var alphadata:BitmapData = new BitmapData( width, height, true, a ); |
|---|
| | 156 | copyChannel( alphadata, rect, zeropoint, BitmapDataChannel.ALPHA, BitmapDataChannel.ALPHA ); |
|---|
| | 157 | alphadata.dispose(); |
|---|
| | 158 | alphadata = null; |
|---|
| | 159 | } |
|---|
| | 160 | else |
|---|
| | 161 | { |
|---|
| | 162 | throw new Error( "this bitmapdata is not supported alpha channel." ); |
|---|
| | 163 | } |
|---|
| | 164 | } |
|---|
| | 165 | |
|---|
| | 166 | /** |
|---|
| | 167 | * オリジナルデータを保持している場合、データを復帰します. |
|---|
| | 168 | */ |
|---|
| | 169 | public function restore():void |
|---|
| | 170 | { |
|---|
| | 171 | if ( _keep_src ) |
|---|
| | 172 | copyPixels( _srcbitmap, rect, zeropoint ); |
|---|
| | 173 | } |
|---|
| | 174 | |
|---|
| | 175 | /** |
|---|
| | 176 | * オリジナルデータを保持している場合、データを反映させます. |
|---|
| | 177 | */ |
|---|
| | 178 | public function store():void |
|---|
| | 179 | { |
|---|
| | 180 | if ( _keep_src ) |
|---|
| | 181 | _srcbitmap.copyPixels( this, rect, zeropoint ); |
|---|
| | 182 | } |
|---|
| | 183 | |
|---|
| | 184 | /** |
|---|
| | 185 | * original bitmapdata. if not keep, return null |
|---|
| | 186 | */ |
|---|
| | 187 | public function get original():BitmapData { return _srcbitmap; } |
|---|
| | 188 | public function set original( value:BitmapData ):void |
|---|
| | 189 | { |
|---|
| | 190 | if ( width != value.width || height != value.height ) |
|---|
| | 191 | { |
|---|
| | 192 | throw new ArgumentError("not match width or height."); |
|---|
| | 193 | } |
|---|
| | 194 | else |
|---|
| | 195 | { |
|---|
| | 196 | if( _srcbitmap ) |
|---|
| | 197 | _srcbitmap.dispose(); |
|---|
| | 198 | _srcbitmap = value; |
|---|
| | 199 | _keep_src = true; |
|---|
| | 200 | } |
|---|
| | 201 | } |
|---|
| | 202 | |
|---|
| | 203 | /** |
|---|
| | 204 | * keep original bitmapdata |
|---|
| | 205 | */ |
|---|
| | 206 | public function get keep():Boolean { return _keep_src; } |
|---|
| | 207 | public function set keep(value:Boolean):void |
|---|
| | 208 | { |
|---|
| | 209 | if ( _keep_src != value ) |
|---|
| | 210 | { |
|---|
| | 211 | _keep_src = value; |
|---|
| | 212 | if ( _keep_src ) |
|---|
| | 213 | { |
|---|
| | 214 | _srcbitmap = super.clone(); |
|---|
| | 215 | } |
|---|
| | 216 | else |
|---|
| | 217 | { |
|---|
| | 218 | _srcbitmap.dispose(); |
|---|
| | 219 | _srcbitmap = null; |
|---|
| | 220 | } |
|---|
| | 221 | } |
|---|
| | 222 | } |
|---|
| | 223 | |
|---|
| | 224 | //--------------------------------------------------------------------------------------------------- |
|---|
| | 225 | |
|---|
| | 226 | /** |
|---|
| | 227 | * BitmapData から FBitmapData のインスタンスを生成します. |
|---|
| | 228 | * @param src |
|---|
| | 229 | * @param transparent |
|---|
| | 230 | * @param disposeSrc |
|---|
| | 231 | */ |
|---|
| | 232 | public static function copyBitmapData( src:BitmapData, transparent_:Boolean=true, disposeSrc:Boolean=false ):FBitmapData |
|---|
| | 233 | { |
|---|
| | 234 | var bd:FBitmapData; |
|---|
| | 235 | if ( arguments.length == 1 ) |
|---|
| | 236 | bd = new FBitmapData( src.width, src.height, src.transparent ); |
|---|
| | 237 | else |
|---|
| | 238 | bd = new FBitmapData( src.width, src.height, transparent_ ); |
|---|
| | 239 | bd.copyPixels( src, src.rect, zeropoint ); |
|---|
| | 240 | if ( disposeSrc ) |
|---|
| | 241 | src.dispose(); |
|---|
| | 242 | return bd; |
|---|
| | 243 | } |
|---|
| | 244 | |
|---|
| | 245 | /** |
|---|
| | 246 | * DisplayObject から FBitmapData のインスタンスを生成します. |
|---|
| | 247 | * @param displayobject |
|---|
| | 248 | * @param margin |
|---|
| | 249 | * @param scale |
|---|
| | 250 | * @param smooth |
|---|
| | 251 | * @param transparent |
|---|
| | 252 | */ |
|---|
| | 253 | public static function copyDisplayObject( displayobject:DisplayObject, margin:int=0, scaleX:Number=1, scaleY:Number=1, smooth:Boolean=false, transparent_:Boolean=true ):FBitmapData |
|---|
| | 254 | { |
|---|
| | 255 | return copyBitmapData( BmpUtil.makeImage( displayobject, margin, scaleX, scaleY, smooth ), transparent_, true ); |
|---|
| | 256 | |
|---|
| | 257 | } |
|---|
| | 258 | |
|---|
| | 259 | //--------------------------------------------------------------------------------------------------- OVERRIDE |
|---|
| | 260 | |
|---|
| | 261 | /** |
|---|
| | 262 | * |
|---|
| | 263 | */ |
|---|
| | 264 | public override function clone():BitmapData |
|---|
| | 265 | { |
|---|
| | 266 | var bd:FBitmapData = new FBitmapData( width, height, transparent ); |
|---|
| | 267 | bd.copyPixels( this, rect, zeropoint ); |
|---|
| | 268 | if ( _keep_src ) |
|---|
| | 269 | bd.original = _srcbitmap.clone(); |
|---|
| | 270 | return bd; |
|---|
| | 271 | } |
|---|
| | 272 | |
|---|
| | 273 | /** |
|---|
| | 274 | * |
|---|
| | 275 | */ |
|---|
| | 276 | public override function dispose():void |
|---|
| | 277 | { |
|---|
| | 278 | super.dispose(); |
|---|
| | 279 | if ( _srcbitmap ) |
|---|
| | 280 | { |
|---|
| | 281 | _srcbitmap.dispose(); |
|---|
| | 282 | _srcbitmap = null; |
|---|
| | 283 | } |
|---|
| | 284 | } |
|---|