Can process a directory, force the build, and almost detect if there's a change. Color indexing is wrong in posterization and needs to enforce result width/height.

master
Zed A. Shaw 1 month ago
parent 95fe050cbb
commit 7cf5ff9c3b
  1. 2
      config.json
  2. 2
      main.go
  3. 26
      processing.go

@ -12,7 +12,7 @@
"Exceptions": { "Exceptions": {
"temp/painted_*.png": { "temp/painted_*.png": {
"PixelWidth": 8, "PixelWidth": 8,
"ColorDepth": 4, "ColorDepth": 16,
"DitherType": 2, "DitherType": 2,
"Width": 256, "Width": 256,
"Height": 256 "Height": 256

@ -24,7 +24,7 @@ func main() {
opts := ParseOpts() opts := ParseOpts()
config := LoadSettings(opts.Config) config := LoadSettings(opts.Config)
err := RenderImages(config) err := RenderImages(config, opts.Force)
if err != nil { if err != nil {
log.Fatalf("failed to walk dir %s: %v", config.Source, err) log.Fatalf("failed to walk dir %s: %v", config.Source, err)

@ -2,6 +2,7 @@ package main
import ( import (
"os" "os"
"errors"
"io/fs" "io/fs"
"fmt" "fmt"
"path/filepath" "path/filepath"
@ -124,7 +125,20 @@ func GetConversion(config Settings, path string) Conversion {
return config.Base return config.Base
} }
func RenderImages(config Settings) error { func HasChanged(old_info fs.FileInfo, new_path string) bool {
new_info, err := os.Stat(new_path)
if errors.Is(err, fs.ErrNotExist) {
return true
} else if err != nil {
log.Printf("!!!! can't stat target: %s: %v", new_path, err)
return false
}
return old_info.ModTime().After(new_info.ModTime())
}
func RenderImages(config Settings, force bool) error {
err := filepath.WalkDir(config.Source, err := filepath.WalkDir(config.Source,
func(path string, d fs.DirEntry, err error) error { func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() && Included(config, path) { if !d.IsDir() && Included(config, path) {
@ -137,7 +151,15 @@ func RenderImages(config Settings) error {
fmt.Println("FILE: ", path, "TARGET:", target) fmt.Println("FILE: ", path, "TARGET:", target)
convert := GetConversion(config, path) convert := GetConversion(config, path)
JankImage(convert, path, target)
path_info, err := d.Info()
if err != nil {
log.Fatalf("failed to stat %s: %v", path, err)
}
if force || HasChanged(path_info, target) {
JankImage(convert, path, target)
}
} else { } else {
fmt.Println("SKIP:", path) fmt.Println("SKIP:", path)
} }

Loading…
Cancel
Save