-
Notifications
You must be signed in to change notification settings - Fork 11
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
1 parent
d1a63ee
commit c1d69bb
Showing
6 changed files
with
180 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
build/ | ||
.vscode/ | ||
.idea/ | ||
|
||
*.elf | ||
*.exe | ||
*.zip | ||
|
||
*-amd64 | ||
*-386 |
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 |
---|---|---|
|
@@ -5,7 +5,8 @@ services: | |
|
||
script: | ||
- docker run -it -v $(pwd):/build jaczekanski/psn00bsdk:latest make | ||
- find . \( -iname "*.exe" -o -iname "*.png" -o -iname "*.log" \) -print | zip tests.zip -@ | ||
- ./tools/diffvram/build-ci.sh | ||
- find . \( -iname "*.exe" -o -iname "*.png" -o -iname "*.log" -o -iname "*-amd64" \) -print | zip tests.zip -@ | ||
|
||
before_deploy: | ||
- git config --global user.email "[email protected]" | ||
|
@@ -25,4 +26,4 @@ deploy: | |
skip_cleanup: true | ||
on: | ||
repo: JaCzekanski/ps1-tests | ||
tags: false | ||
tags: false |
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,27 @@ | ||
#!/bin/bash | ||
|
||
name="diffvram" | ||
docker_image="golang:1.12-alpine" | ||
platforms=("windows/amd64" "linux/amd64" "darwin/amd64") | ||
basedir=$(dirname "$0") | ||
|
||
pushd $basedir | ||
for platform in "${platforms[@]}" | ||
do | ||
platform_split=(${platform//\// }) | ||
GOOS=${platform_split[0]} | ||
GOARCH=${platform_split[1]} | ||
output_name=$name'-'$GOOS'-'$GOARCH | ||
if [ $GOOS = "windows" ]; then | ||
output_name+='.exe' | ||
fi | ||
|
||
echo Building $output_name | ||
env GOOS=$GOOS GOARCH=$GOARCH docker run -v $(pwd):/build -w /build golang:1.12-alpine go build -o $output_name . | ||
if [ $? -ne 0 ]; then | ||
echo 'An error has occurred! Aborting the script execution...' | ||
exit 1 | ||
fi | ||
done | ||
|
||
popd |
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,136 @@ | ||
package main | ||
|
||
import ( | ||
"image" | ||
"image/color" | ||
"image/png" | ||
"log" | ||
"os" | ||
) | ||
|
||
func min(a, b int) int { | ||
if a < b { | ||
return a | ||
} else { | ||
return b | ||
} | ||
} | ||
|
||
func abs(a int) int { | ||
if a < 0 { | ||
return -a | ||
} else { | ||
return a | ||
} | ||
} | ||
|
||
func diff(a, b uint32) uint8 { | ||
if a == b { | ||
return 0 | ||
} | ||
|
||
d := abs(int(a) - int(b)) | ||
|
||
return uint8(128 + d/2) | ||
} | ||
|
||
func main() { | ||
log.SetFlags(0) | ||
|
||
if len(os.Args) < 3 { | ||
log.Printf("usage: diffvram img1.png img2.png [diff.png]") | ||
return | ||
} | ||
|
||
fimg1, err := os.Open(os.Args[1]) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
|
||
fimg2, err := os.Open(os.Args[2]) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
|
||
img1, _, err := image.Decode(fimg1) | ||
if err != nil { | ||
log.Fatalf("%s: %s.\n", os.Args[1], err) | ||
return | ||
} | ||
|
||
img2, _, err := image.Decode(fimg2) | ||
if err != nil { | ||
log.Fatalf("%s: %s.\n", os.Args[2], err) | ||
return | ||
} | ||
|
||
size1 := img1.Bounds().Size() | ||
size2 := img2.Bounds().Size() | ||
|
||
if size1 != size2 { | ||
log.Printf("Size difference: %dx%d vs %dx%d\n", size1.X, size1.Y, size2.X, size2.Y) | ||
} | ||
|
||
size := image.Point{ | ||
X: min(size1.X, size2.X), | ||
Y: min(size1.Y, size2.Y), | ||
} | ||
|
||
diffImage := image.NewRGBA(image.Rectangle{ | ||
Min: image.Point{ | ||
X: 0, | ||
Y: 0, | ||
}, | ||
Max: size, | ||
}) | ||
|
||
diffCount := 0 | ||
for y := 0; y < size.Y; y++ { | ||
for x := 0; x < size.X; x++ { | ||
p1 := img1.At(x, y) | ||
p2 := img2.At(x, y) | ||
|
||
if p1 != p2 { | ||
diffCount++ | ||
} | ||
|
||
r1, g1, b1, a1 := p1.RGBA() | ||
r2, g2, b2, a2 := p2.RGBA() | ||
c := color.RGBA{ | ||
R: diff(r1, r2), | ||
G: diff(g1, g2), | ||
B: diff(b1, b2), | ||
A: 255 - diff(a1, a2), | ||
} | ||
|
||
diffImage.Set(x, y, c) | ||
} | ||
} | ||
|
||
if diffCount != 0 { | ||
log.Printf("Images are different (%d pixels)\n", diffCount) | ||
diffName := "diff.png" | ||
if len(os.Args) >= 4 { | ||
diffName = os.Args[3] | ||
} | ||
|
||
fdiff, err := os.Create(diffName) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
err = png.Encode(fdiff, diffImage) | ||
if err != nil { | ||
log.Fatalf("%s: %s.\n", diffName, err) | ||
return | ||
} | ||
|
||
log.Printf("Diff written to %s", diffName) | ||
os.Exit(2) | ||
return | ||
} | ||
|
||
log.Printf("Images are the same\n") | ||
} |