Пример #1
0
def main(use_rgbimg=1):

    # Create binary test files
    uu.decode(get_qualified_path('testrgb'+os.extsep+'uue'), 'test'+os.extsep+'rgb')

    if use_rgbimg:
        image, width, height = getrgbimage('test'+os.extsep+'rgb')
    else:
        image, width, height = getimage('test'+os.extsep+'rgb')

    # Return the selected part of image, which should by width by height
    # in size and consist of pixels of psize bytes.
    if verbose:
        print 'crop'
    newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 1)

    # Return image scaled to size newwidth by newheight. No interpolation
    # is done, scaling is done by simple-minded pixel duplication or removal.
    # Therefore, computer-generated images or dithered images will
    # not look nice after scaling.
    if verbose:
        print 'scale'
    scaleimage = imageop.scale(image, 4, width, height, 1, 1)

    # Run a vertical low-pass filter over an image. It does so by computing
    # each destination pixel as the average of two vertically-aligned source
    # pixels. The main use of this routine is to forestall excessive flicker
    # if the image two vertically-aligned source pixels,  hence the name.
    if verbose:
        print 'tovideo'
    videoimage = imageop.tovideo (image, 4, width, height)

    # Convert an rgb image to an 8 bit rgb
    if verbose:
        print 'rgb2rgb8'
    greyimage = imageop.rgb2rgb8(image, width, height)

    # Convert an 8 bit rgb image to a 24 bit rgb image
    if verbose:
        print 'rgb82rgb'
    image = imageop.rgb82rgb(greyimage, width, height)

    # Convert an rgb image to an 8 bit greyscale image
    if verbose:
        print 'rgb2grey'
    greyimage = imageop.rgb2grey(image, width, height)

    # Convert an 8 bit greyscale image to a 24 bit rgb image
    if verbose:
        print 'grey2rgb'
    image = imageop.grey2rgb(greyimage, width, height)

    # Convert a 8-bit deep greyscale image to a 1-bit deep image by
    # thresholding all the pixels. The resulting image is tightly packed
    # and is probably only useful as an argument to mono2grey.
    if verbose:
        print 'grey2mono'
    monoimage = imageop.grey2mono (greyimage, width, height, 0)

    # monoimage, width, height = getimage('monotest.rgb')
    # Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
    # All pixels that are zero-valued on input get value p0 on output and
    # all one-value input pixels get value p1 on output. To convert a
    # monochrome  black-and-white image to greyscale pass the values 0 and
    # 255 respectively.
    if verbose:
        print 'mono2grey'
    greyimage = imageop.mono2grey (monoimage, width, height, 0, 255)

    # Convert an 8-bit greyscale image to a 1-bit monochrome image using a
    # (simple-minded) dithering algorithm.
    if verbose:
        print 'dither2mono'
    monoimage = imageop.dither2mono (greyimage, width, height)

    # Convert an 8-bit greyscale image to a 4-bit greyscale image without
    # dithering.
    if verbose:
        print 'grey2grey4'
    grey4image = imageop.grey2grey4 (greyimage, width, height)

    # Convert an 8-bit greyscale image to a 2-bit greyscale image without
    # dithering.
    if verbose:
        print 'grey2grey2'
    grey2image = imageop.grey2grey2 (greyimage, width, height)

    # Convert an 8-bit greyscale image to a 2-bit greyscale image with
    # dithering. As for dither2mono, the dithering algorithm is currently
    # very simple.
    if verbose:
        print 'dither2grey2'
    grey2image = imageop.dither2grey2 (greyimage, width, height)

    # Convert a 4-bit greyscale image to an 8-bit greyscale image.
    if verbose:
        print 'grey42grey'
    greyimage = imageop.grey42grey (grey4image, width, height)

    # Convert a 2-bit greyscale image to an 8-bit greyscale image.
    if verbose:
        print 'grey22grey'
    image = imageop.grey22grey (grey2image, width, height)

    # Cleanup
    unlink('test'+os.extsep+'rgb')
Пример #2
0
def main(use_rgbimg=1):

    # Create binary test files
    uu.decode(get_qualified_path('testrgb' + os.extsep + 'uue'),
              'test' + os.extsep + 'rgb')

    if use_rgbimg:
        image, width, height = getrgbimage('test' + os.extsep + 'rgb')
    else:
        image, width, height = getimage('test' + os.extsep + 'rgb')

    # Return the selected part of image, which should by width by height
    # in size and consist of pixels of psize bytes.
    if verbose:
        print 'crop'
    newimage = imageop.crop(image, 4, width, height, 0, 0, 1, 1)

    # Return image scaled to size newwidth by newheight. No interpolation
    # is done, scaling is done by simple-minded pixel duplication or removal.
    # Therefore, computer-generated images or dithered images will
    # not look nice after scaling.
    if verbose:
        print 'scale'
    scaleimage = imageop.scale(image, 4, width, height, 1, 1)

    # Run a vertical low-pass filter over an image. It does so by computing
    # each destination pixel as the average of two vertically-aligned source
    # pixels. The main use of this routine is to forestall excessive flicker
    # if the image two vertically-aligned source pixels,  hence the name.
    if verbose:
        print 'tovideo'
    videoimage = imageop.tovideo(image, 4, width, height)

    # Convert an rgb image to an 8 bit rgb
    if verbose:
        print 'rgb2rgb8'
    greyimage = imageop.rgb2rgb8(image, width, height)

    # Convert an 8 bit rgb image to a 24 bit rgb image
    if verbose:
        print 'rgb82rgb'
    image = imageop.rgb82rgb(greyimage, width, height)

    # Convert an rgb image to an 8 bit greyscale image
    if verbose:
        print 'rgb2grey'
    greyimage = imageop.rgb2grey(image, width, height)

    # Convert an 8 bit greyscale image to a 24 bit rgb image
    if verbose:
        print 'grey2rgb'
    image = imageop.grey2rgb(greyimage, width, height)

    # Convert a 8-bit deep greyscale image to a 1-bit deep image by
    # thresholding all the pixels. The resulting image is tightly packed
    # and is probably only useful as an argument to mono2grey.
    if verbose:
        print 'grey2mono'
    monoimage = imageop.grey2mono(greyimage, width, height, 0)

    # monoimage, width, height = getimage('monotest.rgb')
    # Convert a 1-bit monochrome image to an 8 bit greyscale or color image.
    # All pixels that are zero-valued on input get value p0 on output and
    # all one-value input pixels get value p1 on output. To convert a
    # monochrome  black-and-white image to greyscale pass the values 0 and
    # 255 respectively.
    if verbose:
        print 'mono2grey'
    greyimage = imageop.mono2grey(monoimage, width, height, 0, 255)

    # Convert an 8-bit greyscale image to a 1-bit monochrome image using a
    # (simple-minded) dithering algorithm.
    if verbose:
        print 'dither2mono'
    monoimage = imageop.dither2mono(greyimage, width, height)

    # Convert an 8-bit greyscale image to a 4-bit greyscale image without
    # dithering.
    if verbose:
        print 'grey2grey4'
    grey4image = imageop.grey2grey4(greyimage, width, height)

    # Convert an 8-bit greyscale image to a 2-bit greyscale image without
    # dithering.
    if verbose:
        print 'grey2grey2'
    grey2image = imageop.grey2grey2(greyimage, width, height)

    # Convert an 8-bit greyscale image to a 2-bit greyscale image with
    # dithering. As for dither2mono, the dithering algorithm is currently
    # very simple.
    if verbose:
        print 'dither2grey2'
    grey2image = imageop.dither2grey2(greyimage, width, height)

    # Convert a 4-bit greyscale image to an 8-bit greyscale image.
    if verbose:
        print 'grey42grey'
    greyimage = imageop.grey42grey(grey4image, width, height)

    # Convert a 2-bit greyscale image to an 8-bit greyscale image.
    if verbose:
        print 'grey22grey'
    image = imageop.grey22grey(grey2image, width, height)

    # Cleanup
    unlink('test' + os.extsep + 'rgb')
Пример #3
0
import imageop
Пример #4
0
import imageop
Пример #5
0
#! /usr/bin/env python
Пример #6
0
class Displayer(VideoParams):

    # Initialize an instance.
    # This does not need a current window

    def __init__(self):
        if no_gl:
            raise RuntimeError, \
               'no gl module available, so cannot display'
        VideoParams.__init__(self)
        # User-settable parameters
        self.magnify = 1.0  # frame magnification factor
        self.xorigin = 0  # x frame offset
        self.yorigin = 0  # y frame offset (from bottom)
        self.quiet = 0  # if set, don't print messages
        self.fallback = 1  # allow fallback to grey
        # Internal flags
        self.colormapinited = 0  # must initialize window
        self.skipchrom = 0  # don't skip chrominance data
        self.color0 = None  # magic, used by clearto()
        self.fixcolor0 = 0  # don't need to fix color0
        self.mustunpack = (not support_packed_pixels())

    # setinfo() must reset some internal flags

    def setinfo(self, values):
        VideoParams.setinfo(self, values)
        self.colormapinited = 0
        self.skipchrom = 0
        self.color0 = None
        self.fixcolor0 = 0

    # Show one frame, initializing the window if necessary

    def showframe(self, data, chromdata):
        self.showpartframe(data, chromdata, \
           (0,0,self.width,self.height))

    def showpartframe(self, data, chromdata, (x, y, w, h)):
        pmsize = self.bpp
        xpf, ypf = self.xpf, self.ypf
        if self.upside_down:
            gl.pixmode(GL.PM_TTOB, 1)
        if self.mirror_image:
            gl.pixmode(GL.PM_RTOL, 1)
        if self.format in ('jpeg', 'jpeggrey'):
            import jpeg
            data, width, height, bytes = jpeg.decompress(data)
            pmsize = bytes * 8
        elif self.format == 'compress':
            data = self.decompress(data)
            pmsize = 32
        elif self.format in ('mono', 'grey4'):
            if self.mustunpack:
                if self.format == 'mono':
                    data = imageop.mono2grey(data, \
                       w/xpf, h/ypf, 0x20, 0xdf)
                elif self.format == 'grey4':
                    data = imageop.grey42grey(data, \
                       w/xpf, h/ypf)
                pmsize = 8
        elif self.format == 'grey2':
            data = imageop.grey22grey(data, w / xpf, h / ypf)
            pmsize = 8
        if not self.colormapinited:
            self.initcolormap()
        if self.fixcolor0:
            gl.mapcolor(self.color0)
            self.fixcolor0 = 0
        xfactor = yfactor = self.magnify
        xfactor = xfactor * xpf
        yfactor = yfactor * ypf
        if chromdata and not self.skipchrom:
            cp = self.chrompack
            cx = int(x * xfactor * cp) + self.xorigin
            cy = int(y * yfactor * cp) + self.yorigin
            cw = (w + cp - 1) / cp
            ch = (h + cp - 1) / cp
            gl.rectzoom(xfactor * cp, yfactor * cp)
            gl.pixmode(GL.PM_SIZE, 16)
            gl.writemask(self.mask - ((1 << self.c0bits) - 1))
            gl.lrectwrite(cx, cy, cx + cw - 1, cy + ch - 1, \
               chromdata)
        #
        if pmsize < 32:
            gl.writemask((1 << self.c0bits) - 1)
        gl.pixmode(GL.PM_SIZE, pmsize)
        w = w / xpf
        h = h / ypf
        x = x / xpf
        y = y / ypf
        gl.rectzoom(xfactor, yfactor)
        x = int(x * xfactor) + self.xorigin
        y = int(y * yfactor) + self.yorigin
        gl.lrectwrite(x, y, x + w - 1, y + h - 1, data)
        gl.gflush()
Пример #7
0
def mono2grey(img, x, y):
    return imageop.mono2grey(img, x, y, 0, 255)
Пример #8
0
#! /usr/bin/env python
Пример #9
0
def mono2grey(img, x, y):
	return imageop.mono2grey(img, x, y, 0, 255)
Пример #10
0
# Classes to read and write CMIF video files.