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
3 // found in the LICENSE file.
5 #ifndef PDF_DRAW_UTILS_H_
6 #define PDF_DRAW_UTILS_H_
10 #include "base/basictypes.h"
11 #include "ppapi/cpp/image_data.h"
12 #include "ppapi/cpp/rect.h"
14 namespace chrome_pdf
{
16 const uint8 kOpaqueAlpha
= 0xFF;
17 const uint8 kTransparentAlpha
= 0x00;
19 void AlphaBlend(const pp::ImageData
& src
, const pp::Rect
& src_rc
,
20 pp::ImageData
* dest
, const pp::Point
& dest_origin
,
21 uint8 alpha_adjustment
);
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.
26 void GradientFill(pp::ImageData
* image
,
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
35 void GradientFill(pp::Instance
* instance
,
37 const pp::Rect
& dirty_rc
,
38 const pp::Rect
& gradient_rc
,
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
48 void CopyImage(const pp::ImageData
& src
, const pp::Rect
& src_rc
,
49 pp::ImageData
* dest
, const pp::Rect
& dest_rc
,
52 // Fill in rectangle with specified color.
53 void FillRect(pp::ImageData
* image
, const pp::Rect
& rc
, uint32 color
);
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.
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
);
69 uint32
GetValue(int32 x
, int32 y
) const { return matrix_
[y
* depth_
+ x
]; }
71 uint32
depth() const { return depth_
; }
72 double factor() const { return factor_
; }
73 uint32
background() const { return background_
; }
79 std::vector
<uint32
> matrix_
;
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
86 void 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
);
92 } // namespace chrome_pdf
94 #endif // PDF_DRAW_UTILS_H_