# Copyright (c) 2018-2020, NVIDIA CORPORATION.  All rights reserved.
#
# NVIDIA CORPORATION and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto.  Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA CORPORATION is strictly prohibited.
#
import os


def get_num_pattern_file_path(frames_dir, file_name, num_pattern, frame_num, file_type, renumber_frames=False, renumber_offset=0):
    if renumber_frames:
        renumbered_frames = frame_num + renumber_offset
    else:
        renumbered_frames = frame_num
    abs_frame_num = abs(renumbered_frames)
    padding_length = len(num_pattern.strip(".")[len(str(abs_frame_num)) :])
    if renumbered_frames >= 0:
        padded_string = "0" * padding_length + str(renumbered_frames)
    else:
        padded_string = "-" + "0" * padding_length + str(abs_frame_num)
    filename = ".".join((file_name, padded_string, file_type.strip(".")))
    frame_path = os.path.join(frames_dir, filename)
    return frame_path
