Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.git
.build
.deps
.worktrees
debug
default
optimized
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sh text eol=lf
12 changes: 12 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ name: Build SpliX
on:
push:
paths:
- 'include/**'
- 'ppd/**'
- 'src/**'
- 'tests/**'
- 'Makefile'
- 'module.mk'
pull_request:
paths:
- 'include/**'
- 'ppd/**'
- 'src/**'
- 'tests/**'
- 'Makefile'
- 'module.mk'
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -62,8 +72,10 @@ jobs:
# force libcupsimage dynamic linking, as newer cups on newer ubuntu links it from libcups
sed -i 's~rastertoqpdl_LIBS.*:= ~rastertoqpdl_LIBS := -lcupsimage ~' module.mk
grep 'libjbig' module.mk
sh tests/run_docker_matrix.sh
make DRV_ONLY=1 -j4
make ppd
python3 tests/fixed_bandwidth_ppd_test.py ppd
rm -rf optimized/src
mv ppd optimized/

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
.gdb_history
gmon.out
.defs.mk
.build/
optimized
ppd/*.drv
tmp
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Aurélien Croc <aurelien AT ap2c DOT org>
Till Kamppeter <till DOT kamppeter AT gmail DOT com>
ValdikSS <iam AT valdikss DOT org DOT ru>
Michael Maertzdorf <dutch2005 AT gmail DOT com>
13 changes: 13 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
Fri Sep 4 12:00:00 2026 Michael Maertzdorf <dutch2005 AT gmail DOT com>

* Make reduced-paper fixed-width bands fully deterministic by using the
protocol bandwidth as the destination stride and zeroing all padding.
* Split compression responsibilities into focused implementation units.
* Add sanitizer-backed band-layout regression tests and generated-PPD
characterization for all fixed-bandwidth printer models.
* Make compiler diagnostics fatal in test builds, fix the warnings they
exposed, and preserve ML-1520 and unaffected ML-2010 A5 QPDL output
with golden tests.
* Check page, band, and plane swap-file I/O so truncation and short I/O
fail safely without leaking descriptors.

Thu Jul 16 21:00:00 2026 ValdikSS <iam AT valdikss DOT org DOT ru>

--- RELEASE OF THE VERSION V. 2.0.2 ---
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,36 @@ Note that older SPL1-based models (ML-12xx, ML-14xx) do not work. Use these prin

See installation instructions in the INSTALL file.

### Fixed-bandwidth protocol handling

Some older SPL2 printers require every compressed row to use the full
4960-pixel protocol width, even on A5 and other reduced paper sizes. SpliX keeps
the raster data left-aligned and zero-fills the remaining band area for those
models. The reusable layout code lives in `src/band_layout.cpp`; the compression
entry point is split into focused `src/compress_*.inc` implementation units.

Run the focused regression and generated-PPD characterization tests with:

```sh
sh tests/run_fixed_bandwidth_tests.sh
sh tests/run_fixed_bandwidth_ppd_test.sh
sh tests/run_protocol_output_test.sh
```

The first command requires a C++23 compiler and runs with AddressSanitizer and
UndefinedBehaviorSanitizer. The second requires `ppdc` and Python 3. The third
generates an A5 CUPS raster and verifies byte-for-byte QPDL output for both the
fixed-width ML-1520 and unaffected variable-width ML-2010.

Run the complete normal, no-thread, no-JBIG, and sanitizer matrix in Debian
stable with:

```sh
docker build -f tests/Dockerfile -t splix-tests .
docker run --rm -v "$PWD:/src" -w /src splix-tests \
sh tests/run_docker_matrix.sh
```

The driver was created by Aurélien Croc (aurelien at ap2c dot org) and contains many contributions from Till Kamppeter (till dot kamppeter at gmail dot com). Development is discontinued as most modern printers do not need drivers any more.

### Supported models
Expand Down
30 changes: 30 additions & 0 deletions include/band_layout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Band layout helpers for SpliX fixed-width printer protocols.
*
* Copyright (C) 2026 Michael Maertzdorf
* SPDX-License-Identifier: GPL-2.0-only
*/
#ifndef SPLIX_BAND_LAYOUT_H
#define SPLIX_BAND_LAYOUT_H

namespace splix {

enum BandLayout {
RowMajor,
ColumnMajor,
};

unsigned long fixedBandWidthBytes(unsigned long xResolution);

void copyBandRows(unsigned char* band,
unsigned long bandWidthInBytes,
unsigned long bandHeight,
const unsigned char* source,
unsigned long sourceStride,
unsigned long sourceOffset,
unsigned long rows,
BandLayout layout);

} // namespace splix

#endif /* SPLIX_BAND_LAYOUT_H */
15 changes: 15 additions & 0 deletions include/io_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* Checked POSIX I/O helpers. Copyright (C) 2026 Michael Maertzdorf. */
#ifndef SPLIX_IO_UTILS_H
#define SPLIX_IO_UTILS_H

#include <cstddef>

namespace splix {

bool readAll(int fd, void* buffer, std::size_t size);
bool writeAll(int fd, const void* buffer, std::size_t size);
bool canRead(int fd, std::size_t size);

} // namespace splix

#endif /* SPLIX_IO_UTILS_H */
6 changes: 6 additions & 0 deletions module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ DISABLE_JBIG ?= 0
DISABLE_THREADS ?= 0
DISABLE_BLACKOPTIM ?= 0
DRV_ONLY ?= 0
WARNINGS_AS_ERRORS ?= 0


# Flags
Expand All @@ -36,6 +37,10 @@ rastertoqpdl_LIBS := `pkg-config --libs cups` -lcupsimage
pstoqpdl_LDFLAGS := $(LDFLAGS)
pstoqpdl_LIBS := `pkg-config --libs cups` -lcupsimage

ifneq ($(WARNINGS_AS_ERRORS),0)
CXXFLAGS += -Werror
endif


# Update compilation flags with defined options
ifneq ($(DISABLE_THREADS),0)
Expand Down Expand Up @@ -76,4 +81,5 @@ src_pstoqpdl_cpp_FLAGS += -DPSTORASTER=\"$(PSTORASTER)\"
src_pstoqpdl_cpp_FLAGS += -DGSTORASTER=\"$(GSTORASTER)\"
src_pstoqpdl_cpp_FLAGS += -DCUPSPPD=\"$(CUPSPPD)\"
src_pstoqpdl_cpp_FLAGS += -DCUPSPROFILE=\"$(CUPSPROFILE)\"
src_ppdfile_cpp_FLAGS += -Wno-deprecated-declarations

21 changes: 13 additions & 8 deletions src/band.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <unistd.h>
#include "errlog.h"
#include "bandplane.h"
#include "io_utils.h"

/*
* Constructeur - Destructeur
Expand Down Expand Up @@ -71,10 +72,11 @@ Band::~Band()
*/
bool Band::swapToDisk(int fd)
{
write(fd, &_bandNr, sizeof(_bandNr));
write(fd, &_colors, sizeof(_colors));
write(fd, &_width, sizeof(_width));
write(fd, &_height, sizeof(_height));
if (!splix::writeAll(fd, &_bandNr, sizeof(_bandNr)) ||
!splix::writeAll(fd, &_colors, sizeof(_colors)) ||
!splix::writeAll(fd, &_width, sizeof(_width)) ||
!splix::writeAll(fd, &_height, sizeof(_height)))
return false;
for (unsigned int i=0; i < _colors; i++)
if (!_planes[i]->swapToDisk(fd))
return false;
Expand All @@ -87,10 +89,13 @@ Band* Band::restoreIntoMemory(int fd)
Band* band;

band = new Band();
read(fd, &band->_bandNr, sizeof(band->_bandNr));
read(fd, &colors, sizeof(colors));
read(fd, &band->_width, sizeof(band->_width));
read(fd, &band->_height, sizeof(band->_height));
if (!splix::readAll(fd, &band->_bandNr, sizeof(band->_bandNr)) ||
!splix::readAll(fd, &colors, sizeof(colors)) || colors > 4 ||
!splix::readAll(fd, &band->_width, sizeof(band->_width)) ||
!splix::readAll(fd, &band->_height, sizeof(band->_height))) {
delete band;
return NULL;
}
for (unsigned int i=0; i < colors; i++) {
BandPlane *plane = BandPlane::restoreIntoMemory(fd);
if (!plane) {
Expand Down
50 changes: 50 additions & 0 deletions src/band_layout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Band layout helpers for SpliX fixed-width printer protocols.
*
* Copyright (C) 2026 Michael Maertzdorf
* SPDX-License-Identifier: GPL-2.0-only
*/
#include "band_layout.h"

#include <algorithm>
#include <cstddef>
#include <cstring>

namespace splix {

unsigned long fixedBandWidthBytes(unsigned long xResolution)
{
const unsigned long fixedWidthAt600Dpi = 4960;
const unsigned long bitsPerByte = 8;
return xResolution * fixedWidthAt600Dpi / 600 / bitsPerByte;
}

void copyBandRows(unsigned char* band,
unsigned long bandWidthInBytes,
unsigned long bandHeight,
const unsigned char* source,
unsigned long sourceStride,
unsigned long sourceOffset,
unsigned long rows,
BandLayout layout)
{
std::memset(band, 0, bandWidthInBytes * bandHeight);
if (sourceOffset >= sourceStride)
return;

const unsigned long copyWidth = std::min(
sourceStride - sourceOffset, bandWidthInBytes);
const unsigned long copyRows = std::min(rows, bandHeight);

for (unsigned long y = 0; y < copyRows; ++y) {
for (unsigned long x = 0; x < copyWidth; ++x) {
const unsigned long destination =
layout == ColumnMajor
? x * bandHeight + y
: y * bandWidthInBytes + x;
band[destination] = source[y * sourceStride + sourceOffset + x];
}
}
}

} // namespace splix
47 changes: 33 additions & 14 deletions src/bandplane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*
*/
#include "bandplane.h"
#include "io_utils.h"
#include <limits>
#include <new>
#include <unistd.h>

/*
Expand Down Expand Up @@ -65,13 +68,12 @@ void BandPlane::setData(unsigned char *data, unsigned long size)
*/
bool BandPlane::swapToDisk(int fd)
{
write(fd, &_colorNr, sizeof(_colorNr));
write(fd, &_size, sizeof(_size));
write(fd, _data, _size);
write(fd, &_checksum, sizeof(_checksum));
write(fd, &_endian, sizeof(_endian));
write(fd, &_compression, sizeof(_compression));
return true;
return splix::writeAll(fd, &_colorNr, sizeof(_colorNr)) &&
splix::writeAll(fd, &_size, sizeof(_size)) &&
splix::writeAll(fd, _data, _size) &&
splix::writeAll(fd, &_checksum, sizeof(_checksum)) &&
splix::writeAll(fd, &_endian, sizeof(_endian)) &&
splix::writeAll(fd, &_compression, sizeof(_compression));
}

BandPlane* BandPlane::restoreIntoMemory(int fd)
Expand All @@ -80,14 +82,31 @@ BandPlane* BandPlane::restoreIntoMemory(int fd)
BandPlane* plane;

plane = new BandPlane();
read(fd, &plane->_colorNr, sizeof(plane->_colorNr));
read(fd, &plane->_size, sizeof(plane->_size));
data = new unsigned char[plane->_size];
read(fd, data, plane->_size);
if (!splix::readAll(fd, &plane->_colorNr, sizeof(plane->_colorNr)) ||
!splix::readAll(fd, &plane->_size, sizeof(plane->_size))) {
delete plane;
return NULL;
}
const std::size_t trailer = sizeof(plane->_checksum) +
sizeof(plane->_endian) + sizeof(plane->_compression);
if (plane->_size > std::numeric_limits<std::size_t>::max() - trailer ||
!splix::canRead(fd, plane->_size + trailer)) {
delete plane;
return NULL;
}
data = new (std::nothrow) unsigned char[plane->_size];
if (!data || !splix::readAll(fd, data, plane->_size)) {
delete[] data;
delete plane;
return NULL;
}
plane->_data = data;
read(fd, &plane->_checksum, sizeof(plane->_checksum));
read(fd, &plane->_endian, sizeof(plane->_endian));
read(fd, &plane->_compression, sizeof(plane->_compression));
if (!splix::readAll(fd, &plane->_checksum, sizeof(plane->_checksum)) ||
!splix::readAll(fd, &plane->_endian, sizeof(plane->_endian)) ||
!splix::readAll(fd, &plane->_compression, sizeof(plane->_compression))) {
delete plane;
return NULL;
}

return plane;
}
Expand Down
4 changes: 3 additions & 1 deletion src/cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ static void* _cacheControllerThread(void *_exitVar)
if (_waitingList && !(_pagesInMemory == CACHESIZE ||
_pagesInMemory == _pagesInTable)) {
preloadPage = whatToDo;
whatToDo = ~whatToDo;
whatToDo = !whatToDo;
// One of the two thing to do
} else
preloadPage = (_waitingList == NULL);
Expand Down Expand Up @@ -549,6 +549,7 @@ bool CacheEntry::swapToDisk()

// Swap the instance into the file
if (!_page->swapToDisk(fd)) {
close(fd);
unlink(_tempFile);
delete[] _tempFile;
_tempFile = NULL;
Expand Down Expand Up @@ -582,6 +583,7 @@ bool CacheEntry::restoreIntoMemory()

// Restore the instance
if (!(_page = Page::restoreIntoMemory(fd))) {
close(fd);
ERRORMSG(_("Cannot restore page into memory"));
return false;
}
Expand Down
Loading