// Package classify 提供纯函数的分辨率归类规则,不依赖任何状态。 package classify import "strings" // Orientation 画面方向 type Orientation int const ( OrientationSquare Orientation = iota OrientationHorizontal OrientationVertical ) // OrientationOf 由宽高判定画面方向 func OrientationOf(width, height int) Orientation { switch { case width > height: return OrientationHorizontal case width < height: return OrientationVertical default: return OrientationSquare } } func (o Orientation) String() string { switch o { case OrientationHorizontal: return "横屏" case OrientationVertical: return "竖屏" default: return "等比" } } // ImageDir 返回图片归类子目录名,如 "图片_横屏_1080P-dark_100" / "图片_GIF"。 // darkScore/lightScore 用于明暗分类(GIF 不做明暗分类,忽略这两项)。 func ImageDir(ext string, width, height int, darkScore, lightScore float64) string { if strings.EqualFold(ext, ".gif") { return "图片_GIF" } dir := resolutionDir("图片", ext, width, height) return dir + "-" + BrightnessName(darkScore, lightScore) } // VideoDir 返回视频归类子目录名,如 "视频_竖屏_4k" / "视频_横屏_GIF" func VideoDir(ext string, width, height int) string { return resolutionDir("视频", ext, width, height) } func resolutionDir(kind, ext string, width, height int) string { ori := OrientationOf(width, height).String() if strings.EqualFold(ext, ".gif") { return kind + "_" + ori + "_GIF" } if suffix := matchStandard(width, height); suffix != "" { return kind + "_" + ori + "_" + suffix } overflow := "原图" if kind == "视频" { overflow = "原画质" } return kind + "_" + ori + "_" + levelName(longEdge(width, height), overflow) } // longEdge 返回长边像素 func longEdge(w, h int) int { if w > h { return w } return h }