<commit_before>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.utils
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.IBitmapDrawable;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;

import mx.core.IUIComponent;
import mx.utils.MatrixUtil;

/**
 *  This class provides bitmap-related utility functions 
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
public class BitmapUtil
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Creates a BitmapData representation of the target object.
     *
     *  @param target The object to capture in the resulting BitmapData
     *   
     *  @param bounds If non-null, this Rectangle will be populated with
     *  the visible bounds of the object, relative to the object itself.
     * 
     *  @param padding Padding, in pixels, around to target to be included in the bitmap.
     *    
     *  @return A BitmapData object containing the image.
     *
     *  @param propagateColorTransform If true, the target's color transform will
     *  be applied to the bitmap capture operation. 
     *
     *  @throws SecurityError The <code>target</code> object and  all of its child
     *  objects do not come from the same domain as the caller,
     *  or are not in a content that is accessible to the caller by having called the
     *  <code>Security.allowDomain()</code> method.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public static function getSnapshotWithPadding(target:IUIComponent, 
                                                  padding:int = 4, 
                                                  propagateColorTransform:Boolean = false,
                                                  bounds:Rectangle = null):BitmapData
    {
        var width:Number = target.width;
        var height:Number = target.height;
        var m:Matrix = MatrixUtil.getConcatenatedComputedMatrix(target as DisplayObject, null);
        
        var position:Point = new Point(-padding, -padding);
        var size:Point = MatrixUtil.transformBounds(width + padding * 2, 
                                                    height + padding * 2, 
                                                    m, 
                                                    position);
        
        // Translate so that when we draw, the bitmap aligns with the top-left
        // corner of the bmpData<commit_msg>Transferred from the Adobe Open Source Subversion Repository<commit_after>////////////////////////////////////////////////////////////////////////////////
//
//  ADOBE SYSTEMS INCORPORATED
//  Copyright 2008 Adobe Systems Incorporated
//  All Rights Reserved.
//
//  NOTICE: Adobe permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////

package spark.utils
{
import flash.display.BitmapData;
import flash.display.DisplayObject;
import flash.display.IBitmapDrawable;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
import flash.geom.Point;
import flash.geom.Rectangle;

import mx.core.IUIComponent;
import mx.utils.MatrixUtil;

/**
 *  This class provides bitmap-related utility functions 
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10
 *  @playerversion AIR 1.5
 *  @productversion Flex 4
 */
public class BitmapUtil
{
    include "../core/Version.as";

    //--------------------------------------------------------------------------
    //
    //  Class methods
    //
    //--------------------------------------------------------------------------

    /**
     *  Creates a BitmapData representation of the target object.
     *
     *  @param target The object to capture in the resulting BitmapData
     * 
     *  @param padding Padding, in pixels, around to target to be included in the bitmap.
     *
     *  @param propagateColorTransform If true, the target's color transform will
     *  be applied to the bitmap capture operation. 
     *   
     *  @param bounds If non-null, this Rectangle will be populated with
     *  the visible bounds of the object, relative to the object itself.
     *    
     *  @return A BitmapData object containing the image.
     *
     *  @throws SecurityError The <code>target</code> object and  all of its child
     *  objects do not come from the same domain as the caller,
     *  or are not in a content that is accessible to the caller by having called the
     *  <code>Security.allowDomain()</code> method.
     *
     *  @langversion 3.0
     *  @playerversion Flash 10
     *  @playerversion AIR 1.5
     *  @productversion Flex 4
     */
    public static function getSnapshotWithPadding(target:IUIComponent, 
                                                  padding:int = 4, 
                                                  propagateColorTransform:Boolean = false,
                                                  bounds:Rectangle = null):BitmapData
    {
        var width:Number = target.width;
        var height:Number = target.height;
        var m:Matrix = MatrixUtil.getConcatenatedComputedMatrix(target as DisplayObject, null);
        
        var position:Point = new Point(-padding, -padding);
        var size:Point = MatrixUtil.transformBounds(width + padding * 2, 
                                                    height + padding * 2, 
                                                    m, 
                                                    position);
        
        // Translate so that when we draw, the bitmap aligns with the top-left
        // corner of the bmpData
{'fraction_non_alphanumeric': 0.16228001868867778, 'fraction_numerical': 0.006541037221616571, 'mean_word_length': 1.4567712318286152, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4260412', 'n_tokens_mistral': 1530, 'n_tokens_neox': 1446, 'n_words': 520}