当前位置: 首页>>代码示例>>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;未经允许,请勿转载。