Ejemplo n.º 1
0
 def parse_table(self):
     marker = ordw(self.buffer[0:2])
     if marker == 0xffc4:
         self.parse_DHT()
     elif marker == 0xffcc:
         self.parse_DAC()
     elif marker == 0xffdb:
         self.parse_DQT()
     elif marker == 0xffdd:
         self.parse_DRI()
     elif marker == 0xffdf:
         self.parse_EXP()
     elif marker == 0xffdc:
         self.parse_DNL()
     elif 0xffe0 <= marker <= 0xffef:
         self.parse_APP(marker - 0xffe0)
     elif marker == 0xfffe:
         self.parse_COM()
     elif marker == 0xffd8:
         self._new_marker("SOI", "Start of image")
         self._end_marker()
     elif marker == 0xffd9:
         self._new_marker("EOI", "End of image")
         self._end_marker()
     elif marker >= 0xff01:
         self._new_marker("???", "Unknown marker %04x" % marker)
         if len(self.buffer) < self.buffer_print_limit:
             print_hex(self.buffer)
         self._end_marker()
Ejemplo n.º 2
0
    def stream_parse(self, file, startpos):
        self.pos = 0
        self.datacount = 0
        self.bytecount = 0
        self.offset = startpos

        self.load_buffer(file)
        if ordw(self.buffer) != 0xff10:
            raise RequiredMarkerMissing("SOI marker missing")

        while len(self.buffer) >= 2:
            marker_value = ordw(self.buffer[0:2])
            if marker_value == 0xff11:
                break
            if marker_value == 0xff10:
                self._new_marker("SOC", "Start of Codestream")
                self._end_marker()
            elif marker_value == 0xff12:
                self.parse_PIH()
            elif marker_value == 0xff13:
                self.parse_CDT()
            elif marker_value == 0xff14:
                self.parse_WGT()
            elif marker_value == 0xff15:
                self.parse_COM()
            elif marker_value == 0xff16:
                self.parse_NLT()
            elif marker_value == 0xff17:
                self.parse_CWD()
            elif marker_value == 0xff18:
                self.parse_CTS()
            elif marker_value == 0xff19:
                self.parse_CRG()
            elif marker_value == 0xff20:
                self.parse_SLC()
                self.parse_Slice(file)
            elif marker_value == 0xff50:
                self.parse_CAP()
            else:
                self._new_marker("???", "Unknown marker %04x" % marker_value)
                if len(self.buffer) < self.buffer_print_limit:
                    print_hex(self.buffer)
                self._end_marker()
            self.load_buffer(file)

        if len(self.buffer) >= 2:
            self._new_marker("EOI", "End of image")
        self._end_marker()
        oh = self.bytecount - self.datacount
        self.check_sublevel(self.bytecount)
        self._print_indent("Size      : %d bytes" % self.bytecount)
        self._print_indent("Data Size : %d bytes" % self.datacount)
        self._print_indent("Overhead  : %d bytes (%d%%)" % (oh, 100 * oh / self.bytecount))
Ejemplo n.º 3
0
 def parse_APP(self, idx):
     if idx == 11 and self.buffer[4:6] == b'JP':
         self._new_marker("APP11", "JPEG XT Extension Marker")
         segment = BoxSegment(self.buffer, self.offset)
         self.boxlist.addBoxSegment(segment)
         if self.boxlist.isComplete(segment):
             box = self.boxlist.toBox(segment, self._indent + 1)
             box.parse(self.superhook)
     else:
         self._new_marker(("APP%x" % idx), ("Application marker #%d" % idx))
         if len(self.buffer) < self.buffer_print_limit:
             print_hex(self.buffer)
     self._end_marker()
Ejemplo n.º 4
0
def print_mluc(buf, indent):
    count = ordl(buf[0:4])
    recs = ordl(buf[4:8])
    offs = 8
    for i in range(count):
        code = ordw(buf[offs:offs + 2])
        cntr = ordw(buf[offs + 2:offs + 4])
        lnth = ordl(buf[offs + 4:offs + 8])
        disp = ordl(buf[offs + 8:offs + 12])
        offs = offs + recs
        print_indent(
            "Entry %d for language %c%c, country %c%c :" %
            (i, code >> 8, code & 0xff, cntr >> 8, cntr & 0xff), indent)
        print_hex(buf[disp - 8:disp - 8 + lnth], indent + 2)
Ejemplo n.º 5
0
 def parse_COM(self):
     self._new_marker("COM", "Extensions Marker")
     tcom = ordw(self.buffer[4:6])
     data = self.buffer[6:]
     if tcom == 0:
         self._print_indent("Vendor                   : %s" % data)
     elif tcom == 1:
         self._print_indent("Copyright                : %s" % data)
     elif tcom >= 0x8000:
         self._print_indent("Vendor 0x%4x information :")
         print_hex(data)
     else:
         self._print_indent("Invalid 0x%4x data       :")
         print_hex(data)
     self._end_marker()
Ejemplo n.º 6
0
def print_tag(buf, size, indent):
    sign = buf[0:4]
    print_indent("Tag type: %s" % sign.decode('ascii'), indent)
    print_indent("Reserved: %d" % ordl(buf[4:8]), indent)
    if sign == "desc":
        size = ordl(buf[8:12])
        print_indent(
            "Profile description: %s" % buf[12:12 + size - 1].decode('ascii'),
            indent)
    elif sign == "text":
        print_indent("Text: %s" % buf[8:len(buf) - 1].decode('ascii'), indent)
    elif sign == "XYZ ":
        count = (len(buf) - 8) // 12
        off = 8
        for i in range(count):
            print_xyz(buf[off:off + 12], indent)
            off += 12
    elif sign == "curv":
        print_curve(buf[8:8 + size], indent)
    elif sign == "dtim":
        print_datetime(buf[8:8 + size], indent)
    elif sign == "view":
        print_view(buf[8:8 + size], indent)
    elif sign == "meas":
        print_meas(buf[8:8 + size], indent)
    elif sign == "sig ":
        print_indent("Signature : %s " % readsignature(buf[8:8 + size]),
                     indent)
    elif sign == "mft1":
        print_lut8(buf[8:8 + size], indent)
    elif sign == "mft2":
        print_lut16(buf[8:8 + size], indent)
    elif sign == "mAB ":
        print_lutmAB(buf[8:8 + size], indent)
    elif sign == "mBA ":
        print_lutmAB(buf[8:8 + size], indent)
    elif sign == "para":
        print_para(buf[8:8 + size], indent)
    elif sign == "mluc":
        print_mluc(buf[8:8 + size], indent)
    elif sign == "sf32":
        print_sf32(buf[8:8 + size], indent)
    else:
        print_hex(buf[8:8 + size], indent)
Ejemplo n.º 7
0
def print_lut16(buf, indent):
    print_lutheader(buf, indent)
    ic = ordb(buf[0])
    oc = ordb(buf[1])
    g = ordb(buf[2])
    n = ordw(buf[40:42])
    m = ordw(buf[42:44])
    print_indent("Input  entries   : %d" % ordw(buf[40:42]), indent)
    print_indent("Output entries   : %d" % ordw(buf[42:44]), indent)
    of = 44
    for i in range(ic):
        print_indent("Input  table %d :" % i, indent)
        print_hex(buf[of:of + 2 * n], indent + 1)
        of += 2 * n
    print_indent("CLUT table %d :" % ic, indent)
    print_hex(buf[of:of + 2 * pow(g, ic) * oc], indent + 1)
    of += 2 * pow(g, ic) * oc
    for i in range(oc):
        print_indent("Output table %d :" % i, indent)
        print_hex(buf[of:of + 2 * m], indent + 1)
        of += 2 * m
Ejemplo n.º 8
0
def print_lut8(buf, indent):
    print_lutheader(buf, indent)
    ic = ordb(buf[0])
    oc = ordb(buf[1])
    g = ordb(buf[2])
    n = 256
    m = 256
    print_indent("Input  entries   : %d" % 256, indent)
    print_indent("Output entries   : %d" % 256, indent)
    of = 40
    for i in range(ic):
        print_indent("Input  table %d :" % i, indent)
        print_hex(buf[of:of + n], indent + 1)
        of += n
    print_indent("CLUT table :", indent)
    print_hex(buf[of:of + pow(g, ic) * oc], indent + 1)
    of += pow(g, ic) * oc
    for i in range(oc):
        print_indent("Output table %d :" % i, indent)
        print_hex(buf[of:of + m], indent + 1)
        of += m
Ejemplo n.º 9
0
 def print_hex(self, buf):
     print_hex(buf, self.indent)
Ejemplo n.º 10
0
 def parse_COM(self):
     self._new_marker("COM", "Comment marker")
     if len(self.buffer) < self.buffer_print_limit:
         print_hex(self.buffer)
     self._end_marker()