當前位置: 首頁>>代碼示例>>Python>>正文


Python array.tostring方法代碼示例

本文整理匯總了Python中array.array.tostring方法的典型用法代碼示例。如果您正苦於以下問題:Python array.tostring方法的具體用法?Python array.tostring怎麽用?Python array.tostring使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在array.array的用法示例。


在下文中一共展示了array.tostring方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: make_palette

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def make_palette(self):
        """Create the byte sequences for a ``PLTE`` and if necessary a
        ``tRNS`` chunk.  Returned as a pair (*p*, *t*).  *t* will be
        ``None`` if no ``tRNS`` chunk is necessary.
        """

        p = array('B')
        t = array('B')

        for x in self.palette:
            p.extend(x[0:3])
            if len(x) > 3:
                t.append(x[3])
        p = tostring(p)
        t = tostring(t)
        if t:
            return p,t
        return p,None 
開發者ID:appleseedhq,項目名稱:blenderseed,代碼行數:20,代碼來源:png.py

示例2: make_palette

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def make_palette(self):
        """Create the byte sequences for a ``PLTE`` and if necessary a
        ``tRNS`` chunk.  Returned as a pair (*p*, *t*).  *t* will be
        ``None`` if no ``tRNS`` chunk is necessary.
        """

        p = array('B')
        t = array('B')

        for x in self.palette:
            p.extend(x[0:3])
            if len(x) > 3:
                t.append(x[3])
        p = tostring(p)
        t = tostring(t)
        if t:
            return p, t
        return p, None 
開發者ID:mcgreentn,項目名稱:GDMC,代碼行數:20,代碼來源:png.py

示例3: tostring

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def tostring(row):
            l = len(row)
            return struct.pack('%dB' % l, *row) 
開發者ID:appleseedhq,項目名稱:blenderseed,代碼行數:5,代碼來源:png.py

示例4: read

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def read(self, n):
        r = self.buf[self.offset:self.offset+n]
        if isarray(r):
            r = r.tostring()
        self.offset += n
        return r 
開發者ID:appleseedhq,項目名稱:blenderseed,代碼行數:8,代碼來源:png.py

示例5: serialtoflat

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def serialtoflat(self, bytes, width=None):
        """Convert serial format (byte stream) pixel data to flat row
        flat pixel.
        """

        if self.bitdepth == 8:
            return bytes
        if self.bitdepth == 16:
            bytes = tostring(bytes)
            return array('H',
              struct.unpack('!%dH' % (len(bytes)//2), bytes))
        assert self.bitdepth < 8
        if width is None:
            width = self.width
        # Samples per byte
        spb = 8//self.bitdepth
        out = array('B')
        mask = 2**self.bitdepth - 1
        shifts = map(self.bitdepth.__mul__, reversed(range(spb)))
        l = width
        for o in bytes:
            out.extend([(mask&(o>>s)) for s in shifts][:l])
            l -= spb
            if l <= 0:
                l = width
        return out 
開發者ID:appleseedhq,項目名稱:blenderseed,代碼行數:28,代碼來源:png.py

示例6: tostring

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def tostring(row):
        l = len(row)
        return struct.pack('%dB' % l, *row) 
開發者ID:scanlime,項目名稱:coastermelt,代碼行數:5,代碼來源:png.py

示例7: iterboxed

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def iterboxed(self, rows):
        """Iterator that yields each scanline in boxed row flat pixel
        format.  `rows` should be an iterator that yields the bytes of
        each row in turn.
        """

        def asvalues(raw):
            """Convert a row of raw bytes into a flat row.  Result may
            or may not share with argument"""

            if self.bitdepth == 8:
                return raw
            if self.bitdepth == 16:
                raw = tostring(raw)
                return array('H', struct.unpack('!%dH' % (len(raw)//2), raw))
            assert self.bitdepth < 8
            width = self.width
            # Samples per byte
            spb = 8//self.bitdepth
            out = array('B')
            mask = 2**self.bitdepth - 1
            shifts = map(self.bitdepth.__mul__, reversed(range(spb)))
            for o in raw:
                out.extend(map(lambda i: mask&(o>>i), shifts))
            return out[:width]

        return itertools.imap(asvalues, rows) 
開發者ID:scanlime,項目名稱:coastermelt,代碼行數:29,代碼來源:png.py

示例8: testTrnsArray

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def testTrnsArray(self):
        """Test that reading a type 2 PNG with tRNS chunk yields each
        row as an array (using asDirect)."""
        r = Reader(bytes=_pngsuite['tbrn2c08'])
        list(r.asDirect()[2])[0].tostring

    # Invalid file format tests.  These construct various badly
    # formatted PNG files, then feed them into a Reader.  When
    # everything is working properly, we should get FormatError
    # exceptions raised. 
開發者ID:scanlime,項目名稱:coastermelt,代碼行數:12,代碼來源:png.py

示例9: iterboxed

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def iterboxed(self, rows):
        """Iterator that yields each scanline in boxed row flat pixel
        format.  `rows` should be an iterator that yields the bytes of
        each row in turn.
        """

        def asvalues(raw):
            """Convert a row of raw bytes into a flat row.  Result may
            or may not share with argument"""

            if self.bitdepth == 8:
                return raw
            if self.bitdepth == 16:
                raw = tostring(raw)
                return array('H', struct.unpack('!%dH' % (len(raw)//2), raw))
            assert self.bitdepth < 8
            width = self.width
            # Samples per byte
            spb = 8//self.bitdepth
            out = array('B')
            mask = 2**self.bitdepth - 1
            shifts = list(map(self.bitdepth.__mul__, reversed(list(range(spb)))))
            for o in raw:
                out.extend([mask&(o>>i) for i in shifts])
            return out[:width]

        return map(asvalues, rows) 
開發者ID:bannsec,項目名稱:stegoVeritas,代碼行數:29,代碼來源:png.py

示例10: read

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def read(self, n):
        r = self.buf[self.offset:self.offset + n]
        if isarray(r):
            r = r.tostring()
        self.offset += n
        return r 
開發者ID:mcgreentn,項目名稱:GDMC,代碼行數:8,代碼來源:png.py

示例11: iterboxed

# 需要導入模塊: from array import array [as 別名]
# 或者: from array.array import tostring [as 別名]
def iterboxed(self, rows):
        """Iterator that yields each scanline in boxed row flat pixel
        format.  `rows` should be an iterator that yields the bytes of
        each row in turn.
        """

        def asvalues(raw):
            """Convert a row of raw bytes into a flat row.  Result may
            or may not share with argument"""

            if self.bitdepth == 8:
                return raw
            if self.bitdepth == 16:
                raw = tostring(raw)
                return array('H', struct.unpack('!%dH' % (len(raw) // 2), raw))
            assert self.bitdepth < 8
            width = self.width
            # Samples per byte
            spb = 8 // self.bitdepth
            out = array('B')
            mask = 2 ** self.bitdepth - 1
            shifts = map(self.bitdepth.__mul__, reversed(range(spb)))
            for o in raw:
                out.extend(map(lambda i: mask & (o >> i), shifts))
            return out[:width]

        return itertools.imap(asvalues, rows) 
開發者ID:mcgreentn,項目名稱:GDMC,代碼行數:29,代碼來源:png.py


注:本文中的array.array.tostring方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。