mirror of
https://github.com/xdsopl/robot36.git
synced 2026-04-05 06:15:12 +00:00
moved code generator to utils/blur.c, moved generated code to blur_generated.rsh
This commit is contained in:
parent
48deba6305
commit
308874b131
5 changed files with 363 additions and 340 deletions
1
utils/.gitignore
vendored
Normal file
1
utils/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
blur
|
||||
7
utils/Makefile
Normal file
7
utils/Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
CFLAGS = -std=gnu99 -W -Wall -O3
|
||||
LDFLAGS = -lm
|
||||
|
||||
generate: blur
|
||||
./blur > ../app/src/main/rs/blur_generated.rsh
|
||||
|
||||
blur: blur.c
|
||||
51
utils/blur.c
Normal file
51
utils/blur.c
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
Copyright 2014 Ahmet Inan <xdsopl@googlemail.com>
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
double gauss(double x, double radius)
|
||||
{
|
||||
double sigma = radius / 3.0;
|
||||
return radius ? exp(- x * x / (2.0 * sigma * sigma)) / sqrt(2.0 * M_PI * sigma * sigma) : 1.0;
|
||||
}
|
||||
void emit(int radius)
|
||||
{
|
||||
printf("\t\tif (i < %d || (buffer_length - %d) <= i)\n\t\t\treturn 0;\n", radius, radius);
|
||||
int sum = 0;
|
||||
for (int i = -radius; i <= radius; ++i)
|
||||
sum += 16384 * gauss(i, radius);
|
||||
int factor = (16384 * 16384) / (sum + 1);
|
||||
for (int i = -radius; i <= radius; ++i)
|
||||
printf("\t\t%s%d * value_buffer[i%s%d]%s\n",
|
||||
i != -radius ? "\t" : "return (",
|
||||
(int)(factor * gauss(i, radius)),
|
||||
i < 0 ? "" : "+",
|
||||
i,
|
||||
i != radius ? " +" : ") >> 14;"
|
||||
);
|
||||
}
|
||||
int main()
|
||||
{
|
||||
printf("/* code generated by 'utils/blur.c' */\n");
|
||||
printf("static uchar value_blur(int i)\n{\n\tswitch (blur_power) {\n");
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
printf("\tcase %d:\n", i);
|
||||
emit((1 << i) | 1);
|
||||
}
|
||||
printf("\tdefault:\n\t\treturn value_buffer[i];\n\t}\n\treturn 0;\n}\n");
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue