Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow remote urls for generate_test_mask_image.py
  • Loading branch information
nyalldawson committed Jun 16, 2015
1 parent cf2fa39 commit a378627
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions scripts/generate_test_mask_image.py
Expand Up @@ -11,6 +11,7 @@
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import struct
import urllib2

def error ( msg ):
print msg
Expand All @@ -22,13 +23,23 @@ def colorDiff( c1, c2 ):
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) )
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) )
return max( redDiff, greenDiff, blueDiff, alphaDiff )

def imageFromPath(path):
if ( path[:7] == 'http://' ):
#fetch remote image
data = urllib2.urlopen(path).read()
image = QImage()
image.loadFromData(data)
else:
image = QImage( path )
return image

def updateMask(control_image_path, rendered_image_path, mask_image_path):
control_image = QImage( control_image_path )
control_image = imageFromPath( control_image_path )
if not control_image:
error('Could not read control image {}'.format(control_image_path))

rendered_image = QImage( rendered_image_path )
rendered_image = imageFromPath( rendered_image_path )
if not rendered_image:
error('Could not read rendered image {}'.format(rendered_image_path))
if not rendered_image.width() == control_image.width() or not rendered_image.height() == control_image.height():
Expand All @@ -38,7 +49,7 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
rendered_image.height()))

#read current mask, if it exist
mask_image = QImage( mask_image_path )
mask_image = imageFromPath( mask_image_path )
if mask_image.isNull():
print 'Mask image does not exist, creating'
mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 )
Expand Down

0 comments on commit a378627

Please sign in to comment.