Skip to content

Instantly share code, notes, and snippets.

@rusq
Last active August 6, 2024 09:20
Show Gist options
  • Select an option

  • Save rusq/fe7754e8cc915125bc83aa520ffd5cfb to your computer and use it in GitHub Desktop.

Select an option

Save rusq/fe7754e8cc915125bc83aa520ffd5cfb to your computer and use it in GitHub Desktop.
View Calculator Image Art of Christoph Giesselink
// 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
}
module github.com/rusq/hpromread
go 1.22.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment