diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f7a3c3e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +stb_image.h diff --git a/pysstv/examples/codegen.py b/pysstv/examples/codegen.py index de83e5e..54faab8 100644 --- a/pysstv/examples/codegen.py +++ b/pysstv/examples/codegen.py @@ -52,7 +52,7 @@ def main(sstv_class=None): n = 0 yield '#define ROW(x) x' yield '#define COL(x) x' - yield '#define RGB(x) (2 - (x))' + yield '#define RGB(x) x' yield 'void convert(unsigned char *img, float *freqs, float *msecs) {\nint frq = 0;' history = [] lut = {} @@ -71,8 +71,8 @@ def main(sstv_class=None): m_start, m_len = gen_matches(same_as, history, n) for i in xrange(same_as[m_start]): yield history[i][0] - yield 'for (int row = {0}; row >= 0; row -= {1}) {{'.format( - (sstv.HEIGHT - 1) * sstv.WIDTH, sstv.WIDTH) + yield 'for (int row = 0; row < {0}; row += {1}) {{'.format( + sstv.HEIGHT * sstv.WIDTH, sstv.WIDTH) for i in xrange(same_as[m_start], same_as[m_start] + m_len - 1): yield ' ' + history[i][1] yield '}' @@ -114,10 +114,13 @@ def test(): from datetime import datetime import struct exe = './codegen-test-executable' + if not path.exists('stb_image.h'): + from urllib import urlretrieve + urlretrieve('https://raw.githubusercontent.com/nothings/stb/master/stb_image.h', 'stb_image.h') try: for sstv_class in supported: print 'Testing', sstv_class - gcc = Popen(['gcc', '-xc', '-o', exe, '-'], stdin=PIPE) + gcc = Popen(['gcc', '-xc', '-lm', '-o', exe, '-'], stdin=PIPE) start = datetime.now() with open(path.join(path.dirname(__file__), 'codeman.c')) as cm: gcc.communicate(cm.read().replace('#include "codegen.c"', '\n'.join(main(sstv_class)))) diff --git a/pysstv/examples/codeman.c b/pysstv/examples/codeman.c index 1074261..0461f76 100644 --- a/pysstv/examples/codeman.c +++ b/pysstv/examples/codeman.c @@ -1,21 +1,13 @@ -#include #include +#define STB_IMAGE_IMPLEMENTATION +#define STBI_ONLY_PNG +#include "stb_image.h" #include "codegen.c" int main() { - uint32_t offset, size; - FILE *f = fopen("320x256rgb.bmp", "r"); - fseek(f, 0x02, SEEK_SET); - fread(&size, 4, 1, f); - fseek(f, 0x0A, SEEK_SET); - fread(&offset, 4, 1, f); - fseek(f, offset, SEEK_SET); - - unsigned char img[size]; - - fread(img, size - offset, 1, f); - fclose(f); + int x, y, n; + unsigned char *img = stbi_load("320x256rgb.png", &x, &y, &n, 0); float freqs[FREQ_COUNT], msecs[FREQ_COUNT];