-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving imageFlip into it's own module.. adding other images
- Loading branch information
Matthew Robertson
committed
Jan 14, 2023
1 parent
4d46ff3
commit 3432a5e
Showing
9 changed files
with
243 additions
and
77 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
[[{"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}] [{"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}] [{"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {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ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}] [{"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}] [{"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"ÿ" "ÿ" "ÿ" "ÿ"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}, {"\x00" "\x00" "\x00" "\x00"}]] |
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,3 @@ | ||
module github.com/metalix2/PiGames/imageFlip | ||
|
||
go 1.19 |
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,48 @@ | ||
package imageFlip | ||
|
||
import ( | ||
"image" | ||
"image/color/palette" | ||
"image/color" | ||
) | ||
|
||
func imageToGrid(img image.Image) [][]color.Color { | ||
// create and return a grid of pixels | ||
var grid [][]color.Color | ||
size := img.Bounds().Size() | ||
for i := 0; i < size.X; i++ { | ||
var y []color.Color | ||
for j := 0; j < size.Y; j++ { | ||
// gray.Set(i, j, img.At(i, j)) | ||
r1, g1, b1, _ := img.At(i, j).RGBA() | ||
r2, g2, b2, _ := color.Black.RGBA() | ||
if (r1 == r2 && g1 == g2 && b1 == b2) { | ||
y = append(y, color.Black) | ||
} else { | ||
y = append(y, color.White) | ||
} | ||
} | ||
grid = append(grid, y) | ||
} | ||
return grid | ||
} | ||
|
||
func flip(img image.Image) image.Image { | ||
// create and return a grid of pixels | ||
var grid = imageToGrid(img) | ||
xlen, ylen := len(grid), len(grid[0]) | ||
|
||
// reverse array | ||
for i, j := 0, len(grid)-1; i < j; i, j = i+1, j-1 { | ||
grid[i], grid[j] = grid[j], grid[i] | ||
} | ||
|
||
rect := image.Rect(0, 0, xlen+1, ylen+1) | ||
img2 := image.NewPaletted(image.Rect(0, 0, xlen+1, ylen+1), palette.Plan9) | ||
for x := 0; x < xlen; x++ { | ||
for y := 0; y < ylen; y++ { | ||
img2.Set(x+1, y+1, grid[x][y]) | ||
} | ||
} | ||
return img2.SubImage(rect) | ||
} |
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,74 @@ | ||
package imageFlip | ||
|
||
import ( | ||
"testing" | ||
"image/gif" | ||
"image/color" | ||
"os" | ||
"reflect" | ||
) | ||
|
||
var b = color.Black | ||
var w = color.White | ||
var output = [][]color.Color{ | ||
{b, b, b, w, w, w, w, w, b, b, b, b, b}, | ||
{b, b, w, w, b, b, b, w, w, b, b, b, b}, | ||
{b, w, w, b, w, b, w, b, b, b, b, b, w}, | ||
{b, w, w, b, w, w, w, b, w, w, b, w, w}, | ||
{b, w, w, b, w, b, w, b, w, w, b, b, b}, | ||
{b, w, w, b, w, w, w, b, w, w, b, w, w}, | ||
{b, w, w, w, b, b, w, b, b, w, b, b, w}, | ||
{b, w, w, w, w, w, b, b, b, b, b, b, b}, | ||
{w, b, w, w, w, w, w, w, b, b, b, b, b}, | ||
{b, b, w, b, w, w, w, b, w, b, b, b, b}, | ||
{b, b, b, b, b, b, w, b, b, b, b, b, b}, | ||
} | ||
|
||
var flipOuput = [][]color.Color{ | ||
{b, b, b, b, b, b, w, b, b, b, b, b, b}, | ||
{b, b, w, b, w, w, w, b, w, b, b, b, b}, | ||
{w, b, w, w, w, w, w, w, b, b, b, b, b}, | ||
{b, w, w, w, w, w, b, b, b, b, b, b, b}, | ||
{b, w, w, w, b, b, w, b, b, w, b, b, w}, | ||
{b, w, w, b, w, w, w, b, w, w, b, w, w}, | ||
{b, w, w, b, w, b, w, b, w, w, b, b, b}, | ||
{b, w, w, b, w, w, w, b, w, w, b, w, w}, | ||
{b, w, w, b, w, b, w, b, b, b, b, b, w}, | ||
{b, b, w, w, b, b, b, w, w, b, b, b, b}, | ||
{b, b, b, w, w, w, w, w, b, b, b, b, b}, | ||
} | ||
|
||
func TestImageToGrid(t *testing.T) { | ||
|
||
avatarpath := "../images/avatar.gif" | ||
f, err := os.Open(avatarpath) | ||
avatarGif, err := gif.DecodeAll(f) | ||
f.Close() | ||
|
||
// expected output | ||
|
||
img := imageToGrid(avatarGif.Image[0]) | ||
|
||
if !reflect.DeepEqual(img, output) || err != nil { | ||
t.Errorf(`imageToGrid(avatarGif.Image[0]) = %q, %q`, img, output) | ||
} | ||
} | ||
|
||
func TestImageFlip(t *testing.T) { | ||
|
||
|
||
avatarpath := "../images/avatar.gif" | ||
f, err := os.Open(avatarpath) | ||
avatarGif, err := gif.DecodeAll(f) | ||
f.Close() | ||
|
||
// expected output | ||
|
||
resultImg := flip(avatarGif.Image[0]) | ||
|
||
result := imageToGrid(resultImg) | ||
|
||
if !reflect.DeepEqual(result, flipOuput) || err != nil { | ||
t.Errorf(`imageToGrid(avatarGif.Image[0]) = %q, %q`, result, flipOuput) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.