-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support drawing compressed lines #9
base: main
Are you sure you want to change the base?
Conversation
If you are sure it’s properly implemented, let’s merge this :) I personally don’t have a “new” device to test it. Little suggestion: use |
What model do you have? I'd test if your device does support this. Also I've found command to send 16 color gray-scale images, and this method uses lzo1x compression, so stay tuned. |
@NaitLee I've been busy lately, but here is what I've figured out from app source code, I don't have time right now to make proper PR, but this should be pretty easy to follow:
I've used this lzo1x library: https://github.com/abraidwood/minilzo-js Example code (written for node.js - buffers might require fixing for browser): export async function printCompressed(buffer) {
if (buffer.length === 0) {
console.error("Nothing to print");
return;
}
if (buffer.length % (DEF_CANVAS_WIDTH / 2) !== 0) {
console.error("Invalid image size");
}
console.log("preparing");
// await printer.feed(8);
await printer.prepare(32, 50000);
let bufferStart = 0;
const slice = (DEF_CANVAS_WIDTH / 2) * 16;
while (bufferStart < buffer.length) {
const state = {
inputBuffer: buffer.slice(bufferStart, (bufferStart += slice)),
outputBuffer: null,
};
const compressed = lzo1x.compress(state);
console.log(
"compressed",
compressed,
"input",
state.inputBuffer.length,
"output buffer length",
state.outputBuffer.length
);
await printer.send(
printer.make(
0xcf,
new Uint8Array([
state.inputBuffer.length & 0xff,
(state.inputBuffer.length >> 8) & 0xff,
state.outputBuffer.length & 0xff,
(state.outputBuffer.length >> 8) & 0xff,
...state.outputBuffer,
])
)
);
}
console.log("finishing");
await printer.finish(32);
await printer.getDeviceState();
await printer.flush();
} Please let me know if this works for you! 😀 P.S. I've done some more tests to figure out other commands: https://github.com/KapitanOczywisty/Cat-Printer-Protocol/blob/main/README.MD |
The printer in my hand is an old model (GB02), it's said that it doesn't support compressed data. I may ask my friend (he has MX06) to test it, but that's likely months later, or not going to happen at all. I can't yet assure design of this program is capable of generating grayscale images by a few changes. I'm personally busy as well, and I'm almost certain that I will no longer focus on my legacy projects (that means everything on github). |
I've implemented drawing compressed lines, as they are sent from iprint. Compression has fallback when it reaches uncompressed line length (48 bytes).