ctucx.git: nimjpg

parse jpg file header

commit 55c1ef17b528b7892caba6a69f8e4d79bce2dd85
parent 6543530ab3297bbc052deaffc710d6c301ccefbe
Author: Milan Pässler <milan@petabyte.dev>
Date: Sat, 13 Mar 2021 13:46:12 +0100

add exifnim as dependency
4 files changed, 2 insertions(+), 71 deletions(-)
D
exif.nim
|
24
------------------------
D
exif.nimble
|
14
--------------
M
jpg.nim
|
4
++--
D
libexif.nim
|
31
-------------------------------
diff --git a/exif.nim b/exif.nim
@@ -1,24 +0,0 @@
-import libexif
-import tables
-
-var buf {.threadvar.}: cstring
-
-# MUST be called once per thread
-proc init_exif*() =
-  buf = cast[cstring](alloc(2001))
-
-proc deinit_exif*() =
-  dealloc(buf)
-
-proc collect_exif_data*(ed: ptr ExifData): Table[string, string] {.gcsafe.} =
-  proc process_entries(entry: ptr ExifEntry , callback_data: pointer) {.cdecl.} =
-    let name = exif_tag_get_name(entry.tag)
-    let val = exif_entry_get_value(entry, buf, 2000)
-    let result_table = cast[ptr Table[string, string]](callback_data)
-    result_table[][$name] = $val
-
-  proc process_contents(content: ptr ExifContent, callback_data: pointer) {.cdecl.} =
-    exif_content_foreach_entry(content, process_entries, callback_data)
-
-  exif_data_foreach_content(ed, process_contents, addr result)
-  exif_data_unref(ed)
diff --git a/exif.nimble b/exif.nimble
@@ -1,14 +0,0 @@
-# Package
-
-version       = "0.1.0"
-author        = "ctucx, Milan"
-description   = "Read exif data using libexif"
-license       = "GPL-3.0"
-srcDir        = "./"
-bin           = @["example"]
-
-
-
-# Dependencies
-requires "nim >= 1.4"
-requires "nimterop"
diff --git a/jpg.nim b/jpg.nim
@@ -2,8 +2,8 @@ import os
 import strutils
 import asyncfile
 import asyncdispatch
-import libexif
-import exif
+import exifnim/libexif
+import exifnim/helpers
 import tables
 import parseutils
 import options
diff --git a/libexif.nim b/libexif.nim
@@ -1,31 +0,0 @@
-import os
-import nimterop/build
-import nimterop/cimport
-
-static:
-  cDebug()  
-
-cPlugin:
-  import strutils
-  # Strip leading and trailing underscores
-  proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
-    sym.name = sym.name.strip(chars={'_'})
-
-const
-  baseDir = getProjectCacheDir("exif" / "libexif")
-
-when isDefined(libexifLocal):
-  cIncludeDir("libexif/include")
-  cImport("libexif/include/libexif/exif-data.h" , recurse = true, dynlib = "libexif/lib/libexif.so")
-
-else:
-  getHeader(
-    header = "libexif/exif-data.h",
-    giturl = "https://github.com/libexif/libexif/",
-    dlurl = "https://github.com/libexif/libexif/releases/download/libexif-0_6_22-release/libexif-0.6.22.tar.gz",
-    outdir = baseDir,
-    altNames = "exif"
-  )
-
-  cIncludeDir(exifdataPath.parentDir())
-  cImport(exifdataPath, recurse = true, dynlib = exifdataLPath)