codegen: replaced BMP with RGB array and STBI

pull/7/merge
András Veres-Szentkirályi 2016-04-19 11:13:57 +02:00
rodzic ec6ff85d06
commit dee321d59e
3 zmienionych plików z 13 dodań i 17 usunięć

1
.gitignore vendored 100644
Wyświetl plik

@ -0,0 +1 @@
stb_image.h

Wyświetl plik

@ -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))))

Wyświetl plik

@ -1,21 +1,13 @@
#include <stdint.h>
#include <stdio.h>
#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];