OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "pdf/draw_utils.h" | 5 #include "pdf/draw_utils.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <math.h> | 8 #include <math.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 start_color, end_color, horizontal); | 138 start_color, end_color, horizontal); |
139 | 139 |
140 pp::Rect copy_rc(draw_rc); | 140 pp::Rect copy_rc(draw_rc); |
141 copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y()); | 141 copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y()); |
142 AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency); | 142 AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency); |
143 } | 143 } |
144 | 144 |
145 void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc, | 145 void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc, |
146 pp::ImageData* dest, const pp::Rect& dest_rc, | 146 pp::ImageData* dest, const pp::Rect& dest_rc, |
147 bool stretch) { | 147 bool stretch) { |
148 DCHECK(src_rc.width() <= dest_rc.width() && | 148 if (src_rc.IsEmpty() || !src.Contains(src_rc)) |
149 src_rc.height() <= dest_rc.height()); | 149 return; |
150 if (src_rc.IsEmpty()) | 150 |
| 151 pp::Rect stretched_rc(dest_rc.point(), |
| 152 stretch ? dest_rc.size() : src_rc.size()); |
| 153 if (stretched_rc.IsEmpty() || !dest->Contains(stretched_rc)) |
151 return; | 154 return; |
152 | 155 |
153 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); | 156 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); |
154 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); | 157 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); |
155 if (stretch) { | 158 if (stretch) { |
156 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); | 159 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); |
157 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); | 160 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); |
158 int32_t height = dest_rc.height(); | 161 int32_t height = dest_rc.height(); |
159 int32_t width = dest_rc.width(); | 162 int32_t width = dest_rc.width(); |
160 for (int32_t y = 0; y < height; ++y) { | 163 for (int32_t y = 0; y < height; ++y) { |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); | 322 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); |
320 | 323 |
321 // Fill right part. | 324 // Fill right part. |
322 rc = pp::Rect(object_rc.right(), object_rc.y(), | 325 rc = pp::Rect(object_rc.right(), object_rc.y(), |
323 shadow_rc.right() - object_rc.right(), object_rc.height()); | 326 shadow_rc.right() - object_rc.right(), object_rc.height()); |
324 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); | 327 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); |
325 } | 328 } |
326 | 329 |
327 } // namespace chrome_pdf | 330 } // namespace chrome_pdf |
328 | 331 |
OLD | NEW |