Skip to content

Commit c93b966

Browse files
committed
Update dcraw.
1 parent eb0f386 commit c93b966

File tree

5 files changed

+19
-21
lines changed

5 files changed

+19
-21
lines changed

Diff for: jpeg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func previewJPEG(ctx context.Context, path string) ([]byte, error) {
3232
return nil, err
3333
}
3434

35-
exf := rotateflip.Orientation(rawOrientation(path))
35+
exf := rotateflip.Orientation(dcraw.GetOrientation(ctx, path))
3636
img = rotateflip.Image(img, exf.Op())
3737

3838
buf := bytes.Buffer{}

Diff for: meta.go

-17
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"bufio"
55
"bytes"
6-
"fmt"
76
"log"
87
"path/filepath"
98

@@ -52,22 +51,6 @@ func dngHasEdits(path string) bool {
5251
return err == nil && len(out) > 0
5352
}
5453

55-
func rawOrientation(path string) int {
56-
log.Print("exiftool (get orientation)...")
57-
out, err := exifserver.Command("--printConv", "-short3", "-fast2", "-Orientation", path)
58-
if err != nil {
59-
return 0
60-
}
61-
62-
var orientation int
63-
_, err = fmt.Fscanf(bytes.NewReader(out), "%d\n", &orientation)
64-
if err != nil {
65-
return 0
66-
}
67-
68-
return orientation
69-
}
70-
7154
func cameraMatchingWhiteBalance(path string) string {
7255
log.Print("exiftool (get camera matching white balance)...")
7356
out, err := exifserver.Command("-duplicates", "-short3", "-fast", "-ExifIFD:WhiteBalance", "-MakerNotes:WhiteBalance", path)

Diff for: pkg/dcraw/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
`dcraw.wasm` is built from:<br>
2-
[github.com/ncruces/dcraw@ncruces-rethinkraw](https://github.com/ncruces/dcraw/tree/ncruces-rethinkraw)
1+
`dcraw.wasm` is built from:\
2+
[github.com/ncruces/dcraw@ncruces-wasm](https://github.com/ncruces/dcraw/tree/ncruces-wasm)

Diff for: pkg/dcraw/dcraw.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var (
3232
wasm wazero.Runtime
3333
module wazero.CompiledModule
3434
sem *semaphore.Weighted
35+
orienRegex *regexp.Regexp
3536
thumbRegex *regexp.Regexp
3637
counter atomic.Uint64
3738
)
@@ -48,6 +49,7 @@ func compile() {
4849
}
4950

5051
sem = semaphore.NewWeighted(6)
52+
orienRegex = regexp.MustCompile(`Orientation: +(\d)`)
5153
thumbRegex = regexp.MustCompile(`Thumb size: +(\d+) x (\d+)`)
5254
}
5355

@@ -78,7 +80,7 @@ func run(ctx context.Context, root fs.FS, args ...string) ([]byte, error) {
7880
// The thumbnail will either be a JPEG, or a PNM file in 8-bit P5/P6 format.
7981
// For more about PNM, see https://en.wikipedia.org/wiki/Netpbm
8082
func GetThumb(ctx context.Context, file string) ([]byte, error) {
81-
out, err := run(ctx, fileFS(file), "dcraw", "-e", "-c", fileFSname)
83+
out, err := run(ctx, fileFS(file), "dcraw", "-e", "-e", "-c", fileFSname)
8284
if err != nil {
8385
return nil, err
8486
}
@@ -121,6 +123,19 @@ func GetThumbSize(ctx context.Context, file string) (int, error) {
121123
return max, nil
122124
}
123125

126+
// GetOrientation returns the EXIF orientation of the RAW file, or 0 if unknown.
127+
func GetOrientation(ctx context.Context, file string) int {
128+
out, err := run(ctx, fileFS(file), "dcraw", "-i", "-v", fileFSname)
129+
if err != nil {
130+
return 0
131+
}
132+
133+
if match := orienRegex.FindSubmatch(out); match != nil {
134+
return int(match[1][0] - '0')
135+
}
136+
return 0
137+
}
138+
124139
// GetRAWPixels develops an half-resolution, demosaiced, not white balanced
125140
// image from the RAW file.
126141
func GetRAWPixels(ctx context.Context, file string) ([]byte, error) {

Diff for: pkg/dcraw/dcraw.wasm

-2.95 KB
Binary file not shown.

0 commit comments

Comments
 (0)