1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17 * @file render_scanline.h
18 * @brief Defines scanline renderer
19 * @since 1.0
20 * @version 1.0
21 */
22 
23 #ifndef GRAPHIC_LITE_RENDER_SCANLINE_H
24 #define GRAPHIC_LITE_RENDER_SCANLINE_H
25 
26 #include <cstdlib>
27 #include <cstring>
28 #include <limits>
29 #include "gfx_utils/color.h"
30 #include "gfx_utils/diagram/spancolorfill/fill_base.h"
31 #include "gfx_utils/diagram/scanline/geometry_scanline.h"
32 #include "gfx_utils/diagram/rasterizer/rasterizer_scanline_antialias.h"
33 #include "render/render_base.h"
34 
35 namespace OHOS {
36 /**
37  * @brief Anti aliasing scanline for rendering solid lines.
38  * Via scanline Begin gets the first span, and + + span gets the next span.
39  * The corresponding function is called by renbase to draw the color to the
40  * canvas where the corresponding span is located.
41  * @param raster grating
42  * @param scanline Scan line
43  * @param renBase Renderer
44  * @param color colour
45  */
46 void RenderScanlinesAntiAliasSolid(RasterizerScanlineAntialias& raster, GeometryScanline& scanline,
47                                    RenderBase& renBase, const Rgba8T& color);
48 
49 /**
50  * @brief Rendering anti aliased scanlines.
51  * Via scanline Begin gets the first span, and + + span gets the next span.
52  * Via allocat_ - > Resize (spanlen) allocates a color_type with the same length as span.
53  * Through segment generator spangenerate_ - > Generate(colors, x, y, len); Fill the color
54  * array to get the color array with values corresponding to the scan line span.
55  * Finally, through renbase_ Call the corresponding function to draw the color array
56  * to the canvas position of the corresponding span.
57  * @param raster grating
58  * @param scanline Scan line
59  * @param renBase Renderer
60  * @param alloc distributor
61  * @param spanGen Segment generator
62  */
63 void RenderScanlinesAntiAlias(RasterizerScanlineAntialias& raster, GeometryScanline& scanline,
64                               RenderBase& renBase, FillBase& alloc, SpanBase& spanGen);
65 
66 void BlendScanLine(GlobalCompositeOperation op, RasterizerScanlineAntialias& raster1,
67                    RasterizerScanlineAntialias& raster2, GeometryScanline& sl1, GeometryScanline& sl2,
68                    RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1, SpanBase& spanGen2);
69 
70 void CalcinterScanline(GeometryScanline& scanline3, int32_t x1, int32_t x2,
71                        GeometryScanline::ConstIterator span1, GeometryScanline::ConstIterator span2);
72 
73 void CalcOutScanlineRight(GeometryScanline& scanline, int32_t x1, int32_t x2,
74                           GeometryScanline::ConstIterator span1, GeometryScanline::ConstIterator span2);
75 
76 void CalcOutScanlineLeft(GeometryScanline& scanline, int32_t x1, int32_t x2,
77                          GeometryScanline::ConstIterator span1, GeometryScanline::ConstIterator span2);
78 
79 void CalcOutScanlineAll(GeometryScanline& scanline, int32_t x1, int32_t x2,
80                         GeometryScanline::ConstIterator span1, GeometryScanline::ConstIterator span2);
81 
82 void BlendSourceAtop(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
83                      GeometryScanline& scanline1, GeometryScanline& scanline2, RenderBase& renBase,
84                      FillBase& alloc, SpanBase& spanGen1, SpanBase& spanGen2);
85 
86 
87 void BlendSourceIn(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
88                    GeometryScanline& scanline1, GeometryScanline& scanline2, RenderBase& renBase,
89                    FillBase& alloc, SpanBase& spanGen1);
90 
91 void BlendSourceInLoop(RasterizerScanlineAntialias& raster1, GeometryScanline& scanline1, GeometryScanline& scanline2,
92                        SpanBase& spanGen1, RenderBase& renBase, FillBase& alloc, int32_t& y1);
93 
94 void BlendSourceOut(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
95                     GeometryScanline& scanline1, GeometryScanline& scanline2,
96                     RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1);
97 
98 void BlendSourceOutWhile(int32_t y1, GeometryScanline& scanline1, RenderBase& renBase,
99                          FillBase& alloc, SpanBase& spanGen1);
100 
101 void BlendSourceOutDrawResetRaster(RasterizerScanlineAntialias& raster1, GeometryScanline& scanline1,
102                                    RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1);
103 
104 void BlendSourceOver(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
105                      GeometryScanline& scanline1, GeometryScanline& scanline2,
106                      RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1, SpanBase& spanGen2);
107 
108 
109 void BlendXOR(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
110               GeometryScanline& scanline1, GeometryScanline& scanline2,
111               RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1, SpanBase& spanGen2);
112 
113 void BlendXORDrawResetRaster(RasterizerScanlineAntialias& raster1, GeometryScanline& scanline1,
114                              RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1);
115 
116 void BlendXORColorHspan(int32_t& y1, RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
117                         GeometryScanline& scanline1, RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1);
118 
119 
120 void BlendLIGHTER(RasterizerScanlineAntialias& raster1, RasterizerScanlineAntialias& raster2,
121                   GeometryScanline& scanline1, GeometryScanline& scanline2,
122                   RenderBase& renBase, FillBase& alloc, SpanBase& spanGen1, SpanBase& spanGen2);
123 } // namespace OHOS
124 #endif
125