Skip to content

Commit 5362c13

Browse files
tidy up docs and comments
1 parent 589168b commit 5362c13

File tree

6 files changed

+29
-50
lines changed

6 files changed

+29
-50
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
99

1010
All the image processing functions provided by the package accept any image type that implements `image.Image` interface
11-
as an input, and return a new image of `*image.NRGBA` type (32bit RGBA colors, not premultiplied by alpha).
11+
as an input, and return a new image of `*image.NRGBA` type (32bit RGBA colors, non-premultiplied alpha).
1212

1313
## Installation
1414

@@ -39,13 +39,12 @@ dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos
3939
```
4040

4141
Imaging supports image resizing using various resampling filters. The most notable ones:
42-
- `NearestNeighbor` - Fastest resampling filter, no antialiasing.
42+
- `Lanczos` - A high-quality resampling filter for photographic images yielding sharp results.
43+
- `CatmullRom` - A sharp cubic filter that is faster than Lanczos filter while providing similar results.
44+
- `MitchellNetravali` - A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
45+
- `Linear` - Bilinear resampling filter, produces smooth output. Faster than cubic filters.
4346
- `Box` - Simple and fast averaging filter appropriate for downscaling. When upscaling it's similar to NearestNeighbor.
44-
- `Linear` - Bilinear filter, smooth and reasonably fast.
45-
- `MitchellNetravali` - А smooth bicubic filter.
46-
- `CatmullRom` - A sharp bicubic filter.
47-
- `Gaussian` - Blurring filter that uses gaussian function, useful for noise removal.
48-
- `Lanczos` - High-quality resampling filter for photographic images yielding sharp results, slower than cubic filters.
47+
- `NearestNeighbor` - Fastest resampling filter, no antialiasing.
4948

5049
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.
5150

adjust.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func Invert(img image.Image) *image.NRGBA {
5858
// The percentage = -100 gives the image with the saturation value zeroed for each pixel (grayscale).
5959
//
6060
// Examples:
61-
// dstImage = imaging.AdjustSaturation(srcImage, 25) // increase image saturation by 25%
62-
// dstImage = imaging.AdjustSaturation(srcImage, -10) // decrease image saturation by 10%
61+
// dstImage = imaging.AdjustSaturation(srcImage, 25) // Increase image saturation by 25%.
62+
// dstImage = imaging.AdjustSaturation(srcImage, -10) // Decrease image saturation by 10%.
6363
//
6464
func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
6565
percentage = math.Min(math.Max(percentage, -100), 100)
@@ -82,8 +82,8 @@ func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA {
8282
//
8383
// Examples:
8484
//
85-
// dstImage = imaging.AdjustContrast(srcImage, -10) // decrease image contrast by 10%
86-
// dstImage = imaging.AdjustContrast(srcImage, 20) // increase image contrast by 20%
85+
// dstImage = imaging.AdjustContrast(srcImage, -10) // Decrease image contrast by 10%.
86+
// dstImage = imaging.AdjustContrast(srcImage, 20) // Increase image contrast by 20%.
8787
//
8888
func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
8989
percentage = math.Min(math.Max(percentage, -100.0), 100.0)
@@ -109,8 +109,8 @@ func AdjustContrast(img image.Image, percentage float64) *image.NRGBA {
109109
//
110110
// Examples:
111111
//
112-
// dstImage = imaging.AdjustBrightness(srcImage, -15) // decrease image brightness by 15%
113-
// dstImage = imaging.AdjustBrightness(srcImage, 10) // increase image brightness by 10%
112+
// dstImage = imaging.AdjustBrightness(srcImage, -15) // Decrease image brightness by 15%.
113+
// dstImage = imaging.AdjustBrightness(srcImage, 10) // Increase image brightness by 10%.
114114
//
115115
func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA {
116116
percentage = math.Min(math.Max(percentage, -100.0), 100.0)
@@ -151,8 +151,8 @@ func AdjustGamma(img image.Image, gamma float64) *image.NRGBA {
151151
//
152152
// Examples:
153153
//
154-
// dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // increase the contrast
155-
// dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // decrease the contrast
154+
// dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // Increase the contrast.
155+
// dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // Decrease the contrast.
156156
//
157157
func AdjustSigmoid(img image.Image, midpoint, factor float64) *image.NRGBA {
158158
if factor == 0 {
@@ -217,7 +217,7 @@ func adjustLUT(img image.Image, lut []uint8) *image.NRGBA {
217217
// dstImage = imaging.AdjustFunc(
218218
// srcImage,
219219
// func(c color.NRGBA) color.NRGBA {
220-
// // shift the red channel by 16
220+
// // Shift the red channel by 16.
221221
// r := int(c.R) + 16
222222
// if r > 255 {
223223
// r = 255

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Package imaging provides basic image processing functions (resize, rotate, crop, brightness/contrast adjustments, etc.).
33
44
All the image processing functions provided by the package accept any image type that implements image.Image interface
5-
as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, not premultiplied by alpha).
5+
as an input, and return a new image of *image.NRGBA type (32bit RGBA colors, non-premultiplied alpha).
66
*/
77
package imaging

effects.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func gaussianBlurKernel(x, sigma float64) float64 {
1212
// Blur produces a blurred version of the image using a Gaussian function.
1313
// Sigma parameter must be positive and indicates how much the image will be blurred.
1414
//
15-
// Usage example:
15+
// Example:
1616
//
1717
// dstImage := imaging.Blur(srcImage, 3.5)
1818
//
@@ -134,7 +134,7 @@ func blurVertical(img image.Image, kernel []float64) *image.NRGBA {
134134
// Sharpen produces a sharpened version of the image.
135135
// Sigma parameter must be positive and indicates how much the image will be sharpened.
136136
//
137-
// Usage example:
137+
// Example:
138138
//
139139
// dstImage := imaging.Sharpen(srcImage, 3.5)
140140
//

resize.go

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ func precomputeWeights(dstSize, srcSize int, filter ResampleFilter) [][]indexWei
5858
// filter and returns the transformed image. If one of width or height is 0, the image aspect
5959
// ratio is preserved.
6060
//
61-
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
62-
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
63-
//
64-
// Usage example:
61+
// Example:
6562
//
6663
// dstImage := imaging.Resize(srcImage, 800, 600, imaging.Lanczos)
6764
//
@@ -218,10 +215,7 @@ func resizeNearest(img image.Image, width, height int) *image.NRGBA {
218215
// Fit scales down the image using the specified resample filter to fit the specified
219216
// maximum width and height and returns the transformed image.
220217
//
221-
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
222-
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
223-
//
224-
// Usage example:
218+
// Example:
225219
//
226220
// dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos)
227221
//
@@ -262,10 +256,7 @@ func Fit(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA
262256
// Fill creates an image with the specified dimensions and fills it with the scaled source image.
263257
// To achieve the correct aspect ratio without stretching, the source image will be cropped.
264258
//
265-
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
266-
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
267-
//
268-
// Usage example:
259+
// Example:
269260
//
270261
// dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos)
271262
//
@@ -344,40 +335,29 @@ func resizeAndCrop(img image.Image, width, height int, anchor Anchor, filter Res
344335
// Thumbnail scales the image up or down using the specified resample filter, crops it
345336
// to the specified width and hight and returns the transformed image.
346337
//
347-
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
348-
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
349-
//
350-
// Usage example:
338+
// Example:
351339
//
352340
// dstImage := imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos)
353341
//
354342
func Thumbnail(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA {
355343
return Fill(img, width, height, Center, filter)
356344
}
357345

358-
// ResampleFilter is a resampling filter struct. It can be used to define custom filters.
359-
//
360-
// Supported resample filters: NearestNeighbor, Box, Linear, Hermite, MitchellNetravali,
361-
// CatmullRom, BSpline, Gaussian, Lanczos, Hann, Hamming, Blackman, Bartlett, Welch, Cosine.
346+
// ResampleFilter specifies a resampling filter to be used for image resizing.
362347
//
363348
// General filter recommendations:
364349
//
365350
// - Lanczos
366-
// High-quality resampling filter for photographic images yielding sharp results.
367-
// It's slower than cubic filters (see below).
351+
// A high-quality resampling filter for photographic images yielding sharp results.
368352
//
369353
// - CatmullRom
370-
// A sharp cubic filter. It's a good filter for both upscaling and downscaling if sharp results are needed.
354+
// A sharp cubic filter that is faster than Lanczos filter while providing similar results.
371355
//
372356
// - MitchellNetravali
373-
// A high quality cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
374-
//
375-
// - BSpline
376-
// A good filter if a very smooth output is needed.
357+
// A cubic filter that produces smoother results with less ringing artifacts than CatmullRom.
377358
//
378359
// - Linear
379-
// Bilinear interpolation filter, produces reasonably good, smooth output.
380-
// It's faster than cubic filters.
360+
// Bilinear resampling filter, produces a smooth output. Faster than cubic filters.
381361
//
382362
// - Box
383363
// Simple and fast averaging filter appropriate for downscaling.
@@ -412,7 +392,7 @@ var CatmullRom ResampleFilter
412392
// BSpline is a smooth cubic filter (BC-spline; B=1; C=0).
413393
var BSpline ResampleFilter
414394

415-
// Gaussian is a Gaussian blurring Filter.
395+
// Gaussian is a Gaussian blurring filter.
416396
var Gaussian ResampleFilter
417397

418398
// Bartlett is a Bartlett-windowed sinc filter (3 lobes).

tools.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func PasteCenter(background, img image.Image) *image.NRGBA {
169169
// and returns the combined image. Opacity parameter is the opacity of the img
170170
// image layer, used to compose the images, it must be from 0.0 to 1.0.
171171
//
172-
// Usage examples:
172+
// Examples:
173173
//
174174
// // Draw spriteImage over backgroundImage at the given position (x=50, y=50).
175175
// dstImage := imaging.Overlay(backgroundImage, spriteImage, image.Pt(50, 50), 1.0)

0 commit comments

Comments
 (0)