<commit_before>//
//  GifCameraPreviewView.swift
//  Pods
//
//  Created by <NAME> on 4/7/16.
//
//

import Foundation
import Darwin
import UIKit
import GLKit
import AVFoundation

protocol PreviewTarget {
    func setImage(image: CIImage)
}

public class GifCameraPreviewView: GLKView, PreviewTarget {
    
    var coreImageContext: CIContext!
    var drawableBounds: CGRect!
    static public var currentFilter: CIFilter!
    
    
    override public init(frame: CGRect) {
        super.init(frame: frame, context: GifContextManager.sharedInstance.eaglContext)
        self.enableSetNeedsDisplay = false
        self.isOpaque = true
        self.frame = frame
        self.backgroundColor = UIColor.cyan
        
        self.bindDrawable()
        self.drawableBounds = self.bounds
        self.drawableBounds.size.width = CGFloat(self.drawableWidth)
        self.drawableBounds.size.height = CGFloat(self.drawableHeight)
        self.coreImageContext = GifContextManager.sharedInstance.ciContext
    }
    
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setImage(image: CIImage) {
        self.bindDrawable()
        
        if let filter = GifCameraPreviewView.currentFilter {

            if GifCameraController.currentDevicePosition == .front {
                self.coreImageContext.draw(image, in: self.drawableBounds, from: image.extent)
                
                self.display()
            } else {
            
            filter.setValue(image, forKey: kCIInputImageKey)
            
            if let output = filter.outputImage {
                if let cgimg = self.coreImageContext.createCGImage(output, from: output.extent) {
                    self.coreImageContext.draw(CIImage(cgImage: cgimg), in: self.drawableBounds, from: image.extent)
                    
                    self.display()
                }
            }
            
            }
        } else {
            self.coreImageContext.draw(image, in: self.drawableBounds, from: image.extent)

            self.display()
        }
        
    }
}

class GifContextManager: NSObject {
    static let sharedInstance = GifContextManager()<commit_msg>front filter<commit_after>//
//  GifCameraPreviewView.swift
//  Pods
//
//  Created by <NAME> on 4/7/16.
//
//

import Foundation
import Darwin
import UIKit
import GLKit
import AVFoundation

protocol PreviewTarget {
    func setImage(image: CIImage)
}

public class GifCameraPreviewView: GLKView, PreviewTarget {
    
    var coreImageContext: CIContext!
    var drawableBounds: CGRect!
    static public var currentFilter: CIFilter!
    
    
    override public init(frame: CGRect) {
        super.init(frame: frame, context: GifContextManager.sharedInstance.eaglContext)
        self.enableSetNeedsDisplay = false
        self.isOpaque = true
        self.frame = frame
        self.backgroundColor = UIColor.cyan
        
        self.bindDrawable()
        self.drawableBounds = self.bounds
        self.drawableBounds.size.width = CGFloat(self.drawableWidth)
        self.drawableBounds.size.height = CGFloat(self.drawableHeight)
        self.coreImageContext = GifContextManager.sharedInstance.ciContext
    }
    
    required public init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    func setImage(image: CIImage) {
        self.bindDrawable()
        
        if let filter = GifCameraPreviewView.currentFilter {
            
            if GifCameraController.currentDevicePosition == .front {
                filter.setValue(image, forKey: kCIInputImageKey)
                if let outputImage = filter.outputImage{
                    self.coreImageContext.draw(outputImage, in: self.drawableBounds, from: image.extent)
                }
                
                self.display()
            } else {
                
                filter.setValue(image, forKey: kCIInputImageKey)
                
                if let output = filter.outputImage {
                    if let cgimg = self.coreImageContext.createCGImage(output, from: output.extent) {
                        self.coreImageContext.draw(CIImage(cgImage: cgimg), in: self.drawableBounds, from: image.extent)
                        
                        self.display()
                    }
                }
                
            }
        } else {
            self.coreImageContext.draw(image, in: self.drawableBounds, from: image.extent)
            
            self.display()
        }
        
    }
}

class GifContextManager: NSObject {
    static let sharedInstance = GifContextManager()
{'fraction_non_alphanumeric': 0.08050938916468811, 'fraction_numerical': 0.0017267429311461256, 'mean_word_length': 1.9053291536050156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7471479', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1261, 'n_words': 253}