diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-09-01 17:27:21 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-09-02 16:37:28 +0200 |
commit | ce47c21a2998630f8edcbd056983d9c59a80b676 (patch) | |
tree | 01b7f680f631cc3418fa0e8457bff2b95a6f553d /resources/images/exif/exif.go | |
parent | de9cbf61954201943a7b170a7d0a8b34afb5942c (diff) |
resources: Cache Exif data to disk
```bash
name old time/op new time/op delta
ImageExif/Cold_cache-4 312µs ±28% 355µs ± 7% ~ (p=0.343 n=4+4)
ImageExif/Cold_cache,_10-4 479µs ± 6% 546µs ± 0% +13.91% (p=0.029 n=4+4)
ImageExif/Warm_cache-4 272µs ± 1% 81µs ± 5% -70.30% (p=0.029 n=4+4)
name old alloc/op new alloc/op delta
ImageExif/Cold_cache-4 151kB ± 0% 161kB ± 0% +6.46% (p=0.029 n=4+4)
ImageExif/Cold_cache,_10-4 179kB ± 0% 189kB ± 0% +5.49% (p=0.029 n=4+4)
ImageExif/Warm_cache-4 151kB ± 0% 13kB ± 0% -91.52% (p=0.029 n=4+4)
name old allocs/op new allocs/op delta
ImageExif/Cold_cache-4 1.03k ± 0% 1.21k ± 0% +17.78% (p=0.029 n=4+4)
ImageExif/Cold_cache,_10-4 1.65k ± 0% 1.83k ± 0% +11.09% (p=0.029 n=4+4)
ImageExif/Warm_cache-4 1.03k ± 0% 0.28k ± 0% -72.40% (p=0.029 n=4+4)
```
Fixes #6291
Diffstat (limited to 'resources/images/exif/exif.go')
-rw-r--r-- | resources/images/exif/exif.go | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/resources/images/exif/exif.go b/resources/images/exif/exif.go index 7a3c982c1..b5161f770 100644 --- a/resources/images/exif/exif.go +++ b/resources/images/exif/exif.go @@ -24,6 +24,8 @@ import ( "unicode" "unicode/utf8" + "github.com/bep/tmc" + _exif "github.com/rwcarlsen/goexif/exif" "github.com/rwcarlsen/goexif/tiff" ) @@ -31,10 +33,10 @@ import ( const exifTimeLayout = "2006:01:02 15:04:05" type Exif struct { - Lat float64 - Long float64 - Date time.Time - Values map[string]interface{} + Lat float64 + Long float64 + Date time.Time + Tags Tags } type Decoder struct { @@ -139,7 +141,7 @@ func (d *Decoder) Decode(r io.Reader) (ex *Exif, err error) { return } - ex = &Exif{Lat: lat, Long: long, Date: tm, Values: walker.vals} + ex = &Exif{Lat: lat, Long: long, Date: tm, Tags: walker.vals} return } @@ -240,3 +242,30 @@ func nullString(in []byte) string { return "" } + +var tcodec *tmc.Codec + +func init() { + var err error + tcodec, err = tmc.New() + if err != nil { + panic(err) + } +} + +type Tags map[string]interface{} + +func (v *Tags) UnmarshalJSON(b []byte) error { + vv := make(map[string]interface{}) + if err := tcodec.Unmarshal(b, &vv); err != nil { + return err + } + + *v = vv + + return nil +} + +func (v Tags) MarshalJSON() ([]byte, error) { + return tcodec.Marshal(v) +} |