Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Allow use of masks for unit test control images
Masks set which pixels in the control image should be tested and an optional tolerance for each pixel. This is done via the colors in the mask image - white pixels are ignored, black must be an exact match, and gray levels represent the maximum color component deviation for that pixel. This should replace the fragile anomaly images, in that a single control image with a suitable mask will not be susceptible to antialiasing differences, etc. A new script (scripts/generate_test_mask_image.py) is included which either creates a new mask or modifies an existing mask to handle an acceptable rendered image. Ultimately, masking along with multi render checks for specific platform differences should be flexible enough to meet our needs.
- Loading branch information
1 parent
bf56457
commit 854c0b8
Showing
67 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#!/usr/bin/env python | ||
|
||
# Generates (or updates) a unit test image mask, which is used to specify whether | ||
# a pixel in the control image should be checked (black pixel in mask) or not (white | ||
# pixel in mask). For non black or white pixels, the pixels lightness is used to | ||
# specify a maximum delta for each color component | ||
|
||
import os | ||
import sys | ||
import argparse | ||
from PyQt4.QtCore import * | ||
from PyQt4.QtGui import * | ||
import struct | ||
|
||
def error ( msg ): | ||
print msg | ||
sys.exit( 1 ) | ||
|
||
def colorDiff( c1, c2 ): | ||
redDiff = abs( qRed( c1 ) - qRed( c2 ) ) | ||
greenDiff = abs( qGreen( c1 ) - qGreen( c2 ) ) | ||
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) ) | ||
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) ) | ||
return max( redDiff, greenDiff, blueDiff, alphaDiff ) | ||
|
||
def updateMask(control_image_path, rendered_image_path, mask_image_path): | ||
control_image = QImage( control_image_path ) | ||
if not control_image: | ||
error('Could not read control image {}'.format(control_image_path)) | ||
|
||
rendered_image = QImage( 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(): | ||
error('Size mismatch - control image is {}x{}, rendered image is {}x{}'.format(control_image.width(), | ||
control_image.height(), | ||
rendered_image.width(), | ||
rendered_image.height())) | ||
|
||
#read current mask, if it exist | ||
mask_image = QImage( 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 ) | ||
mask_image.fill( QColor(0,0,0) ) | ||
|
||
#loop through pixels in rendered image and compare | ||
mismatch_count = 0 | ||
width = control_image.width() | ||
height = control_image.height() | ||
linebytes = width * 4 | ||
for y in xrange( height ): | ||
control_scanline = control_image.constScanLine( y ).asstring(linebytes) | ||
rendered_scanline = rendered_image.constScanLine( y ).asstring(linebytes) | ||
mask_scanline = mask_image.scanLine( y ).asstring(linebytes) | ||
|
||
for x in xrange( width ): | ||
currentTolerance = qRed( struct.unpack('I', mask_scanline[ x*4:x*4+4 ] )[0] ) | ||
|
||
if currentTolerance == 255: | ||
#ignore pixel | ||
continue | ||
|
||
expected_rgb = struct.unpack('I', control_scanline[ x*4:x*4+4 ] )[0] | ||
rendered_rgb = struct.unpack('I', rendered_scanline[ x*4:x*4+4 ] )[0] | ||
difference = colorDiff( expected_rgb, rendered_rgb ) | ||
|
||
if difference > currentTolerance: | ||
#update mask image | ||
mask_image.setPixel( x, y, qRgb( difference, difference, difference ) ) | ||
mismatch_count += 1 | ||
|
||
if mismatch_count: | ||
#update mask | ||
mask_image.save( mask_image_path, "png" ); | ||
print 'Updated {} pixels'.format( mismatch_count ) | ||
|
||
parser = argparse.ArgumentParser() #OptionParser("usage: %prog control_image rendered_image mask_image") | ||
parser.add_argument('control_image') | ||
parser.add_argument('rendered_image') | ||
parser.add_argument('mask_image') | ||
args = parser.parse_args() | ||
|
||
|
||
updateMask(args.control_image, args.rendered_image, args.mask_image) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
Binary file added
BIN
+30 KB
...ata/control_images/expected_atlas_autoscale1/expected_atlas_autoscale1_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-37.1 KB
.../control_images/expected_atlas_autoscale1/quantal/expected_atlas_autoscale1.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+32.7 KB
...ata/control_images/expected_atlas_autoscale2/expected_atlas_autoscale2_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-43.7 KB
.../control_images/expected_atlas_autoscale2/quantal/expected_atlas_autoscale2.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+29.7 KB
...es/expected_atlas_autoscale_old_api1/expected_atlas_autoscale_old_api1_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-37.1 KB
...expected_atlas_autoscale_old_api1/quantal/expected_atlas_autoscale_old_api1.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+32.7 KB
...es/expected_atlas_autoscale_old_api2/expected_atlas_autoscale_old_api2_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-43.7 KB
...expected_atlas_autoscale_old_api2/quantal/expected_atlas_autoscale_old_api2.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+32.9 KB
...ata/control_images/expected_atlas_filtering1/expected_atlas_filtering1_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-43.5 KB
.../control_images/expected_atlas_filtering1/quantal/expected_atlas_filtering1.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+31.2 KB
...a/control_images/expected_atlas_fixedscale1/expected_atlas_fixedscale1_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-38.6 KB
...ontrol_images/expected_atlas_fixedscale1/quantal/expected_atlas_fixedscale1.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+31.8 KB
...a/control_images/expected_atlas_fixedscale2/expected_atlas_fixedscale2_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-42.2 KB
...ontrol_images/expected_atlas_fixedscale2/quantal/expected_atlas_fixedscale2.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+31.2 KB
.../expected_atlas_fixedscale_old_api1/expected_atlas_fixedscale_old_api1_mask.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed
BIN
-38.6 KB
...pected_atlas_fixedscale_old_api1/quantal/expected_atlas_fixedscale_old_api1.png
Binary file not shown.
File renamed without changes
Binary file added
BIN
+31.8 KB
.../expected_atlas_fixedscale_old_api2/expected_atlas_fixedscale_old_api2_mask.png
Oops, something went wrong.
Binary file removed
BIN
-42.2 KB
...pected_atlas_fixedscale_old_api2/quantal/expected_atlas_fixedscale_old_api2.png
Diff not rendered.
Binary file added
BIN
+11.8 KB
.../testdata/control_images/expected_atlas_hiding1/expected_atlas_hiding1_mask.png
Oops, something went wrong.
Binary file added
BIN
+9.65 KB
.../testdata/control_images/expected_atlas_hiding2/expected_atlas_hiding2_mask.png
Oops, something went wrong.
File renamed without changes
Binary file added
BIN
+29.8 KB
...ages/expected_atlas_predefinedscales1/expected_atlas_predefinedscales1_mask.png
Oops, something went wrong.
Binary file removed
BIN
-37.2 KB
...s/expected_atlas_predefinedscales1/quantal/expected_atlas_predefinedscales1.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+28.6 KB
...ages/expected_atlas_predefinedscales2/expected_atlas_predefinedscales2_mask.png
Oops, something went wrong.
Binary file removed
BIN
-37.1 KB
...s/expected_atlas_predefinedscales2/quantal/expected_atlas_predefinedscales2.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+33 KB
...estdata/control_images/expected_atlas_sorting1/expected_atlas_sorting1_mask.png
Oops, something went wrong.
Binary file removed
BIN
-43.6 KB
...data/control_images/expected_atlas_sorting1/quantal/expected_atlas_sorting1.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+26.5 KB
...estdata/control_images/expected_atlas_sorting2/expected_atlas_sorting2_mask.png
Oops, something went wrong.
Binary file removed
BIN
-34.7 KB
...data/control_images/expected_atlas_sorting2/quantal/expected_atlas_sorting2.png
Diff not rendered.
Binary file removed
BIN
-37.6 KB
...ta/control_images/expected_atlas_two_maps1/default/expected_atlas_two_maps1.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+30.1 KB
...tdata/control_images/expected_atlas_two_maps1/expected_atlas_two_maps1_mask.png
Oops, something went wrong.
Binary file removed
BIN
-41.2 KB
...ta/control_images/expected_atlas_two_maps2/default/expected_atlas_two_maps2.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+31.5 KB
...tdata/control_images/expected_atlas_two_maps2/expected_atlas_two_maps2_mask.png
Oops, something went wrong.
Binary file added
BIN
+33.1 KB
...attributetable_columnwidth/expected_composerattributetable_columnwidth_mask.png
Oops, something went wrong.
Binary file added
BIN
+15.6 KB
...attributetable_headersonly/expected_composerattributetable_headersonly_mask.png
Oops, something went wrong.
Binary file added
BIN
+38.8 KB
...d_composerattributetable_render/expected_composerattributetable_render_mask.png
Oops, something went wrong.
Binary file added
BIN
+5.42 KB
...l_images/expected_composereffects_blend/expected_composereffects_blend_mask.png
Oops, something went wrong.
Binary file added
BIN
+18.8 KB
...ata/control_images/expected_composermap_grid/expected_composermap_grid_mask.png
Oops, something went wrong.
Binary file added
BIN
+55.9 KB
...control_images/expected_composermap_render/expected_composermap_render_mask.png
Oops, something went wrong.
Binary file added
BIN
+32 KB
...composermap_rotatedannotations/expected_composermap_rotatedannotations_mask.png
Oops, something went wrong.
Binary file added
BIN
+13.3 KB
...cture_resize_frametoimage/expected_composerpicture_resize_frametoimage_mask.png
Oops, something went wrong.
Binary file added
BIN
+8.61 KB
...images/expected_composerrotation_label/expected_composerrotation_label_mask.png
Oops, something went wrong.
Binary file added
BIN
+7.4 KB
...xpected_composerscalebar_singlebox/expected_composerscalebar_singlebox_mask.png
Oops, something went wrong.
Binary file added
BIN
+7.16 KB
...oserscalebar_singlebox_alpha/expected_composerscalebar_singlebox_alpha_mask.png
Oops, something went wrong.
Binary file removed
BIN
-1.04 KB
tests/testdata/control_images/expected_composerutils_drawtext_pos/anomaly_win7.png
Diff not rendered.
Binary file added
BIN
+2.13 KB
...xpected_composerutils_drawtext_pos/expected_composerutils_drawtext_pos_mask.png
Oops, something went wrong.
Binary file removed
BIN
-1.04 KB
...s/testdata/control_images/expected_composerutils_drawtext_rect/anomaly_win7.png
Diff not rendered.
Binary file added
BIN
+2.13 KB
...ected_composerutils_drawtext_rect/expected_composerutils_drawtext_rect_mask.png
Oops, something went wrong.
Binary file removed
BIN
-627 KB
...expected_inverted_polys_graduated/default/expected_inverted_polys_graduated.png
Diff not rendered.
File renamed without changes
Binary file added
BIN
+43.5 KB
...es/expected_inverted_polys_graduated/expected_inverted_polys_graduated_mask.png
Oops, something went wrong.