Beispiel #1
0
def test_stdin():
    """Test stdin."""
    getinfo = Getinfo()

    getinfo.input = ['image1.hdr', 'image2.hdr']
    getinfo.output = 'combined.hdr'
    assert getinfo.to_radiance(stdin_input=True) == ('getinfo > combined.hdr')
Beispiel #2
0
def test_assignment_options():
    """Test assigning options."""
    getinfo = Getinfo()

    getinfo.input = ['image1.hdr', 'image2.hdr']
    getinfo.options.d = True
    assert getinfo.to_radiance() == 'getinfo -d image1.hdr image2.hdr'
Beispiel #3
0
def test_validation():
    """Validate error for missing argument."""
    getinfo = Getinfo()

    with pytest.raises(exceptions.MissingArgumentError):
        getinfo.to_radiance()

    getinfo.input = ['image1.hdr', 'image2.hdr']
    assert getinfo.to_radiance() == 'getinfo image1.hdr image2.hdr'
Beispiel #4
0
def test_assignment_options_append():
    """Test assigning options."""
    getinfo = Getinfo()

    getinfo.input = ['image1.hdr', 'image2.hdr']
    getinfo.options.a = 'This is some Text to append to the header'
    assert getinfo.to_radiance() == \
        'getinfo -a "This is some Text to append to the header" image1.hdr image2.hdr' \
        or getinfo.to_radiance() == \
        "getinfo -a 'This is some Text to append to the header' image1.hdr image2.hdr"
Beispiel #5
0
def test_assignment():
    """Test assignment."""
    getinfo = Getinfo()

    getinfo.input = ['image1.hdr', 'image2.hdr']
    assert getinfo.input == 'image1.hdr image2.hdr'
    assert getinfo.to_radiance() == 'getinfo image1.hdr image2.hdr'
    getinfo.output = 'combined.hdr'
    assert getinfo.output == 'combined.hdr'
    assert getinfo.to_radiance(
    ) == 'getinfo image1.hdr image2.hdr > combined.hdr'
Beispiel #6
0
def merge_view(input_folder, base_name, extension, scale_factor, folder, name):
    """Merge several radiance HDR image files into a single file.

    This command will also perform an anti-aliasing operation on the output and
    replace the view information in the header of the merged file if a single .vf
    file is found within the root of the input-folder.

    \b
    Args:
        input_folder: Input folder.
        base_name: File base name. All of the files must start with base name and
            continue with _ and an integer values.
        extension: File extention. [Default: .unf]
    """
    try:
        # get all of the files in the folder with the given extension
        pattern = r'{}_\d+{}'.format(base_name, extension)
        images = sorted(f for f in os.listdir(input_folder)
                        if re.match(pattern, f))
        if len(images) == 0:
            raise ValueError('Found no files to merge.')
        name = name or base_name

        # get the new dir name as view name might be group/name
        dirname = os.path.dirname(os.path.normpath(os.path.join(folder, name)))
        if dirname and not os.path.exists(dirname):
            os.makedirs(dirname)
        temp_output = os.path.join(dirname, name + '_temp.HDR')
        output_file = os.path.join(dirname, name + '.HDR')

        # set up the pcompos command
        in_dirname = os.path.normpath(input_folder)
        pcompos = Pcompos(output=temp_output)
        pcompos.input = [os.path.join(in_dirname, img) for img in images]
        pcompos.options.a = 1

        # setup the pfilt command to perform anti-aliasing on the output
        pfilt = Pfilt(input=temp_output)
        pfilt.options.r = 0.6
        if scale_factor != 1:
            pfilt.options.x = '/{}'.format(scale_factor)
            pfilt.options.y = '/{}'.format(scale_factor)

        # search for a single .vf in the folder and, if it's found, grab the info
        views = sorted(f for f in os.listdir(input_folder)
                       if f.endswith('.vf'))
        if len(views) == 1:  # replace the header with the info in the view
            view_obj = View.from_file(os.path.join(input_folder, views[0]))
            getinfo = Getinfo(output=output_file)
            getinfo.options.a = 'VIEW= {}'.format(view_obj)
            pfilt.pipe_to = getinfo
        else:  # just let the output of pfilt be the final output
            pfilt.output = output_file

        # run the commands in series
        env = None
        if folders.env != {}:
            env = folders.env
        env = dict(os.environ, **env) if env else None
        for r_cmd in (pcompos, pfilt):
            r_cmd.run(env)

    except Exception:
        _logger.exception('Failed to merge image files.')
        sys.exit(1)
    else:
        sys.exit(0)
Beispiel #7
0
def test_defaults():
    """Test command."""
    getinfo = Getinfo()

    assert getinfo.command == 'getinfo'
    assert getinfo.options.to_radiance() == ''