added buffering for frame creation

this will soon allow us to compress images
This commit is contained in:
giomba 2021-08-12 20:37:15 +02:00
parent 826234a93d
commit bca7bde569

View File

@ -5,6 +5,7 @@
* */
#include <iostream>
#include <fstream>
#include <sstream>
enum ExitStatus {
BAD_ARGUMENT = 1,
@ -16,6 +17,9 @@ int main(int argc, char** argv) {
if (argc < 2) {
return BAD_ARGUMENT;
}
const int images = argc - 1;
std::stringstream jump_table;
std::stringstream asm_code;
std::fstream outfile;
outfile.open("frame.S", std::ios::out);
@ -23,19 +27,23 @@ int main(int argc, char** argv) {
return FILE_NOT_OPEN;
}
outfile << "#include \"macro.h\"" << std::endl;
outfile << "#include <avr/io.h>" << std::endl;
jump_table << "#include \"macro.h\"" << std::endl;
jump_table << "#include <avr/io.h>" << std::endl;
for (int current_image = 0; current_image < argc - 1; ++current_image) {
outfile << ".global line_jump_table_" << current_image << std::endl;
outfile << "line_jump_table_" << current_image << ":" << std::endl;
for (int current_image = 0; current_image < images; ++current_image) {
jump_table << ".global line_jump_table_" << current_image << std::endl;
jump_table << "line_jump_table_" << current_image << ":" << std::endl;
for (int i = 0; i < 256; ++i) {
outfile << '\t' << "jmp line_" << current_image << "_" << i << std::endl;
jump_table << '\t' << "jmp line_" << current_image << "_" << i << std::endl;
}
}
for (int current_image = 0; current_image < argc - 1; ++current_image) {
char** image = new char*[images];
for (int current_image = 0; current_image < images; ++current_image) {
std::fstream infile;
infile.open(argv[1 + current_image], std::ios::in);
if (! infile) {
return FILE_NOT_OPEN;
@ -60,7 +68,7 @@ int main(int argc, char** argv) {
infile >> width >> height;
std::cout << width << " x " << height << std::endl;
char* image = new char[height * width];
image[current_image] = new char[height * width];
for (int y = 0; y < height; ) {
for (int x = 0; x < width; ) {
@ -68,7 +76,7 @@ int main(int argc, char** argv) {
if (! infile.good())
return FILE_BAD_FORMAT;
if (c == '0' || c == '1') {
image[y * width + x] = c;
image[current_image][y * width + x] = c;
x++;
} else {
continue;
@ -80,13 +88,13 @@ int main(int argc, char** argv) {
infile.close();
for (int y = 0; y < height; ++y) {
outfile << "line_" << current_image << "_" << y << ":" << std::endl;
asm_code << "line_" << current_image << "_" << y << ":" << std::endl;
int count = 0;
char last = image[y * width + 0];
char last = image[current_image][y * width + 0];
for (int x = 0; x < width; ++x) {
char current = image[y * width + x];
char current = image[current_image][y * width + x];
std::cout << "current " << current << " last " << last << std::endl;
if (current == last) {
++count;
@ -94,34 +102,36 @@ int main(int argc, char** argv) {
std::cout << "detected change" << std::endl;
if (last == '0') {
std::cout << "clear" << std::endl;
outfile << '\t' << "cbi IO(PORTB), 4" << std::endl;
asm_code << '\t' << "cbi IO(PORTB), 4" << std::endl;
} else if (last == '1') {
std::cout << "set" << std::endl;
outfile << '\t' << "sbi IO(PORTB), 4" << std::endl;
asm_code << '\t' << "sbi IO(PORTB), 4" << std::endl;
}
if (count > 1) {
outfile << '\t' << "ldi r31, " << count - 1 << std::endl;
outfile << "1:" << std::endl;
outfile << '\t' << "dec r31" << std::endl;
outfile << '\t' << "nop" << std::endl;
outfile << '\t' << "brne 1b" << std::endl;
asm_code << '\t' << "ldi r31, " << count - 1 << std::endl;
asm_code << "1:" << std::endl;
asm_code << '\t' << "dec r31" << std::endl;
asm_code << '\t' << "nop" << std::endl;
asm_code << '\t' << "brne 1b" << std::endl;
}
outfile << '\t' << "rjmp 2f" << std::endl;
outfile << "2:" << std::endl;
asm_code << '\t' << "rjmp 2f" << std::endl;
asm_code << "2:" << std::endl;
last = current;
count = 1;
}
}
outfile << '\t' << "cbi IO(PORTB), 4" << std::endl;
outfile << '\t' << "jmp jump_table_return_address" << std::endl;
asm_code << '\t' << "cbi IO(PORTB), 4" << std::endl;
asm_code << '\t' << "jmp jump_table_return_address" << std::endl;
}
delete[] image;
}
delete[] image;
outfile << jump_table.str() << asm_code.str();
outfile.close();
}