gfx::RectF ApplyDamageToBoundsRect(const gfx::RectF& bounds_rect,
const gfx::Rect& damage_rect,
- const gfx::Size& image_size,
+ const gfx::Rect& crop_rect,
gfx::OverlayTransform overlay_transform) {
auto bounds_damage = damage_rect;
+ bounds_damage.set_x(damage_rect.x() - crop_rect.x());
+ bounds_damage.set_y(damage_rect.y() - crop_rect.y());
+
if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_180 ||
overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_270 ||
overlay_transform == gfx::OVERLAY_TRANSFORM_FLIP_HORIZONTAL) {
- bounds_damage.set_x(image_size.width() - bounds_damage.x() -
+ bounds_damage.set_x(crop_rect.width() - bounds_damage.x() -
bounds_damage.width());
}
if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_180 ||
overlay_transform == gfx::OVERLAY_TRANSFORM_FLIP_VERTICAL) {
- bounds_damage.set_y(image_size.height() - bounds_damage.y() -
+ bounds_damage.set_y(crop_rect.height() - bounds_damage.y() -
bounds_damage.height());
}
- auto scaling = NormalizedRect(bounds_damage, image_size);
+ auto scaling = NormalizedRect(bounds_damage, crop_rect.size());
if (overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_90 ||
overlay_transform == gfx::OVERLAY_TRANSFORM_ROTATE_270) {
scaling.Transpose();
bounds_damage.height());
}
- auto scaling = NormalizedRect(bounds_damage, image_size);
+ const gfx::Rect cropped_rect_in_pixels(gfx::ToNearestRect(
+ gfx::ScaleRect(crop_rect, image_size.width(), image_size.height())));
+
+ bounds_damage.set_x(bounds_damage.x() - cropped_rect_in_pixels.x());
+ bounds_damage.set_y(bounds_damage.y() - cropped_rect_in_pixels.y());
+
+ auto scaling = NormalizedRect(bounds_damage, cropped_rect_in_pixels.size());
return ScaleRect(crop_rect, scaling);
}
gfx::Rect damage_rect,
gfx::OverlayTransform overlay_transform,
bool inverse_clip_damage_for_180_rotation) {
+ const gfx::Rect cropped_rect_in_pixels(gfx::ToNearestRect(
+ gfx::ScaleRect(crop_rect, image_size.width(), image_size.height())));
+
// Step 1. Fix damage so it fits with the image coordinates.
- damage_rect.Intersect(gfx::Rect(image_size));
+ damage_rect.Intersect(cropped_rect_in_pixels);
- // Step 2. Apply damage for bounds rect.
- bounds_rect = ApplyDamageToBoundsRect(bounds_rect, damage_rect, image_size,
- overlay_transform);
+ // Step 2. Apply damage for bounds rect. Bounds rect should be resized
+ // according how much of |picture_rect| is affected by damage.
+ bounds_rect = ApplyDamageToBoundsRect(
+ bounds_rect, damage_rect, cropped_rect_in_pixels, overlay_transform);
// Step 3. Apply damage to the crop rect.
crop_rect = ApplyDamageToCropRect(crop_rect, damage_rect, image_size,