     (when (< (inc i) size) (recur (inc i))))
   target)
 
-(defn buffer->image ^BufferedImage [^Long w ^Long h ^ints buffer]
-  (let [image (BufferedImage. w h BufferedImage/TYPE_INT_RGB)]
-    (.setRGB image 0 0 w h buffer 0 w)
-    image))
-
-(defn read-buffer [^InputStream in ^bytes buffer ^long offset ^long size]
+(defn read-fully [^InputStream in ^bytes buffer ^long offset ^long size]
   (IOUtils/readFully in buffer offset size))
 
 (defn make-reader [^InputStream in]

      (let [picture         (.displayPicture (.priv_data context))
            width           (.imageWidth picture)
            height          (.imageHeight picture)
            picture-buffer  (int-array (* width height))]
        (FrameUtils/YUV2RGB picture picture-buffer)
        (buffer->image width height picture-buffer)))))

(defn open-socket ^Socket []
  (doto (Socket.)
    (.setSoTimeout 2000)
    (.connect (InetSocketAddress. "localhost" #_ comm/drone-ip 5555))))

(defn save [^OutputStream out data]
  (doseq [[buffer size] data]

              (Thread/sleep 1000))
            (finally
              (try (.close socket) (catch Exception _))
              (try (.close ^OutputStream out) (catch Exception _))))))
      (catch Throwable e
        (println "exception while processing video stream" e)
        (.printStackTrace e))
