<commit_before>//
//  Theme.swift
//  WWDC
//
//  Created by <NAME> on 18/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

private let _SharedThemeInstance = Theme()

class Theme: NSObject {

    class var WWDCTheme: Theme {
        return _SharedThemeInstance
    }
    
    let separatorColor = NSColor.grayColor().colorWithAlphaComponent(0.3)
    let backgroundColor = NSColor.whiteColor()
    let fillColor = NSColor(calibratedRed: 0, green: 0.49, blue: 1, alpha: 1)
    
    private var cachedImages: [String:CGImage] = [:]
    
    private let starImageName = "star"
    private let starOutlineImageName = "star-outline"
    
    var starImage: CGImage {
        get {
            return getImage(starImageName)
        }
    }
    var starOutlineImage: CGImage {
        get {
            return getImage(starOutlineImageName)
        }
    }
    
    private func getImage(name: String) -> CGImage {
        if let image = cachedImages[name] {
            return image
        } else {
            cachedImages[name] = NSImage(named: name)?.CGImage
            return cachedImages[name]!
        }
    }
    
}

private extension NSImage {
    var CGImage: CGImageRef {
        get {
            let source = CGImageSourceCreateWithData(self.TIFFRepresentation as! CFDataRef, nil)
            return CGImageSourceCreateImageAtIndex(source, Int(0), nil)
        }
    }
}<commit_msg>Improved NSImage->CGImage conversion<commit_after>//
//  Theme.swift
//  WWDC
//
//  Created by <NAME> on 18/04/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Cocoa

private let _SharedThemeInstance = Theme()

class Theme: NSObject {

    class var WWDCTheme: Theme {
        return _SharedThemeInstance
    }
    
    let separatorColor = NSColor.grayColor().colorWithAlphaComponent(0.3)
    let backgroundColor = NSColor.whiteColor()
    let fillColor = NSColor(calibratedRed: 0, green: 0.49, blue: 1, alpha: 1)
    
    private var cachedImages: [String:CGImage] = [:]
    
    private let starImageName = "star"
    private let starOutlineImageName = "star-outline"
    
    var starImage: CGImage {
        get {
            return getImage(starImageName)
        }
    }
    var starOutlineImage: CGImage {
        get {
            return getImage(starOutlineImageName)
        }
    }
    
    private func getImage(name: String) -> CGImage {
        if let image = cachedImages[name] {
            return image
        } else {
            cachedImages[name] = NSImage(named: name)?.CGImage
            return cachedImages[name]!
        }
    }
    
}

private extension NSImage {
    var CGImage: CGImageRef {
        get {
            var rect = NSMakeRect(0, 0, self.size.width, self.size.height)
            
            var iref = self.CGImageForProposedRect(&rect, context: nil, hints: nil)
            
            return iref!.takeRetainedValue()
        }
    }
}
{'fraction_non_alphanumeric': 0.09623287671232876, 'fraction_numerical': 0.013356164383561644, 'mean_word_length': 2.1240641711229946, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2831206', 'n_tokens_mistral': 933, 'n_tokens_neox': 871, 'n_words': 215}