├── .github
└── workflows
│ └── go.yml
├── .gitignore
├── .vscode
└── settings.json
├── README.md
├── cmd
├── main.go
└── main_test.go
├── example
├── 1
│ ├── demo.png
│ └── demo_hq2x.png
└── 2
│ ├── demo.png
│ └── demo_hq2x.png
├── go.mod
├── hq2x.go
├── interp.go
└── makefile
/.github/workflows/go.yml:
--------------------------------------------------------------------------------
1 | name: Go
2 | on:
3 | push:
4 | branches:
5 | - master
6 | paths-ignore:
7 | - "README.md"
8 |
9 | jobs:
10 | build:
11 | name: Build
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@master
15 | - uses: actions/setup-go@v1
16 | with:
17 | go-version: 1.17
18 | - run: go build -o build ./cmd/main.go
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | hq2x.exe
2 | hq2x
3 | build
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "[go]": {
3 | "editor.formatOnSave": true,
4 | "editor.codeActionsOnSave": {
5 | "source.organizeImports": true
6 | }
7 | },
8 | "go.autocompleteUnimportedPackages": true
9 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # hq2xgo
2 |
3 |  [](https://godoc.org/github.com/pokemium/hq2xgo)
4 |
5 | Enlarge image by 2x with hq2x algorithm
6 |
7 | ## Example(Before -> After)
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | ## Usage
16 |
17 | ### command line
18 |
19 | ```sh
20 | $ make build # require make and go
21 | $ hq2x input.png output.png
22 | ```
23 |
24 | ### golang package
25 |
26 | See [godoc](https://godoc.org/github.com/Akatsuki-py/hq2xgo) for details.
27 |
28 | ```sh
29 | $ go get github.com/pokemium/hq2xgo
30 | ```
31 |
32 | ```go
33 | import (
34 | hq2x "github.com/pokemium/hq2xgo"
35 | )
36 |
37 | after, err := hq2x.HQ2x(before) // var before *image.RGBA
38 | ```
39 |
40 | ## Measure benchmark
41 |
42 | ```sh
43 | $ cd cmd/
44 | $ go test -bench .
45 | ```
46 |
--------------------------------------------------------------------------------
/cmd/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "flag"
5 | "fmt"
6 | "image"
7 | "os"
8 | "path/filepath"
9 | "image/draw"
10 |
11 | hq2x "github.com/pokemium/hq2xgo"
12 |
13 | _ "image/jpeg"
14 | "image/png"
15 | _ "image/png"
16 | )
17 |
18 | func main() {
19 | os.Exit(Run())
20 | }
21 |
22 | // Run - run app
23 | func Run() int {
24 | flag.Parse()
25 |
26 | input := flag.Arg(0)
27 | if input == "" {
28 | help()
29 | return 0
30 | }
31 |
32 | output := flag.Arg(1)
33 | if output == "" {
34 | base, ext := getFileNameWithoutExt(input)
35 | output = base + "_hq2x" + ext
36 | }
37 |
38 | if err := doHQ2x(input, output); err != nil {
39 | fmt.Fprintln(os.Stderr, err)
40 | return 1
41 | }
42 |
43 | return 0
44 | }
45 |
46 | func imageToRGBA(im image.Image) *image.RGBA {
47 | dst := image.NewRGBA(im.Bounds())
48 | draw.Draw(dst, im.Bounds(), im, im.Bounds().Min, draw.Src)
49 | return dst
50 | }
51 |
52 | func doHQ2x(input, output string) error {
53 | before, err := openImage(input)
54 | if err != nil {
55 | return err
56 | }
57 |
58 | b, ok := before.(*image.RGBA)
59 | if !ok {
60 | b = imageToRGBA(before)
61 | }
62 |
63 | after, err := hq2x.HQ2x(b)
64 |
65 | if err := saveImage(output, after); err != nil {
66 | return err
67 | }
68 |
69 | return nil
70 | }
71 |
72 | func help() {
73 | fmt.Println("hq2x [