1- #!/usr/bin/env python
1+ #!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
44"""
3535import argparse
3636from PyQt5 .QtGui import QImage , QColor , qRed , qBlue , qGreen , qAlpha , qRgb
3737import struct
38- import urllib2
38+ import urllib . request , urllib . error , urllib . parse
3939import glob
4040
4141
4242def error (msg ):
43- print msg
43+ print ( msg )
4444 sys .exit (1 )
4545
4646
@@ -53,9 +53,9 @@ def colorDiff(c1, c2):
5353
5454
5555def imageFromPath (path ):
56- if (path [:7 ] == 'http://' or path [:7 ] == 'file://' ):
56+ if (path [:7 ] == 'http://' or path [:7 ] == 'file://' or path [: 8 ] == 'https://' ):
5757 #fetch remote image
58- data = urllib2 .urlopen (path ).read ()
58+ data = urllib . request .urlopen (path ).read ()
5959 image = QImage ()
6060 image .loadFromData (data )
6161 else :
@@ -88,7 +88,7 @@ def getControlImagePath(path):
8888 error ('No matching control images found for {}' .format (path ))
8989
9090 found_image = filtered_images [0 ]
91- print 'Found matching control image: {}' .format (found_image )
91+ print ( 'Found matching control image: {}' .format (found_image ) )
9292 return found_image
9393
9494
@@ -101,30 +101,30 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
101101 if not rendered_image :
102102 error ('Could not read rendered image {}' .format (rendered_image_path ))
103103 if not rendered_image .width () == control_image .width () or not rendered_image .height () == control_image .height ():
104- print ('Size mismatch - control image is {}x{}, rendered image is {}x{}' .format (control_image .width (),
104+ print ( ('Size mismatch - control image is {}x{}, rendered image is {}x{}' .format (control_image .width (),
105105 control_image .height (),
106106 rendered_image .width (),
107- rendered_image .height ()))
107+ rendered_image .height ())))
108108
109109 max_width = min (rendered_image .width (), control_image .width ())
110110 max_height = min (rendered_image .height (), control_image .height ())
111111
112112 #read current mask, if it exist
113113 mask_image = imageFromPath (mask_image_path )
114114 if mask_image .isNull ():
115- print 'Mask image does not exist, creating {}' .format (mask_image_path )
115+ print ( 'Mask image does not exist, creating {}' .format (mask_image_path ) )
116116 mask_image = QImage (control_image .width (), control_image .height (), QImage .Format_ARGB32 )
117117 mask_image .fill (QColor (0 , 0 , 0 ))
118118
119119 #loop through pixels in rendered image and compare
120120 mismatch_count = 0
121121 linebytes = max_width * 4
122- for y in xrange (max_height ):
122+ for y in range (max_height ):
123123 control_scanline = control_image .constScanLine (y ).asstring (linebytes )
124124 rendered_scanline = rendered_image .constScanLine (y ).asstring (linebytes )
125125 mask_scanline = mask_image .scanLine (y ).asstring (linebytes )
126126
127- for x in xrange (max_width ):
127+ for x in range (max_width ):
128128 currentTolerance = qRed (struct .unpack ('I' , mask_scanline [x * 4 :x * 4 + 4 ])[0 ])
129129
130130 if currentTolerance == 255 :
@@ -143,9 +143,9 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
143143 if mismatch_count :
144144 #update mask
145145 mask_image .save (mask_image_path , "png" )
146- print 'Updated {} pixels in {}' .format (mismatch_count , mask_image_path )
146+ print ( 'Updated {} pixels in {}' .format (mismatch_count , mask_image_path ) )
147147 else :
148- print 'No mismatches in {}' .format (mask_image_path )
148+ print ( 'No mismatches in {}' .format (mask_image_path ) )
149149
150150parser = argparse .ArgumentParser () # OptionParser("usage: %prog control_image rendered_image mask_image")
151151parser .add_argument ('control_image' )
0 commit comments