From: Jakob Haufe Date: Tue, 7 Aug 2018 20:10:22 +0000 (+0200) Subject: Import as-is X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fheads%2Fmaster;p=iecprint Import as-is --- a7ac642e73794ceabacc49f65ac499aa93fa8153 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..fff73cc --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +all: iecprint image2mps + +iecprint: iecprint.c + gcc -Wall -std=c99 -o $@ $< -lopencbm + +image2mps: image2mps.cpp + g++ -Wall -std=c++11 $(shell pkg-config --cflags --libs Magick++) -o $@ $< + +clean: + rm -f iecprint image2mps + diff --git a/iecprint.c b/iecprint.c new file mode 100644 index 0000000..bda5b50 --- /dev/null +++ b/iecprint.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include + +#include + +const unsigned int BUFSIZE=16; + +int main(int argc, char **argv) +{ + unsigned char devnr; + CBM_FILE cbm; + char buffer[BUFSIZE]; + ssize_t numbytes; + ssize_t totalbytes=0; + + if(argc != 2) + return 1; + + devnr=atoi(argv[1]); + + setbuf(stdout, NULL); + + cbm_driver_open(&cbm,0); + cbm_lock(cbm); + cbm_listen(cbm, devnr, 0); + while((numbytes=read(0, buffer, BUFSIZE)) > 0) + { + totalbytes+=numbytes; + cbm_raw_write(cbm, buffer, numbytes); + printf("Wrote %6ld bytes\r", totalbytes); + } + + printf("\r\n"); + cbm_unlisten(cbm); + cbm_unlock(cbm); + cbm_driver_close(cbm); + + +} diff --git a/image2mps.cpp b/image2mps.cpp new file mode 100644 index 0000000..9152819 --- /dev/null +++ b/image2mps.cpp @@ -0,0 +1,64 @@ +#include +#include +#include + +#include + +const unsigned int MAX_WIDTH=480; + +int usage(const char* name) +{ + std::cerr << "Usage: " << name << " IMAGE" << std::endl << "MPS801 datastream gets written to stdout" << std::endl; + return 1; +} + +int main(int argc, char **argv) +{ + if(argc != 2) + return usage(argv[0]); + + auto img = Magick::Image(argv[1]); + + if(img.columns() > MAX_WIDTH) + { + std::cerr << "Cropping width to " << MAX_WIDTH << "px" << std::endl; + img.crop(Magick::Geometry(MAX_WIDTH, img.rows(), 0, 0)); + } + + if(img.totalColors() > 2) + { + std::cerr << "Converting to bi-level image." << std::endl; + img.type(Magick::BilevelType); + } + + std::vector> mps; + mps.insert(mps.begin(), { 0x08 }); + + img.modifyImage(); + auto columns = img.columns(); + auto rows = img.columns(); + + auto pixels = img.getPixels(0, 0, columns, rows); + + for(size_t row=0; row < rows; row+=7) + { + std::vector line(columns, 0x80); + for(auto subrow=0; subrow < 7; subrow++) + { + if(row+subrow >= rows) + break; + for(size_t column=0; column < columns; column++) + { + auto pixel = pixels + (row+subrow)*columns + column; + if((pixel->red)==0) + line[column] |= 1<