Beispiel #1
0
func testCrash2() {
	// this is necessary to trigger the problem
	runtime.GOMAXPROCS(32)
	src := toRgbSubset(imgLena, image.Point{200, 20})
	dst := CreateRGBAImageOfSize(image.Point{100, 10})
	fmt.Printf("Before ConvertNoThreads()\n")
	ConvertNoThreads(dst, src, rez.NewBicubicFilter())
	fmt.Printf("Before ConvertThreads()\n")
	ConvertThreads(dst, src, rez.NewBicubicFilter())
}
Beispiel #2
0
// ResizeImage resizes the given image IF it is larger than maxWidth or maxHeight
func ResizeImage(src image.Image, maxWidth int64, maxHeight int64, square bool) (image.Image, error) {
	var dst image.Image

	// Check the original dimensions first, and bail out if this image is not larger than max dimensions
	srcSize := src.Bounds().Size()
	if int64(srcSize.X) < maxWidth && int64(srcSize.Y) < maxHeight {
		return src, nil
	}

	// Use the original image dimensions to keep it in pro
	// Distorting images is a sin of which we are never guilty
	ratio := float64(maxWidth) / float64(srcSize.X)
	yRatio := float64(maxHeight) / float64(srcSize.Y)
	if yRatio < ratio {
		ratio = yRatio
	}

	// Now adjust desired width and height according to ratio
	width := float64(srcSize.X) * ratio
	height := float64(srcSize.Y) * ratio

	// Create a new resized image with the desired dimensions and fill it with resized image data
	// We switch on input image type - is YCbCrSubsampleRatio444 correct?
	switch src.(type) {
	case *image.YCbCr:
		dst = image.NewYCbCr(image.Rect(0, 0, int(width), int(height)), image.YCbCrSubsampleRatio444)
	case *image.RGBA:
		dst = image.NewRGBA(image.Rect(0, 0, int(width), int(height)))
	default:
		dst = nil
	}

	err := rez.Convert(dst, src, rez.NewBicubicFilter())
	// IF we want thumbnails to be square/cropped we could do this
	// for now we don't need this. We may not even want it for camping?
	//   err :=  imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos)

	if err != nil {
		return nil, err
	}

	return dst, nil

}
Beispiel #3
0
func thumbnailRez(imgSrc image.Image, size image.Point, trimmedBounds image.Rectangle) image.Image {

	img := ConvertToRGBAIfNecessary(imgSrc)
	if !trimmedBounds.Empty() && !trimmedBounds.Eq(img.Bounds()) {
		img = img.SubImage(trimmedBounds).(*image.RGBA)
	}

	b := img.Bounds()
	imgSize := image.Point{b.Dx(), b.Dy()}
	thumbSize, downscaling := SizePreservingAspect(imgSize, size)

	resizedImg := img
	if downscaling {
		resizedImg = CreateRGBAImageOfSize(thumbSize)
		convert(resizedImg, img, false, rez.NewBicubicFilter())
	}

	dstImg := CreateRGBAImageOfSize(size)
	// paint the background
	//draw.Draw(dstImg, dstImg.Bounds(), &image.Uniform{bgColor}, image.ZP, draw.Src)
	drawCentered(dstImg, resizedImg)
	return dstImg
}
Beispiel #4
0
func main() {
	im := load()
	resize(im, newResizeFuncNfnt(nfnt_resize.NearestNeighbor), "nfnt_nearest_neighbor.png")
	resize(im, newResizeFuncNfnt(nfnt_resize.Bilinear), "nfnt_bilinear.png")
	resize(im, newResizeFuncNfnt(nfnt_resize.Bicubic), "nfnt_bicubic.png")
	resize(im, newResizeFuncNfnt(nfnt_resize.MitchellNetravali), "nfnt_mitchell_netravali.png")
	resize(im, newResizeFuncNfnt(nfnt_resize.Lanczos2), "nfnt_lanczos2.png")
	resize(im, newResizeFuncNfnt(nfnt_resize.Lanczos3), "nfnt_lanczos3.png")
	resize(im, newResizeFuncXDraw(x_draw.NearestNeighbor), "x_draw_nearest_neighbor.png")
	resize(im, newResizeFuncXDraw(x_draw.ApproxBiLinear), "x_draw_approx_bilinear.png")
	resize(im, newResizeFuncXDraw(x_draw.BiLinear), "x_draw_bilinear.png")
	resize(im, newResizeFuncXDraw(x_draw.CatmullRom), "x_draw_catmull_rom.png")
	resize(im, newResizeFuncImaging(imaging.NearestNeighbor), "imaging_nearest_neighbor.png")
	resize(im, newResizeFuncImaging(imaging.Box), "imaging_box.png")
	resize(im, newResizeFuncImaging(imaging.Linear), "imaging_linear.png")
	resize(im, newResizeFuncImaging(imaging.MitchellNetravali), "imaging_mitchell_netravali.png")
	resize(im, newResizeFuncImaging(imaging.CatmullRom), "imaging_catmull_rom.png")
	resize(im, newResizeFuncImaging(imaging.Gaussian), "imaging_gaussian.png")
	resize(im, newResizeFuncImaging(imaging.Lanczos), "imaging_lanczos.png")
	resize(im, newResizeFuncGift(gift.NearestNeighborResampling), "gift_nearest_neighbor.png")
	resize(im, newResizeFuncGift(gift.BoxResampling), "gift_box.png")
	resize(im, newResizeFuncGift(gift.LinearResampling), "gift_linear.png")
	resize(im, newResizeFuncGift(gift.CubicResampling), "gift_cubic.png")
	resize(im, newResizeFuncGift(gift.LanczosResampling), "gift_lanczos.png")
	func() {
		defer func() {
			err := recover()
			if err != nil {
				fmt.Printf("error with rez: %s\n", err)
			}
		}()
		resize(im, newResizeFuncRez(rez.NewBilinearFilter()), "rez_bilinear.png")
		resize(im, newResizeFuncRez(rez.NewBicubicFilter()), "rez_bicubic.png")
		resize(im, newResizeFuncRez(rez.NewLanczosFilter(2)), "rez_lanczos2.png")
		resize(im, newResizeFuncRez(rez.NewLanczosFilter(3)), "rez_lanczos3.png")
	}()
}
Beispiel #5
0
func resizeTo(src image.Image, dstSize image.Point) image.Image {
	dst := image.NewRGBA(image.Rect(0, 0, dstSize.X, dstSize.Y))
	convert(dst, src, false, rez.NewBicubicFilter())
	return dst
}
func BenchmarkRezBicubic(b *testing.B) {
	benchmarkRez(b, rez.NewBicubicFilter())
}