Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: gm/rebaseline_server/imagediffdb.py

Issue 471033003: Fixing broken images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed overly long lines Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gm/rebaseline_server/imagepair_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 """ 3 """
4 Copyright 2013 Google Inc. 4 Copyright 2013 Google Inc.
5 5
6 Use of this source code is governed by a BSD-style license that can be 6 Use of this source code is governed by a BSD-style license that can be
7 found in the LICENSE file. 7 found in the LICENSE file.
8 8
9 Calulate differences between image pairs, and store them in a database. 9 Calulate differences between image pairs, and store them in a database.
10 """ 10 """
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 RGBDIFFS_SUBDIR = 'diffs' 44 RGBDIFFS_SUBDIR = 'diffs'
45 WHITEDIFFS_SUBDIR = 'whitediffs' 45 WHITEDIFFS_SUBDIR = 'whitediffs'
46 46
47 # Keys used within DiffRecord dictionary representations. 47 # Keys used within DiffRecord dictionary representations.
48 # NOTE: Keep these in sync with static/constants.js 48 # NOTE: Keep these in sync with static/constants.js
49 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL = 'maxDiffPerChannel' 49 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL = 'maxDiffPerChannel'
50 KEY__DIFFERENCES__NUM_DIFF_PIXELS = 'numDifferingPixels' 50 KEY__DIFFERENCES__NUM_DIFF_PIXELS = 'numDifferingPixels'
51 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS = 'percentDifferingPixels' 51 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS = 'percentDifferingPixels'
52 KEY__DIFFERENCES__PERCEPTUAL_DIFF = 'perceptualDifference' 52 KEY__DIFFERENCES__PERCEPTUAL_DIFF = 'perceptualDifference'
53 KEY__DIFFERENCES__DIFF_URL = 'diffUrl'
54 KEY__DIFFERENCES__WHITE_DIFF_URL = 'whiteDiffUrl'
53 55
54 # Special values within ImageDiffDB._diff_dict 56 # Special values within ImageDiffDB._diff_dict
55 _DIFFRECORD_FAILED = 'failed' 57 _DIFFRECORD_FAILED = 'failed'
56 _DIFFRECORD_PENDING = 'pending' 58 _DIFFRECORD_PENDING = 'pending'
57 59
58 # How often to report tasks_queue size 60 # How often to report tasks_queue size
59 QUEUE_LOGGING_GRANULARITY = 1000 61 QUEUE_LOGGING_GRANULARITY = 1000
60 62
61 # Temporary variable to keep track of how many times we download 63 # Temporary variable to keep track of how many times we download
62 # the same file in multiple threads. 64 # the same file in multiple threads.
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 153
152 # Get information out of the skpdiff_summary_file. 154 # Get information out of the skpdiff_summary_file.
153 with contextlib.closing(open(skpdiff_summary_file)) as fp: 155 with contextlib.closing(open(skpdiff_summary_file)) as fp:
154 data = json.load(fp) 156 data = json.load(fp)
155 157
156 # For now, we can assume there is only one record in the output summary, 158 # For now, we can assume there is only one record in the output summary,
157 # since we passed skpdiff only one pair of images. 159 # since we passed skpdiff only one pair of images.
158 record = data['records'][0] 160 record = data['records'][0]
159 self._width = record['width'] 161 self._width = record['width']
160 self._height = record['height'] 162 self._height = record['height']
163 self._diffUrl = os.path.split(record['rgbDiffPath'])[1]
164 self._whiteDiffUrl = os.path.split(record['whiteDiffPath'])[1]
165
161 # TODO: make max_diff_per_channel a tuple instead of a list, because the 166 # TODO: make max_diff_per_channel a tuple instead of a list, because the
162 # structure is meaningful (first element is red, second is green, etc.) 167 # structure is meaningful (first element is red, second is green, etc.)
163 # See http://stackoverflow.com/a/626871 168 # See http://stackoverflow.com/a/626871
164 self._max_diff_per_channel = [ 169 self._max_diff_per_channel = [
165 record['maxRedDiff'], record['maxGreenDiff'], record['maxBlueDiff']] 170 record['maxRedDiff'], record['maxGreenDiff'], record['maxBlueDiff']]
166 per_differ_stats = record['diffs'] 171 per_differ_stats = record['diffs']
167 for stats in per_differ_stats: 172 for stats in per_differ_stats:
168 differ_name = stats['differName'] 173 differ_name = stats['differName']
169 if differ_name == 'different_pixels': 174 if differ_name == 'different_pixels':
170 self._num_pixels_differing = stats['pointsOfInterest'] 175 self._num_pixels_differing = stats['pointsOfInterest']
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 210
206 def as_dict(self): 211 def as_dict(self):
207 """Returns a dictionary representation of this DiffRecord, as needed when 212 """Returns a dictionary representation of this DiffRecord, as needed when
208 constructing the JSON representation.""" 213 constructing the JSON representation."""
209 return { 214 return {
210 KEY__DIFFERENCES__NUM_DIFF_PIXELS: self._num_pixels_differing, 215 KEY__DIFFERENCES__NUM_DIFF_PIXELS: self._num_pixels_differing,
211 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS: 216 KEY__DIFFERENCES__PERCENT_DIFF_PIXELS:
212 self.get_percent_pixels_differing(), 217 self.get_percent_pixels_differing(),
213 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL: self._max_diff_per_channel, 218 KEY__DIFFERENCES__MAX_DIFF_PER_CHANNEL: self._max_diff_per_channel,
214 KEY__DIFFERENCES__PERCEPTUAL_DIFF: self._perceptual_difference, 219 KEY__DIFFERENCES__PERCEPTUAL_DIFF: self._perceptual_difference,
220 KEY__DIFFERENCES__DIFF_URL: self._diffUrl,
221 KEY__DIFFERENCES__WHITE_DIFF_URL: self._whiteDiffUrl,
215 } 222 }
216 223
217 224
225
218 class ImageDiffDB(object): 226 class ImageDiffDB(object):
219 """ Calculates differences between image pairs, maintaining a database of 227 """ Calculates differences between image pairs, maintaining a database of
220 them for download.""" 228 them for download."""
221 229
222 def __init__(self, storage_root, gs=None, 230 def __init__(self, storage_root, gs=None,
223 num_worker_threads=DEFAULT_NUM_WORKER_THREADS): 231 num_worker_threads=DEFAULT_NUM_WORKER_THREADS):
224 """ 232 """
225 Args: 233 Args:
226 storage_root: string; root path within the DB will store all of its stuff 234 storage_root: string; root path within the DB will store all of its stuff
227 gs: instance of GSUtils object we can use to download images 235 gs: instance of GSUtils object we can use to download images
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 468
461 Args: 469 Args:
462 locator: string, or something that can be represented as a string. 470 locator: string, or something that can be represented as a string.
463 If None or '', it is returned without modification, because empty 471 If None or '', it is returned without modification, because empty
464 locators have a particular meaning ("there is no image for this") 472 locators have a particular meaning ("there is no image for this")
465 """ 473 """
466 if locator: 474 if locator:
467 return DISALLOWED_FILEPATH_CHAR_REGEX.sub('_', str(locator)) 475 return DISALLOWED_FILEPATH_CHAR_REGEX.sub('_', str(locator))
468 else: 476 else:
469 return locator 477 return locator
OLDNEW
« no previous file with comments | « no previous file | gm/rebaseline_server/imagepair_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698