Index: pdf/draw_utils.cc |
diff --git a/pdf/draw_utils.cc b/pdf/draw_utils.cc |
index 5d13077e1189244113dbcda17ebcc69f692922b5..79241a2af4af6492fa72914125f7f7da7b0ded34 100644 |
--- a/pdf/draw_utils.cc |
+++ b/pdf/draw_utils.cc |
@@ -41,15 +41,6 @@ inline uint32_t MakePixel(uint8_t red, |
static_cast<uint32_t>(blue); |
} |
-inline uint8_t GradientChannel(uint8_t start, uint8_t end, double ratio) { |
- double new_channel = start - (static_cast<double>(start) - end) * ratio; |
- if (new_channel < 0) |
- return 0; |
- if (new_channel > 255) |
- return 255; |
- return static_cast<uint8_t>(new_channel + 0.5); |
-} |
- |
inline uint8_t ProcessColor(uint8_t src_color, |
uint8_t dest_color, |
uint8_t alpha) { |
@@ -58,183 +49,6 @@ inline uint8_t ProcessColor(uint8_t src_color, |
return static_cast<uint8_t>((processed / 0xFF) & 0xFF); |
} |
-inline bool ImageDataContainsRect(const pp::ImageData& image_data, |
- const pp::Rect& rect) { |
- return rect.width() >= 0 && rect.height() >= 0 && |
- pp::Rect(image_data.size()).Contains(rect); |
-} |
- |
-void AlphaBlend(const pp::ImageData& src, |
- const pp::Rect& src_rc, |
- pp::ImageData* dest, |
- const pp::Point& dest_origin, |
- uint8_t alpha_adjustment) { |
- if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc)) |
- return; |
- |
- pp::Rect dest_rc(dest_origin, src_rc.size()); |
- if (dest_rc.IsEmpty() || !ImageDataContainsRect(*dest, dest_rc)) |
- return; |
- |
- const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); |
- uint32_t* dest_origin_pixel = dest->GetAddr32(dest_origin); |
- |
- int height = src_rc.height(); |
- int width = src_rc.width(); |
- for (int y = 0; y < height; y++) { |
- const uint32_t* src_pixel = src_origin_pixel; |
- uint32_t* dest_pixel = dest_origin_pixel; |
- for (int x = 0; x < width; x++) { |
- uint8_t alpha = |
- static_cast<uint8_t>(static_cast<uint32_t>(alpha_adjustment) * |
- GetAlpha(*src_pixel) / 0xFF); |
- uint8_t red = |
- ProcessColor(GetRed(*src_pixel), GetRed(*dest_pixel), alpha); |
- uint8_t green = |
- ProcessColor(GetGreen(*src_pixel), GetGreen(*dest_pixel), alpha); |
- uint8_t blue = |
- ProcessColor(GetBlue(*src_pixel), GetBlue(*dest_pixel), alpha); |
- *dest_pixel = MakePixel(red, green, blue, GetAlpha(*dest_pixel)); |
- |
- src_pixel++; |
- dest_pixel++; |
- } |
- src_origin_pixel = reinterpret_cast<const uint32_t*>( |
- reinterpret_cast<const char*>(src_origin_pixel) + src.stride()); |
- dest_origin_pixel = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); |
- } |
-} |
- |
-void GradientFill(pp::ImageData* image, |
- const pp::Rect& rc, |
- uint32_t start_color, |
- uint32_t end_color, |
- bool horizontal) { |
- std::vector<uint32_t> colors; |
- colors.resize(horizontal ? rc.width() : rc.height()); |
- for (size_t i = 0; i < colors.size(); ++i) { |
- double ratio = static_cast<double>(i) / colors.size(); |
- colors[i] = MakePixel( |
- GradientChannel(GetRed(start_color), GetRed(end_color), ratio), |
- GradientChannel(GetGreen(start_color), GetGreen(end_color), ratio), |
- GradientChannel(GetBlue(start_color), GetBlue(end_color), ratio), |
- GradientChannel(GetAlpha(start_color), GetAlpha(end_color), ratio)); |
- } |
- |
- if (horizontal) { |
- const void* data = &(colors[0]); |
- size_t size = colors.size() * 4; |
- uint32_t* origin_pixel = image->GetAddr32(rc.point()); |
- for (int y = 0; y < rc.height(); y++) { |
- memcpy(origin_pixel, data, size); |
- origin_pixel = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(origin_pixel) + image->stride()); |
- } |
- } else { |
- uint32_t* origin_pixel = image->GetAddr32(rc.point()); |
- for (int y = 0; y < rc.height(); y++) { |
- uint32_t* pixel = origin_pixel; |
- for (int x = 0; x < rc.width(); x++) { |
- *pixel = colors[y]; |
- pixel++; |
- } |
- origin_pixel = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(origin_pixel) + image->stride()); |
- } |
- } |
-} |
- |
-void GradientFill(pp::Instance* instance, |
- pp::ImageData* image, |
- const pp::Rect& dirty_rc, |
- const pp::Rect& gradient_rc, |
- uint32_t start_color, |
- uint32_t end_color, |
- bool horizontal, |
- uint8_t transparency) { |
- pp::Rect draw_rc = gradient_rc.Intersect(dirty_rc); |
- if (draw_rc.IsEmpty()) |
- return; |
- |
- pp::ImageData gradient(instance, PP_IMAGEDATAFORMAT_BGRA_PREMUL, |
- gradient_rc.size(), false); |
- |
- GradientFill(&gradient, pp::Rect(pp::Point(), gradient_rc.size()), |
- start_color, end_color, horizontal); |
- |
- pp::Rect copy_rc(draw_rc); |
- copy_rc.Offset(-gradient_rc.x(), -gradient_rc.y()); |
- AlphaBlend(gradient, copy_rc, image, draw_rc.point(), transparency); |
-} |
- |
-void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc, |
- pp::ImageData* dest, const pp::Rect& dest_rc, |
- bool stretch) { |
- if (src_rc.IsEmpty() || !ImageDataContainsRect(src, src_rc)) |
- return; |
- |
- pp::Rect stretched_rc(dest_rc.point(), |
- stretch ? dest_rc.size() : src_rc.size()); |
- if (stretched_rc.IsEmpty() || !ImageDataContainsRect(*dest, stretched_rc)) |
- return; |
- |
- const uint32_t* src_origin_pixel = src.GetAddr32(src_rc.point()); |
- uint32_t* dest_origin_pixel = dest->GetAddr32(dest_rc.point()); |
- if (stretch) { |
- double x_ratio = static_cast<double>(src_rc.width()) / dest_rc.width(); |
- double y_ratio = static_cast<double>(src_rc.height()) / dest_rc.height(); |
- int32_t height = dest_rc.height(); |
- int32_t width = dest_rc.width(); |
- for (int32_t y = 0; y < height; ++y) { |
- uint32_t* dest_pixel = dest_origin_pixel; |
- for (int32_t x = 0; x < width; ++x) { |
- uint32_t src_x = static_cast<uint32_t>(x * x_ratio); |
- uint32_t src_y = static_cast<uint32_t>(y * y_ratio); |
- const uint32_t* src_pixel = src.GetAddr32( |
- pp::Point(src_rc.x() + src_x, src_rc.y() + src_y)); |
- *dest_pixel = *src_pixel; |
- dest_pixel++; |
- } |
- dest_origin_pixel = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); |
- } |
- } else { |
- int32_t height = src_rc.height(); |
- base::CheckedNumeric<int32_t> width_bytes = src_rc.width(); |
- width_bytes *= 4; |
- for (int32_t y = 0; y < height; ++y) { |
- memcpy(dest_origin_pixel, src_origin_pixel, width_bytes.ValueOrDie()); |
- src_origin_pixel = reinterpret_cast<const uint32_t*>( |
- reinterpret_cast<const char*>(src_origin_pixel) + src.stride()); |
- dest_origin_pixel = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(dest_origin_pixel) + dest->stride()); |
- } |
- } |
-} |
- |
-void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32_t color) { |
- int height = rc.height(); |
- if (height == 0) |
- return; |
- |
- // Fill in first row. |
- uint32_t* top_line = image->GetAddr32(rc.point()); |
- int width = rc.width(); |
- for (int x = 0; x < width; x++) |
- top_line[x] = color; |
- |
- // Fill in the rest of the rectangle. |
- int byte_width = width * 4; |
- uint32_t* cur_line = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(top_line) + image->stride()); |
- for (int y = 1; y < height; y++) { |
- memcpy(cur_line, top_line, byte_width); |
- cur_line = reinterpret_cast<uint32_t*>( |
- reinterpret_cast<char*>(cur_line) + image->stride()); |
- } |
-} |
- |
ShadowMatrix::ShadowMatrix(uint32_t depth, double factor, uint32_t background) |
: depth_(depth), factor_(factor), background_(background) { |
DCHECK(depth_ > 0); |