当前位置: 首页>>代码示例>>Golang>>正文


Golang image.Decode函数代码示例

本文整理汇总了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)
	}
}
开发者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


注:本文中的github.com/pierrre/imageserver/image.Decode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。