Remove python-imaging related code since we dont need it for the specialized VNC widget code paths

This commit is contained in:
Daniel P. Berrange 2006-08-04 14:37:09 -04:00
parent a9c295f0b2
commit 439c44a384
4 changed files with 4 additions and 411 deletions

1
README
View File

@ -32,7 +32,6 @@ please report any success to the mailing lists
dbus-python >= 0.61
gnome-keyring >= 0.4.9
python-ctypes >= 0.9.9.6
python-imaging
Contact
-------

View File

@ -1,119 +0,0 @@
##
## pyvnc2swf - image.py
##
## $Id: image.py,v 1.9 2005/11/21 04:12:39 euske Exp $
##
## Copyright (C) 2005 by Yusuke Shinyama (yusuke at cs . nyu . edu)
## All Rights Reserved.
##
## This 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 software is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY 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 software; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
## USA.
##
import sys
lowerbound = max
upperbound = min
# format: 1: solid,
# 2: raw (uncompressed)
# 3: DefineBitLossless
# 4: SCREENVIDEOPACKET
IMG_SOLID = 1
IMG_RAW = 2
IMG_LOSSLESS = 3
IMG_VIDEOPACKET = 4
try:
# try to pygame 1.6 or newer.
import pygame
pygame.init()
def imgsize(img):
return img.get_size()
def create_image(w, h):
return pygame.Surface((w, h), 0, 32)
def create_image_from_string_rgb(w, h, data):
return pygame.image.fromstring(data, (w, h), 'RGB')
def create_image_from_string_rgbx(w, h, data):
return pygame.image.fromstring(data, (w, h), 'RGBX')
def create_image_from_string_xrgb(w, h, data):
return pygame.image.fromstring(data[1:]+'x', (w, h), 'RGBX')
def create_image_from_string_bgr_flipped(w, h, data):
data = ''.join([ data[i+2]+data[i+1]+data[i] for i in xrange(0, len(data), 3) ])
return pygame.transform.flip(pygame.image.fromstring(data, (w, h), 'RGB'), 0, 1)
def crop_image(img, (x,y,w,h)):
(wm,hm) = img.get_size()
return img.subsurface((x,y,upperbound(wm-x,w),upperbound(hm-y,h)))
def paste_image(dest, src, (x0, y0)):
return dest.blit(src, (x0, y0))
def save_image(img, fname):
if not fname.endswith('.bmp'):
print >>sys.stderr, 'Warning: this format not supported by pygame, raw rgb is used instead.'
return pygame.image.save(img, fname)
def convert_image_to_string_rgb_flipped(img):
return pygame.image.tostring(img, 'RGB', 1)
def convert_image_to_string_rgb(img):
return pygame.image.tostring(img, 'RGB')
def convert_image_to_string_xrgb(img):
return pygame.image.tostring(img, 'ARGB')
def solid_fill(dest, rect, color):
return dest.fill(color, rect)
def scale_image(img, scaling):
# this might cause segmentation faults sometimes :(
# In that case, use the following instead:
# (w,h) = img.get_size()
# return pygame.transform.scale(img, (int(w*scaling), int(h*scaling)))
return pygame.transform.rotozoom(img, 0, scaling)
except ImportError:
# use PIL instead
pygame = None
try:
import Image
except ImportError:
print >>sys.stderr, 'Either Pygame or Python Imaging Library is required.'
sys.exit(1)
def imgsize(img):
return img.size
def create_image(w, h):
return Image.new('RGB', (w, h))
def create_image_from_string_rgb(w, h, data):
return Image.fromstring('RGB', (w, h), data, 'raw', 'RGB')
def create_image_from_string_rgbx(w, h, data):
return Image.fromstring('RGB', (w, h), data, 'raw', 'RGBX')
def create_image_from_string_xrgb(w, h, data):
return Image.fromstring('RGB', (w, h), data[1:]+'x', 'raw', 'RGBX')
def create_image_from_string_bgr_flipped(w, h, data):
return Image.fromstring('RGB', (w, h), data, 'raw', 'BGR').transpose(Image.FLIP_TOP_BOTTOM)
def crop_image(img, (x0,y0,w,h)):
(wm,hm) = img.size
return img.crop((x0, y0, upperbound(x0+w,wm), upperbound(y0+h,hm)))
def paste_image(dest, src, (x0, y0)):
return dest.paste(src, (x0, y0))
def save_image(img, fname):
return img.save(fname)
def convert_image_to_string_rgb_flipped(img):
return img.transpose(Image.FLIP_TOP_BOTTOM).tostring('raw', 'RGB')
def convert_image_to_string_rgb(img):
return img.tostring('raw', 'RGB')
def convert_image_to_string_xrgb(img):
return img.tostring('raw', 'XRGB')
def solid_fill(dest, (x0,y0,w,h), color):
return dest.paste(color, (x0, y0, x0+w, y0+h))
def scale_image(img, scaling):
img = img.copy()
(w,h) = img.size
img.thumbnail((int(w*scaling), int(h*scaling)), resample=1)
return img

View File

@ -6,6 +6,10 @@
## Copyright (C) 2005 by Yusuke Shinyama (yusuke at cs . nyu . edu)
## All Rights Reserved.
##
## Adapted for use as a VNC widget in virtmanager:
##
## Copyright (C) 2006 Red Hat Inc.
##
## This 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
@ -26,7 +30,6 @@
import sys, time, socket
from struct import pack, unpack
from crippled_des import DesCipher
from image import IMG_SOLID, IMG_RAW
stderr = sys.stderr
lowerbound = max
@ -522,289 +525,3 @@ class RFBNetworkClient(RFBProxy):
return
## RFBNetworkClientForRecording (vncrec equivalent)
##
class RFBNetworkClientForRecording(RFBNetworkClient):
def __init__(self, host, port, fname, pwdfile=None,
preferred_encoding=(5,0), debug=0):
RFBNetworkClient.__init__(self, host, port, fb=None, pwdfile=pwdfile,
preferred_encoding=preferred_encoding, debug=debug)
print >>stderr, 'Creating vncrec: %r: vncLog0.0' % fname
self.fp = file(fname, 'wb')
self.write('vncLog0.0')
# disguise data (security=none)
self.write('RFB 003.003\x0a')
self.write('\x00\x00\x00\x01')
self.updated = True
return
def write(self, x):
self.fp.write(x)
return
def request_update(self):
if self.updated:
self.updated = False
t = time.time()
self.write(pack('>LL', int(t), (t-int(t))*1000000))
RFBNetworkClient.request_update(self)
return
def finish_update(self):
self.updated = True
return
def recv_relay(self, n):
data = self.recv(n)
self.write(data)
return data
def close(self):
RFBNetworkClient.close(self)
self.fp.close()
return
## RFBFileParser
##
class RFBFileParser(RFBProxy):
def __init__(self, fname, fb=None, debug=0):
RFBProxy.__init__(self, fb=fb, debug=debug)
if self.fb:
self.fb.change_format = False
self.fp = file(fname, 'rb')
self.fname = fname
return
def preferred_format(self, bitsperpixel, depth, bigendian, truecolour,
red_max, green_max, blue_max,
red_shift, green_shift, blue_shift):
if (bitsperpixel, depth, bigendian, truecolour,
red_max, green_max, blue_max,
red_shift, green_shift, blue_shift) == self.FASTEST_FORMAT:
return RFBProxy.preferred_format(self, bitsperpixel, depth, bigendian, truecolour,
red_max, green_max, blue_max,
red_shift, green_shift, blue_shift)
elif self.fb:
if bigendian:
endian = '>'
else:
endian = '<'
try:
length = {8:'B', 16:'H', 32:'L'}[bitsperpixel]
except KeyError:
raise 'invalid bitsperpixel: %d' % bitsperpixel
unpackstr = endian + length
nbytes = bitsperpixel / 8
bits = {1:1, 3:2, 7:3, 15:4, 31:5, 63:6, 127:7, 255:8}
try:
e = 'lambda p: (((p>>%d)&%d)<<%d, ((p>>%d)&%d)<<%d, ((p>>%d)&%d)<<%d)' % \
(red_shift, red_max, 8-bits[red_max],
green_shift, green_max, 8-bits[green_max],
blue_shift, blue_max, 8-bits[blue_max])
except KeyError:
raise 'invalid {red,green,blue}_max: %d, %d or %d' % (red_max, green_max, blue_max)
getrgb = eval(e)
unpack_pixels = eval('lambda data: unpack("%s%%d%s" %% (len(data)/%d), data)' % (endian, length, nbytes))
unpack_color1 = eval('lambda data: unpack("%s", data)' % unpackstr)
self.fb.set_converter(lambda data: ''.join([ pack('>BBB', *getrgb(p)) for p in unpack_pixels(data) ]),
lambda data: getrgb(unpack_color1(data)[0]))
return (bitsperpixel, depth, bigendian, truecolour,
red_max, green_max, blue_max,
red_shift, green_shift, blue_shift)
def seek(self, pos):
self.fp.seek(pos)
return
def tell(self):
return self.fp.tell()
def init(self):
self.curtime = 0
version = self.fp.read(9)
print >>stderr, 'Reading vncrec file: %s, version=%r...' % (self.fname, version)
if version != 'vncLog0.0':
raise RFBProtocolError('Unsupported vncrec version: %r' % version)
return RFBProxy.init(self)
def recv(self, n):
x = self.fp.read(n)
if len(x) != n:
raise EOFError
return x
def send(self, s):
return
def auth(self):
if self.protocol_version == 3:
# protocol 3.3
# recv: server security
(server_security,) = unpack('>L', self.recv(4))
if self.debug:
print >>stderr, 'server_security=%r' % server_security
if server_security == 2:
# skip challenge+result (dummy)
self.recv(20)
else:
RFBProxy.auth(self)
return self
def request_update(self):
(sec, usec) = unpack('>LL', self.recv(8))
self.curtime = sec+usec/1000000.0
return
def finish_update(self):
if self.fb:
self.fb.update_screen(self.curtime) # use the file time instead
return
def loop(self, endpos=0):
try:
while self.loop1():
if endpos and endpos <= self.tell(): break
except EOFError:
self.finish_update()
return self
def close(self):
RFBProxy.close(self)
self.fp.close()
return
## RFBConverter
##
class RFBConverter(RFBFrameBuffer):
def __init__(self, info, debug=0):
self.debug = debug
self.info = info
return
def init_screen(self, width, height, name):
print >>stderr, 'VNC Screen: size=%dx%d, name=%r' % (width, height, name)
self.info.set_defaults(width, height)
self.images = []
self.cursor_image = None
self.cursor_pos = None
self.t0 = 0
return self.info.clipping
def process_pixels(self, x, y, width, height, data):
self.images.append( ((x, y), (width, height, (IMG_RAW, self.convert_pixels(data)))) )
return
def process_solid(self, x, y, width, height, data):
self.images.append( ((x, y), (width, height, (IMG_SOLID, self.convert_color1(data)))) )
return
def move_cursor(self, x, y):
self.cursor_pos = (x, y)
return
def change_cursor(self, width, height, dx, dy, data):
if width and height:
self.cursor_image = (width, height, dx, dy, data)
return
def calc_frames(self, t):
if not self.t0:
self.t0 = t
return int((t - self.t0) * self.info.framerate)+1
## RFBMovieConverter
##
class RFBMovieConverter(RFBConverter):
def __init__(self, movie, debug=0):
RFBConverter.__init__(self, movie.info, debug)
self.movie = movie
self.frameinfo = []
return
def process_pixels(self, x, y, width, height, data):
if self.processing:
RFBConverter.process_pixels(self, x, y, width, height, data)
return
def process_solid(self, x, y, width, height, data):
if self.processing:
RFBConverter.process_solid(self, x, y, width, height, data)
return
def update_screen(self, t):
if not self.processing:
frames = RFBConverter.calc_frames(self, t)
done = False
while len(self.frameinfo) < frames:
if done:
self.frameinfo.append((self.beginpos, -1))
else:
endpos = self.rfbparser.tell()
self.frameinfo.append((self.beginpos, endpos))
if self.debug:
print >>stderr, 'scan:', self.beginpos, endpos
self.beginpos = endpos
done = True
return
def open(self, fname, debug=0):
self.processing = False
self.rfbparser = RFBFileParser(fname, self, debug)
self.rfbparser.init().auth().start()
self.beginpos = self.rfbparser.tell()
self.rfbparser.loop()
return
def parse_frame(self, i):
(pos, endpos) = self.frameinfo[i]
if self.debug:
print >>stderr, 'seek:', i, pos, endpos
self.rfbparser.seek(pos)
self.images = []
self.processing = True
self.cursor_image = None
self.cursor_pos = None
self.rfbparser.loop(endpos)
return (self.images, [], (self.cursor_image, self.cursor_pos))
## RFBStreamConverter
##
class RFBStreamConverter(RFBConverter):
def __init__(self, info, stream, debug=0):
RFBConverter.__init__(self, info, debug)
self.stream = stream
return
def init_screen(self, width, height, name):
clipping = RFBConverter.init_screen(self, width, height, name)
self.stream.open()
self.nframes = 0
return clipping
def update_screen(self, t):
frames = RFBConverter.calc_frames(self, t)
if self.nframes < frames:
# First we should create the frames up to now
while self.nframes < frames-1:
self.stream.next_frame()
self.nframes += 1
# And only after that we should paint the frame with the updates
self.stream.paint_frame((self.images, [], (self.cursor_image, self.cursor_pos)))
self.images = []
self.cursor_image = None
self.cursor_pos = None
self.stream.next_frame()
self.nframes += 1
return
def close(self):
self.stream.close()
return

View File

@ -30,10 +30,6 @@ Requires: gnome-keyring >= 0.4.9
# Minimum we've tested with
Requires: python-ctypes >= 0.9.9.6
# src/vncViewer/image.py needs this but we'd like to kill it off
# soon because it pulls in TCL/TK :-(
Requires: python-imaging
BuildRequires: pygtk2-devel
BuildRequires: gtk2-devel
BuildRequires: python-devel