                 let blue = dataType[offset+3]
                 
                 let avg = (UInt32(red) + UInt32(green) + UInt32(blue))/3
-
+                
                 dataType[offset + 1] = UInt8(avg)
                 dataType[offset + 2] = UInt8(avg)
                 dataType[offset + 3] = UInt8(avg)

        let bitmapBytesPerRow = Int(pixelsWide) * 4
        let bitmapByteCount = bitmapBytesPerRow * Int(pixelsHigh)
        
        let finalcontext = CGBitmapContextCreate(data, pixelsWide, pixelsHigh, CUnsignedLong(8),  CUnsignedLong(bitmapBytesPerRow), colorSpace, bitmapInfo)
        
        let imageRef = CGBitmapContextCreateImage(finalcontext)
        return UIImage(CGImage: imageRef, scale: self.scale,orientation: self.imageOrientation)

    }
    
    
    /*
        Get pixel color for a pixel in the image.
    */
    func getPixelColorAtLocation(point:CGPoint)->UIColor? {
        self.sanitizePoint(point)

        let colorSpace = CGColorSpaceCreateDeviceRGB()
        let bitmapInfo = CGBitmapInfo(rawValue: CGImageAlphaInfo.PremultipliedFirst.rawValue)
        
        let finalcontext = CGBitmapContextCreate(data, pixelsWide, pixelsHigh, 8,  bitmapBytesPerRow, colorSpace, bitmapInfo)
        
        let imageRef = CGBitmapContextCreateImage(finalcontext)
        return UIImage(CGImage: imageRef, scale: self.scale,orientation: self.imageOrientation)
