Update of /cvsroot/freevo/kaa/mevas/src/displays
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6532/mevas/src/displays
Added Files:
.cvsignore __init__.py bitmapcanvas.py bmovlcanvas.py
directfbcanvas.py imlib2canvas.py ivtvcanvas.py
pygamecanvas.py
Log Message:
move mevas to kaa.mevas
--- NEW FILE: .cvsignore ---
*.pyc *.pyo
--- NEW FILE: imlib2canvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# imlib2canvas.py - output display for imlib2 window
# -----------------------------------------------------------------------------
# $Id: imlib2canvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# Mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Jason Tackaberry <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
# imlib2
from kaa import Imlib2
# mevas imports
from kaa import mevas
# displays imports
from bitmapcanvas import *
class Imlib2Canvas(BitmapCanvas):
def __init__(self, size, dither = True, blend = False):
super(Imlib2Canvas, self).__init__(size, preserve_alpha = blend)
self._display = Imlib2.Display(size, dither, blend)
self._display.set_cursor_hide_timeout(1)
def _blit(self, img, r):
pos, size = r
if not self._display.backing_store:
# Sets the backing store for the Imlib2 display for default
# expose handler.
# FIXME: this requires app to call canvas._display.handle_events()
# Need to offer an API within mevas for this.
if self.alpha < 255:
bs = self._backing_store_with_alpha
else:
bs = self._backing_store
# We can only use the canvas backing store image if it's an
# Imlib2 image.
if isinstance(bs, mevas.imagelib.get_backend("imlib2").Image):
self._display.set_backing_store(self._backing_store._image)
if isinstance(img, mevas.imagelib.get_backend("imlib2").Image):
self._display.render(img._image, pos, pos, size)
else:
if img.size != size:
img = imagelib.crop(img, pos, size)
data = img.get_raw_data("RGB")
img = Imlib2.new( size, data, "RGB" )
self._display.render(img, pos)
--- NEW FILE: pygamecanvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# pygamecanvas.py - output canvas for pygame (SDL)
# -----------------------------------------------------------------------------
# $Id: pygamecanvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# kaa-mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
# pygame (SDL) imports
import pygame
from pygame.locals import *
# mevas imports
from kaa import mevas
import kaa.mevas.rect as rect
from kaa.display import image_to_surface
# displays import
from bitmapcanvas import *
class PygameCanvas(BitmapCanvas):
def __init__(self, size):
super(PygameCanvas, self).__init__(size, preserve_alpha = False)
# Initialize the PyGame modules.
if not pygame.display.get_init():
pygame.display.init()
pygame.font.init()
self._screen = pygame.display.set_mode(size, 0, 32)
if self._screen.get_bitsize() != 32:
# if the bitsize is not 32 as requested, we need
# a tmp surface to convert from imlib2 to pygame
# because imlib2 uses 32 bit and with a different
# value memcpy will do nasty things
self._surface = pygame.Surface(size, 0, 32)
self._rect = []
def _update_end(self, object = None):
if not self._rect:
return
if hasattr(self, '_surface'):
image_to_surface(self._backing_store._image._image, self._surface)
for pos, size in self._rect:
self._screen.blit(self._surface, pos, pos + size)
else:
image_to_surface(self._backing_store._image._image, self._screen)
pygame.display.update(self._rect)
self._rect = []
def _blit(self, img, r):
if isinstance(img, mevas.imagelib.get_backend("imlib2").Image):
pass
elif isinstance(img, mevas.imagelib.get_backend("pygame").Image):
# FIXME: add code for native pygame images here.
pass
else:
# FIXME: add code for not imlib2 images here
pass
self._rect.append(r)
--- NEW FILE: bitmapcanvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# bitmapcanvas.py - Template for a bitmap based display canvas
# -----------------------------------------------------------------------------
# $Id: bitmapcanvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# kaa-mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Jason Tackaberry <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
from kaa import mevas
from kaa.mevas.util import *
from kaa.mevas.canvas import *
from kaa.mevas.image import *
from kaa.mevas.text import *
from kaa.mevas import rect
class BitmapCanvas(Canvas):
"""
Canvas that renders to a bitmap. This canvas isn't very useful by itself,
but is intended to be derived by bitmap-based displays. This canvas uses
CanvasContainer._get_backing_store to do the heavy lifting, so most of
the real logic can be found in that function.
Derived classes will have to implement _blit(), and likely also
_update_end() to flip the buffered page.
"""
def __init__(self, size, preserve_alpha = False, blit_once = True,
slices = False):
super(BitmapCanvas, self).__init__(size)
self._preserve_alpha = preserve_alpha
self._blit_once = blit_once
self._slices = slices
self._blit_rects = []
self._canvas_frozen = 0
self._backing_store_with_alpha = mevas.imagelib.new(size)
def _update_begin(self, object = None):
# Returning False here will abort the update, such as if the display
# is not yet initialized or otherwise ready for blitting.
return True
def _update_end(self, object = None):
# We don't do anything here, but subclasses will probably flip page
# so what we drew in _blit() gets updated on the display.
return True
def freeze(self):
self._canvas_frozen += 1
def thaw(self):
if self._canvas_frozen > 0:
self._canvas_frozen -= 1
if self._canvas_frozen == 0 and len(self._blit_rects):
self._update_begin()
img = self._get_backing_store(use_cached = True)[0]
self._blit_regions( img, self._blit_rects )
self._update_end()
self._blit_rects = []
def child_paint(self, child, force_children = False):
img, dirty_rects = self._get_backing_store(update = True,
update_object = child,
clip = True,
preserve_alpha = \
self._preserve_alpha)
if len(dirty_rects) == 0:
return
if self._canvas_frozen > 0:
self._blit_rects = rect.reduce(self._blit_rects + dirty_rects)
else:
self._blit_regions(img, dirty_rects)
def _blit_regions(self, img, regions):
# Merge the regions into one big union of blit_once is True
if self._slices:
new_regions = []
for ((x, y), (w, h)) in regions:
new_regions.append( ((0, y), (img.width, h)), )
regions = new_regions
if self._blit_once:
region = regions.pop()
while regions:
region = rect.union(region, regions.pop())
regions = [region]
# It's the container's responsibility to apply children's alpha
# values. But there is no parent of the canvas to do that, so we
# do that here if it's necessary.
if self.alpha < 255:
if self._preserve_alpha:
self._backing_store_with_alpha.clear()
self._backing_store_with_alpha.blend(img, alpha = self.alpha)
else:
self._backing_store_with_alpha.draw_rectangle( (0, 0),
img.size,
(0, 0, 0, 255),
fill = True)
self._backing_store_with_alpha.blend(img, alpha = self.alpha,
merge_alpha = False)
img = self._backing_store_with_alpha
regions = rect.optimize_for_rendering(regions)
for r in regions:
# Clip rectangle to screen.
r = rect.intersect( r, ((0, 0), self.get_size()) )
if r == rect.empty:
continue
self._blit(img, r)
def _blit(self, img, r):
pass
def rebuild(self):
self.queue_paint()
self.update()
def child_deleted(self, child):
# If we have rendered this child to the backing store, we need to
# queue its parent for redraw so that the child gets visibly removed
# on the next update(). The child's rectangle was dirtied on the
# backing store by remove_child(), so all we need to do is ensure it
# gets drawn on the next update.
if child.get_parent() and hasattr(child, "_backing_store_info"):
#print "Child deleted", child
child.parent().queue_paint()
--- NEW FILE: ivtvcanvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# ivtvcanvas.py - output display on ivtv osd
# -----------------------------------------------------------------------------
# $Id: ivtvcanvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# Mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Jason Tackaberry <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
# python imports
import os
import fcntl
import struct
# mevas imports
from kaa import mevas
from kaa.mevas import imagelib
# displays import
from bitmapcanvas import *
IVTVFB_IOCTL_SET_STATE = 1074282498
IVTVFB_IOCTL_PREP_FRAME = 1074544643
FBIOGET_FSCREENINFO = 17922
class IvtvCanvas(BitmapCanvas):
def __init__(self, size, fb_device = "/dev/fb0"):
super(IvtvCanvas, self).__init__(size, preserve_alpha = True,
slices = True)
self._fb_device = fb_device
self._fd = os.open(fb_device, os.O_RDWR)
r = fcntl.ioctl(self._fd, FBIOGET_FSCREENINFO, " " * 68)
r = struct.unpack("16sLLLLLHHHLLLLHHHH", r)
self._fb_size, self._fb_stride = r[2], r[9]
self._fb_height = self._fb_size / self._fb_stride
self._fb_width = self._fb_stride / 4
self._set_ivtv_alpha(255)
def __del__(self):
self.clear()
# We can't call update() because self.canvas weakref is dead.
self.child_paint(self)
def _set_ivtv_alpha(self, alpha):
r = struct.pack("LL", 13L, alpha)
r = fcntl.ioctl(self._fd, IVTVFB_IOCTL_SET_STATE, r)
def _blit(self, img, region):
scale_x = self._fb_width / float(img.width)
scale_y = self._fb_height / float(img.height)
# FIXME: This is weird, but when we blit an image whose height is
# less than 60 or so, things go all screwy.
offset_h = 5
if region[1][1] < 50/scale_y:
offset_h = int(50/scale_y)
region = rect.offset(region, (0, -offset_h), (0, offset_h*2) )
region = rect.clip(region, ((0, 0), self.get_size()) )
# Translate the canvas region to the framebuffer region.
dst_region = rect.translate(region, scale = (scale_x, scale_y),
scale_pos = True)
# Scale the slice to the necessary aspect.
img = imagelib.scale(img, (self._fb_width, dst_region[1][1]),
(0, region[0][1]), (img.width, region[1][1]) )
data = img.get_raw_data("BGRA")
address = data.get_buffer_address()
assert( address != 0)
start = dst_region[0][1] * self._fb_stride
size = dst_region[1][1] * self._fb_stride
#args = struct.pack("PLi", address, 0, len(data))
args = struct.pack("PLi", address, start, size)
r = fcntl.ioctl(self._fd, IVTVFB_IOCTL_PREP_FRAME, args)
--- NEW FILE: bmovlcanvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# bmovlcanvas.py - output canvas for bmovl
# -----------------------------------------------------------------------------
# $Id: bmovlcanvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# kaa-mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Dirk Meyer <[EMAIL PROTECTED]>
# Maintainer: Dirk Meyer <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
# python imports
import os
# mevas imports
import kaa.mevas.rect as rect
from kaa.mevas import imagelib
# displays imports
from bitmapcanvas import *
fifo_counter = 0
def create_fifo():
"""
return a unique fifo name
"""
global fifo_counter
fifo = '/tmp/bmovl-%s-%s' % (os.getpid(), fifo_counter)
fifo_counter += 1
if os.path.exists(fifo):
os.unlink(fifo)
os.mkfifo(fifo)
return fifo
class BmovlCanvas(BitmapCanvas):
def __init__(self, size, fifo = None):
if fifo:
self.__fname = fifo
self.open_fifo()
self.bmovl_visible = True
self.send('SHOW\n')
super(BmovlCanvas, self).__init__(size, preserve_alpha = True)
self._update_rect = None
def open_fifo(self):
self.fifo = os.open(self.get_fname(), os.O_RDWR, os.O_NONBLOCK)
def close_fifo(self):
if self.fifo:
try:
os.close(self.fifo)
except OSError:
self.fifo = None
if os.path.exists(self.get_fname()):
os.unlink(self.get_fname())
def get_fname(self):
"""
return fifo filename
"""
try:
return self.__fname
except AttributeError:
pass
self.__fname = create_fifo()
return self.__fname
def send(self, msg):
try:
os.write(self.fifo, msg)
return True
except (IOError, OSError):
return False
def has_visible_child(self):
for c in self.children:
if c.visible and c.get_alpha():
return True
return False
def _update_end(self, object = None):
if not self._update_rect:
return
if not self.fifo:
return
if self.bmovl_visible and not self.has_visible_child():
self.send('HIDE\n')
self.send('CLEAR %s %s 0 0\n' % \
(self.width, self.height))
self.bmovl_visible = False
return
# get update rect
pos, size = self._update_rect
# increase update rect because mplayer sometimes draws outside
pos = (max(0, pos[0] - 2), max(pos[1] - 2, 0))
size = (min(size[0] + 4, self.width),
min(size[1] + 4, self.height))
img = imagelib.crop(self._backing_store, pos, size)
self.send('RGBA32 %d %d %d %d %d %d\n' % \
(size[0], size[1], pos[0], pos[1], 0, 0))
self.send(str(img.get_raw_data('RGBA')))
self._update_rect = None
if not self.bmovl_visible and self.has_visible_child():
self.send('SHOW\n')
self.bmovl_visible = True
def _blit(self, img, r):
if self._update_rect:
self._update_rect = rect.union(r, self._update_rect)
else:
self._update_rect = r
--- NEW FILE: __init__.py ---
--- NEW FILE: directfbcanvas.py ---
# -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------------
# directfb.py - output canvas for directfb using pydirectfb
# -----------------------------------------------------------------------------
# $Id: directfbcanvas.py,v 1.1 2005/06/26 17:02:06 dischi Exp $
#
# -----------------------------------------------------------------------------
# kaa-mevas - MeBox Canvas System
# Copyright (C) 2004-2005 Jason Tackaberry <[EMAIL PROTECTED]>
#
# First Edition: Rob Shortt <[EMAIL PROTECTED]>
# Maintainer: Rob Shortt <[EMAIL PROTECTED]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------------
_pixel_format = {
0x00118005: 'DSPF_A8',
0x4011420c: 'DSPF_ALUT44',
0x00418c04: 'DSPF_ARGB',
0x00211780: 'DSPF_ARGB1555',
0x08100609: 'DSPF_I420',
0x4011040b: 'DSPF_LUT8',
0x00200801: 'DSPF_RGB16',
0x00300c02: 'DSPF_RGB24',
0x00400c03: 'DSPF_RGB32',
0x00100407: 'DSPF_RGB332',
0x00000000: 'DSPF_UNKNOWN',
0x00200808: 'DSPF_UYVY',
0x00200806: 'DSPF_YUY2',
0x0810060a: 'DSPF_YV12'
}
# dfb import
from directfb import *
# mevas imports
from kaa import mevas
import kaa.mevas.rect as rect
# displays imports
from bitmapcanvas import *
class DirectFBCanvas(BitmapCanvas):
def __init__(self, size, layerno):
super(DirectFBCanvas, self).__init__(size, preserve_alpha = False,
blit_once = True)
width, height = size
self.layerno = layerno
print 'DEBUG: size is %sx%s' % (width, height)
self.dfb = DirectFB()
caps = self.dfb.getCardCapabilities()
self.layer = self.dfb.getDisplayLayer(self.layerno)
self.layer.setCooperativeLevel(DLSCL_ADMINISTRATIVE)
self.layer.setConfiguration(pixelformat = DSPF_RGB32, #DSPF_ARGB,
buffermode = DLBM_BACKSYSTEM,
width = width, height = height)
print 'DirectFB layer config:'
layer_config = self.layer.getConfiguration()
for k, v in layer_config.items():
if not k in ('width', 'height', 'pixelformat'):
print ' %s: %s' % (k, v)
print ' goemetry: %dx%d' % (layer_config.get('width'),
layer_config.get('height'))
print ' pixelformat: %s' % \
_pixel_format[layer_config.get('pixelformat')]
self.layer.enableCursor(0)
self.osd = self.layer.createWindow(caps=DWCAPS_ALPHACHANNEL,
width=width, height=height)
self._surface = self.osd.getSurface()
self.osd.setOpacity(0xFF)
self._rect = []
def _blit(self, img, r):
pos, size = r
self._rect = rect.optimize_for_rendering(self._rect)
# get the raw data from the imlib2 image as buffer
data = img._image.get_raw_data()
# create a new surface
# XXX: Does overlay() handle buffer objects for data? If not,
# pass str(data).
self._surface.overlay(DSPF_ARGB, data)
self._surface.flip(DSFLIP_WAIT)
return
-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog