Skip to content
Permalink
Browse files

Allow remote urls for generate_test_mask_image.py

  • Loading branch information
nyalldawson committed Jun 16, 2015
1 parent cf2fa39 commit a378627bfafd233473dd574d5d46d77cd12a90a7
Showing with 14 additions and 3 deletions.
  1. +14 −3 scripts/generate_test_mask_image.py
@@ -11,6 +11,7 @@
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 )

0 comments on commit a378627

Please sign in to comment.
You can’t perform that action at this time.