mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-18 00:06:00 -04:00
Allow remote urls for generate_test_mask_image.py
This commit is contained in:
parent
cf2fa39691
commit
a378627bfa
@ -11,6 +11,7 @@ import argparse
|
|||||||
from PyQt4.QtCore import *
|
from PyQt4.QtCore import *
|
||||||
from PyQt4.QtGui import *
|
from PyQt4.QtGui import *
|
||||||
import struct
|
import struct
|
||||||
|
import urllib2
|
||||||
|
|
||||||
def error ( msg ):
|
def error ( msg ):
|
||||||
print msg
|
print msg
|
||||||
@ -22,13 +23,23 @@ def colorDiff( c1, c2 ):
|
|||||||
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) )
|
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) )
|
||||||
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) )
|
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) )
|
||||||
return max( redDiff, greenDiff, blueDiff, alphaDiff )
|
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):
|
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:
|
if not control_image:
|
||||||
error('Could not read control image {}'.format(control_image_path))
|
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:
|
if not rendered_image:
|
||||||
error('Could not read rendered image {}'.format(rendered_image_path))
|
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():
|
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()))
|
rendered_image.height()))
|
||||||
|
|
||||||
#read current mask, if it exist
|
#read current mask, if it exist
|
||||||
mask_image = QImage( mask_image_path )
|
mask_image = imageFromPath( mask_image_path )
|
||||||
if mask_image.isNull():
|
if mask_image.isNull():
|
||||||
print 'Mask image does not exist, creating'
|
print 'Mask image does not exist, creating'
|
||||||
mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 )
|
mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user