sw_engine texmap: remove unnecessary conditions.
[platform/core/graphics/tizenvg.git] / src / lib / sw_engine / tvgSwRasterTexmapInternal.h
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
3
4  * Permission is hereby granted, free of charge, to any person obtaining a copy
5  * of this software and associated documentation files (the "Software"), to deal
6  * in the Software without restriction, including without limitation the rights
7  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  * copies of the Software, and to permit persons to whom the Software is
9  * furnished to do so, subject to the following conditions:
10
11  * The above copyright notice and this permission notice shall be included in all
12  * copies or substantial portions of the Software.
13
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  * SOFTWARE.
21  */
22 {
23     float _dudx = dudx, _dvdx = dvdx;
24     float _dxdya = dxdya, _dxdyb = dxdyb, _dudya = dudya, _dvdya = dvdya;
25     float _xa = xa, _xb = xb, _ua = ua, _va = va;
26     auto sbuf = image->data;
27     auto dbuf = surface->buffer;
28     int sw = static_cast<int>(image->stride);
29     int sh = image->h;
30     int dw = surface->stride;
31     int x1, x2, x, y, ar, ab, iru, irv, px;
32     int vv = 0;
33     int uu = 0;
34     float dx, u, v, iptr;
35     uint32_t* buf;
36 #ifdef TEXMAP_MASKING
37     uint32_t* cmp;
38 #endif
39
40     //Range exception handling
41     if (ystart >= region.max.y) return;
42     if (ystart < region.min.y) ystart = region.min.y;
43     if (yend > region.max.y) yend = region.max.y;
44
45     //Loop through all lines in the segment
46     y = ystart;
47
48     while (y < yend) {
49         x1 = _xa;
50         x2 = _xb;
51
52         //Range exception handling
53         if (x1 < region.min.x) x1 = region.min.x;
54         if (x2 > region.max.x) x2 = region.max.x;
55
56         if ((x2 - x1) < 1) goto next;
57         if ((x1 >= region.max.x) || (x2 <= region.min.x)) goto next;
58
59         //Perform subtexel pre-stepping on UV
60         dx = 1 - (_xa - x1);
61         u = _ua + dx * _dudx;
62         v = _va + dx * _dvdx;
63
64         buf = dbuf + ((y * dw) + x1);
65
66         x = x1;
67
68 #ifdef TEXMAP_MASKING
69         cmp = &surface->compositor->image.data[y * surface->compositor->image.stride + x1];
70 #endif
71         //Draw horizontal line
72         while (x++ < x2) {
73             uu = (int) u;
74             vv = (int) v;
75
76             ar = (int)(255 * (1 - modff(u, &iptr)));
77             ab = (int)(255 * (1 - modff(v, &iptr)));
78             iru = uu + 1;
79             irv = vv + 1;
80             px = *(sbuf + (vv * sw) + uu);
81
82             /* horizontal interpolate */
83             if (iru < sw) {
84                 /* right pixel */
85                 int px2 = *(sbuf + (vv * sw) + iru);
86                 px = INTERPOLATE(ar, px, px2);
87             }
88             /* vertical interpolate */
89             if (irv < sh) {
90                 /* bottom pixel */
91                 int px2 = *(sbuf + (irv * sw) + uu);
92
93                 /* horizontal interpolate */
94                 if (iru < sw) {
95                     /* bottom right pixel */
96                     int px3 = *(sbuf + (irv * sw) + iru);
97                     px2 = INTERPOLATE(ar, px2, px3);
98                 }
99                 px = INTERPOLATE(ab, px, px2);
100             }
101 #if defined(TEXMAP_MASKING) && defined(TEXMAP_TRANSLUCENT)
102             auto src = ALPHA_BLEND(px, _multiplyAlpha(opacity, blendMethod(*cmp)));
103 #elif defined(TEXMAP_MASKING)
104             auto src = ALPHA_BLEND(px, blendMethod(*cmp));
105 #elif defined(TEXMAP_TRANSLUCENT)
106             auto src = ALPHA_BLEND(px, opacity);
107 #else
108             auto src = px;            
109 #endif
110             *buf = src + ALPHA_BLEND(*buf, surface->blender.ialpha(src));
111             ++buf;
112 #ifdef TEXMAP_MASKING
113             ++cmp;
114 #endif
115             //Step UV horizontally
116             u += _dudx;
117             v += _dvdx;
118         }
119 next:
120         //Step along both edges
121         _xa += _dxdya;
122         _xb += _dxdyb;
123         _ua += _dudya;
124         _va += _dvdya;
125
126         y++;
127     }
128     xa = _xa;
129     xb = _xb;
130     ua = _ua;
131     va = _va;
132 }