Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Commit

Permalink
Remove soreil/arw dependency
Browse files Browse the repository at this point in the history
Signed-off-by: Igor Shishkin <me@teran.ru>
  • Loading branch information
teran committed Sep 11, 2019
1 parent f27c60f commit 501d24a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/teran/imgsum
go 1.13

require (
github.com/soreil/arw v0.0.0-20180907190942-c71045f5319b
github.com/bamiaux/rez v0.0.0-20170731184118-29f4463c688b
github.com/brett-lempereur/ish v0.0.0-20161214150457-bbdc45bcf55d
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac
Expand Down
18 changes: 18 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
github.com/bamiaux/rez v0.0.0-20170731184118-29f4463c688b h1:5Ci5wpOL75rYF6RQGRoqhEAU6xLJ6n/D4SckXX1yB74=
github.com/bamiaux/rez v0.0.0-20170731184118-29f4463c688b/go.mod h1:obBQGGIFbbv9KWg92Qu9UHeD94JXmHD1jovY/z6I3O8=
github.com/brett-lempereur/ish v0.0.0-20161214150457-bbdc45bcf55d h1:oCP9o9IOvgi0A1biE1EkI/m+pViqJoCQjU/bAopLpBo=
github.com/brett-lempereur/ish v0.0.0-20161214150457-bbdc45bcf55d/go.mod h1:sGi2C1jLbZM77czzwYX70vIkYV8Smll6xG93m96IZYw=
github.com/gonum/blas v0.0.0-20181208220705-f22b278b28ac/go.mod h1:P32wAyui1PQ58Oce/KYkOqQv8cVw1zAapXOl+dRFGbc=
github.com/gonum/floats v0.0.0-20181209220543-c233463c7e82/go.mod h1:PxC8OnwL11+aosOB5+iEPoV3picfs8tUpkVd0pDo+Kg=
github.com/gonum/internal v0.0.0-20181124074243-f884aa714029/go.mod h1:Pu4dmpkhSyOzRwuXkOgAvijx4o+4YMUJJo9OvPYMkks=
github.com/gonum/lapack v0.0.0-20181123203213-e4cdc5a0bff9/go.mod h1:XA3DeT6rxh2EAE789SSiSJNqxPaC0aE9J8NTOI0Jo/A=
github.com/gonum/matrix v0.0.0-20181209220409-c518dec07be9/go.mod h1:0EXg4mc1CNP0HCqCz+K4ts155PXIlUywf0wqN+GfPZw=
github.com/gotk3/gotk3 v0.0.0-20190512183708-8365021fde1a/go.mod h1:Eew3QBwAOBTrfFFDmsDE5wZWbcagBL1NUslj1GhRveo=
github.com/nf/cr2 v0.0.0-20180623103828-4699471a17ed h1:QP63yO3XEt8tJ1DgBsNjbOyBGjy2eHy9ITK4Eisr9rg=
github.com/nf/cr2 v0.0.0-20180623103828-4699471a17ed/go.mod h1:HazDB3gS/i//QXMMRmTAV7Ni9gAi4mDNTH2HjZ5aVgU=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/steakknife/hamming v0.0.0-20180906055317-003c143a81c2 h1:o6NMd68tuqfQ0ZFnz2d16xzFNLWxrCvqF40InOJJHSM=
github.com/steakknife/hamming v0.0.0-20180906055317-003c143a81c2/go.mod h1:hpGUWaI9xL8pRQCTXQgocU38Qw1g0Us7n5PxxTwTCYU=
golang.org/x/image v0.0.0-20190516052701-61b8692d9a5c h1:VgWXv7ME0Tq2L5CBzVvhTMrfcKfvGs7ifTV9PBYTP3I=
golang.org/x/image v0.0.0-20190516052701-61b8692d9a5c/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
42 changes: 0 additions & 42 deletions image/image.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package image

import (
"bytes"
"crypto/sha256"
"encoding/hex"
stdimage "image"
"image/jpeg"
"os"
"regexp"

"github.com/nf/cr2"
"github.com/soreil/arw"
)

var (
reCanon = regexp.MustCompile("(?i).cr(2)$")
reSony = regexp.MustCompile("(?i).(arw|sr2)$")
)

// Image type
Expand Down Expand Up @@ -47,8 +43,6 @@ func (i *Image) open() error {

if reCanon.Match([]byte(i.filename)) {
err = i.openCanonRaw()
} else if reSony.Match([]byte(i.filename)) {
err = i.openSonyRaw()
} else {
err = i.openStdImage()
}
Expand Down Expand Up @@ -78,42 +72,6 @@ func (i *Image) openCanonRaw() error {
return nil
}

func (i *Image) openSonyRaw() error {
var jpegOffset uint32
var jpegLength uint32

header, err := arw.ParseHeader(i.fp)
if err != nil {
return err
}

meta, err := arw.ExtractMetaData(i.fp, int64(header.Offset), 0)
if err != nil {
return err
}

for i := range meta.FIA {
switch meta.FIA[i].Tag {
case arw.JPEGInterchangeFormat:
jpegOffset = meta.FIA[i].Offset
case arw.JPEGInterchangeFormatLength:
jpegLength = meta.FIA[i].Offset
}
}

jpg, err := arw.ExtractThumbnail(i.fp, jpegOffset, jpegLength)
if err != nil {
return err
}

reader := bytes.NewReader(jpg)
i.image, err = jpeg.Decode(reader)
if err != nil {
return err
}
return nil
}

// Hexdigest produces image hash and returns it as string
// actually the string is SHA256 from the hasher's value
func (i *Image) Hexdigest(hashKind HashType, res int) (string, error) {
Expand Down

0 comments on commit 501d24a

Please sign in to comment.