Add support for image sequence strip
This commit is contained in:
@@ -354,6 +354,7 @@ class BlendFileBlock:
|
|||||||
default=...,
|
default=...,
|
||||||
sdna_index_refine=None,
|
sdna_index_refine=None,
|
||||||
use_nil=True, use_str=True,
|
use_nil=True, use_str=True,
|
||||||
|
base_index=0,
|
||||||
):
|
):
|
||||||
|
|
||||||
if sdna_index_refine is None:
|
if sdna_index_refine is None:
|
||||||
@@ -362,7 +363,13 @@ class BlendFileBlock:
|
|||||||
self.file.ensure_subtype_smaller(self.sdna_index, sdna_index_refine)
|
self.file.ensure_subtype_smaller(self.sdna_index, sdna_index_refine)
|
||||||
|
|
||||||
dna_struct = self.file.structs[sdna_index_refine]
|
dna_struct = self.file.structs[sdna_index_refine]
|
||||||
self.file.handle.seek(self.file_offset, os.SEEK_SET)
|
ofs = self.file_offset
|
||||||
|
|
||||||
|
if base_index != 0:
|
||||||
|
assert(base_index < self.count)
|
||||||
|
ofs += (self.size // self.count) * base_index
|
||||||
|
|
||||||
|
self.file.handle.seek(ofs, os.SEEK_SET)
|
||||||
return dna_struct.field_get(
|
return dna_struct.field_get(
|
||||||
self.file.header, self.file.handle, path,
|
self.file.header, self.file.handle, path,
|
||||||
default=default,
|
default=default,
|
||||||
@@ -388,10 +395,15 @@ class BlendFileBlock:
|
|||||||
# Utility get/set
|
# Utility get/set
|
||||||
#
|
#
|
||||||
# avoid inline pointer casting
|
# avoid inline pointer casting
|
||||||
def get_pointer(self, path, default=..., sdna_index_refine=None):
|
def get_pointer(
|
||||||
|
self, path,
|
||||||
|
default=...,
|
||||||
|
sdna_index_refine=None,
|
||||||
|
base_index=0,
|
||||||
|
):
|
||||||
if sdna_index_refine is None:
|
if sdna_index_refine is None:
|
||||||
sdna_index_refine = self.sdna_index
|
sdna_index_refine = self.sdna_index
|
||||||
result = self.get(path, default, sdna_index_refine=sdna_index_refine)
|
result = self.get(path, default, sdna_index_refine=sdna_index_refine, base_index=base_index)
|
||||||
|
|
||||||
# default
|
# default
|
||||||
if type(result) is not int:
|
if type(result) is not int:
|
||||||
|
@@ -238,12 +238,17 @@ def pack(
|
|||||||
# never copy libs (handled separately)
|
# never copy libs (handled separately)
|
||||||
if not isinstance(fp, blendfile_path_walker.FPElem_block_path) or fp.userdata[0].code != b'LI':
|
if not isinstance(fp, blendfile_path_walker.FPElem_block_path) or fp.userdata[0].code != b'LI':
|
||||||
path_copy_files.add((path_src, path_dst))
|
path_copy_files.add((path_src, path_dst))
|
||||||
if fp.is_sequence:
|
|
||||||
|
for file_list in (
|
||||||
|
blendfile_path_walker.utils.find_sequence_paths(path_src) if fp.is_sequence else (),
|
||||||
|
fp.files_siblings(),
|
||||||
|
):
|
||||||
|
|
||||||
_src_dir = os.path.dirname(path_src)
|
_src_dir = os.path.dirname(path_src)
|
||||||
_dst_dir = os.path.dirname(path_dst)
|
_dst_dir = os.path.dirname(path_dst)
|
||||||
path_copy_files.update(
|
path_copy_files.update(
|
||||||
{(os.path.join(_src_dir, f), os.path.join(_dst_dir, f))
|
{(os.path.join(_src_dir, f), os.path.join(_dst_dir, f))
|
||||||
for f in blendfile_path_walker.utils.find_sequence_paths(path_src)
|
for f in file_list
|
||||||
})
|
})
|
||||||
del _src_dir, _dst_dir
|
del _src_dir, _dst_dir
|
||||||
|
|
||||||
|
@@ -84,6 +84,9 @@ class FPElem:
|
|||||||
# subclass must call
|
# subclass must call
|
||||||
self.userdata = userdata
|
self.userdata = userdata
|
||||||
|
|
||||||
|
def files_siblings(self):
|
||||||
|
return ()
|
||||||
|
|
||||||
# --------
|
# --------
|
||||||
# filepath
|
# filepath
|
||||||
|
|
||||||
@@ -150,6 +153,19 @@ class FPElem_sequence_single(FPElem):
|
|||||||
block[path] = head + sep
|
block[path] = head + sep
|
||||||
sub_block[sub_path] = tail
|
sub_block[sub_path] = tail
|
||||||
|
|
||||||
|
class FPElem_sequence_image_seq(FPElem_sequence_single):
|
||||||
|
"""
|
||||||
|
Image sequence
|
||||||
|
userdata = (block, path)
|
||||||
|
"""
|
||||||
|
__slots__ = ()
|
||||||
|
def files_siblings(self):
|
||||||
|
block, path, sub_block, sub_path = self.userdata
|
||||||
|
|
||||||
|
array = block.get_pointer(b'stripdata')
|
||||||
|
files = [array.get(b'name', use_str=False, base_index=i) for i in range(array.count)]
|
||||||
|
return files
|
||||||
|
|
||||||
|
|
||||||
class FilePath:
|
class FilePath:
|
||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
@@ -478,8 +494,7 @@ class FilePath:
|
|||||||
item_stripdata = item_strip.get_pointer(b'stripdata')
|
item_stripdata = item_strip.get_pointer(b'stripdata')
|
||||||
|
|
||||||
if item_type == C_defs.SEQ_TYPE_IMAGE:
|
if item_type == C_defs.SEQ_TYPE_IMAGE:
|
||||||
# TODO, multiple images
|
yield FPElem_sequence_image_seq(basedir, level, (item_strip, b'dir', item_stripdata, b'name')), extra_info
|
||||||
yield FPElem_sequence_single(basedir, level, (item_strip, b'dir', item_stripdata, b'name')), extra_info
|
|
||||||
elif item_type == C_defs.SEQ_TYPE_MOVIE:
|
elif item_type == C_defs.SEQ_TYPE_MOVIE:
|
||||||
yield FPElem_sequence_single(basedir, level, (item_strip, b'dir', item_stripdata, b'name')), extra_info
|
yield FPElem_sequence_single(basedir, level, (item_strip, b'dir', item_stripdata, b'name')), extra_info
|
||||||
elif item_type == C_defs.SEQ_TYPE_SOUND_RAM:
|
elif item_type == C_defs.SEQ_TYPE_SOUND_RAM:
|
||||||
|
Reference in New Issue
Block a user