             var framelosecount = 0
             for j in 1..<displayPosition.count{
                 if(displayPosition[j] == displayPosition[j-1])
-                    {++framelosecount}
+                {++framelosecount}
             }
-
+            
             if(Float(framelosecount) <= Float(displayPosition.count) * (1.0 - self.levelOfIntegrity)||i==displayRefreshDelayTime.count-1){
                 
                 self.imageCount = displayPosition.last!
                 self.displayRefreshFactors = displayRefreshFactors[i]
-
+                
                 var indexOfold = 0
                 var indexOfnew = 0
                 

    //bound to 'displayLink'
    func updateFrame(){
        image = self.currentImage
        //self.layer.setNeedsDisplay()
        dispatch_async(queue,setCurrentImage)
    }
    
    let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,0)
    
    

    func setCurrentImage()
    {
        if(self.frameCache.count == 0){frameProducter()}
        frameConsumer()
    }
    
    
    //product UIImage into frameCache
    private func frameProducter(){
            for _ in 0..<self.frameCacheMaxNumber{
            let cgImage = CGImageSourceCreateImageAtIndex(self.imageSource!,self.displayOrder[self.displayOrderIndex],nil)!
            self.frameCache.append(UIImage(CGImage:cgImage))
            self.displayOrderIndex = (self.displayOrderIndex+1)%self.imageCount
            }
    }


    //get the first image from frameCache,and remove it
    private func frameConsumer(){
        self.currentImage = self.frameCache.first
        self.frameCache.removeFirst()
    }
    
    
    private func GetDelayTimes()->[Float]{
        

        }
        
        let frameProperties = imageProperties.map(){
            unsafeBitCast(
                CFDictionaryGetValue($0,
                    unsafeAddressOf(kCGImagePropertyGIFDictionary)),                CFDictionary.self)
        }
        
        let frameDelays:[Float] = frameProperties.map(){
            var delayObject: AnyObject = unsafeBitCast(
                CFDictionaryGetValue($0,
                    unsafeAddressOf(kCGImagePropertyGIFUnclampedDelayTime)),
                AnyObject.self)
            
            let EPS = 10e-10
            if(delayObject.doubleValue<EPS){
                delayObject = unsafeBitCast(CFDictionaryGetValue($0,
                    unsafeAddressOf(kCGImagePropertyGIFDelayTime)), AnyObject.self)
            }
            return delayObject as! Float
        }
        return frameDelays
    }
    
    private func CalculateFrameDelay(var delays:[Float])
    {
        
        //Factors send to CADisplayLink.frameInterval
