本文整理汇总了Golang中github.com/pierrre/imageserver/image.Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang Decode函数的具体用法?Golang Decode怎么用?Golang Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BenchmarkProcessorHighQuality
func BenchmarkProcessorHighQuality(b *testing.B) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
b.Fatal(err)
}
prc := NewProcessor(2.2, true)
params := imageserver.Params{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
prc.Process(nim, params)
}
}
示例2: TestProcessorProcess
func TestProcessorProcess(t *testing.T) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
t.Fatal(err)
}
for _, highQuality := range []bool{false, true} {
prc := NewProcessor(2.2, highQuality)
_, err = prc.Process(nim, imageserver.Params{})
if err != nil {
t.Fatal(err)
}
}
}
示例3: BenchmarkEncoder
// BenchmarkEncoder is a helper to benchmark Encoder.
func BenchmarkEncoder(b *testing.B, enc imageserver_image.Encoder, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := enc.Encode(ioutil.Discard, nim, params)
if err != nil {
b.Fatal(err)
}
}
}
示例4: BenchmarkProcessorHighQuality
func BenchmarkProcessorHighQuality(b *testing.B) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
b.Fatal(err)
}
prc := NewProcessor(2.2, true)
params := imageserver.Params{}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
prc.Process(nim, params)
}
})
}
示例5: BenchmarkEncoder
// BenchmarkEncoder is a helper to benchmark Encoder.
func BenchmarkEncoder(b *testing.B, enc imageserver_image.Encoder, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := enc.Encode(ioutil.Discard, nim, params)
if err != nil {
b.Fatal(err)
}
}
})
}
示例6: BenchmarkCorrectionProcessor
func BenchmarkCorrectionProcessor(b *testing.B) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
b.Fatal(err)
}
prc := NewCorrectionProcessor(
imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nim, nil
}),
true,
)
params := imageserver.Params{}
for i := 0; i < b.N; i++ {
prc.Process(nim, params)
}
}
示例7: benchmarkRotateProcessor
func benchmarkRotateProcessor(b *testing.B, params imageserver.Params) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
b.Fatal(err)
}
params = imageserver.Params{
rotateParam: params,
}
prc := &RotateProcessor{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := prc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
}
示例8: BenchmarkCorrectionProcessor
func BenchmarkCorrectionProcessor(b *testing.B) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
b.Fatal(err)
}
prc := NewCorrectionProcessor(
imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nim, nil
}),
true,
)
params := imageserver.Params{}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
prc.Process(nim, params)
}
})
}
示例9: benchmark
func benchmark(b *testing.B, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
Param: params,
}
proc := &Processor{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := proc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
}
示例10: benchmarkResizeProcessor
func benchmarkResizeProcessor(b *testing.B, name string, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
resizeParam: params,
}
prc := &ResizeProcessor{}
b.Run(name, func(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := prc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
})
}
示例11: benchmark
func benchmark(b *testing.B, im *imageserver.Image, params imageserver.Params) {
nim, err := imageserver_image.Decode(im)
if err != nil {
b.Fatal(err)
}
params.Set("width", 100)
params = imageserver.Params{
Param: params,
}
proc := &Processor{}
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
_, err := proc.Process(nim, params)
if err != nil {
b.Fatal(err)
}
}
})
}
示例12: TestProcessor
func TestProcessor(t *testing.T) {
nim, err := imageserver_image.Decode(imageserver_testdata.Medium)
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
processor *Processor
params imageserver.Params
expectedWidth int
expectedHeight int
expectedParamError string
}{
// no size
{
name: "Empty",
params: imageserver.Params{},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "ParamEmpty",
params: imageserver.Params{param: imageserver.Params{}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "SizeZero",
params: imageserver.Params{param: imageserver.Params{
"width": 0,
"height": 0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
// with size
{
name: "Width",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
}},
expectedWidth: 100,
},
{
name: "Height",
params: imageserver.Params{param: imageserver.Params{
"height": 100,
}},
expectedHeight: 100,
},
{
name: "WidthHeight",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
"height": 100,
}},
expectedWidth: 100,
expectedHeight: 100,
},
// mode
{
name: "ModeResize",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
"height": 100,
"mode": "resize",
}},
expectedWidth: 100,
expectedHeight: 100,
},
{
name: "ModeThumbnail",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
"height": 100,
"mode": "thumbnail",
}},
expectedWidth: 100,
expectedHeight: 79,
},
// interpolation
{
name: "InterpolationNearestNeighbor",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
"interpolation": "nearest_neighbor",
}},
expectedWidth: 100,
},
{
name: "InterpolationBilinear",
params: imageserver.Params{param: imageserver.Params{
"width": 100,
"interpolation": "bilinear",
}},
expectedWidth: 100,
},
{
name: "InterpolationBicubic",
params: imageserver.Params{param: imageserver.Params{
//.........这里部分代码省略.........
示例13: TestCorrectionProcessor
func TestCorrectionProcessor(t *testing.T) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
t.Fatal(err)
}
simplePrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nim, nil
})
errPrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nil, fmt.Errorf("error")
})
for _, tc := range []struct {
name string
processor imageserver_image.Processor
enabled bool
params imageserver.Params
errorExpected bool
}{
{
name: "DefaultEnabled",
processor: simplePrc,
enabled: true,
},
{
name: "DefaultDisabled",
processor: simplePrc,
enabled: false,
},
{
name: "ParamDisabled",
processor: simplePrc,
enabled: true,
params: imageserver.Params{
"gamma_correction": false,
},
},
{
name: "ParamEnabled",
processor: simplePrc,
enabled: false,
params: imageserver.Params{
"gamma_correction": true,
},
},
{
name: "Error",
processor: errPrc,
enabled: true,
errorExpected: true,
},
{
name: "Invalid",
processor: simplePrc,
enabled: true,
params: imageserver.Params{
"gamma_correction": "invalid",
},
errorExpected: true,
},
} {
t.Run(tc.name, func(t *testing.T) {
prc := NewCorrectionProcessor(tc.processor, tc.enabled)
params := tc.params
if params == nil {
params = imageserver.Params{}
}
_, err = prc.Process(nim, params)
if tc.errorExpected && err == nil {
t.Fatal("no error")
} else if !tc.errorExpected && err != nil {
t.Fatal(err)
}
})
}
}
示例14: TestProcess
func TestProcess(t *testing.T) {
nim, err := imageserver_image.Decode(imageserver_testdata.Medium)
if err != nil {
t.Fatal(err)
}
type TC struct {
processor *Processor
params imageserver.Params
expectedWidth int
expectedHeight int
expectedParamError string
}
for _, tc := range []TC{
// no size
{
params: imageserver.Params{},
expectedWidth: 1024,
expectedHeight: 819,
},
{
params: imageserver.Params{Param: imageserver.Params{}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 0,
"height": 0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
// with size
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
}},
expectedWidth: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"height": 100,
}},
expectedHeight: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"height": 100,
}},
expectedWidth: 100,
expectedHeight: 100,
},
// mode
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"height": 100,
"mode": "fit",
}},
expectedWidth: 100,
expectedHeight: 80,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"height": 100,
"mode": "fill",
}},
expectedWidth: 100,
expectedHeight: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"mode": "fill",
}},
expectedWidth: 100,
expectedHeight: 80,
},
// resampling
{
processor: &Processor{DefaultResampling: gift.NearestNeighborResampling},
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
}},
expectedWidth: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"resampling": "nearest_neighbor",
}},
expectedWidth: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"resampling": "box",
}},
//.........这里部分代码省略.........
示例15: TestCorrectionProcessor
func TestCorrectionProcessor(t *testing.T) {
nim, err := imageserver_image.Decode(testdata.Medium)
if err != nil {
t.Fatal(err)
}
simplePrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nim, nil
})
errPrc := imageserver_image.ProcessorFunc(func(nim image.Image, params imageserver.Params) (image.Image, error) {
return nil, fmt.Errorf("error")
})
type TC struct {
processor imageserver_image.Processor
enabled bool
params imageserver.Params
errorExpected bool
}
for _, tc := range []TC{
{
processor: simplePrc,
enabled: true,
},
{
processor: simplePrc,
enabled: false,
},
{
processor: simplePrc,
enabled: true,
params: imageserver.Params{
"gamma_correction": false,
},
},
{
processor: simplePrc,
enabled: false,
params: imageserver.Params{
"gamma_correction": true,
},
},
{
processor: errPrc,
enabled: true,
errorExpected: true,
},
{
processor: simplePrc,
enabled: true,
params: imageserver.Params{
"gamma_correction": "invalid",
},
errorExpected: true,
},
} {
func() {
defer func() {
if t.Failed() {
t.Logf("%#v", tc)
}
}()
prc := NewCorrectionProcessor(tc.processor, tc.enabled)
params := tc.params
if params == nil {
params = imageserver.Params{}
}
_, err = prc.Process(nim, params)
if tc.errorExpected && err == nil {
t.Fatal("no error")
} else if !tc.errorExpected && err != nil {
t.Fatal(err)
}
}()
}
}