2013-10-13 18:11:41 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2014 The Perkeep Authors.
|
2013-10-13 18:11:41 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"image"
|
2015-12-18 14:41:58 +00:00
|
|
|
"image/jpeg"
|
2013-10-13 18:11:41 +00:00
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2018-01-03 05:03:30 +00:00
|
|
|
"perkeep.org/internal/images/fastjpeg"
|
|
|
|
"perkeep.org/internal/images/resize"
|
2013-10-13 18:11:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// The decode routines being benchmarked in this file will use these bytes for
|
|
|
|
// their in-memory io.Readers.
|
|
|
|
var jpegBytes []byte
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
// Create image with non-uniform color to make decoding more realistic.
|
|
|
|
// Solid color jpeg images decode faster than non-uniform images.
|
|
|
|
b := new(bytes.Buffer)
|
|
|
|
w, h := 4000, 4000
|
|
|
|
im := image.NewNRGBA(image.Rect(0, 0, w, h))
|
|
|
|
for i := range im.Pix {
|
|
|
|
switch {
|
|
|
|
case i%4 == 3:
|
|
|
|
im.Pix[i] = 255
|
|
|
|
default:
|
|
|
|
im.Pix[i] = uint8(i)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := jpeg.Encode(b, im, nil); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
jpegBytes = b.Bytes()
|
|
|
|
}
|
|
|
|
|
|
|
|
type decodeFunc func(r io.Reader) (image.Image, string, error)
|
|
|
|
|
|
|
|
func BenchmarkStdlib(b *testing.B) {
|
|
|
|
common(b, image.Decode)
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeDownsample(factor int) decodeFunc {
|
|
|
|
return func(r io.Reader) (image.Image, string, error) {
|
|
|
|
im, err := fastjpeg.DecodeDownsample(r, factor)
|
|
|
|
return im, "jpeg", err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDjpeg1(b *testing.B) {
|
|
|
|
if !fastjpeg.Available() {
|
|
|
|
b.Skip("Skipping benchmark, djpeg unavailable.")
|
|
|
|
}
|
|
|
|
common(b, decodeDownsample(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDjpeg2(b *testing.B) {
|
|
|
|
if !fastjpeg.Available() {
|
|
|
|
b.Skip("Skipping benchmark, djpeg unavailable.")
|
|
|
|
}
|
|
|
|
common(b, decodeDownsample(2))
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDjpeg4(b *testing.B) {
|
|
|
|
if !fastjpeg.Available() {
|
|
|
|
b.Skip("Skipping benchmark, djpeg unavailable.")
|
|
|
|
}
|
|
|
|
common(b, decodeDownsample(4))
|
|
|
|
}
|
|
|
|
|
|
|
|
func BenchmarkDjpeg8(b *testing.B) {
|
|
|
|
if !fastjpeg.Available() {
|
|
|
|
b.Skip("Skipping benchmark, djpeg unavailable.")
|
|
|
|
}
|
|
|
|
common(b, decodeDownsample(8))
|
|
|
|
}
|
|
|
|
|
2016-02-05 14:56:16 +00:00
|
|
|
func testRun(b testing.TB, decode decodeFunc) {
|
2013-10-13 18:11:41 +00:00
|
|
|
if !fastjpeg.Available() {
|
|
|
|
b.Skip("Skipping benchmark, djpeg unavailable.")
|
|
|
|
}
|
|
|
|
im, _, err := decode(bytes.NewReader(jpegBytes))
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
rect := im.Bounds()
|
|
|
|
w, h := 128, 128
|
|
|
|
im = resize.Resize(im, rect, w, h)
|
|
|
|
err = jpeg.Encode(ioutil.Discard, im, nil)
|
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func common(b *testing.B, decode decodeFunc) {
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
testRun(b, decode)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStdlib(t *testing.T) {
|
|
|
|
testRun(t, decodeDownsample(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDjpeg1(t *testing.T) {
|
|
|
|
testRun(t, decodeDownsample(1))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDjpeg2(t *testing.T) {
|
|
|
|
testRun(t, decodeDownsample(2))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDjpeg4(t *testing.T) {
|
|
|
|
testRun(t, decodeDownsample(4))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDjpeg8(t *testing.T) {
|
|
|
|
testRun(t, decodeDownsample(8))
|
|
|
|
}
|