summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKim Woelders <kim@woelders.dk>2021-04-15 12:57:25 +0200
committerKim Woelders <kim@woelders.dk>2021-04-16 17:15:06 +0200
commit27ab891c56293ed34f592e628ef73ee34c24ef30 (patch)
treec0b7f7e62ed8ce78e143f162bbd607505ef0bd7a
parente82a5997ecf595ceb1ede964337733beb47cb94c (diff)
Fix clang-analyzer warnings - lib (less trivial)
-rw-r--r--src/lib/ellipse.c32
1 files changed, 20 insertions, 12 deletions
diff --git a/src/lib/ellipse.c b/src/lib/ellipse.c
index ddb410b..b7f21dd 100644
--- a/src/lib/ellipse.c
+++ b/src/lib/ellipse.c
@@ -6,6 +6,18 @@
6#include "rgbadraw.h" 6#include "rgbadraw.h"
7#include "span.h" 7#include "span.h"
8 8
9/* Integer divide by 2^16 rounded */
10static int
11div_round_16(int n)
12{
13 int nn;
14
15 nn = n >> 15;
16 nn = (nn >> 1) + (nn & 1);
17
18 return nn;
19}
20
9static void 21static void
10__imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color, 22__imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
11 DATA32 * dst, int dstw, int clx, int cly, int clw, 23 DATA32 * dst, int dstw, int clx, int cly, int clw,
@@ -47,8 +59,7 @@ __imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
47 { 59 {
48 int len; 60 int len;
49 61
50 y = yy >> 16; 62 y = div_round_16(yy);
51 y += ((yy - (y << 16)) >> 15);
52 63
53 if (prev_y != y) 64 if (prev_y != y)
54 { 65 {
@@ -102,8 +113,7 @@ __imlib_Ellipse_DrawToData(int xc, int yc, int a, int b, DATA32 color,
102 { 113 {
103 int len; 114 int len;
104 115
105 x = xx >> 16; 116 x = div_round_16(xx);
106 x += ((xx - (x << 16)) >> 15);
107 117
108 if (prev_x != x) 118 if (prev_x != x)
109 { 119 {
@@ -197,7 +207,7 @@ __imlib_Ellipse_DrawToData_AA(int xc, int yc, int a, int b, DATA32 color,
197 bp -= dstw; 207 bp -= dstw;
198 } 208 }
199 209
200 A_VAL(&col1) = (yy - (y << 16)) >> 8; 210 A_VAL(&col1) = yy >> 8;
201 A_VAL(&col0) = 255 - A_VAL(&col1); 211 A_VAL(&col0) = 255 - A_VAL(&col1);
202 212
203 if (ca < 255) 213 if (ca < 255)
@@ -273,7 +283,7 @@ __imlib_Ellipse_DrawToData_AA(int xc, int yc, int a, int b, DATA32 color,
273 bp--; 283 bp--;
274 } 284 }
275 285
276 A_VAL(&col1) = (xx - (x << 16)) >> 8; 286 A_VAL(&col1) = xx >> 8;
277 A_VAL(&col0) = 255 - A_VAL(&col1); 287 A_VAL(&col0) = 255 - A_VAL(&col1);
278 288
279 if (ca < 255) 289 if (ca < 255)
@@ -365,8 +375,7 @@ __imlib_Ellipse_FillToData(int xc, int yc, int a, int b, DATA32 color,
365 int len; 375 int len;
366 DATA32 *tpp, *bpp; 376 DATA32 *tpp, *bpp;
367 377
368 y = yy >> 16; 378 y = div_round_16(yy);
369 y += ((yy - (y << 16)) >> 15);
370 379
371 if (prev_y != y) 380 if (prev_y != y)
372 { 381 {
@@ -437,8 +446,7 @@ __imlib_Ellipse_FillToData(int xc, int yc, int a, int b, DATA32 color,
437 int len; 446 int len;
438 DATA32 *tpp, *bpp; 447 DATA32 *tpp, *bpp;
439 448
440 x = xx >> 16; 449 x = div_round_16(xx);
441 x += ((xx - (x << 16)) >> 15);
442 450
443 if (prev_x != x) 451 if (prev_x != x)
444 { 452 {
@@ -559,7 +567,7 @@ __imlib_Ellipse_FillToData_AA(int xc, int yc, int a, int b, DATA32 color,
559 sfunc(color, bpp, len); 567 sfunc(color, bpp, len);
560 } 568 }
561 569
562 A_VAL(&col1) = ((yy - (y << 16)) >> 8); 570 A_VAL(&col1) = yy >> 8;
563 if (ca < 255) 571 if (ca < 255)
564 MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp); 572 MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp);
565 573
@@ -635,7 +643,7 @@ __imlib_Ellipse_FillToData_AA(int xc, int yc, int a, int b, DATA32 color,
635 if (((unsigned)by < (unsigned)clh) && (len > 0)) 643 if (((unsigned)by < (unsigned)clh) && (len > 0))
636 sfunc(color, bpp, len); 644 sfunc(color, bpp, len);
637 645
638 A_VAL(&col1) = ((xx - (x << 16)) >> 8); 646 A_VAL(&col1) = xx >> 8;
639 if (ca < 255) 647 if (ca < 255)
640 MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp); 648 MULT(A_VAL(&col1), ca, A_VAL(&col1), tmp);
641 649