kopia lustrzana https://github.com/dnet/pySSTV
codegen: replaced BMP with RGB array and STBI
rodzic
ec6ff85d06
commit
dee321d59e
|
@ -0,0 +1 @@
|
||||||
|
stb_image.h
|
|
@ -52,7 +52,7 @@ def main(sstv_class=None):
|
||||||
n = 0
|
n = 0
|
||||||
yield '#define ROW(x) x'
|
yield '#define ROW(x) x'
|
||||||
yield '#define COL(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;'
|
yield 'void convert(unsigned char *img, float *freqs, float *msecs) {\nint frq = 0;'
|
||||||
history = []
|
history = []
|
||||||
lut = {}
|
lut = {}
|
||||||
|
@ -71,8 +71,8 @@ def main(sstv_class=None):
|
||||||
m_start, m_len = gen_matches(same_as, history, n)
|
m_start, m_len = gen_matches(same_as, history, n)
|
||||||
for i in xrange(same_as[m_start]):
|
for i in xrange(same_as[m_start]):
|
||||||
yield history[i][0]
|
yield history[i][0]
|
||||||
yield 'for (int row = {0}; row >= 0; row -= {1}) {{'.format(
|
yield 'for (int row = 0; row < {0}; row += {1}) {{'.format(
|
||||||
(sstv.HEIGHT - 1) * sstv.WIDTH, sstv.WIDTH)
|
sstv.HEIGHT * sstv.WIDTH, sstv.WIDTH)
|
||||||
for i in xrange(same_as[m_start], same_as[m_start] + m_len - 1):
|
for i in xrange(same_as[m_start], same_as[m_start] + m_len - 1):
|
||||||
yield ' ' + history[i][1]
|
yield ' ' + history[i][1]
|
||||||
yield '}'
|
yield '}'
|
||||||
|
@ -114,10 +114,13 @@ def test():
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import struct
|
import struct
|
||||||
exe = './codegen-test-executable'
|
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:
|
try:
|
||||||
for sstv_class in supported:
|
for sstv_class in supported:
|
||||||
print 'Testing', sstv_class
|
print 'Testing', sstv_class
|
||||||
gcc = Popen(['gcc', '-xc', '-o', exe, '-'], stdin=PIPE)
|
gcc = Popen(['gcc', '-xc', '-lm', '-o', exe, '-'], stdin=PIPE)
|
||||||
start = datetime.now()
|
start = datetime.now()
|
||||||
with open(path.join(path.dirname(__file__), 'codeman.c')) as cm:
|
with open(path.join(path.dirname(__file__), 'codeman.c')) as cm:
|
||||||
gcc.communicate(cm.read().replace('#include "codegen.c"', '\n'.join(main(sstv_class))))
|
gcc.communicate(cm.read().replace('#include "codegen.c"', '\n'.join(main(sstv_class))))
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
|
#define STBI_ONLY_PNG
|
||||||
|
#include "stb_image.h"
|
||||||
#include "codegen.c"
|
#include "codegen.c"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
uint32_t offset, size;
|
int x, y, n;
|
||||||
FILE *f = fopen("320x256rgb.bmp", "r");
|
unsigned char *img = stbi_load("320x256rgb.png", &x, &y, &n, 0);
|
||||||
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);
|
|
||||||
|
|
||||||
float freqs[FREQ_COUNT], msecs[FREQ_COUNT];
|
float freqs[FREQ_COUNT], msecs[FREQ_COUNT];
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue