diff --git a/carver.go b/carver.go index a8239e8..b084dda 100644 --- a/carver.go +++ b/carver.go @@ -26,10 +26,10 @@ var ( // Carver is the main entry struct having as parameters the newly generated image width, height and seam points. type Carver struct { - Width int - Height int Points []float64 Seams []Seam + Width int + Height int } // Seam struct contains the seam pixel coordinates. @@ -41,10 +41,10 @@ type Seam struct { // NewCarver returns an initialized Carver structure. func NewCarver(width, height int) *Carver { return &Carver{ - width, - height, make([]float64, width*height), nil, + width, + height, } } @@ -61,12 +61,13 @@ func (c *Carver) set(x, y int, px float64) { } // ComputeSeams compute the minimum energy level based on the following logic: -// - traverse the image from the second row to the last row -// and compute the cumulative minimum energy M for all possible -// connected seams for each entry (i, j). // -// - the minimum energy level is calculated by summing up the current pixel value -// with the minimum pixel value of the neighboring pixels from the previous row. +// - traverse the image from the second row to the last row +// and compute the cumulative minimum energy M for all possible +// connected seams for each entry (i, j). +// +// - the minimum energy level is calculated by summing up the current pixel value +// with the minimum pixel value of the neighboring pixels from the previous row. func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, error) { var srcImg *image.NRGBA p.GuiDebug = image.NewNRGBA(img.Bounds()) diff --git a/draw.go b/draw.go index 4c774fd..54a939c 100644 --- a/draw.go +++ b/draw.go @@ -19,7 +19,7 @@ const ( ) // DrawSeam visualizes the seam carver in action when the preview mode is activated. -// It receives as parameters the shape type, the seam (x,y) coordinates and a dimmension. +// It receives as parameters the shape type, the seam (x,y) coordinates and a dimension. func (g *Gui) DrawSeam(shape string, x, y, dim float32) { r := getRatio(g.cfg.window.w, g.cfg.window.h) diff --git a/gui.go b/gui.go index 9ff35c6..22b0e5d 100644 --- a/gui.go +++ b/gui.go @@ -26,7 +26,7 @@ import ( ) const ( - // The starting colors for the linear gradient, used when the image is resized both horzontally and vertically. + // The starting colors for the linear gradient, used when the image is resized both horizontally and vertically. // In this case the preview mode is deactivated and a dynamic gradient overlay is shown. redStart = 137 greenStart = 47 @@ -115,7 +115,7 @@ func NewGUI(w, h int) *Gui { return gui } -// Add adds a new hud control for dubugging. +// Add adds a new hud control for debugging. func (g *Gui) Add(index int, title string, enabled bool) { control := &hudCtrl{ index: index, @@ -148,7 +148,7 @@ func (g *Gui) initWindow(w, h int) { g.cfg.window.title = "Preview" } -// getWindowSize returns the resized image dimmension. +// getWindowSize returns the resized image dimension. func (g *Gui) getWindowSize() (float32, float32) { w, h := g.cfg.window.w, g.cfg.window.h // Maintain the image aspect ratio in case the image width and height is greater than the predefined window. @@ -339,17 +339,16 @@ func (g *Gui) draw(gtx layout.Context, bgCol color.NRGBA) { if hud, ok := g.huds[0]; ok { if hud.visible.Value { - var ratio float32 = 1 tr := f32.Affine2D{} screen := layout.FPt(g.ctx.Constraints.Max) width, height := float32(g.proc.img.Bounds().Dx()), float32(g.proc.img.Bounds().Dy()) sw, sh := float32(screen.X), float32(screen.Y) if sw > width { - ratio = sw / width + ratio := sw / width tr = tr.Scale(f32.Pt(sw/2, sh/2), f32.Pt(1, ratio)) } else if sh > height { - ratio = sh / height + ratio := sh / height tr = tr.Scale(f32.Pt(sw/2, sh/2), f32.Pt(ratio, 1)) } diff --git a/preview.go b/preview.go index 61a3dc8..9bb96e1 100644 --- a/preview.go +++ b/preview.go @@ -17,7 +17,7 @@ func (p *Processor) showPreview( gui.cp = p gui.proc.wrk = imgWorker - // Run the Gio GUI app in a seperate goroutine + // Run the Gio GUI app in a separate goroutine go func() { if err := gui.Run(); err != nil { errChan <- err diff --git a/process.go b/process.go index 777d3d6..6e9ed88 100644 --- a/process.go +++ b/process.go @@ -32,14 +32,14 @@ var ( ) var ( - resizeXY = false // the image is resized both verticlaly and horizontally + resizeXY = false // the image is resized both vertically and horizontally isGif = false imgWorker = make(chan worker) // channel used to transfer the image to the GUI errs = make(chan error) ) -// worker struct contains all the information needed for transfering the resized image to the Gio GUI. +// worker struct contains all the information needed for transferring the resized image to the Gio GUI. type worker struct { carver *Carver img *image.NRGBA @@ -132,8 +132,8 @@ func (p *Processor) Resize(img *image.NRGBA) (image.Image, error) { // shrinkHorizFn calls itself recursively to shrink the image horizontally. // If the image is resized on both X and Y axis it calls the shrink and enlarge - // function intermitently up until the desired dimension is reached. - // We are opting for this solution instead of resizing the image secventially, + // function intermittently up until the desired dimension is reached. + // We are opting for this solution instead of resizing the image sequentially, // because this way the horizontal and vertical seams are merged together seamlessly. shrinkHorizFn = func(c *Carver, img *image.NRGBA) (*image.NRGBA, error) { p.vRes = false diff --git a/utils/format.go b/utils/format.go index f204ef0..7b20873 100644 --- a/utils/format.go +++ b/utils/format.go @@ -11,7 +11,7 @@ import ( // MessageType is a custom type used as a placeholder for various message types. type MessageType int -// The message types used accross the CLI application. +// The message types used across the CLI application. const ( DefaultMessage MessageType = iota SuccessMessage @@ -19,7 +19,7 @@ const ( StatusMessage ) -// Colors used accross the CLI application. +// Colors used across the CLI application. const ( DefaultColor = "\x1b[0m" StatusColor = "\x1b[36m"