Implementation of the Canon CAPT v1 protocol and SCoA compression based on reverse engineering of the original driver.
Important
This project is currently in an EXPERIMENTAL state.
NOTE: This is not a full-fledged driver that you can install into your system. It is an implementation of the compression algorithm and protocol, abstracted from any operating system or transmission channel.
Currently, the target devices are printers with CNTblModel = 0 (see Canon's driver PPD).
| Model | Cartridge | PPM (A4) | Max Resolution | Year (approx.) |
|---|---|---|---|---|
| LBP800 | EP-22 | 8 | 600 dpi | 1999-2001 |
| LBP810 | EP-22 | 8 | 600 dpi | 2001-2002 |
| LBP1120 | EP-22 | 10 | 600 dpi | 2003-2004 |
| LBP1210 | EP-25 | 14 | 600 dpi | ~2002 |
| LBP3200 | EP-26/EP-27 | 18 | 600 dpi | 2004-2006 |
cmake -S. -B build
cmake --build build- gcc >= 11 or clang >= 16 or MSVC (tested on 19.44.35217.0)
- cmake >= 3.21
- gtest (+gmock)
- gdb
- ghostscript
- poppler-utils (
pdfseparate,pdfinfo, etc.) - captfilter deps (
libpopt0:i386on Debian)
cmake -S. -B build -DLIBCAPT_BUILD_TESTS=ON
cmake --build build
ctest --test-dir buildcmake -S. -B build -DLIBCAPT_BUILD_TESTS=ON -DLIBCAPT_COMPRESSION_TESTS=ON
cmake --build build
ctest --test-dir buildCompression test files are located at tests/Compression/data.
If you are adding your own files, don't forget to add them into the CMakeLists.txt file.
There are several options if you want to print on your Canon LBP printer (except for the original driver):
- darkvision77/captppd — CUPS driver based on libcapt (CAPTv1 only)
- UoWPrint — print server that supports all Canon LBP models (and other printers)
- mounaiban/captdriver — CUPS driver for the newer Canon LBP models (early alpha stage)
Also, the examples folder contains an example program for printing PBM files.
Keep in mind that this program does not implement all the features and is used only for printing testing.
cmake -S. -B build -DLIBCAPT_BUILD_EXAMPLES=ON
cmake --build build
./build/examples/printpbm /dev/usb/lp0 ./examples/data/example-1.pbmTo rasterize PDF files into PBM, you can use the pdf2pbm.sh script.
Also, you can find some test PBM files in the examples/data folder.
The correct operation of the compressor can be verified using the decoder.
But how can we ensure that the decoder itself is functioning correctly?
General principle:
- The original PBM is converted to
filtered.binusing Canon'scaptfilter, extracting its «command sequence log». - The decoder receives
filtered.bin, decodes the raster, and writes the read commands to its command log. - If the command logs of the
captfilterand decoder are equal, then the commands were correctly recognized. - The original raster is compared with the decoded one from
filtered.bin.
Of course, the original captfilter does not write any logs. So...
The captfilter is not being run directly.
Instead, it is run under a special gdb python script that is responsible for:
- Command log: the
captfilterbinary file contains some debug prints, but the DebugPrint function is disabled in the release build, so for each compression command there is a breakpoint that makes the corresponding entry in the log. - Resolve «Buffer shift bug»: there is a bug in
captfilterrelated to the *ThenRaw* commands that affects the final raster.
Let's say there is a bufferrawData[256]. It can be represented as the following commands:But for some reason, there is no buffer offset, and the output is something like this:char* rawData; CopyThenRawLong(0, rawData, 255); // writes {1, 2, 3, ..., 255} rawData += 255; CopyThenRaw(0, rawData, 1); // writes {256}
This bug can be found by compressing files with random data (seechar* rawData; CopyThenRawLong(0, rawData, 255); // writes {1, 2, 3, ..., 255} // Oops... CopyThenRaw(0, rawData, 1); // writes {1} again...
rand{A..F}.pbm). - Zero margins: to prevent
captfilterfrom resizing the raster, you need to set the margins to zero. But since the printer does not support zero margins,captfilterdoes not support them either. Therefore, we have to use the magic of gdb scripts.
libcapt is licensed under a 2-clause BSD license.