예제 #1
0
 def parse_ne(self):
     """Parse Netscape Extension"""
     length = parse_int(self.next_byte(), 'big')
     bts = self.next_bytes(length)
     self.ind_loops = self._ip - length
     loops = parse_int(bts[-2:], 'big')
     self.loops = "Infinity" if loops == 0 else str(loops)
     self.next_byte()
예제 #2
0
 def parse_gce(self):
     """Parse Graphic Control Extension"""
     length = parse_int(self.next_byte(), 'big')
     bts = self.next_bytes(length)
     delay = parse_int(bts[2:], 'little')
     bg_ind = parse_int(bts[-1:], 'big')
     self.next_byte()
     return delay, bg_ind
예제 #3
0
 def parse_lsd(self, byte_arr):
     """Parse Logical Screen Descriptor"""
     data = byte_arr[:6]
     self.spec = data.decode('utf-8')
     if not self.spec.startswith("GIF"):
         raise ValueError("Wrong gif format")
     width = parse_int(byte_arr[6:8], 'little')
     height = parse_int(byte_arr[8:10], 'little')
     self.size = width, height
     self._parse_bin(byte_arr[10])
     self.num_bg_color = 0 if self.ct_flag else parse_int([byte_arr[11]],
                                                          'big')
     par = parse_int([byte_arr[12]], 'big')
     self.aratio = (par + 15) / 64 if par != 0 else 0
예제 #4
0
 def parse_ce(self):
     """Parse Comment Extension"""
     length = self.next_byte()
     comment = ""
     while length != b"\x00" and length:
         block = self.next_bytes(parse_int(length, 'big'))
         comment += block.decode("utf-8", errors='ignore')
         length = self.next_byte()
     return comment
예제 #5
0
 def skip(self):
     """Skip not interesting block"""
     length = self.next_byte()
     while length != b"\x00" and length:
         self.next_bytes(parse_int(length, 'big'))
         length = self.next_byte()
예제 #6
0
 def _parse_bin(self, byte):
     """Parse some special for gif binary string"""
     bin_line = bin(parse_int([byte], 'big'))[2:].rjust(8, "0")
     self.ct_flag = bool(int(bin_line[0], 2))
     self.ct_len = 3 * 2**(int(bin_line[-3:], 2) + 1) if self.ct_flag else 0
     self.colors_count = 2**(3 * (int(bin_line[1:4], 2) + 1))