<commit_before>
import UIKit
import Accelerate

/// 从 bundle 中按照文件名取图片
public func PNGNamed(name : String) -> UIImage {
	
	if let imageResourceString = NSBundle.mainBundle().pathForResource(name, ofType: "png"), image = UIImage(contentsOfFile: imageResourceString) {
		return image
	} else {
		print("⚠️Halo.framework: Can not find image named \"\(name).png\" in mainBundle")
		return UIImage()
	}
	
}

public extension UIImage {
	
    var pngData : NSData {
		return UIImagePNGRepresentation(self) ?? NSData()
	}
	
    var width : CGFloat {
		return size.width
	}
	
    var height : CGFloat {
		return size.height
	}
	
	class public func pngImageWithColor(color:UIColor, size: CGSize) -> UIImage {
		UIGraphicsBeginImageContext(size)
		let context = UIGraphicsGetCurrentContext()
		CGContextSetFillColorWithColor(context, color.CGColor)
		CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: size.height))
		let pureColorImage = UIGraphicsGetImageFromCurrentImageContext()
		UIGraphicsEndImageContext()
		return pureColorImage
	}
    
    convenience init(pngWithColor:UIColor, size:CGSize) {
        self.init()
    }
    
    class func imageWithColor(color:UIColor, size: CGSize) -> UIImage {
        UIGraphicsBeginImageContext(size)
        let context = UIGraphicsGetCurrentContext()
        CGContextSetFillColorWithColor(context, color.CGColor)
        CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: size.height))
        let pureColorImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return pureColorImage
    }
    
    var edgeInsetsToBubble : UIEdgeInsets {
        let center = CGPoint(x: size.width / 2, y: size.height / 2 )
        return UIEdgeInsets(top: center.y, left: center.x, bottom: center.y, right: center.x)
    }
    
    var resizeableImage : UIImage {
        return resizableImageWithCapInsets(edgeInsetsToBubble, resizingMode: UIImageResizingMode.Stretch)
    }
    
    func blurredImageAsync(radius: CGFloat, iterations: Int, ratio: CGFloat, blendColor: UIColor? = nil, finish: UIImage! -> Void) {
        Last {
            finish(self.blurredImage(radius, iterations: iterations, ratio: ratio, blendColor: blendColor))
        }
    }
    
    /**<commit_msg>FangYuan: 1.快速调用 2.提升效率 3.增强功能<commit_after>
import UIKit
import Accelerate

/// 从 bundle 中按照文件名取图片
public func PNGNamed(name : String) -> UIImage {
	
	if let imageResourceString = NSBundle.mainBundle().pathForResource(name, ofType: "png"), image = UIImage(contentsOfFile: imageResourceString) {
		return image
	} else {
		print("⚠️Halo.framework: Can not find image named \"\(name).png\" in mainBundle")
		return UIImage()
	}
	
}

public extension UIImage {
	
    var pngData : NSData {
		return UIImagePNGRepresentation(self) ?? NSData()
	}
	
    var width : CGFloat {
		return size.width
	}
	
    var height : CGFloat {
		return size.height
	}
    
    class func imageWithColor(color:UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
        UIGraphicsBeginImageContext(size)
        let context = UIGraphicsGetCurrentContext()
        CGContextSetFillColorWithColor(context, color.CGColor)
        CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: size.height))
        let pureColorImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return pureColorImage
    }
    
    var edgeInsetsToBubble : UIEdgeInsets {
        let center = CGPoint(x: size.width / 2, y: size.height / 2 )
        return UIEdgeInsets(top: center.y, left: center.x, bottom: center.y, right: center.x)
    }
    
    var resizeableImage : UIImage {
        return resizableImageWithCapInsets(edgeInsetsToBubble, resizingMode: UIImageResizingMode.Stretch)
    }
    
    func blurredImageAsync(radius: CGFloat, iterations: Int, ratio: CGFloat, blendColor: UIColor? = nil, finish: UIImage! -> Void) {
        Last {
            finish(self.blurredImage(radius, iterations: iterations, ratio: ratio, blendColor: blendColor))
        }
    }
    
    /**
{'fraction_non_alphanumeric': 0.09885281913595313, 'fraction_numerical': 0.00366121552355382, 'mean_word_length': 3.449511400651466, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1547625', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1320, 'n_words': 299}