summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Pässler <milan@petabyte.dev>2021-03-13 11:11:15 +0100
committerMilan Pässler <milan@petabyte.dev>2021-03-13 11:11:15 +0100
commit0d87f77c176d9b73346c865972704a1addfe74ed (patch)
treed776e359c2bccac7bad18b2e80ee1a99dd5a36f7
parentd95ba692278fc6f8ec4ea5c245af87fda1c8b777 (diff)
downloadnimjpg-0d87f77c176d9b73346c865972704a1addfe74ed.tar.gz
nimjpg-0d87f77c176d9b73346c865972704a1addfe74ed.tar.bz2
nimjpg-0d87f77c176d9b73346c865972704a1addfe74ed.zip
parse jpg header
-rw-r--r--example.nim17
-rw-r--r--exif.nim11
-rw-r--r--libexif.nim4
3 files changed, 23 insertions, 9 deletions
diff --git a/example.nim b/example.nim
index 2d5beda..d076d52 100644
--- a/example.nim
+++ b/example.nim
@@ -1,5 +1,7 @@
import os
-import exif
+import jpg
+import asyncdispatch
+import asyncfile
var result: cint
@@ -7,5 +9,14 @@ if paramCount() == 0:
echo "Gimme a file pls"
quit(QuitFailure)
-init_exif()
-echo $collect_exif(paramStr(1))
+let path = paramStr(1)
+
+init_jpg()
+
+if fileExists(path):
+ let file = openAsync(path)
+ echo $(waitFor collect_jpg(file))
+else:
+ echo "Gimme an existing file pls"
+
+deinit_jpg()
diff --git a/exif.nim b/exif.nim
index d28813d..cbc4eaf 100644
--- a/exif.nim
+++ b/exif.nim
@@ -1,21 +1,24 @@
+import asyncdispatch
import libexif
import tables
var ed {.threadvar.}: ptr ExifData
var buf {.threadvar.}: cstring
-var callback_data {.threadvar.}: pointer
+# MUST be called once per thread
proc init_exif*() =
buf = cast[cstring](alloc(2001))
-proc collect_exif*(path: string): Table[string, string] {.gcsafe.} =
+proc deinit_exif*() =
+ dealloc(buf)
+
+proc collect_exif*(path: string): Future[Table[string, string]] {.gcsafe,async.} =
result = initTable[string, string]()
ed = exif_data_new_from_file(path)
- callback_data = nil
if ed == nil:
- echo "error!"
+ # ERROR
quit(0)
proc process_entries(entry: ptr ExifEntry , callback_data: pointer) {.cdecl.} =
diff --git a/libexif.nim b/libexif.nim
index ff4a4c2..0cecffc 100644
--- a/libexif.nim
+++ b/libexif.nim
@@ -15,8 +15,8 @@ const
baseDir = getProjectCacheDir("exif" / "libexif")
when isDefined(libexifLocal):
- cIncludeDir("libexif/include/libexif")
- cImport("libexif/include/libexif/exif-data.h", recurse = true, dynlib = "libexif/lib/libexif.so")
+ cIncludeDir("libexif/include")
+ cImport("libexif/include/libexif/exif-data.h" , recurse = true, dynlib = "libexif/lib/libexif.so")
else:
getHeader(