예제 #1
0
def window_flip_and_save():
    global dump_idx
    win = pymt.getWindow()
    glReadBuffer(GL_FRONT)
    data = glReadPixels(0, 0, win.width, win.height, GL_RGB, GL_UNSIGNED_BYTE)
    surface = pygame.image.fromstring(str(buffer(data)), win.size, "RGB", True)
    filename = "%s%05d.%s" % (dump_prefix, dump_idx, dump_format)
    pygame.image.save(surface, filename)
    dump_idx += 1
예제 #2
0
def window_flip_and_save():
    global dump_idx
    win = pymt.getWindow()
    glReadBuffer(GL_FRONT)
    data = glReadPixels(0, 0, win.width, win.height, GL_RGB, GL_UNSIGNED_BYTE)
    surface = pygame.image.fromstring(str(buffer(data)), win.size, 'RGB', True)
    filename = '%s%05d.%s' % (dump_prefix, dump_idx, dump_format)
    pygame.image.save(surface, filename)
    dump_idx += 1
예제 #3
0
 def on_update(self):
     scale = self.scale
     w, h = getWindow().size
     for child in self.children[:]:
         x, y, r = child.circle
         x, y = self.to_parent(x, y)
         r *= self.scale
         if x+r < 0 or x-r > w or y+r < 0 or y-r > h:
             child.do_draw = False
             continue
         else:
             child.do_draw = True
         child.dispatch_event('on_update')
예제 #4
0
 def on_update(self):
     w, h = getWindow().size
     for child in self.children[:]:
         child.dispatch_event('on_update')
         # update child only if we are drawing too
         if self.do_draw:
             x, y, r = child.circle
             x, y = self.parent.to_parent(x, y)
             r *= self.parent.scale
             if x+r < 0 or x-r > w or y+r < 0 or y-r > h:
                 child.do_draw = False
             else:
                 child.do_draw = True
예제 #5
0
파일: fbo.py 프로젝트: vidriloco/pymt
    def release(self):
        # Restore viewport
        if self.push_viewport:
            glPopAttrib()

        # Copy current buffer into fbo texture
        set_texture(self.texture, target=GL_TEXTURE_2D);
        glReadBuffer(GL_BACK)
        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, self.size[0], self.size[1])

        # Restore old buffer
        w = pymt.getWindow()
        glDrawPixels(w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE, self.pixels)

        glPopAttrib()
예제 #6
0
def window_flip_and_save():
    global img_current
    win = pymt.getWindow()

    with lock_current:
        if not connected:
            return

    sem_next.acquire()

    with lock_current:
        glReadBuffer(GL_FRONT)
        data = glReadPixels(0, 0, win.width, win.height, GL_RGB, GL_UNSIGNED_BYTE)
        img_current = str(buffer(data))

    sem_current.release()
예제 #7
0
def get_screen_texture(mode='back'):
    win = getWindow()
    if mode.lower() == 'front':
        glReadBuffer(GL_FRONT)
    else:
        glReadBuffer(GL_BACK)
    data = glReadPixels(0, 0, win.width, win.height, GL_RGB, GL_UNSIGNED_BYTE)

    # do a mini
    size = win.width / 10, win.height / 10
    surf = pygame.image.fromstring(data, win.size, 'RGB')
    surf = pygame.transform.scale(surf, size)
    data = pygame.image.tostring(surf, 'RGB')

    tex = Texture.create(size[0], size[1], GL_RGB, rectangle=True)
    tex.blit_buffer(data)
    return tex, [size[0], size[1], data]
예제 #8
0
파일: fbo.py 프로젝트: gavine199/pymt
    def release(self):
        # Restore viewport
        if self.push_viewport:
            glPopAttrib()

        # Copy current buffer into fbo texture
        set_texture(self.texture, target=GL_TEXTURE_2D)
        glReadBuffer(GL_BACK)
        glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, self.size[0], self.size[1])

        # Restore old buffer
        w = pymt.getWindow()
        glDrawPixels(w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE, self.pixels)

        glPopAttrib()

        super(SoftwareFbo, self).release()
예제 #9
0
def window_flip_and_save():
    global img_current
    win = pymt.getWindow()

    with lock_current:
        if not connected:
            return

    sem_next.acquire()

    with lock_current:
        glReadBuffer(GL_FRONT)
        data = glReadPixels(0, 0, win.width, win.height, GL_RGB,
                            GL_UNSIGNED_BYTE)
        img_current = str(buffer(data))

    sem_current.release()
예제 #10
0
 def on_draw(self):
     w, h = getWindow().size
     with gx_matrix:
         glMultMatrixf(self.transform_mat)
         self.draw()
         for child in [x for x in self.children if x.do_draw]:
             child.dispatch_event('on_draw')
         # draw pen
         glLineWidth(3)
         set_color(.8, .8, .8, .8)
         for x in self.linepen:
             drawLine(x)
         # draw selection
         if len(self.selection) > 2:
             set_color(.2, .6, .2, .8)
             drawLine(self.selection)
             set_color(.2, .6, .2, .3)
             drawLine(self.selection[-1] + self.selection[0])
예제 #11
0
파일: fbo.py 프로젝트: hansent/pymt
    def bind(self):
        super(SoftwareFbo, self).bind()

        # Save current buffer
        w = pymt.getWindow()
        glReadBuffer(GL_BACK)
        self.pixels = glReadPixels(0, 0, w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE)

        # Push current attrib
        glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_TEST | GL_STENCIL_BUFFER_BIT)
        glDisable(GL_STENCIL_TEST)

        # Save viewport if asked
        if self.push_viewport:
            glPushAttrib(GL_VIEWPORT_BIT)
            glViewport(0, 0, self.size[0], self.size[1])

        # Draw old Framebuffer
        set_color(1, 1, 1)
        drawTexturedRectangle(self.texture, size=self.size)
예제 #12
0
파일: fbo.py 프로젝트: gavine199/pymt
    def bind(self):
        super(SoftwareFbo, self).bind()

        # Save current buffer
        w = pymt.getWindow()
        glReadBuffer(GL_BACK)
        self.pixels = glReadPixels(0, 0, w.width, w.height, GL_RGBA, GL_UNSIGNED_BYTE)

        # Push current attrib
        glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_TEST | GL_STENCIL_BUFFER_BIT)
        glDisable(GL_STENCIL_TEST)

        # Save viewport if asked
        if self.push_viewport:
            glPushAttrib(GL_VIEWPORT_BIT)
            glViewport(0, 0, self.size[0], self.size[1])

        # Draw old Framebuffer
        set_color(1, 1, 1)
        drawTexturedRectangle(self.texture, size=self.size)
예제 #13
0
파일: start.py 프로젝트: arasbm/pymt-apps
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''

if __name__ == '__main__':

    import sys
    from pymt import runTouchApp, getWindow

    if len(sys.argv) < 2:
        print
        print 'Usage: python start.py <filename_of_presentation.m>'
        print
        print 'To create a new presentation, just start application'
        print 'with a new filename.'
        print
        sys.exit(1)


    from app import Presemt

    dontrun = False
    m = Presemt(size=getWindow().size)
    m.load(sys.argv[1])
    if len(sys.argv) >= 3:
        if sys.argv[2] == '--pdf':
            m.export_to_pdf()
            dontrun = True
    if not dontrun:
        runTouchApp(m)

예제 #14
0
    def _stream_video(self):
        global img_current

        lfps        = []
        dt          = 0
        frames      = 0
        fps_wanted  = self.server.config.get('fps')
        if fps_wanted == '':
            fps_wanted = 0
        fps_wanted = float(fps_wanted)
        if fps_wanted <= 1:
            fps_wanted = 0
        else:
            fps_wanted = 1 / fps_wanted
        size        = self.server.config.get('size')
        if size == '':
            size = None
        else:
            size = map(int, size.split('x'))

        pymt.pymt_logger.info(
            'MjpegServer: Client %s:%d connected' % self.client_address)

        self.send_response(200, 'OK')
        self.boundary = 'pymt-mjpegserver-boundary-%d' % (random.randint(1, 9999999))
        self.send_header('Server', 'PyMT MjpegServer')
        self.send_header('Content-type', 'multipart/x-mixed-replace; boundary=%s' % self.boundary)
        self.end_headers()

        # don't accept connection until the window is created
        # XXX really needed ?
        while not pymt.getWindow():
            time.sleep(0.1)
        win = pymt.getWindow()

        dt = dt_current = dt_old = time.time()
        while keep_running():

            # SYNC START
            sem_current.acquire()

            with lock_current:
                im = Image.fromstring('RGB', win.size, img_current)
                img_current = None

            sem_next.release()
            # SYNC END

            buf = StringIO.StringIO()
            if size:
                im = im.resize(size)
            im = im.transpose(Image.FLIP_TOP_BOTTOM)
            im.save(buf, format='JPEG')
            jpeg = buf.getvalue()

            self.wfile.write('--%s\r\n' % self.boundary)
            self.wfile.write('Content-Type: image/jpeg\r\n')
            self.wfile.write('Content-Length: %d\r\n\r\n' % len(jpeg))
            self.wfile.write(jpeg)

            dt_old = dt_current
            dt_current = time.time()

            d = dt_current - dt_old
            if d < fps_wanted:
                time.sleep(d)

            frames += 1
            if dt_current - dt > 2.:
                fps = frames / (dt_current - dt)
                lfps.append(fps)
                x = sum(lfps) / len(lfps)
                pymt.pymt_logger.debug('MjpegServer: current FPS is %.1f, average is %.1f' % (fps, x))
                dt = dt_current
                frames = 0
예제 #15
0
    def _stream_video(self):
        global img_current

        lfps = []
        dt = 0
        frames = 0
        fps_wanted = self.server.config.get('fps')
        if fps_wanted == '':
            fps_wanted = 0
        fps_wanted = float(fps_wanted)
        if fps_wanted <= 1:
            fps_wanted = 0
        else:
            fps_wanted = 1 / fps_wanted
        size = self.server.config.get('size')
        if size == '':
            size = None
        else:
            size = map(int, size.split('x'))

        pymt.pymt_logger.info('MjpegServer: Client %s:%d connected' %
                              self.client_address)

        self.send_response(200, 'OK')
        self.boundary = 'pymt-mjpegserver-boundary-%d' % (random.randint(
            1, 9999999))
        self.send_header('Server', 'PyMT MjpegServer')
        self.send_header(
            'Content-type',
            'multipart/x-mixed-replace; boundary=%s' % self.boundary)
        self.end_headers()

        # don't accept connection until the window is created
        # XXX really needed ?
        while not pymt.getWindow():
            time.sleep(0.1)
        win = pymt.getWindow()

        dt = dt_current = dt_old = time.time()
        while keep_running():

            # SYNC START
            sem_current.acquire()

            with lock_current:
                im = Image.fromstring('RGB', win.size, img_current)
                img_current = None

            sem_next.release()
            # SYNC END

            buf = StringIO.StringIO()
            if size:
                im = im.resize(size)
            im = im.transpose(Image.FLIP_TOP_BOTTOM)
            im.save(buf, format='JPEG')
            jpeg = buf.getvalue()

            self.wfile.write('--%s\r\n' % self.boundary)
            self.wfile.write('Content-Type: image/jpeg\r\n')
            self.wfile.write('Content-Length: %d\r\n\r\n' % len(jpeg))
            self.wfile.write(jpeg)

            dt_old = dt_current
            dt_current = time.time()

            d = dt_current - dt_old
            if d < fps_wanted:
                time.sleep(d)

            frames += 1
            if dt_current - dt > 2.:
                fps = frames / (dt_current - dt)
                lfps.append(fps)
                x = sum(lfps) / len(lfps)
                pymt.pymt_logger.debug(
                    'MjpegServer: current FPS is %.1f, average is %.1f' %
                    (fps, x))
                dt = dt_current
                frames = 0