# ===============================================================================
# ===============================================================================
# ========== CropResize 2019-09-10 ==============================================
# ===============================================================================
# ===============================================================================


function CropResize(clip SourceVideo, \
int "OutWidth", int "OutHeight", \
int "CL", int "CT", int "CR", int "CB", val "CropDAR", int "CSplit", bool "CAlign", \
bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", \
val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", \
bool "NoResize", bool "ResizeWO", \
bool "Borders", bool "CleanBorders", val "BColor", bool "Frosty", \
int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")     {

Try{   IsG1Function = G1_GFunction   }catch(err){   IsG1Function = false   }
Try{   IsG2Function = G2_GFunction   }catch(err){   IsG2Function = false   }
Try{   IsPriorScript = gPriorScript   }catch(err){   IsPriorScript = false   }
Try{   IsGCPreview = (0 <= G_CPreview < 4)   }catch(err){   IsGCPreview = false   }
Try{   IsGInfo = G_Info   }catch(err){   IsGInfo = false   G_Info = false   }
Try{   IsGResizer = defined(G_Resizer)   }catch(err){   IsGResizer = false   }
Try{   IsMX = CR_MeGUI_DAR() && !IsPriorScript && defined(MeGUI_darx)   }catch(err){   IsMX = false   }
Try{   IsMY = CR_MeGUI_DAR() && !IsPriorScript && defined(MeGUI_dary)   }catch(err){   IsMY = false   }
Try{   MInDAR = IsMX && IsMY ? float(MeGUI_darx) / float(MeGUI_dary) : 0.0   }catch(err){   MInDAR = 0.0   }
Try{   MPassDAR = CR_MeGUI_DAR() ? gMPassDAR : 0.0   }catch(err){   MPassDAR = 0.0   }

GMode = default(GMode, 1)
IsGMode0 = (GMode == 0)
IsGMode1 = (GMode == 1)
IsGMode2 = (GMode == 2)

assert(!IsGMode2 || IsG2Function, " CropResize " + chr(10) + \
" GMode can't equal 2 for CropResize unless " + chr(10) + \
" GMode=2 for a previous global GCropResize instance " + chr(10))


# ========== Defaults - Without Global Function =================================


!IsG1Function ? Eval("""

Source_Width = width(SourceVideo)
Source_Height = height(SourceVideo)

OutWidth = default(OutWidth, 0)
OutHeight = default(OutHeight, 0)
CL = default(CL, 0)
CT = default(CT, 0)
CR = (default(CR, 0) <= 0) ? -(default(CR, 0)) : Source_Width - CL - default(CR, 0)
CB = (default(CB, 0) <= 0) ? -(default(CB, 0)) : Source_Height - CT - default(CB, 0)
CropDAR = default(CropDAR, 0.0)
CSplit = default(CSplit, 1)
CAlign = default(CAlign, false)
AutoC = default(AutoC, false)
CThresh = default(CThresh, 30)
CStart = default(CStart, 250)
CSample = default(CSample, 5)
CPreview = default(CPreview, IsGCPreview ? G_CPreview : 0)
CLine = default(CLine, CR_CLine())
InDAR = default(InDAR, 0.0)
InSAR = default(InSAR, 0.0)
OutDAR = default(OutDAR, 0.0)
OutSAR = default(OutSAR, 0.0)
AutoAspect = default(AutoAspect, CR_AutoAspect())
Mod = default(Mod, 4)
HMod = default(HMod, Mod)
NoResize = default(NoResize, false)
ResizeWO = default(ResizeWO, false)
Borders = default(Borders, false)
CleanBorders = default(CleanBorders, false)
BColor = default(BColor, $000000)
Frosty = default(Frosty, false)
ColorCorrect = default(ColorCorrect, CR_ColorCorrect())
Resizer = default(Resizer, IsGResizer ? G_Resizer : "Spline36Resize")
PicDim = default(PicDim, -75)
Info = default(Info, G_Info)

""", "Defaults - IsGFunction False Eval") : Eval("""


# ========== Defaults - With Global Function ====================================


xM = default(Mod, 0)

Source_Width = IsGMode1 && G1_AutoC ? G1_Source_Width : \
IsGMode2 && G2_AutoC ? G2_Source_Width : width(SourceVideo)
Source_Height = IsGMode1 && G1_AutoC ? G1_Source_Height : \
IsGMode2 && G2_AutoC ? G2_Source_Height : height(SourceVideo)

OutWidth = (default(OutWidth, 0) == 0) ? (!IsGMode2 ? G1_OutWidth : G2_OutWidth) : default(OutWidth, 0)
OutHeight = (default(OutHeight, 0) == 0) ? (!IsGMode2 ? G1_OutHeight : G2_OutHeight) : default(OutHeight, 0)
CL = default(CL, IsGMode0 ? 0 : IsGMode1 ? G1_CL : G2_CL)
CT = default(CT, IsGMode0 ? 0 : IsGMode1 ? G1_CT : G2_CT)
CR = default(CR, IsGMode0 ? 0 : IsGMode1 ? G1_CR : G2_CR)
CR = (CR <= 0) ? -CR : Source_Width - CL - CR
CB = default(CB, IsGMode0 ? 0 : IsGMode1 ? G1_CB : G2_CB)
CB = (CB <= 0) ? -CB : Source_Height - CT - CB
CropDAR = default(CropDAR, IsGMode0 ? 0.0 : IsGMode1 ? G1_CropDAR : G2_CropDAR)
CSplit = default(CSplit, IsGMode0 ? 1 : IsGMode1 ? G1_CSplit : G2_CSplit)
CAlign = default(CAlign, IsGMode0 ? false : IsGMode1 ? G1_CAlign : G2_CAlign)
AutoC = default(AutoC, false)
CThresh = default(CThresh, 30)
CStart = default(CStart, 250)
CSample = default(CSample, 5)
CPreview = default(CPreview, IsGCPreview ? G_CPreview : \
IsGMode1 && (G1_CPreview != 4) ? G1_CPreview : IsGMode2 && (G2_CPreview != 4) ? G2_CPreview : 0)
CLine = default(CLine, !IsGMode2 ? G1_CLine : G2_CLine)
InDAR = default(InDAR, 0.0)
InSAR = default(InSAR, 0.0)
OutDAR = default(OutDAR, 0.0)
OutSAR = default(OutSAR, 0.0)
AutoAspect = default(AutoAspect, !IsGMode2 ? G1_AutoAspect : G2_AutoAspect)
Mod = default(Mod, (xM != 0) ? xM : !IsGMode2 ? G1_Mod : G2_Mod)
HMod = default(HMod, (xM != 0) ? xM : !IsGMode2 ? G1_HMod : G2_HMod)
NoResize = default(NoResize, IsGMode0 ? false : IsGMode1 ? G1_NoResize : G2_NoResize)
ResizeWO = default(ResizeWO, IsGMode0 ? false : IsGMode1 ? G1_ResizeWO : G2_ResizeWO)
Borders = default(Borders, IsGMode0 ? false : IsGMode1 ? G1_Borders : G2_Borders)
CleanBorders = default(CleanBorders, IsGMode0 ? false : IsGMode1 ? G1_CleanBorders : G2_CleanBorders)
BColor = default(BColor, IsGMode0 ? $000000 : IsGMode1 ? G1_BColor : G2_BColor)
Frosty = default(Frosty, IsGMode0 ? false : IsGMode1 ? G1_Frosty : G2_Frosty)
ColorCorrect = default(ColorCorrect, !IsGMode2 ? G1_ColorCorrect : G2_ColorCorrect)
Resizer = default(Resizer, IsGResizer ? G_Resizer : !IsGMode2 ? G1_Resizer : G2_Resizer)
PicDim = default(PicDim, IsGMode1 ? G1_PicDim : G2_PicDim)
Info = default(Info, IsGInfo ? G_Info : !IsGMode2 ? G1_Info : G2_Info)

""", "Defaults - IsGFunction True Eval")


# ========== Checks & Miscellaneous =============================================


F_Source_Width = float(Source_Width)
F_Source_Height = float(Source_Height)

DummyVideo=BlankClip().KillAudio()
CM_Video=DummyVideo   RW_Video=DummyVideo
CRA_Video=DummyVideo   CRB_Video=DummyVideo

GInDAR = !IsG1Function || IsGMode0 ? 0.0 : IsGMode1 ? G1_InDAR : G2_InDAR
GInSAR = !IsG1Function || IsGMode0 ? 0.0 : IsGMode1 ? G1_InSAR : G2_InSAR
GOutDAR = !IsG1Function ? 0.0 : !IsGMode2 ? G1_OutDAR : G2_OutDAR
GOutSAR = !IsG1Function ? 0.0 : !IsGMode2 ? G1_OutSAR : G2_OutSAR

IsAvisynthPlus = (FindStr(LCase(VersionString), "avisynth+") > 0)
Source_Bit_Depth = IsAvisynthPlus ? BitsPerComponent(SourceVideo) : 8
Color_Format = SourceVideo.PixelType()
Chroma420 = IsAvisynthPlus ? Is420(SourceVideo) : IsYV12(SourceVideo)
Chroma422 = IsAvisynthPlus ? Is422(SourceVideo) : IsYV16(SourceVideo)
Chroma444 = IsAvisynthPlus ? Is444(SourceVideo) : IsYV24(SourceVideo)
ModTwoWidth = Chroma420 || Chroma422 || IsYUY2(SourceVideo)
ModFourWidth = IsYV411(SourceVideo)
ModTwoHeight = Chroma420

Crop_WMod = ModFourWidth ? 4 : ModTwoWidth ? 2 : 1
Crop_HMod = ModTwoWidth ? 2 : 1
F_Crop_WMod = float(Crop_WMod)
F_Crop_HMod = float(Crop_HMod)

IsRMode = defined(RMode) && RMode
IsCurrentGAutoC = (IsG1Function && IsGMode1 && G1_AutoC) || (IsG2Function && IsGMode2 && G2_AutoC)
IsCurrentGAutoCPreview = \
(IsG1Function && IsGMode1 && (G1_CPreview == 4)) || (IsG2Function && IsGMode2 && (G2_CPreview == 4))
IsScriptCPreview = (0 < CPreview < 4) && !IsCurrentGAutoCPreview
IsAutoCPreview = AutoC && (CPreview == 4)
IsAnyAutoCrop = AutoC || IsCurrentGAutoC
CroppedMoreLeft = (CL > CR)
CroppedMoreTop = (CT > CB)
F_Mod = float(Mod)
F_HMod = float(HMod)


# ===============================================================================
#  The rules preceeded by comments below should be safe to disable by commenting out their
#  Assert line(s). They prevent ambiguity when it doesn't make sense to specify options together,
#  such as specifying an input display and sample aspect ratio at the same time.
#  For those types of rules, without the error message, one of the specified options should take
#  precedence and the other would have no effect.
# ===============================================================================

assert((0 < CSplit < 4), " CropResize " + chr(10) + " CSplit must be 1, 2 or 3 " + chr(10))
assert((1 <= CThresh <= 255), " CropResize " + chr(10) + " CThresh must be 1 thru 255 " + chr(10))
assert(IsInt(CR_CPreview()) && (0 <= CPreview <= 4) && (!IsGCPreview || (0 <= G_CPreview <= 4)), \
" CropResize " + chr(10) + " CPreview must be 0 thru 4 " + chr(10))
assert(IsInt(CR_CLine()) && (CLine >= 1), " CropResize " + chr(10) + \
" CLine must be an integer, greater than or equal to 1 " + chr(10))
assert(IsInt(CR_ColorCorrect()) && (0 <= ColorCorrect <= 4), \
" CropResize " + chr(10) + " ColorCorrect must be an integer, 0 thru 4 " + chr(10))

assert(!AutoC || !IsCurrentGAutoC, " CropResize " + chr(10) + \
" AutoC can't be true for CropResize when global " + chr(10) + \
" auto-cropping has been enabled via the GCropResize function " + chr(10))
assert(AutoC || (CPreview != 4), " CropResize " + chr(10) + " AutoC must be true when CPreview=4 " + chr(10))

assert(((CropDAR == 0) || ((CropDAR > 0) && !IsInt(CropDAR) && IsFloat(CropDAR))) && \
(((InDAR == 0) || ((InDAR > 0) && !IsInt(InDAR) && IsFloat(InDAR))) && \
((GInDAR == 0) || ((GInDAR > 0) && !IsInt(GInDAR) && IsFloat(GInDAR)))) && \
(((InSAR == 0) || ((InSAR > 0) && !IsInt(InSAR) && IsFloat(InSAR))) && \
((GInSAR == 0) || ((GInSAR > 0) && !IsInt(GInSAR) && IsFloat(GInSAR)))) && \
(((OutDAR == 0) || ((OutDAR > 0) && !IsInt(OutDAR) && IsFloat(OutDAR))) && \
((GOutDAR == 0) || ((GOutDAR > 0) && !IsInt(GOutDAR) && IsFloat(GOutDAR)))) && \
(((OutSAR == 0) || ((OutSAR > 0) && !IsInt(OutSAR) && IsFloat(OutSAR))) && \
((GOutSAR == 0) || ((GOutSAR > 0) && !IsInt(GOutSAR) && IsFloat(GOutSAR)))), \
" CropResize " + chr(10) + " CropDAR, InDAR, InSAR, OutDAR & OutSAR " + chr(10) + \
" must be positive floating point numbers " + chr(10) + " (4.0/3.0 or 1.7778 etc) " + chr(10))

assert((Mod == 1) || (Mod == 2) || (Mod == 4) || (Mod == 8) || (Mod == 16), \
" CropResize " + chr(10) + " Mod must be 1, 2, 4, 8 or 16 " + chr(10))
assert((HMod == 1) || (HMod == 2) || (HMod == 4) || (HMod == 8) || (HMod == 16), \
" CropResize " + chr(10) + " HMod must be 1, 2, 4, 8 or 16 " + chr(10))

assert((0 <= GMode < 3), " CropResize " + chr(10) + \
" GMode must be 0, 1 or 2 for CropResize " + chr(10) + " (1 or 2 for GCropResize) " + chr(10))

assert(!ResizeWO || (CropDAR == 0) || \
(((OutDAR == 0) || (OutDAR >= CropDAR)) && ((GOutDAR == 0) || (GOutDAR >= CropDAR))), \
" CropResize " + chr(10) + " When ResizeWO=true and both OutDAR and CropDAR are specified " + chr(10) + \
" OutDAR must be greater than or equal to CropDAR " + chr(10))

assert(!IsMX || (IsInt(MeGUI_darx) && (MeGUI_darx > 0)), \
" CropResize " + chr(10) + " MeGUI_darx must be an integer greater than zero " + chr(10))
assert(!IsMY || (IsInt(MeGUI_dary) && (MeGUI_dary > 0)), \
" CropResize " + chr(10) + " MeGUI_dary must be an integer greater than zero " + chr(10))
assert((IsMX == IsMY), \
" CropResize " + chr(10) + " MeGUI_darx & MeGUI_dary must be specified together " + chr(10))

assert(!ModTwoWidth || (Mod % 2 == 0), \
" CropResize " + chr(10) + Color_Format + " requires a mod2 output width " + chr(10))
assert(!ModFourWidth || (Mod % 4 == 0), \
" CropResize " + chr(10) + Color_Format + " requires a mod4 output width " + chr(10))
assert(!ModTwoHeight || (HMod % 2 == 0), \
" CropResize " + chr(10) + Color_Format + " requires a mod2 output height " + chr(10))

assert((-255 <= PicDim <= 0), " CropResize " + chr(10) + " PicDim must be -255 thru 0 " + chr(10))

### Prevent NoResize & ResizeWO being true at the same time.
assert(!NoResize || !ResizeWO, \
" CropResize " + chr(10) + " NoResize and ResizeWO can't be true at the same time " + chr(10))
### Prevent CleanBorders & ResizeWO being true at the same time.
assert(!CleanBorders || !ResizeWO, \
" CropResize " + chr(10) + " CleanBorders and ResizeWO can't be true at the same time " + chr(10))

### Prevent CropResize from specifying new auto-cropping options when global auto-cropping is enabled.
assert(!IsCurrentGAutoC || (((CThresh == 30) || \
((!IsGMode1 || (CThresh == G1_CThresh)) && (!IsGMode2 || (CThresh == G2_CThresh)))) && \
((CStart == 250) || ((!IsGMode1 || (CStart == G1_CStart)) && (!IsGMode2 || (CStart == G2_CStart)))) && \
((CSample == 5) || ((!IsGMode1 || (CSample == G1_CSample)) && (!IsGMode2 || (CSample == G2_CSample))))), \
" CropResize " + chr(10) + " New auto-cropping options can't be specified for CropResize " + chr(10) + \
" when global auto-cropping is enabled " + chr(10))

### Prevent specifying InDAR & InSAR together.
assert(((InDAR == 0) || (InSAR == 0)), \
" CropResize " + chr(10) + " InDAR and InSAR can't be specified together " + chr(10))
### Prevent specifying OutDAR & OutSAR together.
assert(((OutDAR == 0) || (OutSAR == 0)), \
" CropResize " + chr(10) + " OutDAR and OutSAR can't be specified together " + chr(10))
### Prevent specifying OutDAR/OutSAR when NoResize=true or CleanBorders=true.
assert((!NoResize && !CleanBorders) || \
((OutDAR == 0) && (OutSAR == 0) && (GOutDAR == 0) && (GOutSAR == 0)), \
" CropResize " + chr(10) + " OutDAR/OutSAR can't be specified when " + chr(10) + \
" NoResize=true or CleanBorders=true " + chr(10))


# ========== Define Source ======================================================


AutoC && !IsAutoCPreview && !IsCurrentGAutoC && !IsCurrentGAutoCPreview ? Eval("""

Auto_Cropped_Source = \
SourceVideo.autocrop(mode=0, wMultOf=2, hMultOf=2, leftadd=0, topadd=0, rightadd=0, bottomadd=0, \
threshold=CThresh, samples=CSample, samplestartframe=CStart, sampleendframe=-1, aspect=0)

""", "Define Source 1 Eval") : Eval("""

Auto_Cropped_Source = SourceVideo

""", "Define Source 2 Eval")


# ========== Widths, Heights & Aspect Ratios ====================================


IsCropDAR = (CropDAR > 0)
IsMPassThru = (MPassDAR > 0)
IsMPassedThru = IsMPassThru && IsG1Function && IsGMode1
IsMInDAR = (MInDAR > 0)
IsInDAR = (InDAR > 0)
IsInSAR = (InSAR > 0) && !IsInDAR
IsGInDAR = (GInDAR > 0) && !IsInDAR && !IsInSAR
IsGInSAR = (GInSAR > 0) && !IsInDAR && !IsInSAR && !IsGInDAR
IsOutDAR = (OutDAR > 0)
IsOutSAR = (OutSAR > 0) && !IsOutDAR
IsGOutDAR = (GOutDAR > 0) && !IsOutDAR && !IsOutSAR
IsGOutSAR = (GOutSAR > 0) && !IsOutDAR && !IsOutSAR && !IsGOutDAR

InputDAR = IsInDAR ? InDAR : IsGInDAR ? GInDAR : IsMInDAR ? MInDAR : IsMPassedThru ? MPassDAR : 0
InputSAR = IsInSAR ? InSAR : IsGInSAR ? GInSAR : 0
OutputDAR = IsOutDAR ? OutDAR : IsGOutDAR ? GOutDAR : 0
OutputSAR = IsOutSAR ? OutSAR : IsGOutSAR ? GOutSAR : 0

IsInputDAR = (InputDAR > 0)
IsInputSAR = (InputSAR > 0)
IsOutputDAR = (OutputDAR > 0)
IsOutputSAR = (OutputSAR > 0)

AnamorphicInput = IsInputDAR || IsInputSAR
NoResizing = NoResize || CleanBorders
ResizeWidthOnly = ResizeWO && !NoResizing
FullResizing = !NoResizing && !ResizeWidthOnly
AnamorphicOutput = (NoResizing && AnamorphicInput) || (!NoResizing && (IsOutputDAR || IsOutputSAR))
Bordered = Borders || CleanBorders || ((ResizeWidthOnly || FullResizing) && (IsCropDAR && IsOutputDAR))
ColorCorrection = FullResizing && (0 < ColorCorrect <= 4)

Auto_Cropped_Width = width(Auto_Cropped_Source)
F_Auto_Cropped_Width = float(Auto_Cropped_Width)
Auto_Cropped_Height = height(Auto_Cropped_Source)
F_Auto_Cropped_Height = float(Auto_Cropped_Height)

Auto_Cropped_StorageAR = F_Auto_Cropped_Width / F_Auto_Cropped_Height
Auto_Cropped_DAR = !AnamorphicInput ? Auto_Cropped_StorageAR : IsInputDAR ? \
F_Auto_Cropped_Width * F_Source_Height * InputDAR / F_Auto_Cropped_Height / F_Source_Width : \
F_Auto_Cropped_Width * InputSAR / F_Auto_Cropped_Height

Source_StorageAR = F_Source_Width / F_Source_Height
F_Source_Display_Width = \
!AnamorphicInput ? F_Source_Width : IsInputDAR ? InputDAR * F_Source_Height : F_Source_Width * InputSAR
Source_DAR = \
!AnamorphicInput ? Source_StorageAR : IsInputDAR ? InputDAR : F_Source_Width * InputSAR / F_Source_Height
Source_SAR = !AnamorphicInput ? 1.0 : IsInputDAR ? F_Source_Height * InputDAR / F_Source_Width : InputSAR

Cropped_Source_Width = Auto_Cropped_Width - CL - CR
F_Cropped_Source_Width = float(Cropped_Source_Width)
Cropped_Source_Height = Auto_Cropped_Height - CT - CB
F_Cropped_Source_Height = float(Cropped_Source_Height)

Cropped_Source_StorageAR = F_Cropped_Source_Width / F_Cropped_Source_Height
Cropped_Source_DAR = !AnamorphicInput ? Cropped_Source_StorageAR : IsInputDAR ? \
F_Cropped_Source_Width * F_Source_Height * InputDAR / F_Cropped_Source_Height / F_Source_Width : \
F_Cropped_Source_Width * InputSAR / F_Cropped_Source_Height


# ===============================================================================
# ========== No Resizing Mode - Cropping To The Specified Mod ===================
# ===============================================================================


NoResizing ? Eval("""

CM_Mod = !CleanBorders ? Mod : ModFourWidth ? 4 : ModTwoWidth ? 2 : 1
CM_HMod = !CleanBorders ? HMod : ModTwoHeight ? 2 : 1
F_CM_Mod = float(CM_Mod)
F_CM_HMod = float(CM_HMod)
F_Half_CM_Mod = F_CM_Mod / 2.0
F_Half_CM_HMod = F_CM_HMod / 2.0

CM_CL_Adjust = (CL % Crop_WMod == 0) ? 0 : Crop_WMod - (CL % Crop_WMod)
CM_CT_Adjust = (CT % Crop_HMod == 0) ? 0 : Crop_HMod - (CT % Crop_HMod)
CM_CR_Adjust = (CR % Crop_WMod == 0) ? 0 : Crop_WMod - (CR % Crop_WMod)
CM_CB_Adjust = (CB % Crop_HMod == 0) ? 0 : Crop_HMod - (CB % Crop_HMod)

CM_Mod_Cropped_Width = ((Cropped_Source_Width - CM_CL_Adjust - CM_CR_Adjust) / CM_Mod) * CM_Mod
F_CM_Mod_Cropped_Width = float(CM_Mod_Cropped_Width)
CM_Mod_Cropped_Height = ((Cropped_Source_Height - CM_CT_Adjust - CM_CB_Adjust) / CM_HMod) * CM_HMod
F_CM_Mod_Cropped_Height = float(CM_Mod_Cropped_Height)

CM_Mod_Cropped_StorageAR = F_CM_Mod_Cropped_Width / F_CM_Mod_Cropped_Height
CM_Mod_Cropped_DAR = !AnamorphicInput ? CM_Mod_Cropped_StorageAR : IsInputDAR ? \
F_CM_Mod_Cropped_Width * F_Source_Height * InputDAR / F_CM_Mod_Cropped_Height / F_Source_Width : \
F_CM_Mod_Cropped_Width * InputSAR / F_CM_Mod_Cropped_Height

!IsCropDAR || (abs(CropDAR - CM_Mod_Cropped_DAR) < 0.0001) ? Eval("

CM_Width = CM_Mod_Cropped_Width
F_CM_Width = F_CM_Mod_Cropped_Width
CM_Height = CM_Mod_Cropped_Height
F_CM_Height = F_CM_Mod_Cropped_Height

", "No Resizing 1 Eval") : (CropDAR < CM_Mod_Cropped_DAR) ? Eval("

CM_Height = CM_Mod_Cropped_Height
F_CM_Height = F_CM_Mod_Cropped_Height
F_CM_Intermediate_Width = F_CM_Height * CropDAR / Source_SAR
F_CM_Width_Adjust = F_CM_Intermediate_Width - (floor(F_CM_Intermediate_Width / F_CM_Mod) * CM_Mod)
F_CM_Width_Adjust_Up = F_CM_Intermediate_Width + F_CM_Mod - F_CM_Width_Adjust
F_CM_Width_Adjust_Down = F_CM_Intermediate_Width - F_CM_Width_Adjust
F_CM_Width = (F_CM_Width_Adjust_Up > F_CM_Mod_Cropped_Width) ? F_CM_Width_Adjust_Down : \
(F_CM_Width_Adjust >= F_Half_CM_Mod) ? F_CM_Width_Adjust_Up : F_CM_Width_Adjust_Down
CM_Width = round(F_CM_Width)

", "No Resizing 2 Eval") : (CropDAR > CM_Mod_Cropped_DAR) ? Eval("

CM_Width = CM_Mod_Cropped_Width
F_CM_Width = F_CM_Mod_Cropped_Width
F_CM_Intermediate_Height = F_CM_Width / CropDAR * Source_SAR
F_CM_Height_Adjust = F_CM_Intermediate_Height - (floor(F_CM_Intermediate_Height / F_CM_HMod) * CM_HMod)
F_CM_Height_Adjust_Up = F_CM_Intermediate_Height + F_CM_HMod - F_CM_Height_Adjust
F_CM_Height_Adjust_Down = F_CM_Intermediate_Height - F_CM_Height_Adjust
F_CM_Height = (F_CM_Height_Adjust_Up > F_CM_Mod_Cropped_Height)  ? F_CM_Height_Adjust_Down : \
(F_CM_Height_Adjust > F_Half_CM_HMod) ? F_CM_Height_Adjust_Up : F_CM_Height_Adjust_Down
CM_Height = round(F_CM_Height)

", "No Resizing 3 Eval") : nop()


# ========== No Resizing Mode - Cropping ========================================


CM_Extra_Width_Crop = Cropped_Source_Width - CM_CL_Adjust - CM_CR_Adjust - CM_Width
F_CM_Extra_Width_Crop = float(CM_Extra_Width_Crop)
CM_Extra_Height_Crop = Cropped_Source_Height - CM_CT_Adjust - CM_CB_Adjust - CM_Height
F_CM_Extra_Height_Crop = float(CM_Extra_Height_Crop)

CM_Extra_CL = CroppedMoreLeft ? (ModFourWidth ? (CM_Extra_Width_Crop / 8) * 4 : \
ModTwoWidth ? (CM_Extra_Width_Crop / 4) * 2 : CM_Extra_Width_Crop / 2) : \
(ModFourWidth ? round(F_CM_Extra_Width_Crop / 8.0) * 4 : \
ModTwoWidth ? round(F_CM_Extra_Width_Crop / 4.0) * 2 : round(F_CM_Extra_Width_Crop / 2.0))
CM_Extra_CR = CM_Extra_Width_Crop - CM_Extra_CL

CM_Extra_CT = CroppedMoreTop ? \
(ModTwoHeight ? (CM_Extra_Height_Crop / 4) * 2 : CM_Extra_Height_Crop / 2) : \
(ModTwoHeight ? round(F_CM_Extra_Height_Crop / 4.0) * 2 : round(F_CM_Extra_Height_Crop / 2.0))
CM_Extra_CB = CM_Extra_Height_Crop - CM_Extra_CT

CM_Extra_Crop_L = CM_Extra_CL + CM_CL_Adjust
CM_Extra_Crop_T = CM_Extra_CT + CM_CT_Adjust
CM_Extra_Crop_R = CM_Extra_CR + CM_CR_Adjust
CM_Extra_Crop_B = CM_Extra_CB + CM_CB_Adjust

CM_CL = CM_Extra_Crop_L + CL
CM_CT = CM_Extra_Crop_T + CT
CM_CR = CM_Extra_Crop_R + CR
CM_CB = CM_Extra_Crop_B + CB

CM_Cropped_Width = Cropped_Source_Width - CM_Extra_Crop_L - CM_Extra_Crop_R
F_CM_Cropped_Width = float(CM_Cropped_Width)
CM_Cropped_Height = Cropped_Source_Height - CM_Extra_Crop_T - CM_Extra_Crop_B
F_CM_Cropped_Height = float(CM_Cropped_Height)


# ========== No Resizing Mode - Cropped Aspect Ratios ===========================


CM_Cropped_StorageAR = F_CM_Cropped_Width / F_CM_Cropped_Height
CM_Cropped_DAR = !AnamorphicInput ? CM_Cropped_StorageAR : IsInputDAR ? \
F_CM_Cropped_Width * F_Source_Height * InputDAR / F_CM_Cropped_Height / F_Source_Width : \
F_CM_Cropped_Width * InputSAR / F_CM_Cropped_Height


# ========== No Resizing Mode - Crop ============================================


CM_Video = Auto_Cropped_Source.crop(CM_CL, CM_CT, -CM_CR, -CM_CB, align=CAlign)

""", "No Resizing 4 Eval") : ResizeWidthOnly ? Eval("""


# ===============================================================================
# ========== Resize Width Only Mode =============================================
# ===============================================================================


RW_CT_Adjust = (CT % Crop_HMod == 0) ? 0 : Crop_HMod - (CT % Crop_HMod)
RW_CB_Adjust = (CB % Crop_HMod == 0) ? 0 : Crop_HMod - (CB % Crop_HMod)

F_RW_Cropped_Resized_Width = !AnamorphicInput ? F_Cropped_Source_Width : \
IsInputDAR ? F_Cropped_Source_Width * F_Source_Height * InputDAR / F_Source_Width : \
F_Cropped_Source_Width * InputSAR

RW_Resized_Mod_Cropped_Width = floor(F_RW_Cropped_Resized_Width / F_Mod) * Mod
F_RW_Resized_Mod_Cropped_Width = float(RW_Resized_Mod_Cropped_Width)
RW_Mod_Cropped_Height = ((Cropped_Source_Height - RW_CT_Adjust - RW_CB_Adjust) / HMod) * HMod
F_RW_Mod_Cropped_Height = float(RW_Mod_Cropped_Height)

RW_Cropped_Resized_DAR = F_RW_Cropped_Resized_Width / F_RW_Mod_Cropped_Height
RW_Resized_Mod_Cropped_DAR = F_RW_Resized_Mod_Cropped_Width / F_RW_Mod_Cropped_Height

RW_Resizing_Width = (OutWidth == 0) ? RW_Resized_Mod_Cropped_Width : OutWidth
F_RW_Resizing_Width = float(RW_Resizing_Width)
RW_Resizing_DAR = IsCropDAR ? CropDAR : IsOutputDAR ? OutputDAR : RW_Resized_Mod_Cropped_DAR

RW_Height = (RW_Resizing_DAR <= RW_Cropped_Resized_DAR) || \
(abs(RW_Resizing_DAR - RW_Cropped_Resized_DAR) < 0.0001) ? RW_Mod_Cropped_Height : \
floor(F_RW_Cropped_Resized_Width / RW_Resizing_DAR / F_HMod) * HMod
F_RW_Height = float(RW_Height)

RW_Resizing_SAR = \
IsOutputDAR ? F_RW_Height * OutputDAR / F_RW_Resizing_Width : IsOutputSAR ? OutputSAR : 1.0

F_RW_Intermediate_Width = F_RW_Height * RW_Resizing_DAR / RW_Resizing_SAR
F_RW_Intermediate_Aspect_Width = \
(abs(F_RW_Intermediate_Width - round(F_RW_Intermediate_Width)) < 0.0001) && \
(round(F_RW_Intermediate_Width) % Crop_WMod == 0) ? float(round(F_RW_Intermediate_Width)) : \
F_RW_Intermediate_Width
F_RW_Width_Adjust = \
F_RW_Intermediate_Aspect_Width - (floor(F_RW_Intermediate_Aspect_Width / F_Mod) * Mod)
F_RW_Width_Adjust_Up = F_RW_Intermediate_Aspect_Width + F_Mod - F_RW_Width_Adjust
F_RW_Width_Adjust_Down = F_RW_Intermediate_Aspect_Width - F_RW_Width_Adjust
F_RW_Adjusted_Width = \
(F_RW_Width_Adjust_Up > RW_Resized_Mod_Cropped_Width) ? F_RW_Width_Adjust_Down : \
((F_RW_Width_Adjust_Up - F_RW_Intermediate_Aspect_Width) < (F_Mod / 2.0)) ? F_RW_Width_Adjust_Up : \
F_RW_Width_Adjust_Down
RW_Adjusted_Width = round(F_RW_Adjusted_Width)

F_RW_Aspect_Width = \
IsOutputDAR ? (IsCropDAR ? F_RW_Adjusted_Width : F_RW_Intermediate_Aspect_Width) : F_RW_Adjusted_Width

F_RW_Width = \
IsOutputDAR ? (IsCropDAR ? F_RW_Adjusted_Width : F_RW_Resizing_Width) : F_RW_Aspect_Width
RW_Width = round(F_RW_Width)

F_RW_Extra_Width_Crop = \
!AnamorphicInput ? Cropped_Source_Width - (F_RW_Aspect_Width * RW_Resizing_SAR) : \
IsInputDAR ? Cropped_Source_Width - \
(F_RW_Aspect_Width * RW_Resizing_SAR * F_Source_Width / InputDAR / F_Source_Height) : \
Cropped_Source_Width - (F_RW_Aspect_Width * RW_Resizing_SAR / InputSAR)


# ========== Resize Width Only Mode - Cropping ==================================


RW_Extra_Crop_LR = max(0, F_RW_Extra_Width_Crop / 2.0)

RW_Non_Mod_Crop_LR = RW_Extra_Crop_LR - (floor(RW_Extra_Crop_LR / F_Crop_WMod) * Crop_WMod)
RW_Extra_Mod_Crop_LR = round(RW_Extra_Crop_LR - RW_Non_Mod_Crop_LR)

RW_CL_Adjust = (CL % Crop_WMod == 0) ? 0 : Crop_WMod - (CL % Crop_WMod)
RW_CL_Adjust = (CSplit == 1) ? \
((RW_Non_Mod_Crop_LR >= RW_CL_Adjust) ? RW_CL_Adjust : -RW_CL_Adjust) : \
(RW_Extra_Crop_LR >= RW_CL_Adjust) ? RW_CL_Adjust : -RW_CL_Adjust
RW_CR_Adjust = (CR % Crop_WMod == 0) ? 0 : Crop_WMod - (CR % Crop_WMod)
RW_CR_Adjust = (CSplit == 1) ? \
((RW_Non_Mod_Crop_LR >= RW_CR_Adjust) ? RW_CR_Adjust : -RW_CR_Adjust) : \
(RW_Extra_Crop_LR >= RW_CR_Adjust) ? RW_CR_Adjust : -RW_CR_Adjust

RW_Extra_Height_Crop = Cropped_Source_Height - RW_CT_Adjust - RW_CB_Adjust - RW_Height
F_RW_Extra_Height_Crop = float(RW_Extra_Height_Crop)

RW_Extra_CT = CroppedMoreTop ? \
(ModTwoHeight ? (RW_Extra_Height_Crop / 4) * 2 : RW_Extra_Height_Crop / 2) : \
(ModTwoHeight ? round(F_RW_Extra_Height_Crop / 4.0) * 2 : round(F_RW_Extra_Height_Crop / 2.0))
RW_Extra_CB = RW_Extra_Height_Crop - RW_Extra_CT

RW_Extra_Crop_T = RW_Extra_CT + RW_CT_Adjust
RW_Extra_Crop_B = RW_Extra_CB + RW_CB_Adjust

RW_CL = \
(CSplit == 1) ? CL + RW_CL_Adjust + RW_Extra_Mod_Crop_LR : (CSplit == 2) ? CL + RW_CL_Adjust : 0
RW_CT = \
(CSplit == 1) ? CT + RW_Extra_Crop_T : (CSplit == 2) ? CT + RW_CT_Adjust : 0
RW_CR = \
(CSplit == 1) ? CR + RW_CR_Adjust + RW_Extra_Mod_Crop_LR : (CSplit == 2) ? CR + RW_CR_Adjust : 0
RW_CB = \
(CSplit == 1) ? CB + RW_Extra_Crop_B : (CSplit == 2) ? CB + RW_CB_Adjust : 0

RW_RCL = (CSplit == 1) ? RW_Non_Mod_Crop_LR - RW_CL_Adjust : \
(CSplit == 2) ? RW_Extra_Crop_LR - RW_CL_Adjust : (CL + RW_Extra_Crop_LR)
RW_RCT = (CSplit == 1) ? 0 : (CSplit == 2) ? RW_Extra_CT : CT + RW_Extra_Crop_T
RW_RCR = (CSplit == 1) ? RW_Non_Mod_Crop_LR - RW_CR_Adjust : \
(CSplit == 2) ? RW_Extra_Crop_LR - RW_CR_Adjust : (CR + RW_Extra_Crop_LR)
RW_RCB = (CSplit == 1) ? 0 : (CSplit == 2) ? RW_Extra_CB : CB + RW_Extra_Crop_B

F_RW_Cropped_Width = F_Cropped_Source_Width - F_RW_Extra_Width_Crop
RW_Cropped_Height = Cropped_Source_Height - RW_Extra_Crop_T - RW_Extra_Crop_B
F_RW_Cropped_Height = float(RW_Cropped_Height)


# ========== Resize Width Only Mode - Cropped Aspect Ratios =====================


RW_Cropped_StorageAR = F_RW_Cropped_Width / F_RW_Cropped_Height
RW_Cropped_DAR = !AnamorphicInput ? RW_Cropped_StorageAR : \
IsInputDAR ? F_RW_Cropped_Width * F_Source_Height * InputDAR / F_RW_Cropped_Height / F_Source_Width : \
F_RW_Cropped_Width * InputSAR / F_RW_Cropped_Height


# ========== Resize Width Only Mode - Crop & Resize =============================


RW_Video = Eval("Auto_Cropped_Source.crop(RW_CL, RW_CT, -RW_CR, -RW_CB, align=CAlign)."+Resizer+\
"(RW_Width, RW_Height, src_left=RW_RCL, src_top=RW_RCT, src_width=-RW_RCR, src_height=-RW_RCB)")

""", "Resize Width Only Eval") : FullResizing ? Eval("""


# ===============================================================================
# ========== Full Resizing - Default Width, Height & Aspect Ratios ==============
# ===============================================================================


IsAutoAspect = AutoAspect && !IsCropDAR && !IsOutputDAR && (Borders || !(OutWidth > 0 < OutHeight))

Resizing_Width = (OutWidth == 0) ? floor(F_Cropped_Source_Width * Source_SAR / F_Mod) * Mod : OutWidth
F_Resizing_Width = float(Resizing_Width)
Resizing_Height = (OutHeight == 0) ? floor(F_Cropped_Source_Height / F_HMod) * HMod : OutHeight
F_Resizing_Height = float(Resizing_Height)

Resizing_StorageAR = F_Resizing_Width / F_Resizing_Height
Resizing_DAR = IsOutputDAR && Borders && !IsCropDAR ? Cropped_Source_DAR : \
IsCropDAR ? CropDAR : IsOutputDAR ? OutputDAR : Cropped_Source_DAR
Resizing_SAR = \
!AnamorphicOutput ? 1.0 : IsOutputDAR ? F_Resizing_Height * OutputDAR / F_Resizing_Width : OutputSAR

IsAutoAspect ? Eval("

IsAspect169 = !Borders ? (1.739 < Resizing_DAR < 1.829) : (1.777778 < Resizing_DAR < 1.829)
IsAspect43 = !Borders ? (1.27 < Resizing_DAR < 1.35) : (1.27 < Resizing_DAR < 1.333333)

H169 = !IsOutputSAR ? F_Resizing_Width * 9.0 / 16.0 : F_Resizing_Width * OutputSAR * 9.0 / 16.0
H43 = !IsOutputSAR ? F_Resizing_Width * 3.0 / 4.0 : F_Resizing_Width * OutputSAR * 3.0 / 4.0
W169 = !IsOutputSAR ? F_Resizing_Height * 16.0 / 9.0 : F_Resizing_Height * 16.0 / 9.0 / OutputSAR
W43 = !IsOutputSAR ? F_Resizing_Height * 4.0 / 3.0 : F_Resizing_Height * 4.0 / 3.0 / OutputSAR

IsHeight169Mod = (abs(round(H169) - H169) < 0.0001) && (round(H169) % Crop_HMod == 0)
IsHeight43Mod = (abs(round(H43) - H43) < 0.0001) && (round(H43) % Crop_HMod == 0)
IsWidth169Mod = (abs(round(W169) - W169) < 0.0001) && (round(W169) % Crop_WMod == 0)
IsWidth43Mod = (abs(round(W43) - W43) < 0.0001) && (round(W43) % Crop_WMod == 0)

Height169 = IsHeight169Mod ? round(H169) : H169
Height43 = IsHeight43Mod ? round(H43) : H43
Width169 = IsWidth169Mod ? round(W169) : W169
Width43 = IsWidth43Mod ? round(W43) : W43

IsHeight169 = IsAspect169 && IsHeight169Mod
IsHeight43 = IsAspect43 && IsHeight43Mod
IsWidth169 = IsAspect169 && IsWidth169Mod
IsWidth43 = IsAspect43 && IsWidth43Mod

", "Full Resizing, AutoAspect 1 Eval") : Eval("

IsHeight169=false      IsHeight43=false      IsWidth169=false      IsWidth43=false

", "Full Resizing, AutoAspect 2 Eval")


# ===============================================================================
# ========== Full Resizing Mode (A) - Height Calculated From Width ==============
# ===============================================================================


F_Intermediate_Height = F_Resizing_Width * Resizing_SAR / Resizing_DAR
F_Intermediate_Aspect_Height = \
(abs(F_Intermediate_Height - round(F_Intermediate_Height)) < 0.0001) && \
(round(F_Intermediate_Height) % Crop_HMod == 0) ? float(round(F_Intermediate_Height)) : \
F_Intermediate_Height
F_Height_Adjust = F_Intermediate_Aspect_Height - (floor(F_Intermediate_Aspect_Height / F_HMod) * HMod)
F_Height_Adjust_Up = F_Intermediate_Aspect_Height + F_HMod - F_Height_Adjust
F_Height_Adjust_Down = F_Intermediate_Aspect_Height - F_Height_Adjust
F_Adjusted_Height_1 = ((F_Height_Adjust_Up - F_Intermediate_Aspect_Height) < (F_HMod / 2.0)) ? \
F_Height_Adjust_Up : F_Height_Adjust_Down
F_Adjusted_Height_2 = IsHeight169 ? Height169 : IsHeight43 ? Height43 : F_Adjusted_Height_1

F_Aspect_Height = IsOutputDAR && Bordered && !IsCropDAR ? F_Adjusted_Height_1 : \
IsOutputDAR ? (IsCropDAR ? F_Adjusted_Height_1 : F_Intermediate_Aspect_Height) : \
Bordered || (OutHeight == 0) ? F_Adjusted_Height_2 : F_Resizing_Height

F_CRA_Resizing_Height = IsOutputDAR && Borders && !IsCropDAR ? F_Adjusted_Height_1 : \
IsOutputDAR ? (IsCropDAR ? F_Adjusted_Height_1 : F_Resizing_Height) : F_Aspect_Height
CRA_Resizing_Height = round(F_CRA_Resizing_Height)

CRA_Cropping_DAR = F_Resizing_Width * Resizing_SAR / F_Aspect_Height

(abs(CRA_Cropping_DAR - Cropped_Source_DAR) < 0.0001) ? Eval("

F_CRA_Extra_Width_Crop = 0.0
F_CRA_Extra_Height_Crop = 0.0

", "Full Resizing A1 Eval") : (CRA_Cropping_DAR < Cropped_Source_DAR) ? Eval("

F_CRA_Extra_Width_Crop = \
!AnamorphicInput ? \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Resizing_Width * Resizing_SAR / F_Aspect_Height) : \
IsInputDAR ? \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Resizing_Width * F_Source_Width * Resizing_SAR / InputDAR / F_Aspect_Height / F_Source_Height) : \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Resizing_Width * Resizing_SAR / F_Aspect_Height / InputSAR)
F_CRA_Extra_Height_Crop = 0.0

", "Full Resizing A2 Eval") : (CRA_Cropping_DAR > Cropped_Source_DAR) ? Eval("

F_CRA_Extra_Width_Crop = 0.0
F_CRA_Extra_Height_Crop = \
!AnamorphicInput ? \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Aspect_Height / F_Resizing_Width / Resizing_SAR) : \
IsInputDAR ? \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Aspect_Height * F_Source_Height * InputDAR / F_Resizing_Width / Resizing_SAR / F_Source_Width) : \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Aspect_Height * InputSAR / F_Resizing_Width / Resizing_SAR)

", "Full Resizing A3 Eval") : nop()


# ========== Full Resizing Mode (A) - Cropping ==================================


CRA_Extra_Crop_LR = max(0, F_CRA_Extra_Width_Crop / 2.0)
CRA_Extra_Crop_TB = max(0, F_CRA_Extra_Height_Crop / 2.0)

CRA_Non_Mod_Crop_LR = CRA_Extra_Crop_LR - (floor(CRA_Extra_Crop_LR / F_Crop_WMod) * Crop_WMod)
CRA_Extra_Mod_Crop_LR = round(CRA_Extra_Crop_LR - CRA_Non_Mod_Crop_LR)
CRA_Non_Mod_Crop_TB = CRA_Extra_Crop_TB - (floor(CRA_Extra_Crop_TB / F_Crop_HMod) * Crop_HMod)
CRA_Extra_Mod_Crop_TB = round(CRA_Extra_Crop_TB - CRA_Non_Mod_Crop_TB)

CRA_CL_Adjust = (CL % Crop_WMod == 0) ? 0 : Crop_WMod - (CL % Crop_WMod)
CRA_CL_Adjust = (CSplit == 1) ? \
((CRA_Non_Mod_Crop_LR >= CRA_CL_Adjust) ? CRA_CL_Adjust : -CRA_CL_Adjust) : \
(CRA_Extra_Crop_LR >= CRA_CL_Adjust) ? CRA_CL_Adjust : -CRA_CL_Adjust
CRA_CT_Adjust = (CT % Crop_HMod == 0) ? 0 : Crop_HMod - (CT % Crop_HMod)
CRA_CT_Adjust = (CSplit == 1) ? \
((CRA_Non_Mod_Crop_TB >= CRA_CT_Adjust) ? CRA_CT_Adjust : -CRA_CT_Adjust) : \
(CRA_Extra_Crop_TB >= CRA_CT_Adjust) ? CRA_CT_Adjust : -CRA_CT_Adjust
CRA_CR_Adjust = (CR % Crop_WMod == 0) ? 0 : Crop_WMod - (CR % Crop_WMod)
CRA_CR_Adjust = (CSplit == 1) ? \
((CRA_Non_Mod_Crop_LR >= CRA_CR_Adjust) ? CRA_CR_Adjust : -CRA_CR_Adjust) : \
(CRA_Extra_Crop_LR >= CRA_CR_Adjust) ? CRA_CR_Adjust : -CRA_CR_Adjust
CRA_CB_Adjust = (CB % Crop_HMod == 0) ? 0 : Crop_HMod - (CB % Crop_HMod)
CRA_CB_Adjust = (CSplit == 1) ? \
((CRA_Non_Mod_Crop_TB >= CRA_CB_Adjust) ? CRA_CB_Adjust : -CRA_CB_Adjust) : \
(CRA_Extra_Crop_TB >= CRA_CB_Adjust) ? CRA_CB_Adjust : -CRA_CB_Adjust

CRA_CL = \
(CSplit == 1) ? CL + CRA_CL_Adjust + CRA_Extra_Mod_Crop_LR : (CSplit == 2) ? CL + CRA_CL_Adjust : 0
CRA_CT = \
(CSplit == 1) ? CT + CRA_CT_Adjust + CRA_Extra_Mod_Crop_TB : (CSplit == 2) ? CT + CRA_CT_Adjust : 0
CRA_CR = \
(CSplit == 1) ? CR + CRA_CR_Adjust + CRA_Extra_Mod_Crop_LR : (CSplit == 2) ? CR + CRA_CR_Adjust : 0
CRA_CB = \
(CSplit == 1) ? CB + CRA_CB_Adjust + CRA_Extra_Mod_Crop_TB : (CSplit == 2) ? CB + CRA_CB_Adjust : 0

CRA_RCL = (CSplit == 1) ? CRA_Non_Mod_Crop_LR - CRA_CL_Adjust : \
(CSplit == 2) ? CRA_Extra_Crop_LR - CRA_CL_Adjust : (CL + CRA_Extra_Crop_LR)
CRA_RCT = (CSplit == 1) ? CRA_Non_Mod_Crop_TB - CRA_CT_Adjust : \
(CSplit == 2) ? CRA_Extra_Crop_TB - CRA_CT_Adjust : (CT + CRA_Extra_Crop_TB)
CRA_RCR = (CSplit == 1) ? CRA_Non_Mod_Crop_LR - CRA_CR_Adjust : \
(CSplit == 2) ? CRA_Extra_Crop_LR - CRA_CR_Adjust : (CR + CRA_Extra_Crop_LR)
CRA_RCB = (CSplit == 1) ? CRA_Non_Mod_Crop_TB - CRA_CB_Adjust : \
(CSplit == 2) ? CRA_Extra_Crop_TB - CRA_CB_Adjust : (CB + CRA_Extra_Crop_TB)

F_CRA_Cropped_Width = Cropped_Source_Width - F_CRA_Extra_Width_Crop
F_CRA_Cropped_Height = Cropped_Source_Height - F_CRA_Extra_Height_Crop


# ========== Full Resizing Mode (A) - Cropped Aspect Ratios =====================


CRA_Cropped_StorageAR = F_CRA_Cropped_Width / F_CRA_Cropped_Height
CRA_Cropped_DAR = !AnamorphicInput ? CRA_Cropped_StorageAR : IsInputDAR ? \
F_CRA_Cropped_Width * F_Source_Height * InputDAR / F_CRA_Cropped_Height / F_Source_Width : \
F_CRA_Cropped_Width * InputSAR / F_CRA_Cropped_Height


# ===============================================================================
# ========== Full Resizing Mode (B) - Width Calculated From Height ==============
# ===============================================================================


F_Intermediate_Width = F_Resizing_Height * Resizing_DAR / Resizing_SAR
F_Intermediate_Aspect_Width = \
(abs(F_Intermediate_Width - round(F_Intermediate_Width)) < 0.0001) && \
(round(F_Intermediate_Width) % Crop_WMod == 0) ? float(round(F_Intermediate_Width)) : \
F_Intermediate_Width
F_Width_Adjust = F_Intermediate_Aspect_Width - (floor(F_Intermediate_Aspect_Width / F_Mod) * Mod)
F_Width_Adjust_Up = F_Intermediate_Aspect_Width + Mod - F_Width_Adjust
F_Width_Adjust_Down = F_Intermediate_Aspect_Width - F_Width_Adjust
F_Adjusted_Width_1 = ((F_Width_Adjust_Up - F_Intermediate_Aspect_Width) < (F_Mod / 2.0)) ? \
F_Width_Adjust_Up : F_Width_Adjust_Down
F_Adjusted_Width_2 = IsWidth169 ? Width169 : IsWidth43 ? Width43 : F_Adjusted_Width_1

F_Aspect_Width = IsOutputDAR && Borders && !IsCropDAR ? F_Adjusted_Width_1 : \
IsOutputDAR ? (IsCropDAR ? F_Adjusted_Width_1 : F_Intermediate_Aspect_Width) : \
Bordered || (OutWidth == 0) ? F_Adjusted_Width_2 : F_Resizing_Width

F_CRB_Resizing_Width = IsOutputDAR && Borders && !IsCropDAR ? F_Adjusted_Width_1 : \
IsOutputDAR ? (IsCropDAR ? F_Adjusted_Width_1 : F_Resizing_Width) : F_Aspect_Width
CRB_Resizing_Width = round(F_CRB_Resizing_Width)

CRB_Cropping_DAR = F_Aspect_Width * Resizing_SAR / F_Resizing_Height

(abs(CRB_Cropping_DAR - Cropped_Source_DAR) < 0.0001) ? Eval("

F_CRB_Extra_Width_Crop = 0.0
F_CRB_Extra_Height_Crop = 0.0

", "Full Resizing B1 Eval") : (CRB_Cropping_DAR < Cropped_Source_DAR) ? Eval("

F_CRB_Extra_Width_Crop = \
!AnamorphicInput ? \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Aspect_Width * Resizing_SAR / F_Resizing_Height) : \
IsInputDAR ? \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Aspect_Width * Resizing_SAR * F_Source_Width / InputDAR / F_Resizing_Height / F_Source_Height) : \
Cropped_Source_Width - \
(F_Cropped_Source_Height * F_Aspect_Width * Resizing_SAR / F_Resizing_Height / InputSAR)
F_CRB_Extra_Height_Crop = 0.0

", "Full Resizing B2 Eval") : (CRB_Cropping_DAR > Cropped_Source_DAR) ? Eval("

F_CRB_Extra_Width_Crop = 0.0
F_CRB_Extra_Height_Crop = \
!AnamorphicInput ? \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Resizing_Height / F_Aspect_Width / Resizing_SAR) : \
IsInputDAR ? \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Resizing_Height * F_Source_Height * InputDAR / F_Aspect_Width / Resizing_SAR / F_Source_Width) : \
Cropped_Source_Height - \
(F_Cropped_Source_Width * F_Resizing_Height * InputSAR / F_Aspect_Width / Resizing_SAR)

", "Full Resizing B3 Eval") : nop()


# ========== Full Resizing Mode (B) - Cropping ==================================


CRB_Extra_Crop_LR = max(0, F_CRB_Extra_Width_Crop / 2.0)
CRB_Extra_Crop_TB = max(0, F_CRB_Extra_Height_Crop / 2.0)

CRB_Non_Mod_Crop_LR = CRB_Extra_Crop_LR - (floor(CRB_Extra_Crop_LR / F_Crop_WMod) * Crop_WMod)
CRB_Extra_Mod_Crop_LR = round(CRB_Extra_Crop_LR - CRB_Non_Mod_Crop_LR)
CRB_Non_Mod_Crop_TB = CRB_Extra_Crop_TB - (floor(CRB_Extra_Crop_TB / F_Crop_HMod) * Crop_HMod)
CRB_Extra_Mod_Crop_TB = round(CRB_Extra_Crop_TB - CRB_Non_Mod_Crop_TB)

CRB_CL_Adjust = (CL % Crop_WMod == 0) ? 0 : Crop_WMod - (CL % Crop_WMod)
CRB_CL_Adjust = (CSplit == 1) ? \
((CRB_Non_Mod_Crop_LR >= CRB_CL_Adjust) ? CRB_CL_Adjust : -CRB_CL_Adjust) : \
(CRB_Extra_Crop_LR >= CRB_CL_Adjust) ? CRB_CL_Adjust : -CRB_CL_Adjust
CRB_CT_Adjust = (CT % Crop_HMod == 0) ? 0 : Crop_HMod - (CT % Crop_HMod)
CRB_CT_Adjust = (CSplit == 1) ? \
((CRB_Non_Mod_Crop_TB >= CRB_CT_Adjust) ? CRB_CT_Adjust : -CRB_CT_Adjust) : \
(CRB_Extra_Crop_TB >= CRB_CT_Adjust) ? CRB_CT_Adjust : -CRB_CT_Adjust
CRB_CR_Adjust = (CR % Crop_WMod == 0) ? 0 : Crop_WMod - (CR % Crop_WMod)
CRB_CR_Adjust = (CSplit == 1) ? \
((CRB_Non_Mod_Crop_LR >= CRB_CR_Adjust) ? CRB_CR_Adjust : -CRB_CR_Adjust) : \
(CRB_Extra_Crop_LR >= CRB_CR_Adjust) ? CRB_CR_Adjust : -CRB_CR_Adjust
CRB_CB_Adjust = (CB % Crop_HMod == 0) ? 0 : Crop_HMod - (CB % Crop_HMod)
CRB_CB_Adjust = (CSplit == 1) ? \
((CRB_Non_Mod_Crop_TB >= CRB_CB_Adjust) ? CRB_CB_Adjust : -CRB_CB_Adjust) : \
(CRB_Extra_Crop_TB >= CRB_CB_Adjust) ? CRB_CB_Adjust : -CRB_CB_Adjust

CRB_CL = \
(CSplit == 1) ? CL + CRB_CL_Adjust + CRB_Extra_Mod_Crop_LR : (CSplit == 2) ? CL + CRB_CL_Adjust : 0
CRB_CT = \
(CSplit == 1) ? CT + CRB_CT_Adjust + CRB_Extra_Mod_Crop_TB : (CSplit == 2) ? CT + CRB_CT_Adjust : 0
CRB_CR = \
(CSplit == 1) ? CR + CRB_CR_Adjust + CRB_Extra_Mod_Crop_LR : (CSplit == 2) ? CR + CRB_CR_Adjust : 0
CRB_CB = \
(CSplit == 1) ? CB + CRB_CB_Adjust + CRB_Extra_Mod_Crop_TB : (CSplit == 2) ? CB + CRB_CB_Adjust : 0

CRB_RCL = (CSplit == 1) ? CRB_Non_Mod_Crop_LR - CRB_CL_Adjust : \
(CSplit == 2) ? CRB_Extra_Crop_LR - CRB_CL_Adjust : (CL + CRB_Extra_Crop_LR)
CRB_RCT = (CSplit == 1) ? CRB_Non_Mod_Crop_TB - CRB_CT_Adjust : \
(CSplit == 2) ? CRB_Extra_Crop_TB - CRB_CT_Adjust : (CT + CRB_Extra_Crop_TB)
CRB_RCR = (CSplit == 1) ? CRB_Non_Mod_Crop_LR - CRB_CR_Adjust : \
(CSplit == 2) ? CRB_Extra_Crop_LR - CRB_CR_Adjust : (CR + CRB_Extra_Crop_LR)
CRB_RCB = (CSplit == 1) ? CRB_Non_Mod_Crop_TB - CRB_CB_Adjust : \
(CSplit == 2) ? CRB_Extra_Crop_TB - CRB_CB_Adjust : (CB + CRB_Extra_Crop_TB)

F_CRB_Cropped_Width = Cropped_Source_Width - F_CRB_Extra_Width_Crop
F_CRB_Cropped_Height = Cropped_Source_Height - F_CRB_Extra_Height_Crop


# ========== Full Resizing Mode (B) - Cropped Aspect Ratios =====================


CRB_Cropped_StorageAR = F_CRB_Cropped_Width / F_CRB_Cropped_Height
CRB_Cropped_DAR = !AnamorphicInput ? CRB_Cropped_StorageAR : IsInputDAR ? \
F_CRB_Cropped_Width * F_Source_Height * InputDAR / F_CRB_Cropped_Height / F_Source_Width : \
F_CRB_Cropped_Width * InputSAR / F_CRB_Cropped_Height


""", "Full Resizing Eval") : nop()


# ===============================================================================
# ========== Determine The Cropping & Resizing To Use ===========================
# ===============================================================================


CR_Num = NoResizing ? 1 : ResizeWidthOnly ? 2 : \
Bordered && (OutWidth > 0 < OutHeight) ? \
((Resizing_DAR <= (Resizing_StorageAR * Resizing_SAR)) ? 4 : 3) : \
(OutWidth > 0 == OutHeight) ? 3 : 4


# ========== Output Width, Height & Aspect Ratios ===============================


CRVideo_Width = \
(CR_Num == 1) ? width(CM_Video) : \
(CR_Num == 2) ? RW_Width : \
(CR_Num == 3) ? Resizing_Width : CRB_Resizing_Width
F_CRVideo_Width = float(CRVideo_Width)

CRVideo_Height = \
(CR_Num == 1) ? height(CM_Video) : \
(CR_Num == 2) ? RW_Height : \
(CR_Num == 3) ? CRA_Resizing_Height : Resizing_Height
F_CRVideo_Height = float(CRVideo_Height)

CRVideo_StorageAR = F_CRVideo_Width / F_CRVideo_Height

CRVideo_DAR = NoResizing && !AnamorphicInput ? CRVideo_StorageAR : \
NoResizing && AnamorphicInput ? \
(IsInputDAR ? F_CRVideo_Width * F_Source_Height * InputDAR / F_CRVideo_Height / F_Source_Width : \
F_CRVideo_Width * Source_SAR / F_CRVideo_Height) : \
!AnamorphicOutput ? CRVideo_StorageAR : \
ResizeWidthOnly ? F_CRVideo_Width * RW_Resizing_SAR / F_CRVideo_Height : \
F_CRVideo_Width * Resizing_SAR / F_CRVideo_Height

Final_Width = CleanBorders ? Source_Width : \
Bordered && (OutWidth > CRVideo_Width) && (NoResizing || ResizeWidthOnly) ? OutWidth : \
Bordered && FullResizing && (OutWidth > CRVideo_Width) && (Resizing_StorageAR > CRVideo_StorageAR) ? \
OutWidth : CRVideo_Width

Final_Height = CleanBorders ? Source_Height : \
Bordered && (OutHeight > CRVideo_Height) && (NoResizing || (ResizeWidthOnly && !IsOutputDAR)) ? OutHeight : \
Bordered && FullResizing && (OutHeight > CRVideo_Height) && (Resizing_StorageAR < CRVideo_StorageAR) ? \
OutHeight : CRVideo_Height

F_Final_Width = float(Final_Width)
F_Final_Height = float(Final_Height)
Final_StorageAR = F_Final_Width / F_Final_Height

Final_DAR = NoResizing && !AnamorphicInput ? Final_StorageAR : \
NoResizing && AnamorphicInput ? \
(IsInputDAR ? F_Final_Width * F_Source_Height * InputDAR / F_Final_Height / F_Source_Width : \
F_Final_Width * Source_SAR / F_Final_Height) : \
!AnamorphicOutput ? Final_StorageAR : \
ResizeWidthOnly ? F_Final_Width * RW_Resizing_SAR / F_Final_Height : \
F_Final_Width * Resizing_SAR / F_Final_Height

IsAnamorphicInput = AnamorphicInput && (abs(Source_DAR - Source_StorageAR) > 0.0001)
IsAnamorphicOutput = AnamorphicOutput && (abs(Final_DAR - Final_StorageAR) > 0.0001)

F_Final_Display_Width = \
!IsAnamorphicOutput ? F_Final_Width : \
NoResizing ? F_Final_Width * Source_SAR : \
ResizeWidthOnly ? F_Final_Width * RW_Resizing_SAR : \
F_Final_Width * Resizing_SAR

Final_SAR = !IsAnamorphicOutput ? 1.0 : \
NoResizing ? Source_SAR : ResizeWidthOnly ? RW_Resizing_SAR : Resizing_SAR


# ========== Full Resizing Mode - Color Correct, Crop & Resize ==================


ColorCorrection ? Eval("""

IsSDSource = (F_Source_Display_Width <= 1056) && (Source_Height < 600)
IsHDSource = ((F_Source_Display_Width > 1056) || (Source_Height >= 600)) && \
((F_Source_Display_Width <= 1920) && (Source_Height <= 1080))
IsUHDSource = (F_Source_Display_Width > 1920) || (Source_Height > 1080)

IsSDOut = (F_Final_Display_Width <= 1056) && (Final_Height < 600)
IsHDOut = ((F_Final_Display_Width > 1056) || (Final_Height >= 600)) && \
((F_Final_Display_Width <= 1920) && (Final_Height <= 1080))
IsUHDOut = (F_Final_Display_Width > 1920) || (Final_Height > 1080)

Downscale = IsHDSource && IsSDOut ? 1 : IsUHDSource && IsHDOut ? 2 : IsUHDSource && IsSDOut ? 3 : 4
Upscale = IsSDSource && IsHDOut ? 1 : IsHDSource && IsUHDOut ? 2 : IsSDSource && IsUHDOut ? 3 : 4

CCResizer = RightStr(Resizer, 6) == "Resize" ? LeftStr(Resizer, StrLen(Resizer)-6) : Resizer

ResizeWithDitherTools = (ColorCorrect == 2) && ((DownScale != 4) || (UpScale != 4)) && \
((CCResizer == "Bilinear") || (CCResizer == "Bicubic") || (CCResizer == "Blackman") || \
(CCResizer == "Gauss") || (CCResizer == "Lanczos") || (CCResizer == "Lanczos4") || (CCResizer == "Point") || \
(CCResizer == "Spline16") || (CCResizer == "Spline36") || (CCResizer == "Spline64") || (CCResizer == "Sinc"))

""", "Color Correction Eval") : nop()

(CR_Num == 3) && ColorCorrection && ((DownScale != 4) || (UpScale != 4)) ? Eval("""

CRA_Video = Auto_Cropped_Source.crop(CRA_CL, CRA_CT, -CRA_CR, -CRA_CB, align=CAlign)\
.CR_ColorCorrectResize(Resizing_Width, CRA_Resizing_Height, CRA_RCL, CRA_RCT, CRA_RCR, CRA_RCB, \
ColorCorrect, Color_Format, Downscale, Upscale, Resizer, CCResizer, IsAvisynthPlus, Source_Bit_Depth, \
ResizeWithDitherTools)

""", "Full Resizing A4 Eval") : (CR_Num == 3) && FullResizing ? Eval("""

CRA_Video = Eval("Auto_Cropped_Source.crop(CRA_CL, CRA_CT, -CRA_CR, -CRA_CB, align=CAlign)\
."+Resizer+"(Resizing_Width, CRA_Resizing_Height, \
src_left=CRA_RCL, src_top=CRA_RCT, src_width=-CRA_RCR, src_height=-CRA_RCB)")

""", "Full Resizing A5 Eval") : (CR_Num == 4) && ColorCorrection && ((DownScale != 4) || (UpScale != 4)) ? Eval("""

CRB_Video = Auto_Cropped_Source.crop(CRB_CL, CRB_CT, -CRB_CR, -CRB_CB, align=CAlign)\
.CR_ColorCorrectResize(CRB_Resizing_Width, Resizing_Height, CRB_RCL, CRB_RCT, CRB_RCR, CRB_RCB, \
ColorCorrect, Color_Format, Downscale, Upscale, Resizer, CCResizer, IsAvisynthPlus, Source_Bit_Depth, \
ResizeWithDitherTools)

""", "Full Resizing B4 Eval") : (CR_Num == 4) && FullResizing ? Eval("""

CRB_Video = Eval("Auto_Cropped_Source.crop(CRB_CL, CRB_CT, -CRB_CR, -CRB_CB, align=CAlign)\
."+Resizer+"(CRB_Resizing_Width, Resizing_Height, \
src_left=CRB_RCL, src_top=CRB_RCT, src_width=-CRB_RCR, src_height=-CRB_RCB)")

""", "Full Resizing B5 Eval") : nop()


# ===============================================================================
# ========== Cropped Resized Video ==============================================
# ===============================================================================


CRVideo = (CR_Num == 1) ? CM_Video : (CR_Num == 2) ? RW_Video : (CR_Num == 3) ? CRA_Video : CRB_Video


# ========== Add Borders As Required ============================================


IsBordered = Bordered && ((Final_Width > CRVideo_Width) || (Final_Height > CRVideo_Height))
ShowBorderInfo = Borders || CleanBorders || IsBordered

IsBordered ? Eval("""

BorderMod = ModFourWidth ? 4 : ModTwoWidth ? 2 : 1
BorderHMod = ModTwoHeight ? 2 : 1
F_BorderMod = float(BorderMod)
F_BorderHMod = float(BorderHMod)

WidthBorders = Final_Width - CRVideo_Width
EvenWidthSplit = WidthBorders % (BorderMod * 2) == 0
F_WidthSplit = float(WidthBorders) / 2.0
BL_Adjust = F_WidthSplit - (floor(F_WidthSplit / F_BorderMod) * BorderMod)
BL_Adjust_Up = round(F_WidthSplit + BorderMod - BL_Adjust)
BL_Adjust_Down = round(F_WidthSplit - BL_Adjust)
BL = EvenWidthSplit ? WidthBorders / 2 : CroppedMoreLeft ? BL_Adjust_Up : BL_Adjust_Down
BR = WidthBorders - BL

HeightBorders = Final_Height - CRVideo_Height
EvenHeightSplit = HeightBorders % (BorderHMod * 2) == 0
F_HeightSplit = float(HeightBorders) / 2.0
BT_Adjust = F_HeightSplit - (floor(F_HeightSplit / F_BorderHMod) * BorderHMod)
BT_Adjust_Up = round(F_HeightSplit + BorderHMod - BT_Adjust)
BT_Adjust_Down = round(F_HeightSplit - BT_Adjust)
BT = EvenHeightSplit ? HeightBorders / 2 : CroppedMoreTop ? BT_Adjust_Up : BT_Adjust_Down
BB = HeightBorders - BT

WidthTest = (BL >= 16) && (BR >= 16)
HeightTest = (BT >= 16) && (BB >= 16)

Bordered_Video = !Frosty || (!WidthTest && !HeightTest) ? CRVideo.AddBorders(BL, BT, BR, BB, color=BColor) : \
(Final_StorageAR >= CRVideo_StorageAR) ? (!WidthTest ? CRVideo.AddBorders(BL, BT, BR, BB, color=BColor) : \
CRVideo.CR_FrostyBorders(Final_Width, CRVideo_Height, \
CRVideo_StorageAR, Final_StorageAR, BL, 0, BR, 0).AddBorders(0, BT, 0, BB, color=BColor)) : \
(Final_StorageAR < CRVideo_StorageAR) ? (!HeightTest ? CRVideo.AddBorders(BL, BT, BR, BB, color=BColor) : \
CRVideo.CR_FrostyBorders(CRVideo_Width, Final_Height, \
CRVideo_StorageAR, Final_StorageAR, 0, BT, 0, BB).AddBorders(BL, 0, BR, 0, color=BColor)) : CRVideo

""", "Bordered 1 Eval") : Eval("""

BL=0      BT=0      BR=0      BB=0

""", "Bordered 2 Eval")

CroppedResizedVideo = !IsBordered ? CRVideo : Bordered_Video


# ========== Global Aspect Ratios & Resolutions =================================


CR_MeGUI_DAR() ? Eval("""

MInDARX = IsMInDAR ? MeGUI_darx : 0
MInDARY = IsMInDAR ? MeGUI_dary : 0
global gMPassDAR = IsMInDAR ? MInDAR : IsMPassThru ? MPassDAR : 0.0
global gMPassDARX = IsMInDAR ? MeGUI_darx : IsMPassThru ? gMPassDARX : 0
global gMPassDARY = IsMInDAR ? MeGUI_dary : IsMPassThru ? gMPassDARY : 0

global MeGUI_darx = !IsAnamorphicOutput ? Undefined() : \
NoResizing && (Source_Width == Final_Width) && (Source_Height == Final_Height) ? \
(IsMInDAR ? MeGUI_darx : IsMPassThru ? gMPassDARX : ContinuedNumerator(Final_DAR, limit=5000)) : \
ContinuedNumerator(Final_DAR, limit=5000)

global MeGUI_dary = !IsAnamorphicOutput ? Undefined() : \
NoResizing && (Source_Width == Final_Width) && (Source_Height == Final_Height) ? \
(IsMInDAR ? MeGUI_dary : IsMPassThru ? gMPassDARY : ContinuedDenominator(Final_DAR, limit=5000)) : \
ContinuedDenominator(Final_DAR, limit=5000)

""", "Global Aspect Ratios 1 Eval") : nop()

IsRMode ? Eval("""

global gPriorWidth = IsCurrentGAutoCPreview || IsAutoCPreview ? Source_Width : \
IsScriptCPreview ? Auto_Cropped_Width : Final_Width
global gPriorHeight = IsCurrentGAutoCPreview || IsAutoCPreview ? Source_Height : \
IsScriptCPreview ? Auto_Cropped_Height : Final_Height

""", "Global Aspect Ratios 2 Eval") : nop()

global gPriorScript = true


# ===============================================================================
# ========== Cropping Previews ==================================================
# ===============================================================================


Try{   F_gPriorWidth=float(gPriorWidth)   F_gPriorHeight=float(gPriorHeight)   IsPriorlWidthHeight=true   }
catch(err){   IsPriorlWidthHeight = false   }

IsPreviewResizing = IsPriorlWidthHeight && (((IsCurrentGAutoCPreview || IsAutoCPreview) && \
((Source_Width != gPriorWidth) || (Source_Height != gPriorHeight))) || \
(IsScriptCPreview && ((Auto_Cropped_Width != gPriorWidth) || (Auto_Cropped_Height != gPriorHeight))) || \
(!IsScriptCPreview && !IsAutoCPreview && !IsCurrentGAutoCPreview && \
((Final_Width != gPriorWidth) || (Final_Height != gPriorHeight))))


# ========== Auto Cropping Preview ==============================================


IsAutoCPreview ? Eval("""

ACP_Sub_Text = !IsPreviewResizing ? "\nAutoCrop Preview" : \
"RMode\nAutoCrop Preview\nResized To " + string(gPriorWidth, "%.0f x ") + string(gPriorHeight, "%.0f") + \
(!IsG1Function || (IsG1Function && !IsG2Function && (IsGMode1 || IsGMode2)) ? "" : \
"\n\n" + (IsGMode0 ? "GMode = 0" : IsGMode1 ? "GMode = 1" : "GMode = 2"))

ACP_Sub_Size = !IsPreviewResizing ? min(F_Source_Width * 0.033, F_Source_Height * 0.035) : \
min(F_gPriorWidth * 0.033, F_gPriorHeight * 0.035)

AutoCPreviewVid = \
SourceVideo.autocrop(mode=1, wMultOf=2, hMultOf=2, leftadd=0, topadd=0, rightadd=0, bottomadd=0, \
threshold=CThresh, samples=CSample, samplestartframe=CStart, sampleendframe=-1, aspect=0)
AutoCPreviewVideo = !IsPreviewResizing ? AutoCPreviewVid : \
AutoCPreviewVid.Spline36Resize(gPriorWidth, gPriorHeight)\
.subtitle(ACP_Sub_Text, x=-1, y=-1, size=ACP_Sub_Size, text_color=$F0FFFF, lsp=20)

""", "Auto Cropping Preview Eval") : nop()


# ========== Global Auto Cropping Preview =======================================


IsCurrentGAutoCPreview ? Eval("""

GACP_Sub_Text = !IsPreviewResizing ? "\nGlobal AutoCrop Preview" : \
"RMode\nGlobal AutoCrop Preview\nResized To " + string(gPriorWidth, "%.0f x ") + string(gPriorHeight, "%.0f") + \
(!IsG1Function || (IsG1Function && !IsG2Function && (IsGMode1 || IsGMode2)) ? "" : \
"\n\n" + (IsGMode0 ? "GMode = 0" : IsGMode1 ? "GMode = 1" : "GMode = 2"))

GACP_Sub_Size = !IsPreviewResizing ? min(F_Source_Width * 0.033, F_Source_Height * 0.035) : \
min(F_gPriorWidth * 0.033, F_gPriorHeight * 0.035)

GAutoCPreviewVideo = !IsPreviewResizing ? SourceVideo : \
SourceVideo.Spline36Resize(gPriorWidth, gPriorHeight)\
.subtitle(GACP_Sub_Text, x=-1, y=-1, size=GACP_Sub_Size, text_color=$F0FFFF, lsp=20)

""", "Global Auto Cropping Preview Eval") : nop()


# ===============================================================================


(Info || IsScriptCPreview) ? Eval("""

Extra_CL = \
NoResizing ? CM_Extra_Crop_L : ResizeWidthOnly ? RW_Extra_Crop_LR : \
(CRVideo == CRA_Video) ? CRA_Extra_Crop_LR : CRB_Extra_Crop_LR
Extra_CT = \
NoResizing ? CM_Extra_Crop_T : ResizeWidthOnly ? RW_Extra_Crop_T : \
(CRVideo == CRA_Video) ? CRA_Extra_Crop_TB : CRB_Extra_Crop_TB
Extra_CR = \
NoResizing ? CM_Extra_Crop_R : ResizeWidthOnly ? RW_Extra_Crop_LR : \
(CRVideo == CRA_Video) ? CRA_Extra_Crop_LR : CRB_Extra_Crop_LR
Extra_CB = \
NoResizing ? CM_Extra_Crop_B : ResizeWidthOnly ? RW_Extra_Crop_B : \
(CRVideo == CRA_Video) ? CRA_Extra_Crop_TB : CRB_Extra_Crop_TB

Total_CL = Extra_CL + CL
Total_CT = Extra_CT + CT
Total_CR = Extra_CR + CR
Total_CB = Extra_CB + CB

""", "Info & Script Cropping Preview Eval") : nop()

(Info || IsScriptCPreview) && IsAvisynthPlus ? Eval("""

#  Avisynth+ currently displays -zz as -0.00 for the following, where zz = float(0): subtitle(string(-zz, "%.2f"))
#  Make it display 0.00 for the following instead (no negative sign), when Info=true
Extra_CR = (Extra_CR == 0) ? 0 : Extra_CR
Extra_CB = (Extra_CB == 0) ? 0 : Extra_CB
Total_CR = (Total_CR == 0) ? 0 : Total_CR
Total_CB = (Total_CB == 0) ? 0 : Total_CB
RW_RCR = ResizeWidthOnly ? ((RW_RCR == 0) ? 0 : RW_RCR) : nop()
RW_RCB = ResizeWidthOnly ? ((RW_RCB == 0) ? 0 : RW_RCB) : nop()
CRA_RCR = (CRVideo == CRA_Video) ? ((CRA_RCR == 0) ? 0 : CRA_RCR) : nop()
CRA_RCB = (CRVideo == CRA_Video) ? ((CRA_RCB == 0) ? 0 : CRA_RCB) : nop()
CRB_RCR = (CRVideo == CRA_Video) ? ((CRB_RCR == 0) ? 0 : CRB_RCR) : nop()
CRB_RCB = (CRVideo == CRA_Video) ? ((CRB_RCB == 0) ? 0 : CRB_RCB) : nop()

""", "Avisynth+ Fix Eval") : nop()


# ========== Script Cropping Preview ============================================


IsScriptCPreview && !Info ? Eval("""

SCP_InDAR_Text = IsMInDAR ? string(MInDARX, "  (DAR  %.0f:") + string(MInDARY, "%.0f)") : \
IsMPassedThru ? string(gMPassDARX, "  (DAR  %.0f:") + string(gMPassDARY, "%.0f)") : CR_FTF(Source_DAR, 2)

SCP_Source_Text = (IsAnyAutoCrop && !IsAnamorphicInput ? "\n\n" : "\n\n\n") + \
(!IsAnyAutoCrop && IsAnamorphicInput ? \
string(Source_Width, "Source\n%.0f x ") + string(Source_Height, "%.0f") : \
string(Source_Width, "Source  %.0f x ") + string(Source_Height, "%.0f")) + \
(AnamorphicInput ? SCP_InDAR_Text : "") + (!IsAnyAutoCrop ? "" : \
string(Auto_Cropped_Width, "\nAuto Cropped  %.0f x ") + string(Auto_Cropped_Height, "%.0f") + \
(AnamorphicInput ? \
(NoResizing && (Auto_Cropped_Width == Source_Width) && (Auto_Cropped_Height == Source_Height) ? \
SCP_InDAR_Text : CR_FTF(Auto_Cropped_DAR, 2)) : "")) + \
(!IsAnamorphicInput ? "\nNot Anamorphic" : "")

SCP_Specified_Cropping_Text = "\n\n\n\n\n\n" + (!IsAnyAutoCrop ? \
string(CL, "Specified Cropping\n(%.0f, ") : string(CL, "Specified Cropping (After AutoC)\n(%.0f, ")) + \
string(CT, "%.0f, ") + string(-CR, "%.0f, ") + string(-CB, "%.0f)")

SCP_Total_Cropping_Text = "\n\n\n\n\n\n\n\n" + \
(!IsAnyAutoCrop ? "Total Cropping\n" : "Total Cropping (After AutoC)\n") + \
(NoResizing ? \
string(Total_CL, "(%.0f, ") + string(Total_CT, "%.0f, ") + \
string(-Total_CR, "%.0f, ") + string(-Total_CB, "%.0f)") : \
ResizeWidthOnly ? \
string(Total_CL, "(%.2f, ") + string(Total_CT, "%.0f, ") + \
string(-Total_CR, "%.2f, ") + string(-Total_CB, "%.0f)") : \
string(Total_CL, "(%.2f, ") + string(Total_CT, "%.2f, ") + \
string(-Total_CR, "%.2f, ") + string(-Total_CB, "%.2f)"))

SCP_Output_Text = "\n\n\n\n\n\n\n" + (!ShowBorderInfo ? (IsAnamorphicOutput ? \
string(CRVideo_Width, "Output\n%.0f x ") + string(CRVideo_Height, "%.0f") : \
string(CRVideo_Width, "Output %.0f x ") + string(CRVideo_Height, "%.0f")) : \
string(CRVideo_Width, "Output\nExc Borders  %.0f x ") + string(CRVideo_Height, "%.0f")) + \
(AnamorphicOutput ? \
(NoResizing && (CRVideo_Width == Source_Width) && (CRVideo_Height == Source_Height) ? \
SCP_InDAR_Text : CR_FTF(CRVideo_DAR, 2)) : "") + (!ShowBorderInfo ? "" : \
string(Final_Width, "\nInc Borders  %.0f x ") + string(Final_Height, "%.0f") + \
(AnamorphicOutput ? \
(NoResizing && (Final_Width == Source_Width) && (Final_Height == Source_Height) ? \
SCP_InDAR_Text : CR_FTF(Final_DAR, 2)) : "")) + \
(!IsAnamorphicOutput ? "\nNot Anamorphic" : CR_FTF(Final_SAR))

SCP_Common_Resize_Text = !IsPreviewResizing ? "" : "\n\nRMode\nCropping Preview Resized To " + \
string(gPriorWidth, "%.0f x ") + string(gPriorHeight, "%.0f")

SCP_NoGMode = !IsG1Function || (IsG1Function && !IsG2Function && (IsGMode1 || IsGMode2))

SCP_GMode_Text = \
SCP_NoGMode ? "" : "\n\n" + (IsGMode0 ? "GMode = 0" : IsGMode1 ? "GMode = 1" : "GMode = 2")

SCP_Break_Text = \
IsPreviewResizing && !SCP_NoGMode ? "" : !IsPreviewResizing && SCP_NoGMode ? "\n\n" : "\n"

SCP_Sub_Color = FullResizing ? $FFFFE0 : $F0FFFF
SCP_Sub_Size = !IsPreviewResizing ? \
min(F_Auto_Cropped_Width * 0.028, F_Auto_Cropped_Height * 0.03) : \
min(F_gPriorWidth * 0.028, F_gPriorHeight * 0.03)
SCP_Sub_Y = ((!IsPreviewResizing ? F_Source_Height : F_gPriorHeight) / 2.0) - \
((!IsPreviewResizing ? F_Source_Height : F_gPriorHeight) * 0.375)

SCP_Preview_Text1 = \
SCP_Break_Text + SCP_Source_Text + SCP_Output_Text + SCP_Common_Resize_Text + SCP_GMode_Text
SCP_Preview_Text2 = SCP_Break_Text + SCP_Specified_Cropping_Text
SCP_Preview_Text3 = SCP_Break_Text + SCP_Total_Cropping_Text

""", "Script Cropping Preview 1 Eval") : nop()

IsScriptCPreview ? Eval("""

CLine_L = (CL == 0) ? 0 : (CL >= CLine) ? CLine : CL
CLine_T = (CT == 0) ? 0 : (CT >= CLine) ? CLine : CT
CLine_R = (CR == 0) ? 0 : (CR >= CLine) ? CLine : CR
CLine_B = (CB == 0) ? 0 : (CB >= CLine) ? CLine : CB

Script_CL = (round(Total_CL) > CL) ? round(Total_CL) : 0
Script_CT = (round(Total_CT) > CT) ? round(Total_CT) : 0
Script_CR = (round(Total_CR) > CR) ? round(Total_CR) : 0
Script_CB = (round(Total_CB) > CB) ? round(Total_CB) : 0

SLine_L = (Script_CL == 0) ? 0 : (Script_CL >= CLine) ? CLine : Script_CL
SLine_T = (Script_CT == 0) ? 0 : (Script_CT >= CLine) ? CLine : Script_CT
SLine_R = (Script_CR == 0) ? 0 : (Script_CR >= CLine) ? CLine : Script_CR
SLine_B = (Script_CB == 0) ? 0 : (Script_CB >= CLine) ? CLine : Script_CB

YV24_Input_Clip = Auto_Cropped_Source.ConvertToYV24()

(CPreview == 1) ? Eval("

Overlay_Clip = BlankClip(YV24_Input_Clip).crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(SLine_L, SLine_T, SLine_R, SLine_B, color=$ADD8E6)\
.AddBorders(Script_CL - SLine_L, Script_CT - SLine_T, Script_CR - SLine_R, Script_CB - SLine_B)\
.crop(CL, CT, -CR, -CB).AddBorders(CLine_L, CLine_T, CLine_R, CLine_B, color=$FFFF00)\
.AddBorders(CL - CLine_L, CT - CLine_T, CR - CLine_R, CB - CLine_B)
Mask_Clip = BlankClip(YV24_Input_Clip).crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(SLine_L, SLine_T, SLine_R, SLine_B, color=$FFFFFF)\
.AddBorders(Script_CL - SLine_L, Script_CT - SLine_T, Script_CR - SLine_R, Script_CB - SLine_B)\
.crop(CL, CT, -CR, -CB).AddBorders(CLine_L, CLine_T, CLine_R, CLine_B, color=$e4e4e4)\
.AddBorders(CL - CLine_L, CT - CLine_T, CR - CLine_R, CB - CLine_B).Levels(16, 1.0, 235, 0, 255, coring=false)

Preview_Clip = Overlay(Auto_Cropped_Source, Overlay_Clip, mask=Mask_Clip)

", "CPreview 1 Eval") : (CPreview == 2) ? Eval("

Overlay_Clip = BlankClip(YV24_Input_Clip).crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(Script_CL, Script_CT, Script_CR, Script_CB, color=$ADD8E6)\
.crop(CL, CT, -CR, -CB).AddBorders(CL, CT, CR, CB, color=$FFFF00)
Mask_Clip = BlankClip(YV24_Input_Clip).crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(Script_CL, Script_CT, Script_CR, Script_CB, color=$7f7f7f)\
.crop(CL, CT, -CR, -CB).AddBorders(CL, CT, CR, CB, color=$4b4b4b).Levels(16, 1.0, 235, 0, 255, coring=false)

Preview_Clip = Overlay(Auto_Cropped_Source, Overlay_Clip, mask=Mask_Clip)

", "CPreview 2 Eval") : Eval("

Overlay_Clip = YV24_Input_Clip.crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(Script_CL, Script_CT, Script_CR, Script_CB, color=$FF0000)\
.crop(CL, CT, -CR, -CB).AddBorders(CL, CT, CR, CB)
Mask_Clip = BlankClip(YV24_Input_Clip, color=$FFFFFF).crop(Script_CL, Script_CT, -Script_CR, -Script_CB)\
.AddBorders(Script_CL, Script_CT, Script_CR, Script_CB, color=$4b4b4b)\
.crop(CL, CT, -CR, -CB).AddBorders(CL, CT, CR, CB).Levels(16, 1.0, 235, 0, 255, coring=false)

Preview_Clip = Overlay(invert(Auto_Cropped_Source), Overlay_Clip, mask=Mask_Clip)

", "CPreview 3 Eval")

Preview_Clip = !IsPreviewResizing ? Preview_Clip : Preview_Clip.Spline36Resize(gPriorWidth, gPriorHeight)

ScriptCPreviewVideo = Info ? Preview_Clip : Preview_Clip\
.subtitle(SCP_Preview_Text1, y=SCP_Sub_Y, size=SCP_Sub_Size, text_color=SCP_Sub_Color, align=8, lsp=20)\
.subtitle(SCP_Preview_Text2, y=SCP_Sub_Y, size=SCP_Sub_Size, text_color=$F0E68C, align=8, lsp=20)\
.subtitle(SCP_Preview_Text3, y=SCP_Sub_Y, size=SCP_Sub_Size, text_color=$B0C4DE, align=8, lsp=20)

""", "Script Cropping Preview 2 Eval") : nop()


# ===============================================================================
# ========== Display Info =======================================================
# ===============================================================================

Info && !IsAutoCPreview && !IsCurrentGAutoCPreview ? Eval("""

InDAR_Text = IsMInDAR ? string(MInDARX, "   (%.0f:") + string(MInDARY, "%.0f)") : \
IsMPassedThru ? string(gMPassDARX, "   (%.0f:") + string(gMPassDARY, "%.0f)") : CR_FTF(Source_DAR, 1)

Info_Clip = IsScriptCPreview ? ScriptCPreviewVideo : !IsPreviewResizing ? CroppedResizedVideo : \
CroppedResizedVideo.Spline36Resize(gPriorWidth, gPriorHeight)

F_Info_Clip_Width = !IsPreviewResizing ? float(width(Info_Clip)) : F_GPriorWidth
F_Info_Clip_Height = !IsPreviewResizing ? float(height(Info_Clip)) : F_GPriorHeight

# ---------- Left Column --------------------------------------------------------

Source_Text = string(Source_Width, "Source Resolution   %.0f x ") + string(Source_Height, "%.0f") + \
string(Source_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(Source_StorageAR, 1) + \
string(Source_DAR, "\nDisplay Aspect Ratio   %.6f") + InDAR_Text + \
"\nSource Format   " + string(Source_Bit_Depth, "%.0f bit  ") + Color_Format

Auto_Cropping_Text = !IsAnyAutoCrop ? "" : \
string(Auto_Cropped_Width, "\n\nAuto Cropped Resolution   %.0f x ") + string(Auto_Cropped_Height, "%.0f") + \
string(Auto_Cropped_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(Auto_Cropped_StorageAR, 1) + \
string(Auto_Cropped_DAR, "\nDisplay Aspect Ratio   %.6f") + \
(NoResizing && (Auto_Cropped_Width == Source_Width) && (Auto_Cropped_Height == Source_Height) ? \
InDAR_Text : CR_FTF(Auto_Cropped_DAR, 1))

Specified_Cropping_Text = \
string(CL, "\n\nSpecified Cropping\n(%.0f, ") + string(CT, "%.0f, ") + string(-CR, "%.0f, ") + string(-CB, "%.0f)")

Extra_Cropping_Text = "\nAdditional Script Cropping\n" + \
(NoResizing ? \
string(Extra_CL, "(%.0f, ") + string(Extra_CT, "%.0f, ") + \
string(-Extra_CR, "%.0f, ") + string(-Extra_CB, "%.0f)") : \
ResizeWidthOnly ? \
string(Extra_CL, "(%.2f, ") + string(Extra_CT, "%.0f, ") + \
string(-Extra_CR, "%.2f, ") + string(-Extra_CB, "%.0f)") : \
string(Extra_CL, "(%.2f, ") + string(Extra_CT, "%.2f, ") + \
string(-Extra_CR, "%.2f, ") + string(-Extra_CB, "%.2f)"))

CSplit_Crop_Text = NoResizing ? "" : "\n\nCrop " + \
(ResizeWidthOnly ? \
string(RW_CL, "(%.0f, ") + string(RW_CT, "%.0f, ") + string(-RW_CR, "%.0f, ") + string(-RW_CB, "%.0f)") : \
(CRVideo == CRA_Video) ? \
string(CRA_CL, "(%.0f, ") + string(CRA_CT, "%.0f, ") + string(-CRA_CR, "%.0f, ") + string(-CRA_CB, "%.0f)") : \
string(CRB_CL, "(%.0f, ") + string(CRB_CT, "%.0f, ") + string(-CRB_CR, "%.0f, ") + string(-CRB_CB, "%.0f)"))

CSplit_Resizer_Text = NoResizing ? "" : "\nResizer Cropping\n" + \
(ResizeWidthOnly ? \
string(RW_RCL, "(%.2f, ") + string(RW_RCT, "%.0f, ") + \
string(-RW_RCR, "%.2f, ") + string(-RW_RCB, "%.0f)") : \
(CRVideo == CRA_Video) ? \
string(CRA_RCL, "(%.2f, ") + string(CRA_RCT, "%.2f, ") + \
string(-CRA_RCR, "%.2f, ") + string(-CRA_RCB, "%.2f)") : \
string(CRB_RCL, "(%.2f, ") + string(CRB_RCT, "%.2f, ") + \
string(-CRB_RCR, "%.2f, ") + string(-CRB_RCB, "%.2f)"))

Total_Cropping_Text = "\nTotal Cropping\n" + \
(NoResizing ? \
string(Total_CL, "(%.0f, ") + string(Total_CT, "%.0f, ") + \
string(-Total_CR, "%.0f, ") + string(-Total_CB, "%.0f)") : \
ResizeWidthOnly ? \
string(Total_CL, "(%.2f, ") + string(Total_CT, "%.0f, ") + \
string(-Total_CR, "%.2f, ") + string(-Total_CB, "%.0f)") : \
(CRVideo == CRA_Video) ? \
string(Total_CL, "(%.2f, ") + string(Total_CT, "%.2f, ") + \
string(-Total_CR, "%.2f, ") + string(-Total_CB, "%.2f)") : \
string(Total_CL, "(%.2f, ") + string(Total_CT, "%.2f, ") + \
string(-Total_CR, "%.2f, ") + string(-Total_CB, "%.2f)"))

Cropped_Resolution_Text = "\n\nCropped Resolution   " + \
(NoResizing ? string(CM_Cropped_Width, "%.0f x ") + string(CM_Cropped_Height, "%.0f") : \
ResizeWidthOnly ? string(F_RW_Cropped_Width, "%.2f x ") + string(RW_Cropped_Height, "%.0f") : \
(CRVideo == CRA_Video) ? string(F_CRA_Cropped_Width, "%.2f x ") + string(F_CRA_Cropped_Height, "%.2f") : \
string(F_CRB_Cropped_Width, "%.2f x ") + string(F_CRB_Cropped_Height, "%.2f"))

Cropped_Aspect_Text = NoResizing ? \
string(CM_Cropped_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(CM_Cropped_StorageAR, 1) + \
string(CM_Cropped_DAR, "\nDisplay Aspect Ratio   %.6f") + \
((Cropped_Source_Width == Source_Width) && (Cropped_Source_Height == Source_Height) ? \
InDAR_Text : CR_FTF(CM_Cropped_DAR, 1)) : \
ResizeWidthOnly ? \
string(RW_Cropped_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(RW_Cropped_StorageAR, 1) + \
string(RW_Cropped_DAR, "\nDisplay Aspect Ratio   %.6f") + CR_FTF(RW_Cropped_DAR, 1) : \
(CRVideo == CRA_Video) ? \
string(CRA_Cropped_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(CRA_Cropped_StorageAR, 1) + \
string(CRA_Cropped_DAR, "\nDisplay Aspect Ratio   %.6f") + CR_FTF(CRA_Cropped_DAR, 1) : \
string(CRB_Cropped_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(CRB_Cropped_StorageAR, 1) + \
string(CRB_Cropped_DAR, "\nDisplay Aspect Ratio   %.6f") + CR_FTF(CRB_Cropped_DAR, 1)

Output_Text = !ShowBorderInfo ? \
string(CRVideo_Width, "\n\nOutput Resolution   %.0f x ") + string(CRVideo_Height, "%.0f") + \
string(CRVideo_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(CRVideo_StorageAR, 1) + \
string(CRVideo_DAR, "\nDisplay Aspect Ratio   %.6f") + \
(NoResizing && (CRVideo_Width == Source_Width) && (CRVideo_Height == Source_Height) ? \
InDAR_Text : CR_FTF(CRVideo_DAR, 1)) : \
string(CRVideo_Width, "\n\nOutput Excluding Borders   %.0f x ") + string(CRVideo_Height, "%.0f") + \
string(CRVideo_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(CRVideo_StorageAR, 1) + \
string(CRVideo_DAR, "\nDisplay Aspect Ratio   %.6f") + \
(NoResizing && (CRVideo_Width == Source_Width) && (CRVideo_Height == Source_Height) ? \
InDAR_Text : CR_FTF(CRVideo_DAR, 1)) + \
string(BL, "\n\nAddBorders (%.0f, ") + string(BT, "%.0f, ") + string(BR, "%.0f, ") + string(BB, "%.0f)") + \
string(Final_Width, "\nOutput Including Borders   %.0f x ") + string(Final_Height, "%.0f") + \
string(Final_StorageAR, "\nStorage Aspect Ratio   %.6f") + CR_FTF(Final_StorageAR, 1) + \
string(Final_DAR, "\nDisplay Aspect Ratio   %.6f") + \
(NoResizing && (Final_Width == Source_Width) && (Final_Height == Source_Height) ? \
InDAR_Text : CR_FTF(Final_DAR, 1))

# ---------- Right Column --------------------------------------------------------

Resizer_Text = (NoResizing ? "No Resizing\n" : \
ResizeWidthOnly ? "Resize Width Only\nResizer  -  " : "Full Resizing Mode\nResizer  -  ") + \
(ColorCorrection && ResizeWithDitherTools ? "DitherTools & " + CCResizer : \
!NoResizing ? Resizer : (!CleanBorders ? "" : "Clean Borders"))

NoGMode = !IsG1Function || (IsG1Function && !IsG2Function && (IsGMode1 || IsGMode2))

GMode_Text = NoGMode ? "" : \
(!NoResize ? "\n\n" : "\n") + (IsGMode0 ? "GMode = 0" : IsGMode1 ? "GMode = 1" : "GMode = 2")

AutoC_Text = !IsAnyAutoCrop ? "" : (!NoResize ? "\n\n" : "\n") + (NoGMode ? "" : "\n") + \
(IsCurrentGAutoC ? "Global AutoCrop" : "AutoCrop")

Input_Aspect_Text = "\n\n\n\nInput Aspect" + \
(IsInDAR ? string(InDAR, "  -  InDAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(InDAR, 1) + \
string(Source_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Source_SAR, 1) : \
IsInSAR ? string(Source_DAR, "  -  InSAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(Source_DAR, 1) + \
string(InSAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(InSAR, 1) : \
IsGInDAR ? string(GInDAR, "  -  Global InDAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(GInDAR, 1) + \
string(Source_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Source_SAR, 1) : \
IsGInSAR ? string(Source_DAR, "  -  Global InSAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(Source_DAR, 1) + \
string(GInSAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(GInSAR, 1) : \
IsMInDAR ? string(MInDAR, "  -  MeGUI DAR\nDisplay Aspect Ratio   %.6f") + \
string(MInDARX, "   (%.0f:") + string(MInDARY, "%.0f)") + \
string(Source_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Source_SAR, 1) : \
IsMPassedThru ? string(MPassDAR, "  -  MeGUI DAR\nDisplay Aspect Ratio   %.6f") + \
string(gMPassDARX, "   (%.0f:") + string(gMPassDARY, "%.0f)") + \
string(Source_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Source_SAR, 1) : "") + \
(AnamorphicInput && !IsAnamorphicInput ? "\nNot Anamorphic" : !AnamorphicInput ? "\nNot Specified" : "")

Output_Aspect_Text = "\n\nOutput Aspect" + \
(NoResizing && IsAnamorphicOutput && (Final_Width == Source_Width) && (Final_Height == Source_Height) ? \
string(Final_DAR, "\nDisplay Aspect Ratio   %.6f") + InDAR_Text + \
string(Final_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Final_SAR, 1) : \
NoResizing && IsAnamorphicOutput ? \
string(Final_DAR, "\nDisplay Aspect Ratio   %.6f") + CR_FTF(Final_DAR, 1) + \
string(Final_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Final_SAR, 1) : \
IsOutDAR ? string(OutDAR, "  -  OutDAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(OutDAR, 1) + \
string(Final_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Final_SAR, 1) : \
IsOutSAR ? string(Final_DAR, "  -  OutSAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(Final_DAR, 1) + \
string(OutSAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(OutSAR, 1) : \
IsGOutDAR ? string(GOutDAR, "  -  Global OutDAR\nDisplay Aspect Ratio   %. && 6f") + CR_FTF(GOutDAR, 1) + \
string(Final_SAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(Final_SAR, 1) : \
IsGOutSAR ? string(Final_DAR, "  -  Global OutSAR\nDisplay Aspect Ratio   %.6f") + CR_FTF(Final_DAR, 1) + \
string(GOutSAR, "\nSample Aspect Ratio   %.6f") + CR_FTF(GOutSAR, 1) : "") + \
(AnamorphicOutput && !IsAnamorphicOutput ? "\nNot Anamorphic" : \
!AnamorphicOutput ? "\nNot Specified" : "") + \
(!AnamorphicOutput ? "\nSample Aspect Ratio" + CR_FTF(Final_SAR, 1) : "") + \
(!IsAnamorphicOutput ? "" : \
string(F_Final_Display_Width, "\nDisplay Dimensions   %.0f x ") + string(Final_Height, "%.0f"))

MeGUI_Aspect_Text = "\n\nMeGUI Output DAR" + \
(!CR_MeGUI_DAR() ? "\nDisabled" : !IsAnamorphicOutput ? "\nNot Anamorphic" : \
string(MeGUI_darx, "\nMeGUI_darx = %.0f") + string(MeGUI_dary, "\nMeGUI_dary = %.0f"))

AutoAspect_CRA_Pre_Adjust_Aspect = (CRVideo == CRA_Video) ? (!IsOutputSAR ? \
F_Resizing_Width / F_Adjusted_Height_1 : F_Resizing_Width * OutputSAR / F_Adjusted_Height_1) : 0.0
AutoAspect_CRB_Pre_Adjust_Aspect = (CRVideo == CRB_Video) ? (!IsOutputSAR ? \
F_Adjusted_Width_1 / F_Resizing_Height : F_Adjusted_Width_1 * OutputSAR / F_Resizing_Height) : 0.0

AutoAspect_Text = !AutoAspect || NoResizing || ResizeWidthOnly ? "" : \
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nAutoAspect  -  " + \
((CRVideo == CRA_Video) && IsHeight169 && (F_Adjusted_Height_1 != F_Adjusted_Height_2) ? \
string(AutoAspect_CRA_Pre_Adjust_Aspect, "%.6f to 16:9") : \
(CRVideo == CRA_Video) && IsHeight43 && (F_Adjusted_Height_1 != F_Adjusted_Height_2) ? \
string(AutoAspect_CRA_Pre_Adjust_Aspect, "%.6f to 4:3") : \
(CRVideo == CRB_Video) && IsWidth169 && (F_Adjusted_Width_1 != F_Adjusted_Width_2) ? \
string(AutoAspect_CRB_Pre_Adjust_Aspect, "%.6f to 16:9") : \
(CRVideo == CRB_Video) && IsWidth43 && (F_Adjusted_Width_1 != F_Adjusted_Width_2) ? \
string(AutoAspect_CRB_Pre_Adjust_Aspect, "%.6f to 4:3") : "Not Applicable")

Common_Resize_Text = !IsPreviewResizing ? "" : "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" + \
(!AutoAspect && !IsAnyAutoCrop ? "" : "\n\n") + \
(IsScriptCPreview ? "RMode\nCPreview Resized To " : "RMode\nOutput Resized To ") + \
string(gPriorWidth, "%.0f x ") + string(gPriorHeight, "%.0f")

Color_Correction_Text = !ColorCorrection ? "" : \
((!IsPreviewResizing ? "" : "\n\n\n") + (!AutoAspect && !IsAnyAutoCrop ? "" : "\n\n") + \
"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nColor Correction\n" + \
(!FullResizing ? "N/A - Full Resizing Disabled" : \
(Downscale == 4) && (Upscale == 4) ? "None Required" : \
(ColorCorrect == 1) ? "ColorMatrix\n" + ((Downscale == 1) ? "Rec.709 -> Rec.601" : "Rec.601 -> Rec.709") : \
(ColorCorrect == 2) ? "DitherTools\n" + ((Downscale == 1) ? "Rec.709 -> Rec.601" : "Rec.601 -> Rec.709") : \
"HDRTools\n" + \
((Downscale == 1) ? ((ColorCorrect == 3) ? "Rec.709 -> Rec.601 (170m)" : "Rec.709 -> Rec.601 (470bg)") : \
(Downscale == 2) ? "Rec.2020 -> Rec.709" : \
(Downscale == 3) ? ((ColorCorrect == 3) ? "Rec.2020 -> Rec.601 (170m)" : "Rec.2020 -> Rec.601 (470bg)") : \
(Upscale == 1) ? ((ColorCorrect == 3) ? "Rec.601 (170m) -> Rec.709" : "Rec.601 (470bg) -> Rec.709") : \
(Upscale == 2) ? "Rec.709 -> Rec.2020" : \
(Upscale == 3) ? ((ColorCorrect == 3) ? "Rec.601 (170m) -> Rec.2020" : "Rec.601 (470bg) -> Rec.2020") : "")))

# -------------------------------------------------------------------------------

InfoPicDim = \
!CR_ColorCorrectPicDim() && ColorCorrection && ((Downscale != 4) || (Upscale != 4)) ? 255 : \
!IsScriptCPreview ? PicDim + 255 : max(255, PicDim + 255 + 25)

Sub_Color1 = FullResizing ? $FFFFE0 : $F0FFFF
Sub_Color2 = !IsCurrentGAutoC ? Sub_Color1 : $FFA07A
Sub_Color3 = (rightstr(GMode_Text, 9) == "GMode = 0") || \
(rightstr(GMode_Text, 9) == "GMode = 2") ? $FFA07A : Sub_Color1
Sub_Color4 = (((CRVideo == CRA_Video) && (IsHeight169 || IsHeight43)) && \
(F_Adjusted_Height_1 != F_Adjusted_Height_2)) || \
(((CRVideo == CRB_Video) && (IsWidth169 || IsWidth43)) && \
(F_Adjusted_Width_1 != F_Adjusted_Width_2)) ? $FFA07A : Sub_Color1
Sub_Color5 = \
ColorCorrection && ((Downscale != 4) || (Upscale != 4)) ? $FFA07A : Sub_Color1

Sub_Size_Multi = (F_Info_Clip_Height <= 300) ? \
(IsAnyAutoCrop && ShowBorderInfo ? 0.020 : ShowBorderInfo ? 0.0245 : IsAnyAutoCrop ? 0.0255 : 0.0323) : \
(F_Info_Clip_Height <= 400) ? \
(IsAnyAutoCrop && ShowBorderInfo ? 0.0216 : ShowBorderInfo ? 0.025 : IsAnyAutoCrop ? 0.0269 : 0.0328) : \
(F_Info_Clip_Height <= 500) ? \
(IsAnyAutoCrop && ShowBorderInfo ? 0.0232 : ShowBorderInfo ? 0.027 : IsAnyAutoCrop ? 0.0285 : 0.034) : \
(F_Info_Clip_Height <= 600) ? \
(IsAnyAutoCrop && ShowBorderInfo ? 0.024 : ShowBorderInfo ? 0.0275 : IsAnyAutoCrop ? 0.029 : 0.035) : \
(IsAnyAutoCrop && ShowBorderInfo ? 0.0245 : ShowBorderInfo ? 0.028 : IsAnyAutoCrop ? 0.0295 : 0.035)

Sub_Y_Multi = (F_Info_Clip_Height <= 500) ? 0.03 : (F_Info_Clip_Height <= 700) ? 0.04 : 0.05

Sub_Size = min(F_Info_Clip_Width * 0.022, F_Info_Clip_Height * Sub_Size_Multi)

Sub_X1 = F_Info_Clip_Width * 0.05
Sub_X2 = F_Info_Clip_Width * 0.515
Sub_Y = F_Info_Clip_Height * Sub_Y_Multi

Info_Text1 = \
Source_Text + Auto_Cropping_Text + Specified_Cropping_Text + Extra_Cropping_Text + CSplit_Crop_Text + \
CSplit_Resizer_Text + Total_Cropping_Text + Cropped_Resolution_Text + Cropped_Aspect_Text + Output_Text
Info_Text2 = Resizer_Text + Input_Aspect_Text + Output_Aspect_Text + MeGUI_Aspect_Text

InfoVideo = ((InfoPicDim == 0) ? Info_Clip : Info_Clip.Levels(0, 1.0, 255, 0, InfoPicDim, coring=false))\
.subtitle(Info_Text1, x=Sub_X1, y=Sub_Y, size=Sub_Size, text_color=Sub_Color1, align=7, lsp=20)\
.subtitle(Info_Text2, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=Sub_Color1, lsp=20)\
.subtitle(GMode_Text, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=Sub_Color3, lsp=20)\
.subtitle(AutoC_Text, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=Sub_Color2, lsp=20)\
.subtitle(AutoAspect_Text, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=Sub_Color4, lsp=20)\
.subtitle(Common_Resize_Text, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=$FFA07A, lsp=20)\
.subtitle(Color_Correction_Text, x=Sub_X2, y=Sub_Y, size=Sub_Size, text_color=Sub_Color5, lsp=20)

""", "Info Eval") : nop()


# ===============================================================================
# ========== Final Output =======================================================
# ===============================================================================


IsPreviewResizing && !Info && !IsScriptCPreview && !IsAutoCPreview && !IsCurrentGAutoCPreview ? Eval("""

Output_Common_Resize_Text = \
"RMode\nOutput Video\nResized To " + string(gPriorWidth, "%.0f x ") + string(gPriorHeight, "%.0f") + \
(!IsG1Function || (IsG1Function && !IsG2Function && (IsGMode1 || IsGMode2)) ? "" : \
"\n\n" + (IsGMode0 ? "GMode = 0" : IsGMode1 ? "GMode = 1" : "GMode = 2"))

Output_Sub_Size = min(F_gPriorWidth * 0.033, F_gPriorHeight * 0.035)

CroppedResizedVideo = ((InfoPicDim == 0) ? CroppedResizedVideo : \
CroppedResizedVideo.Levels(0, 1.0, 255, 0, PicDim + 255, coring=false)).Spline36Resize(gPriorWidth, gPriorHeight)\
.subtitle(Output_Common_Resize_Text, x=-1, y=-1, size=Output_Sub_Size, text_color=$F0FFFF, lsp=20)

""", "Final Output Preview Resize Eval") : nop()

return IsCurrentGAutoCPreview ? GAutoCPreviewVideo : IsAutoCPreview ? AutoCPreviewVideo : \
Info ? InfoVideo : IsScriptCPreview ? ScriptCPreviewVideo : CroppedResizedVideo     }


# ===============================================================================
# ===============================================================================
# ========== Global GCropResize Function ========================================
# ===============================================================================
# ===============================================================================


function GCropResize(clip SourceVideo, \
int "OutWidth", int "OutHeight", \
int "CL", int "CT", int "CR", int "CB", val "CropDAR", int "CSplit", bool "CAlign", \
bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", \
val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", \
bool "NoResize", bool "ResizeWO", \
bool "Borders", bool "CleanBorders", val "BColor", bool "Frosty", \
int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")     {

OutWidth = default(OutWidth, 0)
OutHeight = default(OutHeight, 0)
AutoC = default(AutoC, false)
CThresh = default(CThresh, 30)
CStart = default(CStart, 250)
CSample = default(CSample, 5)
gInDAR = default(InDAR, 0.0)
gInSAR = default(InSAR, 0.0)
gOutDAR = default(OutDAR, 0.0)
gOutSAR = default(OutSAR, 0.0)
GMode = default(GMode, 1)
IsGMode1 = (GMode == 1)
IsGMode2 = (GMode == 2)

assert(!defined(RMode), " GCropResize " + chr(10) + \
" RMode can't be used with the global GCropResize function " + chr(10))

Try{   IsG1Function = G1_GFunction   }catch(err){   IsG1Function = false   }

# -------------------------------------------------------------------------------

IsGMode1 ? Eval("""

G1PriorGAutoC = IsG1Function && G1_AutoC
G1PriorGAutoCPreview = IsG1Function && (G1_CPreview == 4)
global G1_GFunction = true

global G1_Source_Width = AutoC || !G1PriorGAutoC ? width(SourceVideo) : G1_Source_Width
global G1_Source_Height = AutoC || !G1PriorGAutoC ? height(SourceVideo) : G1_Source_Height

global G1_OutWidth = (OutWidth == 0) && IsG1Function ? G1_OutWidth : OutWidth
global G1_OutHeight = (OutHeight == 0) && IsG1Function ? G1_OutHeight : OutHeight
global G1_CL = default(CL, !IsG1Function ? 0 : G1_CL)
global G1_CT = default(CT, !IsG1Function ? 0 : G1_CT)
global G1_CR = default(CR, !IsG1Function ? 0 : G1_CR)
global G1_CB = default(CB, !IsG1Function ? 0 : G1_CB)
global G1_CropDAR = default(CropDAR, !IsG1Function ? 0.0 : G1_CropDAR)
global G1_CSplit = default(CSplit, !IsG1Function ? 1 : G1_CSplit)
global G1_CAlign = default(CAlign, !IsG1Function ? false : G1_CAlign)
global G1_AutoC = AutoC || G1PriorGAutoC
global G1_CThresh = CThresh
global G1_CStart = CStart
global G1_CSample = CSample
global G1_CPreview = default(CPreview, !IsG1Function ? 0 : G1_CPreview)
global G1_CLine = default(CLine, !IsG1Function ? CR_CLine() : G1_CLine)
global G1_InDAR = default(gInDAR, (gInSAR > 0) || !IsG1Function ? 0.0 : G1_InDAR)
global G1_InSAR = default(gInSAR, (gInDAR > 0) || !IsG1Function ? 0.0 : G1_InSAR)
global G1_OutDAR = default(gOutDAR, (gOutSAR > 0) || !IsG1Function ? 0.0 : G1_OutDAR)
global G1_OutSAR = default(gOutSAR, (gOutDAR > 0) || !IsG1Function ? 0.0 : G1_OutSAR)
global G1_AutoAspect = default(AutoAspect, !IsG1Function ? CR_AutoAspect() : G1_AutoAspect)
global G1_Mod = default(Mod, !IsG1Function ? 4 : G1_Mod)
global G1_HMod = default(HMod, !IsG1Function ? G1_Mod : G1_HMod)
global G1_NoResize = default(NoResize, !IsG1Function ? false : G1_NoResize)
global G1_ResizeWO = default(ResizeWO, !IsG1Function ? false : G1_ResizeWO)
global G1_Borders = default(Borders, !IsG1Function ? false : G1_Borders)
global G1_CleanBorders = default(CleanBorders, !IsG1Function ? false : G1_CleanBorders)
global G1_BColor = default(BColor, !IsG1Function ? $000000 : G1_BColor)
global G1_Frosty = default(Frosty, !IsG1Function ? false : G1_Frosty)
global G1_ColorCorrect = default(ColorCorrect, !IsG1Function ? CR_ColorCorrect() : G1_ColorCorrect)
global G1_Resizer = default(Resizer, !IsG1Function ? "Spline36Resize" : G1_Resizer)
global G1_GMode = GMode
global G1_PicDim = default(PicDim, !IsG1Function ? -75 : G1_PicDim)
global G1_Info = default(Info, !IsG1Function ? false : G1_Info)

""", "GCropResize Defaults - GMode 1 Eval") : Eval("""

# -------------------------------------------------------------------------------

assert(IsG1Function, " GCropResize " + chr(10) + \
" For the first instance of GCropResize, GMode must equal one " + chr(10))

Try{   IsG2Function = G2_GFunction   }catch(err){   IsG2Function = false   }

G2PriorGAutoC = IsG2Function && G2_AutoC
G2PriorGAutoCPreview = IsG2Function && (G2_CPreview == 4)
global G2_GFunction = true

xM = default(Mod, 0)

global G2_Source_Width = AutoC || !G2PriorGAutoC ? width(SourceVideo) : G2_Source_Width
global G2_Source_Height = AutoC || !G2PriorGAutoC ? height(SourceVideo) : G2_Source_Height

global G2_OutWidth = (OutWidth == 0) ? (!IsG2Function ? G1_OutWidth : G2_OutWidth) : OutWidth
global G2_OutHeight = (OutHeight == 0) ? (!IsG2Function ? G1_OutHeight : G2_OutHeight) : OutHeight
global G2_CL = default(CL, !IsG2Function ? 0 : G2_CL)
global G2_CT = default(CT, !IsG2Function ? 0 : G2_CT)
global G2_CR = default(CR, !IsG2Function ? 0 : G2_CR)
global G2_CB = default(CB, !IsG2Function ? 0 : G2_CB)
global G2_CropDAR = default(CropDAR, !IsG2Function ? 0.0 : G2_CropDAR)
global G2_CSplit = default(CSplit, !IsG2Function ? 1 : G2_CSplit)
global G2_CAlign = default(CAlign, !IsG2Function ? false : G2_CAlign)
global G2_AutoC = AutoC || G2PriorGAutoC
global G2_CThresh = CThresh
global G2_CStart = CStart
global G2_CSample = CSample
global G2_CPreview = default(CPreview, !IsG2Function && (G1_CPreview == 4) && AutoC ? G1_CPreview : \
!IsG2Function && (G1_CPreview == 4) ? 0 : !IsG2Function ? G1_CPreview : G2_CPreview)
global G2_CLine = default(CLine, !IsG2Function ? G1_CLine : G2_CLine)
global G2_InDAR = default(gInDAR, (gInSAR > 0) || !IsG2Function ? 0.0 : G2_InDAR)
global G2_InSAR = default(gInSAR, (gInDAR > 0) || !IsG2Function ? 0.0 : G2_InSAR)
global G2_OutDAR = default(gOutDAR, (gOutSAR > 0) ? 0.0 : !IsG2Function ? G1_OutDAR : G2_OutDAR)
global G2_OutSAR = default(gOutSAR, (gOutDAR > 0) ? 0.0 : !IsG2Function ? G1_OutSAR : G2_OutSAR)
global G2_AutoAspect = default(AutoAspect, !IsG2Function ? G1_AutoAspect : G2_AutoAspect)
global G2_Mod = default(Mod, (xM != 0) ? xM : !IsG2Function ? G1_Mod : G2_Mod)
global G2_HMod = default(HMod, (xM != 0) ? xM : !IsG2Function ? G1_HMod : G2_HMod)
global G2_NoResize = default(NoResize, !IsG2Function ? false : G2_NoResize)
global G2_ResizeWO = default(ResizeWO, !IsG2Function ? false : G2_ResizeWO)
global G2_Borders = default(Borders, !IsG2Function ? false : G2_Borders)
global G2_CleanBorders = default(CleanBorders, !IsG2Function ? false : G2_CleanBorders)
global G2_BColor = default(BColor, !IsG2Function ? $000000 : G2_BColor)
global G2_Frosty = default(Frosty, !IsG2Function ? false : G2_Frosty)
global G2_ColorCorrect = default(ColorCorrect, !IsG2Function ? G1_ColorCorrect : G2_ColorCorrect)
global G2_Resizer = default(Resizer, !IsG2Function ? G1_Resizer : G2_Resizer)
global G2_GMode = GMode
global G2_PicDim = default(PicDim, !IsG2Function ? G1_PicDim : G2_PicDim)
global G2_Info = default(Info, !IsG2Function ? G1_Info : G2_Info)

""", "GCropResize Defaults - GMode 2 Eval")

# -------------------------------------------------------------------------------

assert((!IsGMode1 || (1 <= G1_CThresh <= 255)) && (!IsGMode2 || (1 <= G2_CThresh <= 255)), \
" GCropResize " + chr(10) + " CThresh must be 1 thru 255 " + chr(10))
assert((!IsGMode1 || (0 <= G1_CPreview <= 4)) && (!IsGMode2 || (0 <= G2_CPreview <= 4)), \
" GCropResize " + chr(10) + " CPreview must be 0 thru 4 " + chr(10))

assert((!IsGMode1 || (!AutoC || !G1PriorGAutoC)) && (!IsGMode2 || (!AutoC || !G2PriorGAutoC)), \
" GCropResize " + chr(10) + " AutoC can't be true for GCropResize when global auto-cropping " + chr(10) + \
" has previously been enabled via the GCropResize function " + chr(10) + \
" This applies only to more than one instance of GCropResize(GMode=1) " + chr(10) + \
" and only to more than one instance of GCropResize(GMode=2) " + chr(10))

assert((!IsGMode1 || (AutoC || (G1_CPreview != 4))) && (!IsGMode2 || (AutoC || (G2_CPreview != 4))), \
" GCropResize " + chr(10) + " When CPreview=4, AutoC must be true " + chr(10))

assert((0 < GMode < 3), " GCropResize " + chr(10) + \
" GMode must be 1 or 2 for GCropResize " + chr(10) + " (0, 1 or 2 for CropResize) " + chr(10))

### Prevent GCropResize from specifying new auto-cropping options after global auto-cropping has been enabled.
assert(((!IsGMode1 || !G1PriorGAutoC) || (((CThresh == 30) || (CThresh == G1_CThresh)) && \
((CStart == 250) || (CStart == G1_CStart)) && ((CSample == 5) || (CSample == G1_CSample)))) && \
((!IsGMode2 || !G2PriorGAutoC) || (((CThresh == 30) || (CThresh == G2_CThresh)) && \
((CStart == 250) || (CStart == G2_CStart)) && ((CSample == 5) || (CSample == G2_CSample)))), \
" GCropResize " + chr(10) + \
" New auto-cropping options can't be specified by GCropResize when global " + chr(10) + \
" auto-cropping has previously been enabled via the GCropResize function " + chr(10) + \
" This applies only to more than one instance of GCropResize(GMode=1) " + chr(10) + \
" and only to more than one instance of GCropResize(GMode=2) " + chr(10))

### Prevent specifying InDAR & InSAR together.
assert((gInDAR == 0) || (gInSAR == 0), \
" GCropResize " + chr(10) + " InDAR and InSAR can't be specified together " + chr(10))

### Prevent specifying OutDAR & OutSAR together.
assert((gOutDAR == 0) || (gOutSAR == 0), \
" GCropResize " + chr(10) + " OutDAR and OutSAR can't be specified together " + chr(10))

# -------------------------------------------------------------------------------

IsAutoCVideo = \
(IsGMode1 && AutoC && (G1_CPreview != 4)) || (IsGMode2 && AutoC && (G2_CPreview != 4))
IsAutoCPreviewVideo = \
(IsGMode1 && AutoC && (G1_CPreview == 4)) || (IsGMode2 && AutoC && (G2_CPreview == 4))

IsAutoCVideo ? Eval("""

AutoCVideo = \
SourceVideo.autocrop(mode=0, wMultOf=2, hMultOf=2, leftadd=0, topadd=0, rightadd=0, bottomadd=0, \
threshold=CThresh, samples=CSample, samplestartframe=CStart, sampleendframe=-1, aspect=0)

""", "GCropResize - Auto Cropped Video Eval") : nop()

IsAutoCPreviewVideo ? Eval("""

AutoCPreviewVideo = \
SourceVideo.autocrop(mode=1, wMultOf=2, hMultOf=2, leftadd=0, topadd=0, rightadd=0, bottomadd=0, \
threshold=CThresh, samples=CSample, samplestartframe=CStart, sampleendframe=-1, aspect=0)

""", "GCropResize - Auto Cropping Preview Eval") : nop()

return IsAutoCVideo ? AutoCVideo : IsAutoCPreviewVideo ? AutoCPreviewVideo : SourceVideo     }


# ===============================================================================
# ===============================================================================
# ========== Frosty Borders Function ============================================
# ===============================================================================
# ===============================================================================


function CR_FrostyBorders(clip SourceVideo, int Total_Width, int Total_Height, \
float SourceStorageAR, float OutStorageAR, int BL, int BT, int BR, int BB, \
float "Bright", float "BrightL", float "Cont", float "ContL", float "Sat", float "SatL", \
float "Blend", float "BlendL", float "Blur", float "BlurL", float "VBlur", float "VBlurL", \
Int "Iterations", Int "IterationsL", float "Texture", float "TextureL")     {

# ---------- Defaults -----------------------------------------------------------

Try{   IsFrostyFunction = defined(G_Bright)   }catch(err){   IsFrostyFunction = false   }

Bright = default(Bright, !IsFrostyFunction ? 0.0 : G_Bright)
BrightL = default(BrightL, !IsFrostyFunction ? -25.0 : G_BrightL)
Cont = default(Cont, !IsFrostyFunction ? 1.0 : G_Cont)
ContL = default(ContL, !IsFrostyFunction ? 0.66 : G_ContL)
Sat = default(Sat, !IsFrostyFunction ? 0.85 : G_Sat)
SatL = default(SatL, !IsFrostyFunction ? 0.66 : G_SatL)
Blend = default(Blend, !IsFrostyFunction ? 0.20 : G_Blend)
BlendL = default(BlendL, !IsFrostyFunction ? Blend : G_BlendL)
Blur = default(Blur, !IsFrostyFunction ? 50 : G_Blur)
BlurL = default(BlurL, !IsFrostyFunction ? Blur : G_BlurL)
VBlur = default(VBlur, !IsFrostyFunction ? Blur : G_VBlur)
VBlurL = default(VBlurL, !IsFrostyFunction ? BlurL : G_VBlurL)
Iterations = default(Iterations, !IsFrostyFunction ? 3 : G_Iterations)
IterationsL = default(IterationsL, !IsFrostyFunction ? Iterations : G_IterationsL)
Texture = default(Texture, !IsFrostyFunction ? 5.0 : G_Texture)
TextureL = default(TextureL, !IsFrostyFunction ? Texture : G_TextureL)

# ---------- Insist -------------------------------------------------------------

assert(-255 <= Bright <= 255, " FrostyBorders " + chr(10) + " The valid range for Bright is -255 thru 255 ")
assert(-255 <= BrightL <= 255, " FrostyBorders " + chr(10) + " The valid range for BrightL is -255 thru 255 ")
assert(0 <= Cont <= 10, " FrostyBorders " + chr(10) + " The valid range for Cont is 0.0 thru 10.0 ")
assert(0 <= ContL <= 10, " FrostyBorders " + chr(10) + " The valid range for ContL is 0.0 thru 10.0 ")
assert(0 <= Sat <= 10, " FrostyBorders " + chr(10) + " The valid range for SatL is 0.0 thru 10.0 ")
assert(0 <= SatL <= 10, " FrostyBorders " + chr(10) + " The valid range for Sat is 0.0 thru 10.0 ")
assert(0 <= Blend <= 1, " FrostyBorders " + chr(10) + " The valid range for Blend is 0.0 to 1.0 ")
assert(0 <= BlendL <= 1, " FrostyBorders " + chr(10) + " The valid range for BlendL is 0.0 to 1.0 ")

# ---------- Add Borders --------------------------------------------------------

(OutStorageAR >= SourceStorageAR) ? Eval("""

W_Crop = width(SourceVideo) - 64
PillarBox_Background = StackHorizontal(SourceVideo.crop(0, 0, -W_Crop, 0), SourceVideo.crop(W_Crop, 0, 0, 0))\
.TemporalSoften(7, 255, 255, 20, 2).Tweak(bright=Bright, cont=Cont, sat=Sat)
PB_Crop = width(PillarBox_Background) - 16

Left = PillarBox_Background.crop(0, 0, -PB_Crop, 0)
Right = PillarBox_Background.crop(PB_Crop, 0, 0, 0)
Blend_Left = \
(Blend == 0) ? Left : (Blend == 1) ? FlipHorizontal(Right) : Overlay(Left, FlipHorizontal(Right), Opacity=Blend)
Blend_Right = \
(Blend == 0) ? Right : (Blend == 1) ? FlipHorizontal(Left) : Overlay(Right, FlipHorizontal(Left), Opacity=Blend)

Frosty_Left = Blend_Left.GaussResize(BL, Total_Height)\
.FastBlur(Blur, y_blur=VBlur, iterations=Iterations, dither=true).AddGrain(var=Texture, constant=true)
Frosty_Right = Blend_Right.GaussResize(BR, Total_Height)\
.FastBlur(Blur, y_blur=VBlur, iterations=Iterations, dither=true).AddGrain(var=Texture, constant=true)

Frosty_Output = StackHorizontal(StackHorizontal(Frosty_Left, SourceVideo), Frosty_Right)

""", "Frosty Borders 1 Eval") : (OutStorageAR < SourceStorageAR) ? Eval("""

# -------------------------------------------------------------------------------

H_Crop = height(SourceVideo) - 64
LetterBox_Background = StackVertical(SourceVideo.crop(0, 0, 0, -H_Crop), SourceVideo.crop(0, H_Crop, 0, 0))\
.TemporalSoften(5, 255, 255, 20, 2).Tweak(bright=BrightL, cont=ContL, sat=SatL)
LB_Crop = height(LetterBox_Background) - 16

Top = LetterBox_Background.crop(0, 0, 0, -LB_Crop)
Bottom = LetterBox_Background.crop(0, LB_Crop, 0, 0)
Blend_Top = \
(BlendL == 0) ? Top : (BlendL == 1) ? FlipVertical(Bottom) : Overlay(Top, FlipVertical(Bottom), Opacity=BlendL)
Blend_Bottom = \
(BlendL == 0) ? Bottom : (BlendL == 1) ? FlipVertical(Top) : Overlay(Bottom, FlipVertical(Top), Opacity=BlendL)

Frosty_Top = Blend_Top.GaussResize(Total_Width, BT)\
.FastBlur(BlurL, y_blur=VBlurL, iterations=IterationsL, dither=true).AddGrain(var=TextureL, constant=true)
Frosty_Bottom = Blend_Bottom.GaussResize(Total_Width, BB)\
.FastBlur(BlurL, y_blur=VBlurL, iterations=IterationsL, dither=true).AddGrain(var=TextureL, constant=true)

Frosty_Output = StackVertical(StackVertical(Frosty_Top, SourceVideo), Frosty_Bottom)

""", "Frosty Borders 2 Eval") : Eval("""

# -------------------------------------------------------------------------------

Frosty_Output = SourceVideo

""", "Frosty Borders 3 Eval")

# -------------------------------------------------------------------------------

return Frosty_Output     }


# ===============================================================================
# ===============================================================================
# ========== Global FCropResize Function ========================================
# ===============================================================================
# ===============================================================================


function FCropResize(clip SourceVideo, \
float "Bright", float "BrightL", float "Cont", float "ContL", float "Sat", float "SatL", \
float "Blend", float "BlendL", float "Blur", float "BlurL", float "VBlur", float "VBlurL", \
Int "Iterations", Int "IterationsL", float "Texture", float "TextureL")     {

global G_Bright = default(Bright, 0.0)
global G_BrightL = default(BrightL, -25.0)
global G_Cont = default(Cont, 1.0)
global G_ContL = default(ContL, 0.66)
global G_Sat = default(Sat, 0.85)
global G_SatL = default(SatL, 0.66)
global G_Blend = default(Blend, 0.20)
global G_BlendL = default(BlendL, G_Blend)
global G_Blur = default(Blur, 50)
global G_BlurL = default(BlurL, G_Blur)
global G_VBlur = default(VBlur, G_Blur)
global G_VBlurL = default(VBlurL, G_BlurL)
global G_Iterations = default(Iterations, 3)
global G_IterationsL = default(IterationsL, G_Iterations)
global G_Texture = default(Texture, 5.0)
global G_TextureL = default(TextureL, G_Texture)

return SourceVideo     }


# ===============================================================================
# ===============================================================================
# ========== Color Correct & Resize Function ====================================
# ===============================================================================
# ===============================================================================


function CR_ColorCorrectResize(clip SourceVideo, \
int "Resize_Width", int "Resize_Height", float "RCL", float "RCT", float "RCR", float "RCB", \
int "ColorCorrect", string "Color_Format", int "DownScale", int "UpScale", string "Resizer", string "CCResizer", \
bool "IsAVSPlus", int "Source_Bit_Depth", bool "ResizeWithDitherTools")     {

# ---------- Default Resizing String --------------------------------------------

Default_Resizing = \
Resizer+"(Resize_Width, Resize_Height, src_left=RCL, src_top=RCT, src_width=-RCR, src_height=-RCB)"

(ColorCorrect == 1) ? Eval("""

# ---------- ColorMatrix --------------------------------------------------------

Color_Format = IsYV12(SourceVideo) ? "YV12" : IsYUY2(SourceVideo) ? "YUY2" : ""

assert((Source_Bit_Depth == 8) && (Color_Format != ""), \
" CropResize " + chr(10) + " Automatic color correction with ColorMatrix only supports " + chr(10) + \
" 8 bit YV12 & YUY2 video " + chr(10))

assert((2 != DownScale != 3) && (2 != UpScale != 3), " CropResize " + chr(10) + \
" ColorMatrix can't be used for UHD color correcton (conversions to or from Rec.2020) " + chr(10) + \
" Use HDRTools or set ColorCorrect=0 to color correct manually " + chr(10))

Color_Corrected_Video = \
(DownScale == 1) ? SourceVideo.Eval(Default_Resizing).ColorMatrix(mode="Rec.709->Rec.601", clamp=0) : \
(UpScale == 1) ? SourceVideo.ColorMatrix(mode="Rec.601->Rec.709", clamp=0).Eval(Default_Resizing) : \
Eval(Default_Resizing)

""", "Color Correction - ColorMatrix Eval") : (ColorCorrect == 2) ? Eval("""

# ---------- DitherTools --------------------------------------------------------

Color_Format = IsYV12(SourceVideo) ? "YV12" : IsYV24(SourceVideo) ? "YV24" : IsYV16(SourceVideo) ? "YV16" : \
IsYUY2(SourceVideo) ? "YUY2" : IsYV411(SourceVideo) ? "YV411" : IsY8(SourceVideo) ? "Y8" : ""

assert((Source_Bit_Depth == 8) && ((Color_Format != "YUY2") && (Color_Format != "")), \
" CropResize " + chr(10) + " Automatic color correction with DitherTools only supports " + chr(10) + \
" 8 bit YV12, YV16, YV24, YV411, and Y8 video " + chr(10))

assert((2 != DownScale != 3) && (2 != UpScale != 3), " CropResize " + chr(10) + \
" DitherTools can't be used for UHD color correcton (conversions to or from Rec.2020) " + chr(10) + \
" Use HDRTools or set ColorCorrect=0 to color correct manually " + chr(10))

Resizer = ResizeWithDitherTools ? ((CCResizer == "Lanczos4") ? "Lanczos" : CCResizer) : Resizer
Taps = ResizeWithDitherTools && (CCResizer == "Lanczos4") ? 4 : Undefined()

To_RGB = (DownScale == 1) ? "709" : (DownScale == 2) ? "2020" : (DownScale == 3) ? "2020" : \
(UpScale == 1) ? "601" : (UpScale == 2) ? "709" : (UpScale == 3) ? "601" : ""
From_RGB = (DownScale == 1) ? "601" : (DownScale == 2) ? "709" : (DownScale == 3) ? "601" : \
(UpScale == 1) ? "709" : (UpScale == 2) ? "2020" : (UpScale == 3) ? "2020" : ""

Color_Corrected_Video = ResizeWithDitherTools ? \
SourceVideo.Dither_convert_8_to_16().Dither_resize16(Resize_Width, Resize_Height, \
src_left=RCL, src_top=RCT, src_width=-RCR, src_height=-RCB, kernel=Resizer, taps=Taps)\
.Dither_convert_yuv_to_rgb(matrix=To_RGB, slice=false, lsb_in=true)\
.Dither_convert_rgb_to_yuv(matrix=From_RGB, output=Color_Format, lsb=false, mode=0) : \
(DownScale != 4) || (UpScale != 4) ? SourceVideo.Eval(Default_Resizing).Dither_convert_8_to_16()\
.Dither_convert_yuv_to_rgb(matrix=To_RGB, slice=false, lsb_in=true)\
.Dither_convert_rgb_to_yuv(matrix=From_RGB, output=Color_Format, lsb=false, mode=0) : \
SourceVideo.Eval(Default_Resizing)

""", "Color Correction - DitherTools Eval") : (ColorCorrect == 3) || (ColorCorrect == 4) ? Eval("""

# ---------- HDRTools -----------------------------------------------------------

Convert_To = IsAVSPlus && (Source_Bit_Depth != 8) ? "ConvertBits(16).ConvertToYUV444()" : "ConvertToYV24()"

Color_A = (DownScale == 1) ? 2 : (DownScale == 2) ? 1 : (DownScale == 3) ? 1 : \
(UpScale == 1) && (ColorCorrect == 3) ? 3 : (UpScale == 1) && (ColorCorrect == 4) ? 4 : \
(UpScale == 2) ? 2 : \
(UpScale == 3) && (ColorCorrect == 3) ? 3 : (UpScale == 3) && (ColorCorrect == 4) ? 4 : 2

Color_B = (DownScale == 1) && (ColorCorrect == 3) ? 3 : (DownScale == 1) && (ColorCorrect == 4) ? 4 : \
(DownScale == 2) ? 2 : \
(DownScale == 3) && (ColorCorrect == 3) ? 3 : (DownScale == 3) && (ColorCorrect == 4) ? 4 : \
(UpScale == 1) ? 2 : (UpScale == 2) ? 1 : (UpScale == 3) ? 1 : 2

CC_Video = (DownScale != 4) ? SourceVideo.Eval(Default_Resizing).Eval(Convert_To)\
.ConvertYUVtoXYZ(Color=Color_A).ConvertXYZtoYUV(Color=Color_B, PColor=Color_A) : \
(UpScale != 4) ? SourceVideo.Eval(Convert_To)\
.ConvertYUVtoXYZ(Color=Color_A).ConvertXYZtoYUV(Color=Color_B, PColor=Color_A).Eval(Default_Resizing) : \
SourceVideo.Eval(Default_Resizing)

Color_Corrected_Video = \
(DownScale == 4) && (UpScale == 4) ? CC_Video : CC_Video.CR_MCF(SourceVideo, IsAVSPlus, true)

""", "Color Correction - HDRTools Eval") : nop()

# -------------------------------------------------------------------------------

return Color_Corrected_Video     }


# ===============================================================================
# ===============================================================================
# ========== Match Color Format Function ========================================
# ===============================================================================
# ===============================================================================


# Function for converting back to the original format after color correction with HDRTools
# Courtesy Of Raffriff42 http://avisynth.nl/index.php/User:Raffriff42/Utils-r41_Quick_Reference

function CR_MCF(clip Source, clip Template, bool "IsAVSPlus", bool "Dither", string "Matrix", bool "KeepBits")   {

IsAvsPlus ? Eval("""

Matrix = default(Matrix, "Rec601")
KeepBits = default(KeepBits, false)
BitsIn = Source.BitsPerComponent()
BitsOut = (KeepBits) ? Source.BitsPerComponent() : Template.BitsPerComponent()
Dither = default(Dither, false)
DitherType = Dither && (BitsIn > 8) && (BitsIn < 32) && (BitsOut < BitsIn) ? 0 : -1
Error_Text = " Failed to convert back to original format after color correction "

A = Source.HasAlpha() ? Source.ExtractA().ConvertBits(BitsOut) : nop()
Source = \
Source.IsPlanar() ? Source : Source.IsRGB() ? Source.ConvertToPlanarRGB() : Source.ConvertToYUV444()

# Upconvert (if applicable) before YUV<>RGB 
Source = (BitsIn < BitsOut) ? Source.ConvertBits(BitsOut) : Source

Output = \
Template.IsRGB() ? (Source.IsRGB() ? Source : Source.ConvertToPlanarRGB(matrix=Matrix)) : \
Template.Is444() ? (Source.IsRGB() ? Source.ConvertToYUV444(matrix=Matrix) : Source.ConvertToYUV444()) : \
Template.Is422() ? (Source.IsRGB() ? Source.ConvertToYUV422(matrix=Matrix) : Source.ConvertToYUV422()) : \
Template.Is420() ? (Source.IsRGB() ? Source.ConvertToYUV420(matrix=Matrix) : Source.ConvertToYUV420()) : \
Template.IsYV411() ? (Source.IsRGB() ? \
Source.ConvertToYUV411(matrix=Matrix).ConvertBits(8, dither=DitherType).ConvertToYV411() : \
Source.ConvertToYUV411().ConvertBits(8, dither=DitherType).ConvertToYV411()) : \
Template.IsY() ? (Source.IsRGB() ? \
Source.ConvertToYUV420(matrix=Matrix).ConvertToY() : Source.ConvertToYUV420().ConvertToY()) : \
Assert(false, " CropResize " + chr(10) + " Unrecognized source format " + chr(10) + Error_Text + chr(10))

BitsOutput = Output.BitsPerComponent()
DitherType = Dither && (BitsOutput > 8) && (BitsOutput < 32) && (BitsOut < BitsOutput) ? 0 : -1
Output = Output.ConvertBits(BitsOut, dither=DitherType)

Assert((Template.BitsPerComponent() == Output.BitsPerComponent()) && \
(Template.IsRGB() == Output.IsRGB()) && (Template.Is444() == Output.Is444()) && \
(Template.Is422() == Output.Is422()) && (Template.Is420() == Output.Is420()) && \
(Template.IsYV411() == Output.IsYV411()) && (Template.IsY() == Output.IsY()), \
" CropResize (Match Color Format) " + chr(10) + " Can't keep original bitdepth " + chr(10) + \
" Template=" + Template.PixelType() + "  Output=" + Output.PixelType() + " " + chr(10) + Error_Text + chr(10))

Output = \
Template.IsRGB32() ? Output.ConvertToRGB32() : Template.IsRGB24() ? Output.ConvertToRGB24() : \
Template.IsRGB64() ? Output.ConvertToRGB64() : Template.IsRGB48() ? Output.ConvertToRGB48() : \
Template.IsYV24() ? Output.ConvertToYV24() : Template.IsYUY2() ? Output.ConvertToYUY2() : \
Template.IsYV16() ? Output.ConvertToYV16() : Template.IsYV12() ? Output.ConvertToYV12() : \
Template.IsYV411() ? Output.ConvertToYV411() : Template.IsY8() ? Output.ConvertToY8() : \
(Template.IsRGB() || Template.Is444() || Template.Is422() || Template.Is420() || Template.IsY()) ? Output : \
Assert(false, " CropResize " + chr(10) + " Unrecognized source format " + chr(10) + Error_Text + chr(10))

Output = Template.HasAlpha() && Source.HasAlpha() ? Output.AddAlphaPlane(A) : Output 
Output = Template.HasAlpha() ? Output.HasAlpha() ? Output : Output.AddAlphaPlane() : \
!HasAlpha(Output) ? Output : Output.RemoveAlphaPlane()

Assert((Template.PixelType() == Output.PixelType()), " CropResize (Match Color Format) " + chr(10) + \
" Template=" + Template.PixelType() + "  Output=" + Output.PixelType() + " " + chr(10) + Error_Text + chr(10))

return Output

""", "MCF AVS Plus Eval") : Eval("""

return \
Template.IsRGB24 ? Source.ConvertToRGB24() : Template.IsRGB32 ? Source.ConvertToRGB32() : \
Template.IsYV24 ? Source.ConvertToYV24() : Template.IsYV16 ? Source.ConvertToYV16() : \
Template.IsYUY2 ? Source.ConvertToYUY2() : Template.IsYV12 ? Source.ConvertToYV12() : \
Template.IsYV411 ? Source.ConvertToYV411() : Template.IsY8 ? Source.ConvertToY8() : \
Source.ConvertToYV12()

""", "MCF AVS Classic Eval")   }


# ===============================================================================
# ===============================================================================
# ========== Float To Fraction Function =========================================
# ===============================================================================
# ===============================================================================


function CR_FTF(float Decimal, int "Out")     {
Out = default(Out, 0)
Numerator = (Decimal == 0) ? "0" : string(ContinuedNumerator(Decimal, Limit=5000))
Denominator = (Decimal == 0) ? "1" : string(ContinuedDenominator(Decimal, Limit=5000))
return (Out == 1) ? "   (" + Numerator + ":" + Denominator + ")" : \
(Out == 2) ? "  (DAR  " + Numerator + ":" + Denominator + ")" : \
"\nSample Aspect Ratio  " + Numerator + ":" + Denominator     }


# ===============================================================================
# ===============================================================================
# ========== CropResize Defaults ================================================
# ===============================================================================
# ===============================================================================


# Setting these options incorrecting will break something, so take care when changing them.
# The functions can't be commented out.

function CR_AutoAspect() { return false }
function CR_ColorCorrect() { return 0 }
function CR_CPreview() { return 1 }
function CR_CLine() { return 1 }
function CR_MeGUI_DAR() { return true }
function CR_ColorCorrectPicDim() { return true }
function CR_Resizer() { return "Resize8" }


# ===============================================================================
# ===============================================================================
# ===============================================================================

# ===============================================================================
# ========== Resizer Wrapper Functions 2019-09-10 ===============================
# ===============================================================================

#  PLEASE NOTE: Any resizers or resizer wrapper functions used with CropResize must accept
#  cropping arguments as float, and for wrapper functions, the cropping arguments must be included.
#  Without the ability to apply sub-pixel cropping with a resizer, the script's cropping won't be accurate.
#
#  The included wrapper functions for Avisynth resizers with optional arguments are:
#  CR_Bicubic(), CR_Blackman(), CR_Gauss(), CR_Lanczos() and CR_Sinc().
#  There are also wrapper functions included for three other resizing scripts/plugins:
#  CR_Resize8(), CR_ResizeX() and CR_ResampleHQ().
#
#  The wrapper functions can easily be modified to specify or change any optional resizer arguments.
#  Should you wish to use a resizer with different settings on ocasion, make a copy of the appropriate wrapper
#  function and add the copy to the script, change it's default options and give the function a unique name.
#  Configuring optional arguments is the primary reason for including the resizer wrapper functions,
#  as it's not possible to configure them directly via the CropResize script itself.
#
#  CropResize resizes with Avisynth's Spline36Resize unless a different method is specified via the "Resizer"
#  option. For the examples below, 1 & 2 resize with Avisynth's BilinearResize and BicubicResize respectively,
#  and 3 resizes with BicubicResize via the included CR_Bicubic wrapper function.
#
#  1. CropResize(Resizer="BilinearResize")
#  2. CropResize(Resizer="BicubicResize")
#  3. CropResize(Resizer="CR_Bicubic")
#
#  CropResize also includes wrapper functions for enabling an alternative resizing method without having
#  to use the Resizer option and type a resizer name. The alternative resizer can be enabled simply by
#  appending an "X" to the CropResize or GCropResize function names. ie
#
#  CropResizeX()
#  GCropResizeX()
#
#  The above method would resize with the Resize8 script by default, but it can be any compatible resizer.
#  To change the resizing method when "X" is appended to a function name, open the CropResize script
#  with Notepad and find the 6th line from the bottom. Change "Resize8" in that line to your preferred
#  method and resave the script. ie
#
#  This line:
#  function CR_Resizer() { return "Resize8" }
#
#  would be changed to the following to use BicubicResize instead of Resize8.
#
#  function CR_Resizer() { return "BicubicResize" }

# ===============================================================================
# ========== CR_Bicubic() - BicubicResize Wrapper Function ======================
# ===============================================================================

function CR_Bicubic(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", float "B", float "C")     {

# The defaults are B=1 and C=3
# New values for the two lines below will change those defaults
B = default(B, 1.0)
C = default(C, 3.0)

BicubicResize(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, b=B, c=C)     }

# ===============================================================================
# ========== CR_Blackman() - BlackmanResize Wrapper Function ====================
# ===============================================================================

function CR_Blackman(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", int "Taps")     {

# Replace "4" in the line below to set a different default value for "Taps"
default(Taps, 4)

BlackmanResize(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, taps=Taps)     }

# ===============================================================================
# ========== CR_Gauss() - GaussResize Wrapper Function ==========================
# ===============================================================================

function CR_Gauss(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", float "P")     {

# Replace "30.0" in the line below to set a different default value for "P"
default(P, 30.0)

GaussResize(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, p=P)     }

# ===============================================================================
# ========== CR_Lanczos() - LanczosResize Wrapper Function ======================
# ===============================================================================

function CR_Lanczos(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", int "Taps")     {

# Replace "3" in the line below to set a different default value for "Taps"
default(Taps, 3)

LanczosResize(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, taps=Taps)     }

# ===============================================================================
# ========== CR_Sinc() - SincResize Wrapper Function ============================
# ===============================================================================

function CR_Sinc(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", int "Taps")     {

# Replace "4" in the line below to set a different default value for "Taps"
default(Taps, 4)

SincResize(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, taps=Taps)     }

# ===============================================================================
# ========== CR_Resize8() - Resize8 Wrapper Function ============================
# ===============================================================================

# http://avisynth.nl/index.php/Resize8

function CR_Resize8(clip SourceVideo, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", \
string "kernel", string "kernel_c", float "a1", float "a2", float "a1_c", float "a2_c", \
val "noring", val "noring_c", string "cplace", bool "Y", bool "U", bool "V", bool "Alpha")     {

# Uncomment any line below and replace "xxx" to set a preferred default value for Resize8()
# kernel = default(kernel, xxx)
# kernel_c = default(kernel_c, xxx)
# a1 = default(a1, xxx)
# a2 = default(a2, xxx)
# a1_c = default(a1_c, xxx)
# a2_c = default(a2_c, xxx)
# noring_c = default(noring_c, xxx)
# cplace = default(cplace, xxx)
# Y = default(Y, xxx)
# U = default(U, xxx)
# V = default(V, xxx)
# Alpha = default(Alpha, xxx)

Resize8(SourceVideo, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, \
kernel=kernel, kernel_c=kernel_c, a1=a1, a2=a2, a1_c=a1_c, a2_c=a2_c, \
noring=noring, noring_c=noring_c, cplace=cplace, Y=Y, U=U, V=V, Alpha=Alpha)     }

# ===============================================================================
# ========== CR_Resize16X() - ResizeX Wrapper Function - 16 Bit Resizing ========
# ===============================================================================

# https://pastebin.com/LP7kDbe6
# With "lsb" set to true below, the clip is converted to stacked 16 bit, resized, then dithered back to 8 bit.
# Requires the Dithertools plugin and whatever DitherTools needs.
# http://avisynth.nl/index.php/Dither_tools
#
# Please note: Enabling "lsb_out" doubles the height of the output clip due to the stacked 16 bit output, and will
# effect CropResize's ability to add borders, color correct and calculate the correct output display aspect ratio,
# however the copping and resizing should still be correct.

function CR_Resize16X(clip input, int target_width, int target_height, \
float "src_left", float "src_top", float "src_width", float "src_height", \
string "kernel", int "taps", float "a1", float "a2", string "cplace", bool "luma", bool "chroma", \
bool "lsb_in", bool "lsb", bool "mt", string "mt_params", string "dither_params", \
bool "lsb_out", bool "desampling", int "dither_mode")     {

# Uncomment any line below and replace "xxx" to set a preferred default value for ResizeX()
# kernel = default(kernel, xxx)
# taps = default(taps, xxx)
# a1 = default(a1, xxx)
# a2 = default(a2, xxx)
# cplace = default(cplace, xxx)
# cplace = default(cplace, xxx)
# luma = default(luma, xxx)
# chroma = default(chroma, xxx)
# lsb_in = default(lsb_in, xxx)
   lsb = default(lsb, true)
# mt = default(mt, xxx)
# mt_params = default(mt_params, xxx)
# dither_params = default(dither_params, xxx)
# lsb_out = default(lsb_out, xxx)
# desampling = default(desampling, xxx)
# dither_mode = default(dither_mode, xxx)

ResizeX(input, target_width, target_height, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, \
kernel=kernel, taps=taps, a1=a1, a2=a2, cplace=cplace, luma=luma, chroma=chroma, \
lsb_in=lsb_in, lsb=lsb, mt=mt, mt_params=mt_params, dither_params=dither_params, \
lsb_out=lsb_out, desampling=desampling, dither_mode=dither_mode)     }

# ===============================================================================
# ========== CR_ResampleHQ() - ResampleHQ Wrapper Function ======================
# ===============================================================================

# ResampleHQ 32 bit: https://forum.doom9.org/showthread.php?t=160038
# ResampleHQ 64 bit: https://forum.doom9.org/showthread.php?p=1722300#post1722300

function CR_ResampleHQ(clip SourceVideo, int target_width, int target_height, \
string "dstcolorspace", string "srcmatrix", string "dstmatrix", bool "dither", \
float "src_left", float "src_top", float "src_width", float "src_height", \
string "kernel", float "karg1", float "karg2", float "kblur_x", float "kblur_y", \
string "chroma_kernel", float "chroma_karg1", float "chroma_karg2")     {

# Uncomment any line below and replace "xxx" to set a preferred value for ResampleHQ()
# dstcolorspace = default(dstcolorspace, xxx)
# srcmatrix = srcmatrix(srcmatrix, xxx)
# dstmatrix = default(dstmatrix, xxx)
# dither = default(dither, xxx)
# kernel = default(kernel, xxx)
# karg1 = default(karg1, xxx)
# karg2 = default(karg2, xxx)
# kblur_x = default(kblur_x, xxx)
# kblur_y = default(kblur_y, xxx)
# chroma_kernel = default(chroma_kernel, xxx)
# chroma_karg1 = default(chroma_karg1, xxx)
# chroma_karg2 = default(chroma_karg2, xxx)

ResampleHQ(SourceVideo, target_width, target_height, \
dstcolorspace=dstcolorspace, srcmatrix=srcmatrix, dstmatrix=dstmatrix, \
src_left=src_left, src_top=src_top, src_width=src_width, src_height=src_height, \
kernel=kernel, karg1=karg1, karg2=karg2, kblur_x=kblur_x, kblur_y=kblur_y, \
chroma_kernel=chroma_kernel, chroma_karg1=chroma_karg1, chroma_karg2=chroma_karg2)     }

# ===============================================================================
# ===============================================================================
# ===============================================================================

# ===============================================================================
# ===============================================================================
# ========== CropResize Wrapper Functions 2019-09-10 ============================
# ===============================================================================
# ===============================================================================

# ========== CropResizeX ========================================================

function CropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_Resizer = default(Resizer, CR_Resizer())

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== pCropResize ========================================================

function pCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_CPreview = default(CPreview, CR_CPreview())

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== pCropResizeX =======================================================

function pCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_CPreview = default(CPreview, CR_CPreview())
global G_Resizer = default(Resizer, CR_Resizer())

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== iCropResize ========================================================

function iCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_Info = default(Info, true)

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== iCropResizeX =======================================================

function iCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_Resizer = default(Resizer, CR_Resizer())
global G_Info = default(Info, true)

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== piCropResize ======================================================

function piCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_CPreview = default(CPreview, CR_CPreview())
global G_Info = default(Info, true)

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== piCropResizeX ======================================================

function piCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

global G_CPreview = default(CPreview, CR_CPreview())
global G_Resizer = default(Resizer, CR_Resizer())
global G_Info = default(Info, true)

return CropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ===============================================================================
# ===============================================================================
# ========== GCropResize Wrapper Functions ======================================
# ===============================================================================
# ===============================================================================

# ========== GCropResizeX =======================================================

function GCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

Resizer = default(Resizer, CR_Resizer())

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== pGCropResize =======================================================

function pGCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

CPreview = default(CPreview, CR_CPreview())

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== pGCropResizeX ======================================================

function pGCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

CPreview = default(CPreview, CR_CPreview())
Resizer = default(Resizer, CR_Resizer())

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== iGCropResize =======================================================

function iGCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

Info = default(Info, true)

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== iGCropResizeX ======================================================

function iGCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

Resizer = default(Resizer, CR_Resizer())
Info = default(Info, true)

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== piGCropResize ======================================================

function piGCropResize(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

CPreview = default(CPreview, CR_CPreview())
Info = default(Info, true)

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ========== piGCropResizeX =====================================================

function piGCropResizeX(clip SourceVideo, int "OutWidth", int "OutHeight", int "CL", int "CT", int "CR", int "CB", \
val "CropDAR", int "CSplit", bool "CAlign", bool "AutoC", int "CThresh", int "CStart", int "CSample", \
int "CPreview", int "CLine", val "InDAR", val "InSAR", val "OutDAR", val "OutSAR", bool "AutoAspect", \
int "Mod", int "HMod", bool "NoResize", bool "ResizeWO", bool "Borders", bool "CleanBorders", val "BColor", \
bool "Frosty", int "ColorCorrect", string "Resizer", int "GMode", bool "RMode", int "PicDim", bool "Info")  {

CPreview = default(CPreview, CR_CPreview())
Resizer = default(Resizer, CR_Resizer())
Info = default(Info, true)

return GCropResize(SourceVideo, OutWidth, OutHeight, CL, CT, CR, CB, CropDAR, CSplit, CAlign, AutoC, \
CThresh, CStart, CSample, CPreview, CLine, InDAR, InSAR, OutDAR, OutSAR, AutoAspect, Mod, HMod, \
NoResize, ResizeWO, Borders, CleanBorders, BColor, Frosty, ColorCorrect, Resizer, GMode, RMode, PicDim, Info)  }

# ===============================================================================
# ===============================================================================
# ===============================================================================