-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
41 changed files
with
363 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package bridge | ||
|
||
import ( | ||
"log" | ||
|
||
"gopkg.in/urfave/cli.v1" | ||
|
||
"github.com/octu0/blurry" | ||
) | ||
|
||
func invertAction(c *cli.Context) error { | ||
in, err := loadImage(c.String("input")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
out, err := blurry.Invert(in) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
path, err := saveImage(out) | ||
if err != nil { | ||
return err | ||
} | ||
log.Printf("info: open %s", path) | ||
return nil | ||
} | ||
|
||
func init() { | ||
addCommand(cli.Command{ | ||
Name: "invert", | ||
Action: invertAction, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "i,input", | ||
Usage: "/path/to/input image", | ||
Value: "./testdata/src.png", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package genrun | ||
|
||
import ( | ||
"gopkg.in/urfave/cli.v1" | ||
) | ||
|
||
func invertAction(c *cli.Context) error { | ||
runtimePath := c.String("runtime") | ||
generateOutFilePath, err := generate(runtimePath, c.String("file")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := runLocal(runtimePath, generateOutFilePath, c.String("input"), "invert", nil); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func init() { | ||
addCommand(cli.Command{ | ||
Name: "invert", | ||
Action: invertAction, | ||
Flags: []cli.Flag{ | ||
cli.StringFlag{ | ||
Name: "i,input", | ||
Usage: "/path/to/input image", | ||
Value: "./testdata/src.png", | ||
}, | ||
cli.StringFlag{ | ||
Name: "r,runtime", | ||
Usage: "halide runtime path", | ||
Value: "./Halide-Runtime", | ||
}, | ||
cli.StringFlag{ | ||
Name: "f,file", | ||
Usage: "/path/to/blurry.cpp path", | ||
Value: "./blurry.cpp", | ||
}, | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package blurry | ||
|
||
/* | ||
#cgo CFLAGS: -I${SRCDIR} | ||
#cgo darwin LDFLAGS: -L${SRCDIR} -lruntime_osx -linvert_osx -ldl -lm | ||
#cgo linux LDFLAGS: -L${SRCDIR} -lruntime_linux -linvert_linux -ldl -lm | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "bridge.h" | ||
#ifdef __APPLE__ | ||
#include "libinvert_osx.h" | ||
#elif __linux__ | ||
#include "libinvert_linux.h" | ||
#endif | ||
int libinvert(unsigned char *src, int32_t width, int32_t height, unsigned char *out) { | ||
halide_buffer_t *in_rgba_buf = create_rgba_buffer(src, width, height); | ||
if(in_rgba_buf == NULL){ | ||
return 1; | ||
} | ||
halide_buffer_t *out_rgba_buf = create_rgba_buffer(out, width, height); | ||
if(out_rgba_buf == NULL){ | ||
return 1; | ||
} | ||
int ret = invert(in_rgba_buf, width, height, out_rgba_buf); | ||
free_buf(in_rgba_buf); | ||
free_buf(out_rgba_buf); | ||
return ret; | ||
} | ||
*/ | ||
import "C" | ||
import ( | ||
"errors" | ||
"image" | ||
) | ||
|
||
var ( | ||
ErrInvert = errors.New("invert cgo call error") | ||
) | ||
|
||
func Invert(img *image.RGBA) (*image.RGBA, error) { | ||
width, height := wh(img) | ||
out := GetRGBA(width, height) | ||
|
||
ret := C.libinvert( | ||
(*C.uchar)(&img.Pix[0]), | ||
C.int(width), | ||
C.int(height), | ||
(*C.uchar)(&out.Pix[0]), | ||
) | ||
if int(ret) != 0 { | ||
return nil, ErrInvert | ||
} | ||
return out, nil | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.