Last active
August 6, 2024 09:20
-
-
Save rusq/fe7754e8cc915125bc83aa520ffd5cfb to your computer and use it in GitHub Desktop.
View Calculator Image Art of Christoph Giesselink
This file contains hidden or 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
| // Command artwork converts the ARTWORK of a talented artist Christoph Giesselink | |
| // to machine readable format. | |
| // | |
| // Artwork location: https://hp.giesselink.com/ImageArt/ImageArt.htm | |
| /* | |
| This program is free software: you can redistribute it and/or modify it under the terms | |
| of the GNU General Public License as published by the Free Software Foundation, | |
| either version 3 of the License, or (at your option) any later version. | |
| This program is distributed in the hope that it will be useful, but WITHOUT ANY | |
| WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | |
| PARTICULAR PURPOSE. See the GNU General Public License for more details. | |
| You should have received a copy of the GNU General Public License along with this | |
| program. If not, see <https://www.gnu.org/licenses/>. | |
| */ | |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "image" | |
| "image/png" | |
| "log" | |
| "os" | |
| "path/filepath" | |
| ) | |
| var ( | |
| input = flag.String("i", "hp17bii.png", "input image") | |
| output = flag.String("o", "", "output file") | |
| ) | |
| func swapExt(s string, ext string) string { | |
| return s[:len(s)-len(filepath.Ext(s))] + ext | |
| } | |
| func main() { | |
| flag.Parse() | |
| if *input == "" { | |
| log.Fatal("no input artwork specified") | |
| } | |
| if *output == "" { | |
| *output = swapExt(*input, ".rom") | |
| } | |
| if err := convert(*input, *output); err != nil { | |
| log.Fatal(err) | |
| } | |
| } | |
| func convert(pngIn string, romOut string) error { | |
| f, err := os.Open(pngIn) | |
| if err != nil { | |
| return fmt.Errorf("error opening artwork: %w", err) | |
| } | |
| defer f.Close() | |
| iimg, err := png.Decode(f) | |
| if err != nil { | |
| return fmt.Errorf("error loading artwork: %w", err) | |
| } | |
| img, ok := iimg.(*image.Paletted) | |
| if !ok { | |
| return fmt.Errorf("invalid artwork type: %T", img) | |
| } | |
| if err := os.WriteFile(romOut, img.Pix, 0644); err != nil { | |
| return fmt.Errorf("error writing output file: %w", err) | |
| } | |
| return nil | |
| } |
This file contains hidden or 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
| module github.com/rusq/hpromread | |
| go 1.22.2 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment