本文整理汇总了Golang中github.com/pierrre/imageserver/image.Decode函数的典型用法代码示例。如果您正苦于以下问题:Golang Decode函数的具体用法?Golang Decode怎么用?Golang Decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Decode函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:12,代码来源:gamma_benchmark_test.go
示例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)
}
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:13,代码来源:gamma_test.go
示例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)
}
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:14,代码来源:benchmark.go
示例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)
}
})
}
开发者ID:phamhongviet,项目名称:imageserver,代码行数:14,代码来源:gamma_benchmark_test.go
示例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)
}
}
})
}
开发者ID:phamhongviet,项目名称:imageserver,代码行数:16,代码来源:benchmark.go
示例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)
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:16,代码来源:gamma_benchmark_test.go
示例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)
}
}
}
开发者ID:xiangxi,项目名称:imageserver,代码行数:17,代码来源:rotate_benchmark_test.go
示例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)
}
})
}
开发者ID:phamhongviet,项目名称:imageserver,代码行数:18,代码来源:gamma_benchmark_test.go
示例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)
}
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:18,代码来源:benchmark_test.go
示例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)
}
}
})
}
开发者ID:pierrre,项目名称:imageserver,代码行数:19,代码来源:resize_benchmark_test.go
示例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)
}
}
})
}
开发者ID:phamhongviet,项目名称:imageserver,代码行数:20,代码来源:benchmark_test.go
示例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{
//.........这里部分代码省略.........
开发者ID:pierrre,项目名称:imageserver,代码行数:101,代码来源:nfntresize_test.go
示例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)
}
})
}
}
开发者ID:pierrre,项目名称:imageserver,代码行数:75,代码来源:gamma_test.go
示例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",
}},
//.........这里部分代码省略.........
开发者ID:cautio,项目名称:imageserver,代码行数:101,代码来源:gift_test.go
示例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)
}
}()
}
}
开发者ID:cautio,项目名称:imageserver,代码行数:75,代码来源:gamma_test.go
示例16: TestResizeProcessorProcess
func TestResizeProcessorProcess(t *testing.T) {
nim, err := imageserver_image.Decode(imageserver_testdata.Medium)
if err != nil {
t.Fatal(err)
}
for _, tc := range []struct {
name string
processor *ResizeProcessor
params imageserver.Params
expectedWidth int
expectedHeight int
expectedParamError string
}{
// no size
{
name: "Empty",
params: imageserver.Params{},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "EmptyParam",
params: imageserver.Params{resizeParam: imageserver.Params{}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "SizeZero",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 0,
"height": 0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
// with size
{
name: "Width",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
}},
expectedWidth: 100,
},
{
name: "Height",
params: imageserver.Params{resizeParam: imageserver.Params{
"height": 100,
}},
expectedHeight: 100,
},
{
name: "WidthHeight",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
"height": 100,
}},
expectedWidth: 100,
expectedHeight: 100,
},
// mode
{
name: "ModeFit",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
"height": 100,
"mode": "fit",
}},
expectedWidth: 100,
expectedHeight: 80,
},
{
name: "ModeFillWidthHeight",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
"height": 100,
"mode": "fill",
}},
expectedWidth: 100,
expectedHeight: 100,
},
{
name: "ModeFill",
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
"mode": "fill",
}},
expectedWidth: 100,
expectedHeight: 80,
},
// resampling
{
name: "ResamplingDefault",
processor: &ResizeProcessor{DefaultResampling: gift.NearestNeighborResampling},
params: imageserver.Params{resizeParam: imageserver.Params{
"width": 100,
}},
expectedWidth: 100,
},
{
name: "ResamplingNearestNeighbor",
//.........这里部分代码省略.........
开发者ID:pierrre,项目名称:imageserver,代码行数:101,代码来源:resize_test.go
示例17: TestRotateProcessorProcess
func TestRotateProcessorProcess(t *testing.T) {
nim, err := imageserver_image.Decode(imageserver_testdata.Medium)
if err != nil {
t.Fatal(err)
}
prc := &RotateProcessor{}
for _, tc := range []struct {
name string
params imageserver.Params
expectedWidth int
expectedHeight int
expectedParamError string
}{
// no rotation
{
name: "Empty",
params: imageserver.Params{},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "EmptyParam",
params: imageserver.Params{rotateParam: imageserver.Params{}},
expectedWidth: 1024,
expectedHeight: 819,
},
// with rotation
{
name: "Rotation0",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 0.0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "Rotation360",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 360.0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "Rotation90",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 90.0,
}},
expectedWidth: 819,
expectedHeight: 1024,
},
{
name: "Rotation180",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 180.0,
}},
expectedWidth: 1024,
expectedHeight: 819,
},
{
name: "Rotation270",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 270.0,
}},
expectedWidth: 819,
expectedHeight: 1024,
},
{
name: "Rotation45",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 45.0,
}},
expectedWidth: 1304,
expectedHeight: 1304,
},
// background
{
name: "Background",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 45.0,
"background": "FF0000",
}},
},
// interpolation
{
name: "InterpolationNearestNeighbor",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 45.0,
"interpolation": "nearest_neighbor",
}},
},
{
name: "InterpolationLinear",
params: imageserver.Params{rotateParam: imageserver.Params{
"rotation": 45.0,
"interpolation": "linear",
}},
},
{
name: "InterpolationCubic",
//.........这里部分代码省略.........
开发者ID:pierrre,项目名称:imageserver,代码行数:101,代码来源:rotate_test.go
示例18: TestProcessor
//.........这里部分代码省略.........
"width": 100,
"height": 100,
"mode": "resize",
}},
expectedWidth: 100,
expectedHeight: 100,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"height": 100,
"mode": "thumbnail",
}},
expectedWidth: 100,
expectedHeight: 79, // 819 * 100 / 1024
},
// error
{
params: imageserver.Params{Param: "invalid"},
expectedParamError: Param,
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": "invalid",
}},
expectedParamError: Param + ".width",
},
{
params: imageserver.Params{Param: imageserver.Params{
"height": "invalid",
}},
expectedParamError: Param + ".height",
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": -1,
}},
expectedParamError: Param + ".width",
},
{
params: imageserver.Params{Param: imageserver.Params{
"height": -1,
}},
expectedParamError: Param + ".height",
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"interpolation": false,
}},
expectedParamError: Param + ".interpolation",
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"interpolation": "invalid",
}},
expectedParamError: Param + ".interpolation",
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"mode": false,
}},
expectedParamError: Param + ".mode",
},
{
params: imageserver.Params{Param: imageserver.Params{
"width": 100,
"mode": "invalid",
}},
expectedParamError: Param + ".mode",
},
} {
func() {
defer func() {
if t.Failed() {
t.Logf("%#v", tc)
}
}()
im, err := imageserver_image.Decode(imageserver_testdata.Medium)
if err != nil {
t.Fatal(err)
}
im, err = prc.Process(im, tc.params)
if err != nil {
if err, ok := err.(*imageserver.ParamError); ok && err.Param == tc.expectedParamError {
return
}
t.Fatal(err)
}
if tc.expectedWidth != 0 && im.Bounds().Dx() != tc.expectedWidth {
t.Fatalf("unexpected width: got %d, want %d", im.Bounds().Dx(), tc.expectedWidth)
}
if tc.expectedHeight != 0 && im.Bounds().Dy() != tc.expectedHeight {
t.Fatalf("unexpected height: got %d, want %d", im.Bounds().Dy(), tc.expectedHeight)
}
}()
}
}
开发者ID:CarverLab,项目名称:imageserver,代码行数:101,代码来源:nfntresize_test.go
注:本文中的github.com/pierrre/imageserver/image.Decode函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论