Chromium Code Reviews| Index: ui/resources/resource_check/resource_scale_factors.py |
| diff --git a/ui/resources/resource_check/resource_scale_factors.py b/ui/resources/resource_check/resource_scale_factors.py |
| index c3118de892989094d4af7daa52b8c97e3c8466c0..4a2dc5789a2de7fd1d816bca87f7e8a2553cf041 100644 |
| --- a/ui/resources/resource_check/resource_scale_factors.py |
| +++ b/ui/resources/resource_check/resource_scale_factors.py |
| @@ -47,11 +47,13 @@ class ResourceScaleFactors(object): |
| assert data[:8] == '\x89PNG\r\n\x1A\n' and data[12:16] == 'IHDR' |
| return struct.unpack('>ii', data[16:24]) |
| - # TODO(flackr): This should allow some flexibility for non-integer scale |
| - # factors such as allowing any size between the floor and ceiling of |
| - # base * scale. |
| - def ExpectedSize(base_width, base_height, scale): |
| - return round(base_width * scale), round(base_height * scale) |
| + # Returns a list of valid scaled image sizes. The valid sizes are the |
| + # floor and ceiling of (base_size * scale_percent / 100). This is equivalent |
| + # to requiring that the actual scaled size is less than one pixel away from |
| + # the exact scaled size. |
| + def ValidSizes(base_size, scale_percent): |
| + return sorted(set([(base_size * scale_percent) / 100, |
| + (base_size * scale_percent + 99) / 100])) |
|
flackr
2012/08/28 16:51:28
This isn't exactly the same as ceil(base_size * sc
benrg
2012/08/28 18:03:09
I think it is (when base_size and scale_percent ar
flackr
2012/08/28 21:45:25
Right, was thinking of floats but these are both i
|
| repository_path = self.input_api.os_path.relpath( |
| self.input_api.PresubmitLocalPath(), |
| @@ -80,7 +82,7 @@ class ResourceScaleFactors(object): |
| 'Base image %s does not exist' % self.input_api.os_path.join( |
| repository_path, base_image))) |
| continue |
| - base_width, base_height = ImageSize(base_image) |
| + base_dimensions = ImageSize(base_image) |
| # Find all scaled versions of the base image and verify their sizes. |
| for i in range(1, len(self.paths)): |
| image_path = self.input_api.os_path.join(self.paths[i][1], f) |
| @@ -88,12 +90,15 @@ class ResourceScaleFactors(object): |
| continue |
| # Ensure that each image for a particular scale factor is the |
| # correct scale of the base image. |
| - exp_width, exp_height = ExpectedSize(base_width, base_height, |
| - self.paths[i][0]) |
| - width, height = ImageSize(image_path) |
| - if width != exp_width or height != exp_height: |
| - results.append(self.output_api.PresubmitError( |
| - 'Image %s is %dx%d, expected to be %dx%d' % ( |
| - self.input_api.os_path.join(repository_path, image_path), |
| - width, height, exp_width, exp_height))) |
| + scaled_dimensions = ImageSize(image_path) |
| + for dimension_name, base_size, scaled_size in zip( |
| + ('width', 'height'), base_dimensions, scaled_dimensions): |
| + valid_sizes = ValidSizes(base_size, self.paths[i][0]) |
| + if scaled_size not in valid_sizes: |
| + results.append(self.output_api.PresubmitError( |
| + 'Image %s has %s %d, expected to be %s' % ( |
| + self.input_api.os_path.join(repository_path, image_path), |
| + dimension_name, |
| + scaled_size, |
| + ' or '.join(map(str, valid_sizes))))) |
| return results |