Reformat code with linter

This commit is contained in:
Endre Simo
2018-04-13 21:27:39 +03:00
parent 9c1074a8f2
commit 88f7f5e41b

39
main.go
View File

@@ -4,13 +4,14 @@ import (
"fmt" "fmt"
"image" "image"
"image/color" "image/color"
"image/draw"
_ "image/jpeg" _ "image/jpeg"
"image/png" "image/png"
_ "image/png" _ "image/png"
"image/draw"
"math" "math"
"os" "os"
"time" "time"
"go4.org/sort" "go4.org/sort"
) )
@@ -25,14 +26,14 @@ type pixel struct {
type dctPx [][]pixel type dctPx [][]pixel
type imageBlock struct { type imageBlock struct {
x int x int
y int y int
img image.Image img image.Image
} }
type vector struct { type vector struct {
xa, ya int xa, ya int
xb, yb int xb, yb int
offsetX, offsetY int offsetX, offsetY int
} }
@@ -43,8 +44,8 @@ type feature struct {
} }
var ( var (
features []feature features []feature
vectors []vector vectors []vector
cr, cg, cb, cy float64 cr, cg, cb, cy float64
) )
@@ -142,9 +143,9 @@ func main() {
dctPixels[u][v] = pixel{cr, cg, cb, cy} dctPixels[u][v] = pixel{cr, cg, cb, cy}
} }
} }
avr /= float64(BlockSize*BlockSize) avr /= float64(BlockSize * BlockSize)
avg /= float64(BlockSize*BlockSize) avg /= float64(BlockSize * BlockSize)
avb /= float64(BlockSize*BlockSize) avb /= float64(BlockSize * BlockSize)
features = append(features, feature{x: block.x, y: block.y, val: dctPixels[0][0].y}) features = append(features, feature{x: block.x, y: block.y, val: dctPixels[0][0].y})
features = append(features, feature{x: block.x, y: block.y, val: dctPixels[0][1].y}) features = append(features, feature{x: block.x, y: block.y, val: dctPixels[0][1].y})
@@ -195,8 +196,8 @@ func convertRGBImageToYUV(img image.Image) image.Image {
} }
func dct(x, y, u, v, w float64) float64 { func dct(x, y, u, v, w float64) float64 {
a := math.Cos(((2.0*x+1)*(u*math.Pi))/(2*w)) a := math.Cos(((2.0*x + 1) * (u * math.Pi)) / (2 * w))
b := math.Cos(((2.0*y+1)*(v*math.Pi))/(2*w)) b := math.Cos(((2.0*y + 1) * (v * math.Pi)) / (2 * w))
return a * b return a * b
} }
@@ -255,10 +256,10 @@ func analyze(blockA, blockB feature) *vector {
dist := math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2)) dist := math.Sqrt(math.Pow(dx, 2) + math.Pow(dy, 2))
res := &vector{ res := &vector{
xa: blockA.x, xa: blockA.x,
ya: blockA.y, ya: blockA.y,
xb: blockB.x, xb: blockB.x,
yb: blockB.y, yb: blockB.y,
offsetX: int(dx), offsetX: int(dx),
offsetY: int(dy), offsetY: int(dy),
} }
@@ -274,7 +275,7 @@ type offset struct {
type newVector []vector type newVector []vector
// Analyze pair of candidate and check for similarity by computing the accumulative number of shift vectors. // Analyze pair of candidate and check for similarity by computing the accumulative number of shift vectors.
func checkForSimilarity(vect []vector)newVector { func checkForSimilarity(vect []vector) newVector {
//For each pair of candidate compute the accumulative number of the corresponding shift vectors. //For each pair of candidate compute the accumulative number of the corresponding shift vectors.
duplicateItems := make(map[offset]int) duplicateItems := make(map[offset]int)
@@ -298,8 +299,8 @@ func checkForSimilarity(vect []vector)newVector {
// Implement sorting function on feature vector // Implement sorting function on feature vector
type featVec []feature type featVec []feature
func (a featVec) Len() int { return len(a) } func (a featVec) Len() int { return len(a) }
func (a featVec) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a featVec) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a featVec) Less(i, j int) bool { func (a featVec) Less(i, j int) bool {
if a[i].val < a[j].val { if a[i].val < a[j].val {
return true return true