Skip to content

Instantly share code, notes, and snippets.

@Luiz-Monad
Created September 29, 2019 00:15
Show Gist options
  • Save Luiz-Monad/1646da1adc5becd60b5eaf3bbb012766 to your computer and use it in GitHub Desktop.
Save Luiz-Monad/1646da1adc5becd60b5eaf3bbb012766 to your computer and use it in GitHub Desktop.
ostringstream param;
param << "\x4c\x1b\x47\x4c\x31\x2c\x30\x2c";
param << string(3 - swidth.size(), '0') << swidth;
param << ",";
param << string(3 - sheight.size(), '0') << sheight;
param << ";";
string cmd = param.str();
write(f, cmd.c_str(), cmd.size());
vector<char> bytedata;
bytedata.resize(width * height / 8);
int c = 0;
int p = 128;
int i = 0;
for (int y = 0; y < height; y++)
{
for (int x = 0; x < width; x++)
{
int n = pixeldata[y * width + x] ? 1 : 0;
c += p * n;
p /= 2;
if (p == 0)
{
//dbprintf("%4d", c);
bytedata[i++] = c;
p = 128;
c = 0;
}
}
//dbprintf("\n");
}
write(f, (const char *)&bytedata[0], bytedata.size());
close(f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment