<commit_before>//
//  CAColorArtwork.swift
//  ColorArtwork
//
//  Created by 邓翔 on 2017/2/24.
//
//

import Foundation
import CoreGraphics

public class CAColorArtwork {
    
    public var image: CGImage
    
    public var backgroundColor: CGColor?
    public var primaryColor: CGColor?
    public var secondaryColor: CGColor?
    public var detailColor: CGColor?
    
    static public var defaultScaleSize = CGSize(width: 300, height: 300)
    
    public init(image: CGImage, scale: CGSize = defaultScaleSize) {
        guard scale != .zero else {
            self.image = image
            return
        }
        
        // never scale up
        guard image.width > Int(scale.width),
            image.height > Int(scale.height) else {
            self.image = image
            return
        }
        
        self.image = image.scaling(to: scale) ?? image
    }
    
    public func analyze() {
        guard let data = image.dataProvider?.data,
            let dataPtr = CFDataGetBytePtr(data) else {
                return
        }
        
        let edgeColors = findEdgeColors(data: dataPtr)
        let background = findEdgeColor(in: edgeColors) ?? CARGBColor(r: 1, g: 1, b: 1)
        
        let colors = findColors(data: dataPtr, isDarkBackground: background.isDark)
        let textColors = findTextColor(in: colors, background: background)
        <commit_msg>Privatize defaultScaleSize and image property<commit_after>//
//  CAColorArtwork.swift
//  ColorArtwork
//
//  Created by 邓翔 on 2017/2/24.
//
//

import Foundation
import CoreGraphics

public class CAColorArtwork {
    
    var image: CGImage
    
    public var backgroundColor: CGColor?
    public var primaryColor: CGColor?
    public var secondaryColor: CGColor?
    public var detailColor: CGColor?
    
    static let defaultScaleSize = CGSize(width: 300, height: 300)
    
    public init(image: CGImage, scale: CGSize = defaultScaleSize) {
        guard scale != .zero else {
            self.image = image
            return
        }
        
        // never scale up
        guard image.width > Int(scale.width),
            image.height > Int(scale.height) else {
            self.image = image
            return
        }
        
        self.image = image.scaling(to: scale) ?? image
    }
    
    public func analyze() {
        guard let data = image.dataProvider?.data,
            let dataPtr = CFDataGetBytePtr(data) else {
                return
        }
        
        let edgeColors = findEdgeColors(data: dataPtr)
        let background = findEdgeColor(in: edgeColors) ?? CARGBColor(r: 1, g: 1, b: 1)
        
        let colors = findColors(data: dataPtr, isDarkBackground: background.isDark)
        let textColors = findTextColor(in: colors, background: background)
        
{'fraction_non_alphanumeric': 0.08583690987124463, 'fraction_numerical': 0.011444921316165951, 'mean_word_length': 1.9723698193411265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2966116', 'n_tokens_mistral': 837, 'n_tokens_neox': 792, 'n_words': 222}