(defn
get-image
[fname callback]
#?(:clj (let [is (io/input-stream (io/resource (str "dynadoc-extend/cljs/" fname))) bytes (with-open [out (java.io.ByteArrayOutputStream.)] (io/copy is out) (.toByteArray out)) *width (MemoryUtil/memAllocInt 1) *height (MemoryUtil/memAllocInt 1) *components (MemoryUtil/memAllocInt 1) direct-buffer (doto (ByteBuffer/allocateDirect (alength bytes)) (.put bytes) (.flip)) decoded-image (STBImage/stbi_load_from_memory direct-buffer *width *height *components STBImage/STBI_rgb_alpha) image {:data decoded-image, :width (.get *width), :height (.get *height)}] (MemoryUtil/memFree *width) (MemoryUtil/memFree *height) (MemoryUtil/memFree *components) (callback image)) :cljs (let [image (js/Image.)] (doto image (-> .-src (set! fname)) (-> .-onload (set! (fn* [] (callback {:data image, :width image.width, :height image.height}))))))))