summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Pässler <milan@petabyte.dev>2021-03-13 16:20:15 +0100
committerMilan Pässler <milan@petabyte.dev>2021-03-13 16:20:15 +0100
commit0a72ba7cd4dcbe80b4594becbc81ae4cd5b2f9e2 (patch)
treed7268c1a7a76ba195c44c1fbd1d7bc3f169cb9e9
parent7cfcb30c2f3ffc4e71df1445c99f2a9444d2cb86 (diff)
downloadnimjpg-0a72ba7cd4dcbe80b4594becbc81ae4cd5b2f9e2.tar.gz
nimjpg-0a72ba7cd4dcbe80b4594becbc81ae4cd5b2f9e2.tar.bz2
nimjpg-0a72ba7cd4dcbe80b4594becbc81ae4cd5b2f9e2.zip
choose sof section with bigger resolution
-rw-r--r--nimjpg.nim6
-rw-r--r--utils.nim2
2 files changed, 5 insertions, 3 deletions
diff --git a/nimjpg.nim b/nimjpg.nim
index 58ff67b..a5d43b8 100644
--- a/nimjpg.nim
+++ b/nimjpg.nim
@@ -49,7 +49,6 @@ proc getSectionSize(file: Stream | AsyncFile): Future[uint16] {.multisync.} =
var size: uint16
let val = toHex(file.read(2).await)
discard parseHex(val, size)
- echo val
return size - uint16(2)
proc skipSection(file: Stream | AsyncFile): Future[int] {.multisync.} =
@@ -68,6 +67,9 @@ proc process_sof*(file: Stream | AsyncFile): Future[SofData] {.multisync.} =
discard parseHex(toHex(file.read(2).await), result.width)
discard parseHex(toHex(file.read(1).await), result.components)
+proc calcRes(sd: SofData): uint64 =
+ return uint64(sd.height) * uint64(sd.width)
+
proc collect_jpg*(file: Stream | AsyncFile): Future[JpgInfo] {.multisync,gcsafe.} =
var done = false
var byte: string
@@ -107,7 +109,7 @@ proc collect_jpg*(file: Stream | AsyncFile): Future[JpgInfo] {.multisync,gcsafe.
let section_start = file.getFilePos() + 2
let section_end = section_start + int64(file.getSectionSize().await)
let sd = file.process_sof().await
- if result.sofData.isNone:
+ if result.sofData.isNone or sd.calcRes() > result.sofData.get.calcRes():
result.sofData = some(sd)
debug sd
file.setFilePos(section_end)
diff --git a/utils.nim b/utils.nim
index 2eb09ae..ae563c1 100644
--- a/utils.nim
+++ b/utils.nim
@@ -21,4 +21,4 @@ proc setFilePos*(stream: Stream, position: int64) =
stream.setPosition(int(position))
proc readBuffer*(stream: Stream, buffer: pointer, length: int): int =
- result = stream.readData(buffer, length)
+ return stream.readData(buffer, length)