浏览代码

Support image.NRGBA, image.NRGBA16 in resize.Resize function.

jst 11 年之前
父节点
当前提交
ebea2e66be
共有 1 个文件被更改,包括 59 次插入0 次删除
  1. 59 0
      resize.go

+ 59 - 0
resize.go

@@ -132,6 +132,36 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
 		}
 		wg.Wait()
 		return result
+	case *image.NRGBA:
+		// 8-bit precision
+		temp := image.NewNRGBA(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
+		result := image.NewNRGBA(image.Rect(0, 0, int(width), int(height)))
+
+		// horizontal filter, results in transposed temporary image
+		coeffs, offset, filterLength := createWeights8(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
+		wg.Add(cpus)
+		for i := 0; i < cpus; i++ {
+			slice := makeSlice(temp, i, cpus).(*image.NRGBA)
+			go func() {
+				defer wg.Done()
+				resizeNRGBA(input, slice, scaleX, coeffs, offset, filterLength)
+			}()
+		}
+		wg.Wait()
+
+		// horizontal filter on transposed image, result is not transposed
+		coeffs, offset, filterLength = createWeights8(result.Bounds().Dy(), taps, blur, scaleY, kernel)
+		wg.Add(cpus)
+		for i := 0; i < cpus; i++ {
+			slice := makeSlice(result, i, cpus).(*image.NRGBA)
+			go func() {
+				defer wg.Done()
+				resizeNRGBA(temp, slice, scaleY, coeffs, offset, filterLength)
+			}()
+		}
+		wg.Wait()
+		return result
+
 	case *image.YCbCr:
 		// 8-bit precision
 		// accessing the YCbCr arrays in a tight loop is slow.
@@ -179,6 +209,35 @@ func Resize(width, height uint, img image.Image, interp InterpolationFunction) i
 		}
 		wg.Wait()
 
+		// horizontal filter on transposed image, result is not transposed
+		coeffs, offset, filterLength = createWeights16(result.Bounds().Dy(), taps, blur, scaleY, kernel)
+		wg.Add(cpus)
+		for i := 0; i < cpus; i++ {
+			slice := makeSlice(result, i, cpus).(*image.NRGBA64)
+			go func() {
+				defer wg.Done()
+				resizeNRGBA64(temp, slice, scaleY, coeffs, offset, filterLength)
+			}()
+		}
+		wg.Wait()
+		return result
+	case *image.NRGBA64:
+		// 16-bit precision
+		temp := image.NewNRGBA64(image.Rect(0, 0, input.Bounds().Dy(), int(width)))
+		result := image.NewNRGBA64(image.Rect(0, 0, int(width), int(height)))
+
+		// horizontal filter, results in transposed temporary image
+		coeffs, offset, filterLength := createWeights16(temp.Bounds().Dy(), taps, blur, scaleX, kernel)
+		wg.Add(cpus)
+		for i := 0; i < cpus; i++ {
+			slice := makeSlice(temp, i, cpus).(*image.NRGBA64)
+			go func() {
+				defer wg.Done()
+				resizeNRGBA64(input, slice, scaleX, coeffs, offset, filterLength)
+			}()
+		}
+		wg.Wait()
+
 		// horizontal filter on transposed image, result is not transposed
 		coeffs, offset, filterLength = createWeights16(result.Bounds().Dy(), taps, blur, scaleY, kernel)
 		wg.Add(cpus)