Index: gm/rebaseline_server/imagediffdb.py |
=================================================================== |
--- gm/rebaseline_server/imagediffdb.py (revision 12765) |
+++ gm/rebaseline_server/imagediffdb.py (working copy) |
@@ -20,9 +20,9 @@ |
raise ImportError('Requires PIL to be installed; see ' |
+ 'http://www.pythonware.com/products/pil/') |
-IMAGE_SUFFIX = '.png' |
+DEFAULT_IMAGE_SUFFIX = '.png' |
+DEFAULT_IMAGES_SUBDIR = 'images' |
-IMAGES_SUBDIR = 'images' |
DIFFS_SUBDIR = 'diffs' |
WHITEDIFFS_SUBDIR = 'whitediffs' |
@@ -34,7 +34,11 @@ |
def __init__(self, storage_root, |
expected_image_url, expected_image_locator, |
- actual_image_url, actual_image_locator): |
+ actual_image_url, actual_image_locator, |
+ images_subdir=DEFAULT_IMAGES_SUBDIR, |
+ actual_images_subdir=DEFAULT_IMAGES_SUBDIR, |
+ use_diff_image_locator=True, |
+ image_suffix=DEFAULT_IMAGE_SUFFIX): |
"""Download this pair of images (unless we already have them on local disk), |
and prepare a DiffRecord for them. |
@@ -54,15 +58,26 @@ |
actual_image_locator: a unique ID string under which we will store the |
actual image within storage_root (probably including a checksum to |
guarantee uniqueness) |
+ images_subdir: the subdirectory images are stored in. Optional parameter, |
epoger
2013/12/20 19:46:37
what are "images" as opposed to "actual images"?
rmistry
2013/12/20 20:00:04
Ah right. Done.
|
+ the default value is in DEFAULT_IMAGES_SUBDIR. |
epoger
2013/12/20 19:46:37
Thank you for being descriptive, but I think we're
rmistry
2013/12/20 20:00:04
Done.
|
+ actual_images_subdir: the subdirectory actual images are stored in. |
+ Optional parameter, the default value is in DEFAULT_IMAGES_SUBDIR. |
+ use_diff_image_locator: If True outputs differences as |
+ 'expected_image_locator-vs-actual_image_locator' else outputs |
+ differences using the expected_image_locator if expected_image_locator |
epoger
2013/12/20 19:46:37
Confusing description... so, if this is False, but
rmistry
2013/12/20 20:00:04
Agreed. Done.
|
+ is equal to the actual_image_locator. Optional parameter, the default |
+ value is True. |
+ image_suffix: the suffix of images. Optional parameter, the default |
+ value is in DEFAULT_IMAGE_SUFFIX. |
""" |
# Download the expected/actual images, if we don't have them already. |
expected_image = _download_and_open_image( |
- os.path.join(storage_root, IMAGES_SUBDIR, |
- str(expected_image_locator) + IMAGE_SUFFIX), |
+ os.path.join(storage_root, images_subdir, |
+ str(expected_image_locator) + image_suffix), |
epoger
2013/12/20 19:46:37
Warning: if you are not using checksums to generat
rmistry
2013/12/20 20:00:04
I tested this through the python interpreter and i
epoger
2013/12/20 20:05:08
Sounds like a good idea. More than anything, I wa
rmistry
2013/12/20 20:53:27
Added a TODO.
|
expected_image_url) |
actual_image = _download_and_open_image( |
- os.path.join(storage_root, IMAGES_SUBDIR, |
- str(actual_image_locator) + IMAGE_SUFFIX), |
+ os.path.join(storage_root, actual_images_subdir, |
+ str(actual_image_locator) + image_suffix), |
actual_image_url) |
# Generate the diff image (absolute diff at each pixel) and |
@@ -89,10 +104,14 @@ |
diff_image.putalpha(whitediff_image) |
# Store the diff and whitediff images generated above. |
- diff_image_locator = _get_difference_locator( |
- expected_image_locator=expected_image_locator, |
- actual_image_locator=actual_image_locator) |
- basename = str(diff_image_locator) + IMAGE_SUFFIX |
+ if not use_diff_image_locator and ( |
+ expected_image_locator == actual_image_locator): |
+ basename = expected_image_locator + image_suffix |
+ else: |
+ diff_image_locator = _get_difference_locator( |
+ expected_image_locator=expected_image_locator, |
+ actual_image_locator=actual_image_locator) |
+ basename = str(diff_image_locator) + image_suffix |
_save_image(diff_image, os.path.join( |
storage_root, DIFFS_SUBDIR, basename)) |
_save_image(whitediff_image, os.path.join( |