Skip to content

Commit

Permalink
gofmt -s -w -l .
Browse files Browse the repository at this point in the history
  • Loading branch information
kbinani committed Sep 29, 2016
1 parent 517e40d commit a244110
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 163 deletions.
2 changes: 1 addition & 1 deletion example/example.go
@@ -1,11 +1,11 @@
package main

import (
"fmt"
"github.com/kbinani/screenshot"
"image"
"image/png"
"os"
"fmt"
)

// save *image.RGBA to filePath with PNG format.
Expand Down
4 changes: 2 additions & 2 deletions internal/util/util.go
@@ -1,8 +1,8 @@
package util

import (
"image"
"errors"
"image"
)

func CreateImage(rect image.Rectangle) (img *image.RGBA, e error) {
Expand All @@ -14,7 +14,7 @@ func CreateImage(rect image.Rectangle) (img *image.RGBA, e error) {
if err == nil {
e = nil
}
} ()
}()
// image.NewRGBA may panic if rect is too large.
img = image.NewRGBA(rect)

Expand Down
39 changes: 19 additions & 20 deletions internal/xwindow/xwindow.go
@@ -1,24 +1,24 @@
package xwindow

import (
"fmt"
"errors"
"image"
"image/color"
"github.com/kbinani/screenshot/internal/util"
"fmt"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xproto"
"github.com/BurntSushi/xgb/xinerama"
"github.com/BurntSushi/xgb/xproto"
"github.com/kbinani/screenshot/internal/util"
"image"
"image/color"
)

func Capture(x, y, width, height int) (img *image.RGBA, e error) {
defer func () {
defer func() {
err := recover()
if err != nil {
img = nil
e = errors.New(fmt.Sprintf("%v", err))
}
} ()
}()
c, err := xgb.NewConn()
if err != nil {
return nil, err
Expand All @@ -37,7 +37,7 @@ func Capture(x, y, width, height int) (img *image.RGBA, e error) {

screen := xproto.Setup(c).DefaultScreen(c)
wholeScreenBounds := image.Rect(0, 0, int(screen.WidthInPixels), int(screen.HeightInPixels))
targetBounds := image.Rect(x + x0, y + y0, x + x0 + width, y + y0 + height)
targetBounds := image.Rect(x+x0, y+y0, x+x0+width, y+y0+height)
intersect := wholeScreenBounds.Intersect(targetBounds)

rect := image.Rect(0, 0, width, height)
Expand All @@ -51,16 +51,16 @@ func Capture(x, y, width, height int) (img *image.RGBA, e error) {
for iy := 0; iy < height; iy++ {
j := index
for ix := 0; ix < width; ix++ {
img.Pix[j + 3] = 255
img.Pix[j+3] = 255
j += 4
}
index += img.Stride
}

if !intersect.Empty() {
xImg, err := xproto.GetImage(c, xproto.ImageFormatZPixmap, xproto.Drawable(screen.Root),
int16(intersect.Min.X), int16(intersect.Min.Y),
uint16(intersect.Dx()), uint16(intersect.Dy()), 0xffffffff).Reply()
int16(intersect.Min.X), int16(intersect.Min.Y),
uint16(intersect.Dx()), uint16(intersect.Dy()), 0xffffffff).Reply()
if err != nil {
return nil, err
}
Expand All @@ -69,10 +69,10 @@ func Capture(x, y, width, height int) (img *image.RGBA, e error) {
offset := 0
for iy := intersect.Min.Y; iy < intersect.Max.Y; iy++ {
for ix := intersect.Min.X; ix < intersect.Max.X; ix++ {
r := xImg.Data[offset + 2]
g := xImg.Data[offset + 1]
r := xImg.Data[offset+2]
g := xImg.Data[offset+1]
b := xImg.Data[offset]
img.SetRGBA(ix - (x + x0), iy - (y + y0), color.RGBA{r, g, b, 255})
img.SetRGBA(ix-(x+x0), iy-(y+y0), color.RGBA{r, g, b, 255})
offset += 4
}
}
Expand All @@ -82,12 +82,12 @@ func Capture(x, y, width, height int) (img *image.RGBA, e error) {
}

func NumActiveDisplays() (num int) {
defer func () {
defer func() {
e := recover()
if e != nil {
num = 0
}
} ()
}()

c, err := xgb.NewConn()
if err != nil {
Expand All @@ -110,12 +110,12 @@ func NumActiveDisplays() (num int) {
}

func GetDisplayBounds(displayIndex int) (rect image.Rectangle) {
defer func () {
defer func() {
e := recover()
if e != nil {
rect = image.ZR
}
} ()
}()

c, err := xgb.NewConn()
if err != nil {
Expand Down Expand Up @@ -143,7 +143,6 @@ func GetDisplayBounds(displayIndex int) (rect image.Rectangle) {
y := int(screen.YOrg) - y0
w := int(screen.Width)
h := int(screen.Height)
rect = image.Rect(x, y, x + w, y + h)
rect = image.Rect(x, y, x+w, y+h)
return rect
}

6 changes: 3 additions & 3 deletions screenshot_darwin.go
Expand Up @@ -8,10 +8,10 @@ package screenshot
import "C"

import (
"image"
"errors"
"unsafe"
"github.com/kbinani/screenshot/internal/util"
"image"
"unsafe"
)

func Capture(x, y, width, height int) (*image.RGBA, error) {
Expand Down Expand Up @@ -42,5 +42,5 @@ func GetDisplayBounds(displayIndex int) image.Rectangle {
w = 0
h = 0
C.GetDisplayBounds(C.int(displayIndex), &x, &y, &w, &h)
return image.Rect(int(x), int(y), int(x + w), int(y + h))
return image.Rect(int(x), int(y), int(x+w), int(y+h))
}
2 changes: 1 addition & 1 deletion screenshot_freebsd.go
@@ -1,8 +1,8 @@
package screenshot

import (
"image"
"github.com/kbinani/screenshot/internal/xwindow"
"image"
)

// Capture returns screen capture of specified desktop region.
Expand Down
2 changes: 1 addition & 1 deletion screenshot_linux.go
@@ -1,8 +1,8 @@
package screenshot

import (
"image"
"github.com/kbinani/screenshot/internal/xwindow"
"image"
)

// Capture returns screen capture of specified desktop region.
Expand Down

0 comments on commit a244110

Please sign in to comment.