Browse Source

tidy up docs and comments

Grigory Dryapak 6 years ago
parent
commit
5362c131d5
6 changed files with 29 additions and 50 deletions
  1. 6 7
      README.md
  2. 9 9
      adjust.go
  3. 1 1
      doc.go
  4. 2 2
      effects.go
  5. 10 30
      resize.go
  6. 1 1
      tools.go

+ 6 - 7
README.md

@@ -8,7 +8,7 @@
 Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
 Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
 
 
 All the image processing functions provided by the package accept any image type that implements `image.Image` interface
 All the image processing functions provided by the package accept any image type that implements `image.Image` interface
-as an input, and return a new image of `*image.NRGBA` type (32bit RGBA colors, not premultiplied by alpha).
+as an input, and return a new image of `*image.NRGBA` type (32bit RGBA colors, non-premultiplied alpha).
 
 
 ## Installation
 ## Installation
 
 
@@ -39,13 +39,12 @@ dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos
 ```
 ```
 
 
 Imaging supports image resizing using various resampling filters. The most notable ones:
 Imaging supports image resizing using various resampling filters. The most notable ones:
-- `NearestNeighbor` - Fastest resampling filter, no antialiasing.
+- `Lanczos` - A high-quality resampling filter for photographic images yielding sharp results.
+- `CatmullRom` - A sharp cubic filter that is faster than Lanczos filter while providing similar results.
+- `MitchellNetravali` - A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
+- `Linear` - Bilinear resampling filter, produces smooth output. Faster than cubic filters.
 - `Box` - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
 - `Box` - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
-- `Linear` - Bilinear filter, smooth and reasonably fast.
-- `MitchellNetravali` - А smooth bicubic filter.
-- `CatmullRom` - A sharp bicubic filter.
-- `Gaussian` - Blurring filter that uses gaussian function, useful for noise removal.
-- `Lanczos` - High-quality resampling filter for photographic images yielding sharp results, slower than cubic filters.
+- `NearestNeighbor` - Fastest resampling filter, no antialiasing.
 
 
 The full list of supported filters:  NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine. Custom filters can be created using ResampleFilter struct.
 The full list of supported filters:  NearestNeighbor, Box, Linear, Hermite, MitchellNetravali, CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine. Custom filters can be created using ResampleFilter struct.
 
 

+ 9 - 9
adjust.go

@@ -58,8 +58,8 @@ func Invert(img image.Image) *image.NRGBA {
 // The percentage = -100 gives the image with the saturation value zeroed for each pixel (grayscale).
 // The percentage = -100 gives the image with the saturation value zeroed for each pixel (grayscale).
 //
 //
 // Examples:
 // Examples:
-//  dstImage = imaging.AdjustSaturation(srcImage, 25) // increase image saturation by 25%
-//  dstImage = imaging.AdjustSaturation(srcImage, -10) // decrease image saturation by 10%
+//  dstImage = imaging.AdjustSaturation(srcImage, 25) // Increase image saturation by 25%.
+//  dstImage = imaging.AdjustSaturation(srcImage, -10) // Decrease image saturation by 10%.
 //
 //
 func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
 func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
 	percentage = math.Min(math.Max(percentage, -100), 100)
 	percentage = math.Min(math.Max(percentage, -100), 100)
@@ -82,8 +82,8 @@ func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
 //
 //
 // Examples:
 // Examples:
 //
 //
-//	dstImage = imaging.AdjustContrast(srcImage, -10) // decrease image contrast by 10%
-//	dstImage = imaging.AdjustContrast(srcImage, 20) // increase image contrast by 20%
+//	dstImage = imaging.AdjustContrast(srcImage, -10) // Decrease image contrast by 10%.
+//	dstImage = imaging.AdjustContrast(srcImage, 20) // Increase image contrast by 20%.
 //
 //
 func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
 func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
 	percentage = math.Min(math.Max(percentage, -100.0), 100.0)
 	percentage = math.Min(math.Max(percentage, -100.0), 100.0)
@@ -109,8 +109,8 @@ func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
 //
 //
 // Examples:
 // Examples:
 //
 //
-//	dstImage = imaging.AdjustBrightness(srcImage, -15) // decrease image brightness by 15%
-//	dstImage = imaging.AdjustBrightness(srcImage, 10) // increase image brightness by 10%
+//	dstImage = imaging.AdjustBrightness(srcImage, -15) // Decrease image brightness by 15%.
+//	dstImage = imaging.AdjustBrightness(srcImage, 10) // Increase image brightness by 10%.
 //
 //
 func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA {
 func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA {
 	percentage = math.Min(math.Max(percentage, -100.0), 100.0)
 	percentage = math.Min(math.Max(percentage, -100.0), 100.0)
@@ -151,8 +151,8 @@ func AdjustGamma(img image.Image, gamma float64) *image.NRGBA {
 //
 //
 // Examples:
 // Examples:
 //
 //
-//	dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // increase the contrast
-//	dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // decrease the contrast
+//	dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // Increase the contrast.
+//	dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // Decrease the contrast.
 //
 //
 func AdjustSigmoid(img image.Image, midpoint, factor float64) *image.NRGBA {
 func AdjustSigmoid(img image.Image, midpoint, factor float64) *image.NRGBA {
 	if factor == 0 {
 	if factor == 0 {
@@ -217,7 +217,7 @@ func adjustLUT(img image.Image, lut []uint8) *image.NRGBA {
 //	dstImage = imaging.AdjustFunc(
 //	dstImage = imaging.AdjustFunc(
 //		srcImage,
 //		srcImage,
 //		func(c color.NRGBA) color.NRGBA {
 //		func(c color.NRGBA) color.NRGBA {
-//			// shift the red channel by 16
+//			// Shift the red channel by 16.
 //			r := int(c.R) + 16
 //			r := int(c.R) + 16
 //			if r > 255 {
 //			if r > 255 {
 //				r = 255
 //				r = 255

+ 1 - 1
doc.go

@@ -2,6 +2,6 @@
 Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
 Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
 
 
 All the image processing functions provided by the package accept any image type that implements image.Image interface
 All the image processing functions provided by the package accept any image type that implements image.Image interface
-as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, not premultiplied by alpha).
+as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, non-premultiplied alpha).
 */
 */
 package imaging
 package imaging

+ 2 - 2
effects.go

@@ -12,7 +12,7 @@ func gaussianBlurKernel(x, sigma float64) float64 {
 // Blur produces a blurred version of the image using a Gaussian function.
 // Blur produces a blurred version of the image using a Gaussian function.
 // Sigma parameter must be positive and indicates how much the image will be blurred.
 // Sigma parameter must be positive and indicates how much the image will be blurred.
 //
 //
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Blur(srcImage, 3.5)
 //	dstImage := imaging.Blur(srcImage, 3.5)
 //
 //
@@ -134,7 +134,7 @@ func blurVertical(img image.Image, kernel []float64) *image.NRGBA {
 // Sharpen produces a sharpened version of the image.
 // Sharpen produces a sharpened version of the image.
 // Sigma parameter must be positive and indicates how much the image will be sharpened.
 // Sigma parameter must be positive and indicates how much the image will be sharpened.
 //
 //
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Sharpen(srcImage, 3.5)
 //	dstImage := imaging.Sharpen(srcImage, 3.5)
 //
 //

+ 10 - 30
resize.go

@@ -58,10 +58,7 @@ func precomputeWeights(dstSize, srcSize int, filter ResampleFilter) [][]indexWei
 // filter and returns the transformed image. If one of width or height is 0, the image aspect
 // filter and returns the transformed image. If one of width or height is 0, the image aspect
 // ratio is preserved.
 // ratio is preserved.
 //
 //
-// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
-// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
-//
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Resize(srcImage, 800, 600, imaging.Lanczos)
 //	dstImage := imaging.Resize(srcImage, 800, 600, imaging.Lanczos)
 //
 //
@@ -218,10 +215,7 @@ func resizeNearest(img image.Image, width, height int) *image.NRGBA {
 // Fit scales down the image using the specified resample filter to fit the specified
 // Fit scales down the image using the specified resample filter to fit the specified
 // maximum width and height and returns the transformed image.
 // maximum width and height and returns the transformed image.
 //
 //
-// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
-// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
-//
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)
 //	dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)
 //
 //
@@ -262,10 +256,7 @@ func Fit(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA
 // Fill creates an image with the specified dimensions and fills it with the scaled source image.
 // Fill creates an image with the specified dimensions and fills it with the scaled source image.
 // To achieve the correct aspect ratio without stretching, the source image will be cropped.
 // To achieve the correct aspect ratio without stretching, the source image will be cropped.
 //
 //
-// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
-// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
-//
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos)
 //	dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos)
 //
 //
@@ -344,10 +335,7 @@ func resizeAndCrop(img image.Image, width, height int, anchor Anchor, filter Res
 // Thumbnail scales the image up or down using the specified resample filter, crops it
 // Thumbnail scales the image up or down using the specified resample filter, crops it
 // to the specified width and hight and returns the transformed image.
 // to the specified width and hight and returns the transformed image.
 //
 //
-// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
-// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
-//
-// Usage example:
+// Example:
 //
 //
 //	dstImage := imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos)
 //	dstImage := imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos)
 //
 //
@@ -355,29 +343,21 @@ func Thumbnail(img image.Image, width, height int, filter ResampleFilter) *image
 	return Fill(img, width, height, Center, filter)
 	return Fill(img, width, height, Center, filter)
 }
 }
 
 
-// ResampleFilter is a resampling filter struct. It can be used to define custom filters.
-//
-// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
-// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
+// ResampleFilter specifies a resampling filter to be used for image resizing.
 //
 //
 //	General filter recommendations:
 //	General filter recommendations:
 //
 //
 //	- Lanczos
 //	- Lanczos
-//		High-quality resampling filter for photographic images yielding sharp results.
-//		It's slower than cubic filters (see below).
+//		A high-quality resampling filter for photographic images yielding sharp results.
 //
 //
 //	- CatmullRom
 //	- CatmullRom
-//		A sharp cubic filter. It's a good filter for both upscaling and downscaling if sharp results are needed.
+//		A sharp cubic filter that is faster than Lanczos filter while providing similar results.
 //
 //
 //	- MitchellNetravali
 //	- MitchellNetravali
-//		A high quality cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
-//
-//	- BSpline
-//		A good filter if a very smooth output is needed.
+//		A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
 //
 //
 //	- Linear
 //	- Linear
-//		Bilinear interpolation filter, produces reasonably good, smooth output.
-//		It's faster than cubic filters.
+//		Bilinear resampling filter, produces a smooth output. Faster than cubic filters.
 //
 //
 //	- Box
 //	- Box
 //		Simple and fast averaging filter appropriate for downscaling.
 //		Simple and fast averaging filter appropriate for downscaling.
@@ -412,7 +392,7 @@ var CatmullRom ResampleFilter
 // BSpline is a smooth cubic filter (BC-spline; B=1; C=0).
 // BSpline is a smooth cubic filter (BC-spline; B=1; C=0).
 var BSpline ResampleFilter
 var BSpline ResampleFilter
 
 
-// Gaussian is a Gaussian blurring Filter.
+// Gaussian is a Gaussian blurring filter.
 var Gaussian ResampleFilter
 var Gaussian ResampleFilter
 
 
 // Bartlett is a Bartlett-windowed sinc filter (3 lobes).
 // Bartlett is a Bartlett-windowed sinc filter (3 lobes).

+ 1 - 1
tools.go

@@ -169,7 +169,7 @@ func PasteCenter(background, img image.Image) *image.NRGBA {
 // and returns the combined image. Opacity parameter is the opacity of the img
 // and returns the combined image. Opacity parameter is the opacity of the img
 // image layer, used to compose the images, it must be from 0.0 to 1.0.
 // image layer, used to compose the images, it must be from 0.0 to 1.0.
 //
 //
-// Usage examples:
+// Examples:
 //
 //
 //	// Draw spriteImage over backgroundImage at the given position (x=50, y=50).
 //	// Draw spriteImage over backgroundImage at the given position (x=50, y=50).
 //	dstImage := imaging.Overlay(backgroundImage, spriteImage, image.Pt(50, 50), 1.0)
 //	dstImage := imaging.Overlay(backgroundImage, spriteImage, image.Pt(50, 50), 1.0)