mirror of
https://github.com/esimov/caire.git
synced 2025-09-26 20:41:14 +08:00
Merge branch 'master' of https://github.com/esimov/caire
This commit is contained in:
@@ -76,7 +76,6 @@ func (c *Carver) set(x, y int, px float64) {
|
||||
// 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.DebugMask = image.NewNRGBA(img.Bounds())
|
||||
|
||||
width, height := img.Bounds().Dx(), img.Bounds().Dy()
|
||||
sobel = c.SobelDetector(img, float64(p.SobelThreshold))
|
||||
@@ -134,6 +133,8 @@ func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, err
|
||||
// which we do not want to be altered by the seam carver,
|
||||
// obtain the white patches and apply it to the sobel image.
|
||||
if len(p.MaskPath) > 0 && p.Mask != nil {
|
||||
p.DebugMask = image.NewNRGBA(img.Bounds())
|
||||
|
||||
for i := 0; i < width*height; i++ {
|
||||
x := i % width
|
||||
y := (i - x) / width
|
||||
@@ -156,6 +157,8 @@ func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, err
|
||||
// we do not want to be retained in the final image, obtain the white patches,
|
||||
// but this time inverse the colors to black and merge it back to the sobel image.
|
||||
if len(p.RMaskPath) > 0 && p.RMask != nil {
|
||||
p.DebugMask = image.NewNRGBA(img.Bounds())
|
||||
|
||||
for i := 0; i < width*height; i++ {
|
||||
x := i % width
|
||||
y := (i - x) / width
|
||||
@@ -195,6 +198,7 @@ func (c *Carver) ComputeSeams(p *Processor, img *image.NRGBA) (*image.NRGBA, err
|
||||
face.Col+scale,
|
||||
face.Row+scale,
|
||||
)
|
||||
p.DebugMask = image.NewNRGBA(img.Bounds())
|
||||
draw.Draw(sobel, rect, &image.Uniform{color.White}, image.Point{}, draw.Src)
|
||||
draw.Draw(p.DebugMask, rect, &image.Uniform{color.White}, image.Point{}, draw.Src)
|
||||
}
|
||||
|
12
gui.go
12
gui.go
@@ -101,7 +101,7 @@ type Gui struct {
|
||||
}
|
||||
|
||||
type hudCtrl struct {
|
||||
visible widget.Bool
|
||||
enabled widget.Bool
|
||||
hudType hudControlType
|
||||
title string
|
||||
}
|
||||
@@ -138,9 +138,9 @@ func (g *Gui) AddHudControl(hudControlType hudControlType, title string, enabled
|
||||
control := &hudCtrl{
|
||||
hudType: hudControlType,
|
||||
title: title,
|
||||
visible: widget.Bool{},
|
||||
enabled: widget.Bool{},
|
||||
}
|
||||
control.visible.Value = enabled
|
||||
control.enabled.Value = enabled
|
||||
g.huds[hudControlType] = control
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ func (g *Gui) Run() error {
|
||||
g.process.seams = res.seams
|
||||
|
||||
if mask, ok := g.huds[hudShowDebugMask]; ok {
|
||||
if mask.visible.Value {
|
||||
if mask.enabled.Value && res.mask != nil {
|
||||
bounds := res.img.Bounds()
|
||||
srcBitmap := imop.NewBitmap(bounds)
|
||||
dstBitmap := imop.NewBitmap(bounds)
|
||||
@@ -381,7 +381,7 @@ func (g *Gui) draw(bgColor color.NRGBA) {
|
||||
}.Layout(gtx)
|
||||
|
||||
if seam, ok := g.huds[hudShowSeams]; ok {
|
||||
if seam.visible.Value {
|
||||
if seam.enabled.Value {
|
||||
tr := f32.Affine2D{}
|
||||
screen := layout.FPt(g.ctx.Constraints.Max)
|
||||
width, height := float32(g.process.img.Bounds().Dx()), float32(g.process.img.Bounds().Dy())
|
||||
@@ -453,7 +453,7 @@ func (g *Gui) draw(bgColor color.NRGBA) {
|
||||
return g.view.huds.Layout(gtx, len(g.huds),
|
||||
func(gtx layout.Context, index int) D {
|
||||
if hud, ok := g.huds[hudControlType(index)]; ok {
|
||||
checkbox := material.CheckBox(g.theme, &hud.visible, fmt.Sprintf("%v", hud.title))
|
||||
checkbox := material.CheckBox(g.theme, &hud.enabled, fmt.Sprintf("%v", hud.title))
|
||||
checkbox.Size = 20
|
||||
return checkbox.Layout(gtx)
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@ var (
|
||||
errs = make(chan error)
|
||||
)
|
||||
|
||||
var _ SeamCarver = (*Processor)(nil)
|
||||
|
||||
// worker struct contains all the information needed for transferring the resized image to the Gio GUI.
|
||||
type worker struct {
|
||||
img *image.NRGBA
|
||||
@@ -32,8 +34,6 @@ type worker struct {
|
||||
done bool
|
||||
}
|
||||
|
||||
var _ SeamCarver = (*Processor)(nil)
|
||||
|
||||
// shrinkFn is a generic function used to shrink an image.
|
||||
type shrinkFn func(*image.NRGBA) (*image.NRGBA, error)
|
||||
|
||||
|
Reference in New Issue
Block a user