- 移除固定的明暗阈值等级数组,改用动态分档机制 - 引入 neutralMargin 常量,当两分差幅小于 0.15 时视为中性图 - 修改 BrightnessName 函数,实现三分法分类:bright_N、dark_N、mid - 新增 brightnessTier 辅助函数,将占比分档到最接近的 10% - 完全透明的像素(alpha=0)不再参与明暗统计计算 - 更新错误提示信息,明暗分析失败时按中性 mid 归类 - 调整 README 文档描述,同步更新明暗分类规则说明
75 lines
1.9 KiB
Go
75 lines
1.9 KiB
Go
// 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_70" / "图片_横屏_1080P-mid" / "图片_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
|
|
}
|