11
11
from PyQt4 .QtCore import *
12
12
from PyQt4 .QtGui import *
13
13
import struct
14
+ import urllib2
14
15
15
16
def error ( msg ):
16
17
print msg
@@ -22,13 +23,23 @@ def colorDiff( c1, c2 ):
22
23
blueDiff = abs ( qBlue ( c1 ) - qBlue ( c2 ) )
23
24
alphaDiff = abs ( qAlpha ( c1 ) - qAlpha ( c2 ) )
24
25
return max ( redDiff , greenDiff , blueDiff , alphaDiff )
26
+
27
+ def imageFromPath (path ):
28
+ if ( path [:7 ] == 'http://' ):
29
+ #fetch remote image
30
+ data = urllib2 .urlopen (path ).read ()
31
+ image = QImage ()
32
+ image .loadFromData (data )
33
+ else :
34
+ image = QImage ( path )
35
+ return image
25
36
26
37
def updateMask (control_image_path , rendered_image_path , mask_image_path ):
27
- control_image = QImage ( control_image_path )
38
+ control_image = imageFromPath ( control_image_path )
28
39
if not control_image :
29
40
error ('Could not read control image {}' .format (control_image_path ))
30
41
31
- rendered_image = QImage ( rendered_image_path )
42
+ rendered_image = imageFromPath ( rendered_image_path )
32
43
if not rendered_image :
33
44
error ('Could not read rendered image {}' .format (rendered_image_path ))
34
45
if not rendered_image .width () == control_image .width () or not rendered_image .height () == control_image .height ():
@@ -38,7 +49,7 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
38
49
rendered_image .height ()))
39
50
40
51
#read current mask, if it exist
41
- mask_image = QImage ( mask_image_path )
52
+ mask_image = imageFromPath ( mask_image_path )
42
53
if mask_image .isNull ():
43
54
print 'Mask image does not exist, creating'
44
55
mask_image = QImage ( control_image .width (), control_image .height (), QImage .Format_ARGB32 )
0 commit comments