ARM NEON Compositor  master
Fast SIMD alpha overlay and blending for ARM
test-round.cpp
Go to the documentation of this file.
1 #include <assert.h>
2 #include <math.h>
3 #include <stdint.h>
4 #include <stdio.h>
5 
6 int main(int argc, char **argv) {
7  int i, j, alpha;
8  long err = 0;
9  long tot = 0;
10  for (i = 0; i < 256; i++) {
11  for (j = 0; j < 256; j++) {
12  for (alpha = 0; alpha < 256; alpha++) {
13  uint32_t value = (i * alpha + j * (255 - alpha));
14 #if 0 // sloppy, just dividing by 256: 8546790/16777216 = 50.942838% incorrect
15  int a = value >> 8;
16  int b = value / 255;
17 #elif 0 // better: 446670/16777216 = 2.662361%
18  int a = (value * 0x101) >> 16;
19  int b = value / 255;
20 #elif 0 // better: 446670/16777216 = 2.662361%
21  int a = (value * 0x4040) >> 22;
22  int b = value / 255;
23 #elif 0 // rounding, /256: 8323072/16777216 = 49.609375%
24  int a = (value + (1 << 7)) >> 8;
25  int b = round(value / 255.);
26 #elif 0 // rounding: 16224/16777216 = 0.096703%
27  int a = (value * 0x101 + (1 << 15)) >> 16;
28  int b = round(value / 255.);
29 #elif 0 // rounding: 15948/16777216 = 0.095057%
30  int a = (value * 0x8081 + (1 << 22)) >> 23;
31  int b = round(value / 255.);
32 #elif 0 // exact rounding: 0/16777216 = 0.000000%
33  int a = ((value + (1 << 7)) * 0x101) >> 16;
34  int b = round(value / 255.);
35 #elif 0 // exact: 0/16777216 = 0.000000%
36  int a = (value * 0x8081) >> 23;
37  int b = value / 255;
38 #else // exact: 0/16777216 = 0.000000%
39  int a = (value * 257 + i + j) >> 16;
40  int b = value / 255;
41 #endif
42  if (a != b) {
43  // printf("%d, %d, %d\n", i, j, alpha);
44  assert(abs(a - b) <= 1);
45  err++;
46  }
47  tot++;
48  }
49  }
50  }
51 
52  printf("%ld/%ld = %f%%\n", err, tot, 100. * err / tot);
53  return 0;
54 }
main
int main(int argc, char **argv)
Definition: test-round.cpp:6