예제 #1
0
    def __init__(self):
        self.width = 16
        self.height = 16
        format = imgformat.colormap
        self.format = format
        self.format_choices = (format, )
        import imgcolormap
        if _bigendian:
            self.colormap = imgcolormap.new('''\
\0\0\0\0\0f\377f\0\0\377\0\0\1\1\1''')
        else:
            self.colormap = imgcolormap.new('''\
\0\0\0\0f\377f\0\0\377\0\0\1\1\1\0''')
        self.transparent = 3
        self.top = 0
        self.left = 0
        self.aspect = 0
예제 #2
0
 def __init__(self):
     self.width = 16
     self.height = 16
     self.format = imgformat.colormap
     self.format_choices = (self.format, )
     import imgcolormap
     self.colormap = imgcolormap.new('''\0\377\0\0''')
     self.transparent = 0
     self.top = 0
     self.left = 0
     self.aspect = 0
예제 #3
0
def findformat(dpy, visual):
    import imgformat
    cmap = visual.CreateColormap(X.AllocNone)
    if visual.c_class == X.PseudoColor:
        r, g, b = imgformat.xrgb8.descr['comp'][:3]
        red_shift,   red_mask   = r[0], (1 << r[1]) - 1
        green_shift, green_mask = g[0], (1 << g[1]) - 1
        blue_shift,  blue_mask  = b[0], (1 << b[1]) - 1
        (plane_masks, pixels) = cmap.AllocColorCells(1, 8, 1)
        xcolors = []
        for n in range(256):
            # The colormap is set up so that the colormap
            # index has the meaning: rrrbbggg (same as
            # imgformat.xrgb8).
            xcolors.append(
                    (n+pixels[0],
                     int(float((n >> red_shift) & red_mask) / red_mask * 65535. + .5),
                     int(float((n >> green_shift) & green_mask) / green_mask * 65535. + .5),
                     int(float((n >> blue_shift) & blue_mask) / blue_mask * 65535. + .5),
                      X.DoRed|X.DoGreen|X.DoBlue))
        cmap.StoreColors(xcolors)
    else:
        red_shift, red_mask = _colormask(visual.red_mask)
        green_shift, green_mask = _colormask(visual.green_mask)
        blue_shift, blue_mask = _colormask(visual.blue_mask)
    if visual.depth == 8:
        import imgcolormap, imgconvert
        imgconvert.setquality(0)
        r, g, b = imgformat.xrgb8.descr['comp'][:3]
        xrs, xrm = r[0], (1 << r[1]) - 1
        xgs, xgm = g[0], (1 << g[1]) - 1
        xbs, xbm = b[0], (1 << b[1]) - 1
        c = []
        if (red_mask,green_mask,blue_mask) != (xrm,xgm,xbm):
            for n in range(256):
                r = roundi(((n>>xrs) & xrm) /
                            float(xrm) * red_mask)
                g = roundi(((n>>xgs) & xgm) /
                            float(xgm) * green_mask)
                b = roundi(((n>>xbs) & xbm) /
                            float(xbm) * blue_mask)
                c.append((r << red_shift) |
                         (g << green_shift) |
                         (b << blue_shift))
            lossy = 2
        elif (red_shift,green_shift,blue_shift)==(xrs,xgs,xbs):
            # no need for extra conversion
            myxrgb8 = imgformat.xrgb8
        else:
            for n in range(256):
                r = (n >> xrs) & xrm
                g = (n >> xgs) & xgm
                b = (n >> xbs) & xbm
                c.append((r << red_shift) |
                         (g << green_shift) |
                         (b << blue_shift))
            lossy = 0
        if c:
            myxrgb8 = imgformat.new('myxrgb8',
                    'X 3:3:2 RGB top-to-bottom',
                    {'type': 'rgb',
                     'b2t': 0,
                     'size': 8,
                     'align': 8,
                     # the 3,3,2 below are not
                     # necessarily correct, but they
                     # are not used anyway
                     'comp': ((red_shift, 3),
                              (green_shift, 3),
                              (blue_shift, 2))})
            cm = imgcolormap.new(
                    reduce(lambda x, y: x + '000' + chr(y), c, ''))
            imgconvert.addconverter(
                    imgformat.xrgb8,
                    imgformat.myxrgb8,
                    lambda d, r, src, dst, m=cm: m.map8(d),
                    lossy)
        format = myxrgb8
    else:
        # find an imgformat that corresponds with our visual and
        # with the available pixmap formats
        formats = []
        for pmf in dpy.ListPixmapFormats():
            if pmf[0] == visual.depth:
                formats.append(pmf)
        if not formats:
            raise error, 'no matching Pixmap formats found'
        for name, format in imgformat.__dict__.items():
            if type(format) is not type(imgformat.rgb):
                continue
            descr = format.descr
            if descr['type'] != 'rgb' or descr['b2t'] != 0:
                continue
            for pmf in formats:
                if descr['size'] == pmf[1] and \
                   descr['align'] == pmf[2]:
                    break
            else:
                continue
            r, g, b = descr['comp'][:3]
            if visual.red_mask   == ((1<<r[1])-1) << r[0] and \
               visual.green_mask == ((1<<g[1])-1) << g[0] and \
               visual.blue_mask  == ((1<<b[1])-1) << b[0]:
                break
        else:
            raise error, 'no proper imgformat available'
    return format, cmap, red_shift, red_mask, green_shift, green_mask, blue_shift, blue_mask
예제 #4
0
"""Module to handle conversion between in-core image formats."""