blob: eedf24f27d8e47b70cfe1b5abbccf3ee1b6b1b77 [file] [log] [blame]
[email protected]1b1e9eff2014-05-20 01:56:401// 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
3// found in the LICENSE file.
4
5#ifndef PDF_DRAW_UTILS_H_
6#define PDF_DRAW_UTILS_H_
7
8#include <vector>
9
10#include "base/basictypes.h"
11#include "ppapi/cpp/image_data.h"
12#include "ppapi/cpp/rect.h"
13
14namespace chrome_pdf {
15
16const uint8 kOpaqueAlpha = 0xFF;
17const uint8 kTransparentAlpha = 0x00;
18
tsepez8f079832014-09-05 05:42:2819void AlphaBlend(const pp::ImageData& src, const pp::Rect& src_rc,
[email protected]1b1e9eff2014-05-20 01:56:4020 pp::ImageData* dest, const pp::Point& dest_origin,
21 uint8 alpha_adjustment);
22
23// Fill rectangle with gradient horizontally or vertically. Start is a color of
24// top-left point of the rectangle, end color is a color of
25// top-right (horizontal==true) or bottom-left (horizontal==false) point.
26void GradientFill(pp::ImageData* image,
27 const pp::Rect& rc,
28 uint32 start_color,
29 uint32 end_color,
30 bool horizontal);
31
32// Fill dirty rectangle with gradient, where gradient color set for corners of
33// gradient rectangle. Parts of the dirty rect outside of gradient rect will
34// be unchanged.
35void GradientFill(pp::Instance* instance,
36 pp::ImageData* image,
37 const pp::Rect& dirty_rc,
38 const pp::Rect& gradient_rc,
39 uint32 start_color,
40 uint32 end_color,
41 bool horizontal,
42 uint8 transparency);
43
44// Copy one image into another. If stretch is true, the result occupy the entire
45// dest_rc. If stretch is false, dest_rc.point will be used as an origin of the
46// result image. Copy will ignore all pixels with transparent alpha from the
47// source image.
48void CopyImage(const pp::ImageData& src, const pp::Rect& src_rc,
49 pp::ImageData* dest, const pp::Rect& dest_rc,
50 bool stretch);
51
52// Fill in rectangle with specified color.
53void FillRect(pp::ImageData* image, const pp::Rect& rc, uint32 color);
54
55// Shadow Matrix contains matrix for shadow rendering. To reduce amount of
56// calculations user may choose to cache matrix and reuse it if nothing changed.
57class ShadowMatrix {
58 public:
59 // Matrix parameters.
60 // depth - how big matrix should be. Shadow will go smoothly across the
61 // entire matrix from black to background color.
62 // If factor == 1, smoothing will be linear from 0 to the end (depth),
63 // if 0 < factor < 1, smoothing will drop faster near 0.
64 // if factor > 1, smoothing will drop faster near the end (depth).
65 ShadowMatrix(uint32 depth, double factor, uint32 background);
66
67 ~ShadowMatrix();
68
69 uint32 GetValue(int32 x, int32 y) const { return matrix_[y * depth_ + x]; }
70
71 uint32 depth() const { return depth_; }
72 double factor() const { return factor_; }
73 uint32 background() const { return background_; }
74
75 private:
76 uint32 depth_;
77 double factor_;
78 uint32 background_;
79 std::vector<uint32> matrix_;
80};
81
82// Draw shadow on the image using provided ShadowMatrix.
83// shadow_rc - rectangle occupied by shadow
84// object_rc - rectangle that drops the shadow
85// clip_rc - clipping region
86void DrawShadow(pp::ImageData* image,
87 const pp::Rect& shadow_rc,
88 const pp::Rect& object_rc,
89 const pp::Rect& clip_rc,
90 const ShadowMatrix& matrix);
91
92} // namespace chrome_pdf
93
94#endif // PDF_DRAW_UTILS_H_