Mostly working but have to resolve dealing with wider/taller animation images.

master
Zed A. Shaw 1 month ago
parent 860a0d99a2
commit 2d7c8031b9
  1. 55
      processing.go

@ -39,35 +39,38 @@ func SaveImage(filename string, img image.Image) {
} }
} }
func AdjustDim(src_dim int, setting_dim int) int {
// BUG: should use the aspect ratio
if setting_dim == 0 {
return src_dim
} else {
return setting_dim
}
}
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)
src_bounds := src.Bounds() src_bounds := src.Bounds()
target_bounds := src_bounds var target_bounds image.Rectangle
if settings.Width > 0 { target_bounds.Max.X = AdjustDim(src_bounds.Max.X, settings.Width)
target_bounds.Max.X = settings.Width target_bounds.Max.Y = AdjustDim(src_bounds.Max.Y, settings.Height)
}
if settings.Height > 0 {
target_bounds.Max.Y = settings.Height
}
fmt.Println("final size is: ", target_bounds.Max.X, target_bounds.Max.Y) fmt.Println("final size is: ", target_bounds.Max.X, target_bounds.Max.Y)
// only done when shrinking/growing // BUG: use the shortest dimension for the pixelate, or add a framesize setting
presize := gift.Resize(target_bounds.Max.X, target_bounds.Max.Y, gift.NearestNeighborResampling) resize := gift.Resize(src_bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling)
// posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType)
resize := gift.Resize(target_bounds.Max.X / settings.PixelWidth, 0, gift.NearestNeighborResampling) upscale := filters.Upscale(src_bounds, settings.PixelWidth)
posterize := filters.Posterize(uint16(settings.ColorDepth), settings.DitherType) final_size := gift.Resize(target_bounds.Max.X, target_bounds.Max.Y, gift.NearestNeighborResampling)
upscale := filters.Upscale(target_bounds, settings.PixelWidth)
sharpen := gift.UnsharpMask(1, 1, 0) sharpen := gift.UnsharpMask(1, 1, 0)
var g *gift.GIFT var g *gift.GIFT
if target_bounds.Max.X != src_bounds.Max.X || target_bounds.Max.Y != src_bounds.Max.Y { 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) g = gift.New(resize, upscale, sharpen, final_size)
} else { } else {
g = gift.New(resize, posterize, upscale, sharpen) g = gift.New(resize, upscale, sharpen)
} }
out_img := image.NewNRGBA(g.Bounds(target_bounds)) out_img := image.NewNRGBA(g.Bounds(target_bounds))
@ -91,10 +94,12 @@ func SplitPathExt(path string) (string, string, bool) {
return source_name, ext, found return source_name, ext, found
} }
func RePrefixPath(path string, new_prefix string) string { func RePrefixPath(source string, path string, new_prefix string) string {
split_path := UnfuckedPathSplit(path) split_path := UnfuckedPathSplit(path)
split_source := UnfuckedPathSplit(source)
tail := split_path[len(split_source) - 1:]
prefixed_path := append([]string{new_prefix}, split_path...) prefixed_path := append([]string{new_prefix}, tail...)
res := filepath.Join(prefixed_path...) res := filepath.Join(prefixed_path...)
return filepath.ToSlash(res) return filepath.ToSlash(res)
@ -134,7 +139,8 @@ func Included(config Settings, path string) bool {
} }
func GetConversion(config Settings, path string) Conversion { func GetConversion(config Settings, path string) Conversion {
path = RePrefixPath(path, "") path = strings.ToLower(RePrefixPath(config.Source, 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) }
@ -166,7 +172,8 @@ func RenderImages(config Settings, force bool) error {
path = filepath.ToSlash(path) path = filepath.ToSlash(path)
if !d.IsDir() && Included(config, path) { if !d.IsDir() && Included(config, path) {
target := RePrefixPath(path, config.Target) // have to lowercase the target path to avoid windows issues
target := strings.ToLower(RePrefixPath(config.Source, path, config.Target))
err = MkdirPath(target) err = MkdirPath(target)
if err != nil { if err != nil {
@ -182,11 +189,11 @@ func RenderImages(config Settings, force bool) error {
} }
if force || HasChanged(path_info, target) { if force || HasChanged(path_info, target) {
// have to lowercase the target path to avoid windows issues fmt.Println("JANKIFY: ", path, "->", target)
JankImage(convert, path, strings.ToLower(target)) JankImage(convert, path, target)
} else {
fmt.Println("UNCHANGED: ", path, "->", target)
} }
} else {
fmt.Println("SKIP:", path)
} }
return nil return nil

Loading…
Cancel
Save