Skip to content

Commit

Permalink
Introduced Frame Properties Support
Browse files Browse the repository at this point in the history
Introduced Frame Properties Support as now the _ColorRange flag is correctly set to 1, namely Limited TV Range when filtering is applied on YUV (and Y only) at any bit depth, while RGB is passed through untouched.
  • Loading branch information
FranceBB authored Dec 1, 2023
1 parent 62fc501 commit 9b81222
Showing 1 changed file with 106 additions and 40 deletions.
146 changes: 106 additions & 40 deletions SafeColorLimiter.avsi
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ Function SafeColorLimiter(clip clp) {
\ : clp.Is420 ? "YUV420" : clp.IsYV411 ? "YUV411" : clp.Is422 ? "YUV422" : clp.Is444 ? "YUV444"
\ : ""

#Bit Depth
Bpc = clp.BitsPerComponent

#Check bit depth
Assert(Bpc == 8 || Bpc == 10 || Bpc == 12 || Bpc == 14 || Bpc == 16 || Bpc == 32, "Safe Color Limiter: Bit Depth not supported," + Chr(10)+"8bit, 10bit, 12bit, 14bit, 16bit, 32bit planar are supported!")

#Values for 32bit Float
Expand All @@ -15,45 +17,109 @@ Function SafeColorLimiter(clip clp) {
min_chroma_float=-112/255.0
max_chroma_float=107/255.0

Original == "Y8" ? Limiter(clp, min_luma=16, max_luma=235)
\ : Original == "YUV411" && Bpc == 8 ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YV12" ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YUV420" && Bpc == 8 ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YV16" ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YUY2" ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YUV422" && Bpc == 8 ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YV24" ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "YUV444" && Bpc == 8 ? Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240)
\ : Original == "Y" && Bpc == 10 ? Limiter(clp, min_luma=64, max_luma=940)
\ : Original == "YUV420" && Bpc == 10 ? Limiter(clp, min_luma=64, max_luma=940, min_chroma=64, max_chroma=940)
\ : Original == "YUV411" && Bpc == 10 ? Limiter(clp, min_luma=64, max_luma=940, min_chroma=64, max_chroma=940)
\ : Original == "YUV422" && Bpc == 10 ? Limiter(clp, min_luma=64, max_luma=940, min_chroma=64, max_chroma=940)
\ : Original == "YUV444" && Bpc == 10 ? Limiter(clp, min_luma=64, max_luma=940, min_chroma=64, max_chroma=940)
\ : Original == "Y" && Bpc == 12 ? Limiter(clp, min_luma=256, max_luma=3760)
\ : Original == "YUV420" && Bpc == 12 ? Limiter(clp, min_luma=256, max_luma=3760, min_chroma=256, max_chroma=3760)
\ : Original == "YUV411" && Bpc == 12 ? Limiter(clp, min_luma=256, max_luma=3760, min_chroma=256, max_chroma=3760)
\ : Original == "YUV422" && Bpc == 12 ? Limiter(clp, min_luma=256, max_luma=3760, min_chroma=256, max_chroma=3760)
\ : Original == "YUV444" && Bpc == 12 ? Limiter(clp, min_luma=256, max_luma=3760, min_chroma=256, max_chroma=3760)
\ : Original == "Y" && Bpc == 14 ? Limiter(clp, min_luma=1024, max_luma=15040)
\ : Original == "YUV420" && Bpc == 14 ? Limiter(clp, min_luma=1024, max_luma=15040, min_chroma=1024, max_chroma=15040)
\ : Original == "YUV411" && Bpc == 14 ? Limiter(clp, min_luma=1024, max_luma=15040, min_chroma=1024, max_chroma=15040)
\ : Original == "YUV422" && Bpc == 14 ? Limiter(clp, min_luma=1024, max_luma=15040, min_chroma=1024, max_chroma=15040)
\ : Original == "YUV444" && Bpc == 14 ? Limiter(clp, min_luma=1024, max_luma=15040, min_chroma=1024, max_chroma=15040)
\ : Original == "Y" && Bpc == 16 ? Limiter(clp, min_luma=4096, max_luma=60160)
\ : Original == "YUV420" && Bpc == 16 ? Limiter(clp, min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=60160)
\ : Original == "YUV411" && Bpc == 16 ? Limiter(clp, min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=60160)
\ : Original == "YUV422" && Bpc == 16 ? Limiter(clp, min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=60160)
\ : Original == "YUV444" && Bpc == 16 ? Limiter(clp, min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=60160)
\ : Original == "Y" && Bpc == 32 ? Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float)
\ : Original == "YUV420" && Bpc == 32 ? Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float)
\ : Original == "YUV411" && Bpc == 32 ? Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float)
\ : Original == "YUV422" && Bpc == 32 ? Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float)
\ : Original == "YUV444" && Bpc == 32 ? Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float)
\: ""

my_out=last
my_catched_out=clp

(Original == "Y" || Original == "Y8" || Original == "YUV411" || Original == "YV12" || Original == "YUY2" || Original == "YV16" || Original == "YUV420" || Original == "YUV411" || Original == "YUV422" || Original == "YUV444") ? last : clp
#Apply the appropriate clipping according to the bit depth
if (Original == "Y" && Bpc == 8) {

#Luma only
Limiter(clp, min_luma=16, max_luma=235) #8bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "YUV411" || Original == "YV12" || Original == "YUV420" && Bpc == 8 || Original == "YV16" || Original == "YUY2" || Original == "YUV422" && Bpc == 8 || Original == "YV24" || Original == "YUV444" && Bpc == 8) {

#Luma & Chroma
Limiter(clp, min_luma=16, max_luma=235, min_chroma=16, max_chroma=240) #8bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "Y" && Bpc == 10) {

#Luma only
Limiter(clp, min_luma=64, max_luma=940) #10bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last
}
else if (Original == "YUV420" && Bpc == 10 || Original == "YUV411" && Bpc == 10 || Original == "YUV422" && Bpc == 10 || Original == "YUV444" && Bpc == 10) {

#Luma & Chroma
Limiter(clp, min_luma=64, max_luma=940, min_chroma=64, max_chroma=940) #10bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "Y" && Bpc == 12) {

#Luma only
Limiter(clp, min_luma=256, max_luma=3760) #12bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "YUV420" && Bpc == 12 || Original == "YUV411" && Bpc == 12 || Original == "YUV422" && Bpc == 12 || Original == "YUV444" && Bpc == 12) {

#Luma & Chroma
Limiter(clp, min_luma=256, max_luma=3760, min_chroma=256, max_chroma=3760) #12bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "Y" && Bpc == 14) {

#Luma only
Limiter(clp, min_luma=1024, max_luma=15040) #14bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "YUV420" && Bpc == 14 || Original == "YUV411" && Bpc == 14 || Original == "YUV422" && Bpc == 14 || Original == "YUV444" && Bpc == 14) {

#Luma & Chroma
Limiter(clp, min_luma=1024, max_luma=15040, min_chroma=1024, max_chroma=15040) #14bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "Y" && Bpc == 16) {

#Luma only
Limiter(clp, min_luma=4096, max_luma=60160) #16bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "YUV420" && Bpc == 16 || Original == "YUV411" && Bpc == 16 || Original == "YUV422" && Bpc == 16 || Original == "YUV444" && Bpc == 16) {

#Luma & Chroma
Limiter(clp, min_luma=4096, max_luma=60160, min_chroma=4096, max_chroma=60160) #16bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "Y" && Bpc == 32) {

#Luma only
Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float) #32bit Y
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else if (Original == "YUV420" && Bpc == 32 || Original == "YUV411" && Bpc == 32 || Original == "YUV422" && Bpc == 32 || Original == "YUV444" && Bpc == 32) {

#Luma & Chroma
Limiter(clp, min_luma=min_luma_float, max_luma=max_luma_float, min_chroma=min_chroma_float, max_chroma=max_chroma_float) #32bit YUV
propSet("_ColorRange", 1) #Limited TV Range
my_output=last

}
else {

#return RGB as-is
my_output=clp

}

return my_output

}

0 comments on commit 9b81222

Please sign in to comment.