Files
kenaito-media-picker/internal/classify/brightness.go
T
2025-09-24 21:19:55 +08:00

42 lines
1.0 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package classify
import "fmt"
// BrightnessName 根据暗色像素占比,给图片定"明暗等级",返回类似:
// - "dark_25" → 暗色像素占 0%~33% 的偏亮图
// - "dark_50" → 暗色像素占 33%~66% 的中间调
// - "dark_75" → 暗色像素占 66%~100% 的暗图
//
// 三档按 33%/66% 等分。
func BrightnessName(darkScore, lightScore float64) string {
return fmt.Sprintf("dark_%d", brightnessTier(darkScore))
}
// brightnessTier 把暗色占比(0~1)映射到三档:25/50/75。
// 分界点:33% 和 66%。
func brightnessTier(score float64) int {
switch {
case score < 0.33:
return 25
case score < 0.66:
return 50
default:
return 75
}
}
// NsfwLevelName 根据色情评分(0~1)返回中文分档名称。
// 四档:安全(0~0.25)/ 低俗(0.25~0.5)/ 擦边(0.5~0.75)/ 色情(0.75~1)。
func NsfwLevelName(score float64) string {
switch {
case score < 0.25:
return "安全"
case score < 0.5:
return "低俗"
case score < 0.75:
return "擦边"
default:
return "色情"
}
}