Almost working. Only thing is the color is off when indexed.

master
Zed A. Shaw 1 month ago
parent 7cf5ff9c3b
commit 42431a756e
  1. 4
      config.json
  2. 34
      processing.go

@ -10,8 +10,8 @@
"Target": "temp", "Target": "temp",
"Include": [ ".png", ".jpg" ], "Include": [ ".png", ".jpg" ],
"Exceptions": { "Exceptions": {
"temp/painted_*.png": { "images/painted_.*.png": {
"PixelWidth": 8, "PixelWidth": 2,
"ColorDepth": 16, "ColorDepth": 16,
"DitherType": 2, "DitherType": 2,
"Width": 256, "Width": 256,

@ -41,15 +41,36 @@ func SaveImage(filename string, img image.Image) {
func JankImage(settings Conversion, in_file string, out_file string) { func JankImage(settings Conversion, in_file string, out_file string) {
src := LoadImage(in_file) src := LoadImage(in_file)
bounds := src.Bounds() src_bounds := src.Bounds()
target_bounds := src_bounds
resize := gift.Resize(bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling) if settings.Width > 0 {
target_bounds.Max.X = settings.Width
}
if settings.Height > 0 {
target_bounds.Max.Y = settings.Height
}
fmt.Println("final size is: ", target_bounds.Max.X, target_bounds.Max.Y)
// only done when shrinking/growing
presize := gift.Resize(target_bounds.Max.X, target_bounds.Max.Y, gift.NearestNeighborResampling)
resize := gift.Resize(target_bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling)
posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType) posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType)
upscale := filters.Upscale(bounds, settings.PixelWidth) upscale := filters.Upscale(target_bounds, settings.PixelWidth)
sharpen := gift.UnsharpMask(1, 1, 0) sharpen := gift.UnsharpMask(1, 1, 0)
g := gift.New(resize, posterize, upscale, sharpen) var g *gift.GIFT
out_img := image.NewNRGBA(g.Bounds(bounds))
if target_bounds.Max.X != src_bounds.Max.X || target_bounds.Max.Y != src_bounds.Max.Y {
g = gift.New(presize, resize, posterize, upscale, sharpen)
} else {
g = gift.New(resize, posterize, upscale, sharpen)
}
out_img := image.NewNRGBA(g.Bounds(target_bounds))
g.Draw(out_img, src) g.Draw(out_img, src)
SaveImage(out_file, out_img) SaveImage(out_file, out_img)
@ -113,6 +134,7 @@ func Included(config Settings, path string) bool {
} }
func GetConversion(config Settings, path string) Conversion { func GetConversion(config Settings, path string) Conversion {
path = RePrefixPath(path, "")
for key, conversion := range config.Exceptions { for key, conversion := range config.Exceptions {
match, err := regexp.MatchString(key, path) match, err := regexp.MatchString(key, path)
if err != nil { log.Fatalf("problem matching regex %s: %v", key, err) } if err != nil { log.Fatalf("problem matching regex %s: %v", key, err) }
@ -141,6 +163,8 @@ func HasChanged(old_info fs.FileInfo, new_path string) bool {
func RenderImages(config Settings, force bool) error { 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 {
path = filepath.ToSlash(path)
if !d.IsDir() && Included(config, path) { if !d.IsDir() && Included(config, path) {
target := RePrefixPath(path, config.Target) target := RePrefixPath(path, config.Target)

Loading…
Cancel
Save