ctucx.git: nimjpg

parse jpg file header

commit 234c1fc04fef5848a205a7dea96bea29ba5d4e65
parent 5637b7d5aaccda626b7b274bfb72a69324bb4720
Author: Milan Pässler <milan@petabyte.dev>
Date: Sat, 13 Mar 2021 11:49:03 +0100

parse sof section
2 files changed, 13 insertions(+), 2 deletions(-)
M
exif.nim
|
1
-
M
jpg.nim
|
14
+++++++++++++-
diff --git a/exif.nim b/exif.nim
@@ -1,4 +1,3 @@
-import asyncdispatch
 import libexif
 import tables
 
diff --git a/jpg.nim b/jpg.nim
@@ -86,7 +86,19 @@ proc collect_jpg*(file: AsyncFile): Future[JpgInfo] {.gcsafe,async.} =
     else:
       if toHex(marker).startsWith("C"):
         echo "found SOF"
-        file.skipSection().await
+        let section_start = file.getFilePos() + 2
+        let section_end = section_start + int64(file.getSectionSize().await)
+        var precision, components: uint8
+        var height, width: uint16
+        discard parseHex(toHex(file.read(1).await), precision)
+        echo("  precision ", precision)
+        discard parseHex(toHex(file.read(2).await), height)
+        echo("  height ", height)
+        discard parseHex(toHex(file.read(2).await), width)
+        echo("  width ", width)
+        discard parseHex(toHex(file.read(1).await), components)
+        echo("  components ", components)
+        file.setFilePos(section_end)
         continue
 
       echo("unknown section: ", toHex(marker))