diff --git a/scripts/generate_test_mask_image.py b/scripts/generate_test_mask_image.py index 48fe04c948b..0dccc39991b 100644 --- a/scripts/generate_test_mask_image.py +++ b/scripts/generate_test_mask_image.py @@ -11,6 +11,7 @@ import argparse from PyQt4.QtCore import * from PyQt4.QtGui import * import struct +import urllib2 def error ( msg ): print msg @@ -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(): @@ -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 )