Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to auto-adjust the level of 0 IRE based on the back porch #163

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion vhsdecode/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,19 @@ def hz_to_output(self, input):
if self.rf.options.export_raw_tbc:
return input.astype(np.single)
else:
ire0 = self.rf.DecoderParams["ire0"]
if self.rf.options.ire0_adjust and input.size == self.outlinecount * self.outlinelen:
blank_levels = np.empty(self.outlinecount)
for i in range(0, self.outlinecount):
blank_levels[i] = np.median(
input[i * self.outlinelen + self.ire0_backporch[0] : i * self.outlinelen + self.ire0_backporch[1]]
)
blank_levels = np.sort(blank_levels)
ire0 = np.mean(blank_levels[int(self.outlinecount / 3) : int(self.outlinecount * 2 / 3)])
ldd.logger.debug("calculated ire0: %.02f", ire0)
return hz_to_output_array(
input,
self.rf.DecoderParams["ire0"]
ire0
+ self.rf.DecoderParams["track_ire0_offset"][
self.rf.track_phase ^ (self.field_number % 2)
],
Expand Down Expand Up @@ -1079,6 +1089,7 @@ def fix_badlines(self, linelocs_in, linelocs_backup_in=None):
class FieldPALShared(FieldShared, ldd.FieldPAL):
def __init__(self, *args, **kwargs):
super(FieldPALShared, self).__init__(*args, **kwargs)
self.ire0_backporch = (96, 160)

def refine_linelocs_pilot(self, linelocs=None):
"""Override this as most regular band tape formats does not use have a pilot burst.
Expand All @@ -1101,6 +1112,7 @@ class FieldNTSCShared(FieldShared, ldd.FieldNTSC):
def __init__(self, *args, **kwargs):
super(FieldNTSCShared, self).__init__(*args, **kwargs)
self.fieldPhaseID = 0
self.ire0_backporch = (74, 124)

def refine_linelocs_burst(self, linelocs=None):
"""Override this as it's LD specific
Expand Down
8 changes: 8 additions & 0 deletions vhsdecode/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ def main(args=None, use_gui=False):
default=0.1,
help="Multiply top/bottom IRE in json by 1 +/- this value (used to avoid clipping on RGB conversion in chroma decoder).",
)
luma_group.add_argument(
"--ire0_adjust",
dest="ire0_adjust",
action="store_true",
default=False,
help="Automatic adjust of ire0 based blanking level",
)
luma_group.add_argument(
"--high_boost",
metavar="High frequency boost multiplier",
Expand Down Expand Up @@ -391,6 +398,7 @@ def main(args=None, use_gui=False):
rf_options["skip_hsync_refine"] = args.skip_hsync_refine
rf_options["export_raw_tbc"] = args.export_raw_tbc
rf_options["tape_speed"] = args.tape_speed
rf_options["ire0_adjust"] = args.ire0_adjust

extra_options = get_extra_options(args, not use_gui)
extra_options["params_file"] = args.params_file
Expand Down
3 changes: 3 additions & 0 deletions vhsdecode/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ def __init__(
)

export_raw_tbc = rf_options.get("export_raw_tbc", False)
ire0_adjust = rf_options.get("ire0_adjust", False)
is_color_under = vhs_formats.is_color_under(tape_format)
write_chroma = (
is_color_under
Expand Down Expand Up @@ -602,6 +603,7 @@ def __init__(
"export_raw_tbc",
"fm_audio_notch",
"chroma_offset",
"ire0_adjust",
],
)(
self.iretohz(100) * 2,
Expand Down Expand Up @@ -631,6 +633,7 @@ def __init__(
export_raw_tbc,
rf_options.get("fm_audio_notch", 0),
int(self.DecoderParams.get("chroma_offset", 5) * (self.freq / 40.0)),
ire0_adjust,
)

# As agc can alter these sysParams values, store a copy to then
Expand Down