当前位置: 首页>>代码示例>>Python>>正文


Python Bits._description方法代码示例

本文整理汇总了Python中hachoir_core.field.Bits._description方法的典型用法代码示例。如果您正苦于以下问题:Python Bits._description方法的具体用法?Python Bits._description怎么用?Python Bits._description使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在hachoir_core.field.Bits的用法示例。


在下文中一共展示了Bits._description方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createFields

# 需要导入模块: from hachoir_core.field import Bits [as 别名]
# 或者: from hachoir_core.field.Bits import _description [as 别名]
 def createFields(self):
     for i in xrange(20):
         yield Bits(self, "pretree_lengths[]", 4)
     pre_tree = build_tree([self['pretree_lengths[%d]'%x].value for x in xrange(20)])
     if not hasattr(self.root, "lzx_tree_lengths_"+self.name):
         self.lengths = [0] * self.num_elements
         setattr(self.root, "lzx_tree_lengths_"+self.name, self.lengths)
     else:
         self.lengths = getattr(self.root, "lzx_tree_lengths_"+self.name)
     i = 0
     while i < self.num_elements:
         field = HuffmanCode(self, "tree_code[]", pre_tree)
         if field.realvalue <= 16:
             self.lengths[i] = (self.lengths[i] - field.realvalue) % 17
             field._description = "Literal tree delta length %i (new length value %i for element %i)" % (
                     field.realvalue, self.lengths[i], i)
             i += 1
             yield field
         elif field.realvalue == 17:
             field._description = "Tree Code 17: Zeros for 4-19 elements"
             yield field
             extra = Bits(self, "extra[]", 4)
             zeros = 4 + extra.value
             extra._description = "Extra bits: zeros for %i elements (elements %i through %i)" % (zeros, i, i+zeros-1)
             yield extra
             self.lengths[i:i+zeros] = [0] * zeros
             i += zeros
         elif field.realvalue == 18:
             field._description = "Tree Code 18: Zeros for 20-51 elements"
             yield field
             extra = Bits(self, "extra[]", 5)
             zeros = 20 + extra.value
             extra._description = "Extra bits: zeros for %i elements (elements %i through %i)" % (zeros, i, i+zeros-1)
             yield extra
             self.lengths[i:i+zeros] = [0] * zeros
             i += zeros
         elif field.realvalue == 19:
             field._description = "Tree Code 19: Same code for 4-5 elements"
             yield field
             extra = Bits(self, "extra[]", 1)
             run = 4 + extra.value
             extra._description = "Extra bits: run for %i elements (elements %i through %i)" % (run, i, i+run-1)
             yield extra
             newfield = HuffmanCode(self, "tree_code[]", pre_tree)
             assert newfield.realvalue <= 16
             newfield._description = "Literal tree delta length %i (new length value %i for elements %i through %i)" % (
                     newfield.realvalue, self.lengths[i], i, i+run-1)
             self.lengths[i:i+run] = [(self.lengths[i] - newfield.realvalue) % 17] * run
             i += run
             yield newfield
开发者ID:AdriSol,项目名称:metagoofil,代码行数:52,代码来源:lzx.py

示例2: createFields

# 需要导入模块: from hachoir_core.field import Bits [as 别名]
# 或者: from hachoir_core.field.Bits import _description [as 别名]
 def createFields(self):
     values = [[], []]
     for i in (0, 1):
         yield Bits(self, "blue[]", 5)
         yield Bits(self, "green[]", 6)
         yield Bits(self, "red[]", 5)
         values[i] = [self["red[%i]" % i].value,
                      self["green[%i]" % i].value,
                      self["blue[%i]" % i].value]
     if values[0] > values[1] or self.dxt2_mode:
         values += interp_avg(values[0], values[1], 3)
     else:
         values += interp_avg(values[0], values[1], 2)
         values.append(None) # transparent
     for i in xrange(16):
         pixel = Bits(self, "pixel[%i][%i]" % divmod(i, 4), 2)
         color = values[pixel.value]
         if color is None:
             pixel._description = "Transparent"
         else:
             pixel._description = "RGB color: %s" % color_name(color, [5, 6, 5])
         yield pixel
开发者ID:AdriSol,项目名称:metagoofil,代码行数:24,代码来源:blp.py

示例3: createFields

# 需要导入模块: from hachoir_core.field import Bits [as 别名]
# 或者: from hachoir_core.field.Bits import _description [as 别名]
 def createFields(self):
     field = HuffmanCode(self, "dc_data", self.dc_tree)
     field._description = "DC Code %i (Huffman Code %i)" % (field.realvalue, field.value) + field._description
     yield field
     if field.realvalue != 0:
         extra = Bits(self, "dc_data_extra", field.realvalue)
         if extra.value < 2**(field.realvalue - 1):
             corrected_value = extra.value + (-1 << field.realvalue) + 1
         else:
             corrected_value = extra.value
         extra._description = "Extra Bits: Corrected DC Value %i" % corrected_value
         yield extra
     data = []
     while len(data) < 63:
         field = HuffmanCode(self, "ac_data[]", self.ac_tree)
         value_r = field.realvalue >> 4
         if value_r:
             data += [0] * value_r
         value_s = field.realvalue & 0x0F
         if value_r == value_s == 0:
             field._description = "AC Code Block Terminator (0, 0) (Huffman Code %i)" % field.value + field._description
             yield field
             return
         field._description = "AC Code %i, %i (Huffman Code %i)" % (value_r, value_s, field.value) + field._description
         yield field
         if value_s != 0:
             extra = Bits(self, "ac_data_extra[%s" % field.name.split('[')[1], value_s)
             if extra.value < 2**(value_s - 1):
                 corrected_value = extra.value + (-1 << value_s) + 1
             else:
                 corrected_value = extra.value
             extra._description = "Extra Bits: Corrected AC Value %i" % corrected_value
             data.append(corrected_value)
             yield extra
         else:
             data.append(0)
开发者ID:AdriSol,项目名称:metagoofil,代码行数:38,代码来源:jpeg.py

示例4: createFields

# 需要导入模块: from hachoir_core.field import Bits [as 别名]
# 或者: from hachoir_core.field.Bits import _description [as 别名]
 def createFields(self):
     yield Bit(self, "final", "Is this the final block?") # BFINAL
     yield Enum(Bits(self, "compression_type", 2), # BTYPE
                {0:"None", 1:"Fixed Huffman", 2:"Dynamic Huffman", 3:"Reserved"})
     if self["compression_type"].value == 0: # no compression
         padding = paddingSize(self.current_size + self.absolute_address, 8) # align on byte boundary
         if padding:
             yield PaddingBits(self, "padding[]", padding)
         yield Int16(self, "len")
         yield Int16(self, "nlen", "One's complement of len")
         if self["len"].value != ~self["nlen"].value:
             raise ParserError("len must be equal to the one's complement of nlen!")
         if self["len"].value: # null stored blocks produced by some encoders (e.g. PIL)
             yield RawBytes(self, "data", self["len"].value, "Uncompressed data")
         return
     elif self["compression_type"].value == 1: # Fixed Huffman
         length_tree = {} # (size, huffman code): value
         distance_tree = {}
         for i in xrange(144):
             length_tree[(8, i+48)] = i
         for i in xrange(144, 256):
             length_tree[(9, i+256)] = i
         for i in xrange(256, 280):
             length_tree[(7, i-256)] = i
         for i in xrange(280, 288):
             length_tree[(8, i-88)] = i
         for i in xrange(32):
             distance_tree[(5, i)] = i
     elif self["compression_type"].value == 2: # Dynamic Huffman
         yield Bits(self, "huff_num_length_codes", 5, "Number of Literal/Length Codes, minus 257")
         yield Bits(self, "huff_num_distance_codes", 5, "Number of Distance Codes, minus 1")
         yield Bits(self, "huff_num_code_length_codes", 4, "Number of Code Length Codes, minus 4")
         code_length_code_lengths = [0]*19 # confusing variable name...
         for i in self.CODE_LENGTH_ORDER[:self["huff_num_code_length_codes"].value+4]:
             field = Bits(self, "huff_code_length_code[%i]" % i, 3, "Code lengths for the code length alphabet")
             yield field
             code_length_code_lengths[i] = field.value
         code_length_tree = build_tree(code_length_code_lengths)
         length_code_lengths = []
         distance_code_lengths = []
         for numcodes, name, lengths in (
             (self["huff_num_length_codes"].value + 257, "length", length_code_lengths),
             (self["huff_num_distance_codes"].value + 1, "distance", distance_code_lengths)):
             while len(lengths) < numcodes:
                 field = HuffmanCode(self, "huff_%s_code[]" % name, code_length_tree)
                 value = field.realvalue
                 if value < 16:
                     prev_value = value
                     field._description = "Literal Code Length %i (Huffman Code %i)" % (value, field.value)
                     yield field
                     lengths.append(value)
                 else:
                     info = {16: (3,6,2),
                             17: (3,10,3),
                             18: (11,138,7)}[value]
                     if value == 16:
                         repvalue = prev_value
                     else:
                         repvalue = 0
                     field._description = "Repeat Code %i, Repeating value (%i) %i to %i times (Huffman Code %i)" % (value, repvalue, info[0], info[1], field.value)
                     yield field
                     extrafield = Bits(self, "huff_%s_code_extra[%s" % (name, field.name.split('[')[1]), info[2])
                     num_repeats = extrafield.value+info[0]
                     extrafield._description = "Repeat Extra Bits (%i), total repeats %i"%(extrafield.value, num_repeats)
                     yield extrafield
                     lengths += [repvalue]*num_repeats
         length_tree = build_tree(length_code_lengths)
         distance_tree = build_tree(distance_code_lengths)
     else:
         raise ParserError("Unsupported compression type 3!")
     while True:
         field = HuffmanCode(self, "length_code[]", length_tree)
         value = field.realvalue
         if value < 256:
             field._description = "Literal Code %r (Huffman Code %i)" % (chr(value), field.value)
             yield field
             self.uncomp_data += chr(value)
         if value == 256:
             field._description = "Block Terminator Code (256) (Huffman Code %i)" % field.value
             yield field
             break
         elif value > 256:
             info = self.LENGTH_SYMBOLS[value]
             if info[2] == 0:
                 field._description = "Length Code %i, Value %i (Huffman Code %i)" % (value, info[0], field.value)
                 length = info[0]
                 yield field
             else:
                 field._description = "Length Code %i, Values %i to %i (Huffman Code %i)" % (value, info[0], info[1], field.value)
                 yield field
                 extrafield = Bits(self, "length_extra[%s" % field.name.split('[')[1], info[2])
                 length = extrafield.value + info[0]
                 extrafield._description = "Length Extra Bits (%i), total length %i"%(extrafield.value, length)
                 yield extrafield
             field = HuffmanCode(self, "distance_code[]", distance_tree)
             value = field.realvalue
             info = self.DISTANCE_SYMBOLS[value]
             if info[2] == 0:
                 field._description = "Distance Code %i, Value %i (Huffman Code %i)" % (value, info[0], field.value)
                 distance = info[0]
#.........这里部分代码省略.........
开发者ID:AdriSol,项目名称:metagoofil,代码行数:103,代码来源:zlib.py


注:本文中的hachoir_core.field.Bits._description方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。