| 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 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/numerics/safe_math.h" |
| 12 | 13 |
| 13 namespace chrome_pdf { | 14 namespace chrome_pdf { |
| 14 | 15 |
| 15 inline uint8 GetBlue(const uint32& pixel) { | 16 inline uint8 GetBlue(const uint32& pixel) { |
| 16 return static_cast<uint8>(pixel & 0xFF); | 17 return static_cast<uint8>(pixel & 0xFF); |
| 17 } | 18 } |
| 18 | 19 |
| 19 inline uint8 GetGreen(const uint32& pixel) { | 20 inline uint8 GetGreen(const uint32& pixel) { |
| 20 return static_cast<uint8>((pixel >> 8) & 0xFF); | 21 return static_cast<uint8>((pixel >> 8) & 0xFF); |
| 21 } | 22 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 pp::ImageData* dest, const pp::Rect& dest_rc, | 146 pp::ImageData* dest, const pp::Rect& dest_rc, |
| 146 bool stretch) { | 147 bool stretch) { |
| 147 DCHECK(src_rc.width() <= dest_rc.width() && | 148 DCHECK(src_rc.width() <= dest_rc.width() && |
| 148 src_rc.height() <= dest_rc.height()); | 149 src_rc.height() <= dest_rc.height()); |
| 149 | 150 |
| 150 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); | 151 const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); |
| 151 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); | 152 uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); |
| 152 if (stretch) { | 153 if (stretch) { |
| 153 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); | 154 double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); |
| 154 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); | 155 double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); |
| 155 int height = dest_rc.height(); | 156 int32_t height = dest_rc.height(); |
| 156 int width = dest_rc.width(); | 157 int32_t width = dest_rc.width(); |
| 157 for (int y = 0; y < height; y++) { | 158 for (int32_t y = 0; y < height; ++y) { |
| 158 uint32_t* dest_pixel = dest_origin_pixel; | 159 uint32_t* dest_pixel = dest_origin_pixel; |
| 159 for (int x = 0; x < width; x++) { | 160 for (int32_t x = 0; x < width; ++x) { |
| 160 uint32 src_x = static_cast<uint32>(x * x_ratio); | 161 uint32 src_x = static_cast<uint32>(x * x_ratio); |
| 161 uint32 src_y = static_cast<uint32>(y * y_ratio); | 162 uint32 src_y = static_cast<uint32>(y * y_ratio); |
| 162 const uint32_t* src_pixel = src.GetAddr32( | 163 const uint32_t* src_pixel = src.GetAddr32( |
| 163 pp::Point(src_rc.x() + src_x, src_rc.y() + src_y)); | 164 pp::Point(src_rc.x() + src_x, src_rc.y() + src_y)); |
| 164 *dest_pixel = *src_pixel; | 165 *dest_pixel = *src_pixel; |
| 165 dest_pixel++; | 166 dest_pixel++; |
| 166 } | 167 } |
| 167 dest_origin_pixel = reinterpret_cast<uint32_t*>( | 168 dest_origin_pixel = reinterpret_cast<uint32_t*>( |
| 168 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); | 169 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); |
| 169 } | 170 } |
| 170 } else { | 171 } else { |
| 171 int height = src_rc.height(); | 172 int32_t height = src_rc.height(); |
| 172 int width_bytes = src_rc.width() * 4; | 173 base::CheckedNumeric<int32_t> width_bytes = src_rc.width(); |
| 173 for (int y = 0; y < height; y++) { | 174 width_bytes *= 4; |
| 174 memcpy(dest_origin_pixel, src_origin_pixel, width_bytes); | 175 for (int32_t y = 0; y < height; ++y) { |
| 176 memcpy(dest_origin_pixel, src_origin_pixel, width_bytes.ValueOrDie()); |
| 175 src_origin_pixel = reinterpret_cast<const uint32_t*>( | 177 src_origin_pixel = reinterpret_cast<const uint32_t*>( |
| 176 reinterpret_cast<const char*>(src_origin_pixel) + src.stride()); | 178 reinterpret_cast<const char*>(src_origin_pixel) + src.stride()); |
| 177 dest_origin_pixel = reinterpret_cast<uint32_t*>( | 179 dest_origin_pixel = reinterpret_cast<uint32_t*>( |
| 178 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); | 180 reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); |
| 179 } | 181 } |
| 180 } | 182 } |
| 181 } | 183 } |
| 182 | 184 |
| 183 void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color) { | 185 void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color) { |
| 184 int height = rc.height(); | 186 int height = rc.height(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); | 317 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); |
| 316 | 318 |
| 317 // Fill right part. | 319 // Fill right part. |
| 318 rc = pp::Rect(object_rc.right(), object_rc.y(), | 320 rc = pp::Rect(object_rc.right(), object_rc.y(), |
| 319 shadow_rc.right() - object_rc.right(), object_rc.height()); | 321 shadow_rc.right() - object_rc.right(), object_rc.height()); |
| 320 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); | 322 PaintShadow(image, rc.Intersect(clip_rc), shadow_rc, matrix); |
| 321 } | 323 } |
| 322 | 324 |
| 323 } // namespace chrome_pdf | 325 } // namespace chrome_pdf |
| 324 | 326 |
| OLD | NEW |