summaryrefslogtreecommitdiffstats
path: root/exif.nim
blob: e5e72108322f6ddce4ea2d45f5226d99a2660287 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)