CAPS Universe documentation  1.0.4
All you need to know to be successful
Data Structures | Macros | Functions | Variables
samsung-spl2-protocol.c File Reference

Create printer's wire data for SPL2 monochrome laser printers. More...

Data Structures

struct  band_info
 Information about one band to be able to process it in parallel. More...
 
struct  worker_info
 Band processing is done in multiple threads. More...
 

Macros

#define LINES_IN_ONE_BAND   128
 

Functions

static int drv_spl2_page_header_write (struct spl2_drv *info, struct caps_drv *drvi, FILE *outstream)
 
static int drv_spl2_write_band_header (unsigned band_no, unsigned dots, size_t data_size, FILE *outstream)
 
static int drv_spl2_page_footer_write (unsigned copies, FILE *outstream)
 
static void drv_spl2_band_exit (struct spl2_band_buffer *band)
 
static void drv_spl2_line_create (size_t dcnt, uint8_t dst[dcnt], size_t scnt, const uint8_t src[scnt], size_t skip)
 
static void drv_spl2_cb_fill (struct band_info *bi, struct caps_drv *drvi, unsigned band_no)
 
static struct worker_infoto_worker_info (void *d)
 
static struct band_infoto_band_info (struct worker_info *wi, unsigned no)
 
static void drv_spl2_buffer_prepare (struct band_info *bi)
 
static int spl2_drv_cb_band_process (void *anonymous_data, unsigned band_no)
 
static int spl2_drv_cb_band_is_ready (void *anonymous_data, unsigned band_no)
 
static int spl2_drv_cb_send (void *anonymous_data, unsigned band_no)
 
static struct band_infodrv_spl2_page_bis_create (size_t cnt, unsigned hw, unsigned dots_per_line, unsigned skip)
 
static void drv_spl2_page_bis_destroy (size_t cnt, struct band_info band_list[cnt])
 
int ml1640_driver_page_print (struct caps_drv *drvi, void *d)
 

Variables

static const struct caps_worker_idx worker
 

Detailed Description

This covers the following list of monochrome laser printers:

Macro Definition Documentation

◆ LINES_IN_ONE_BAND

#define LINES_IN_ONE_BAND   128

printer accepts data in 'bands', each contains 128 lines of data

Function Documentation

◆ drv_spl2_page_header_write()

static int drv_spl2_page_header_write ( struct spl2_drv info,
struct caps_drv drvi,
FILE *  outstream 
)
static

Write a "page header", a data structure leading page data

Parameters
[in]info
[in]rasterInfo about the raster for this page
[in]outstreamStream IO to the printer
Return values
0On success
negativeError codes from fwrite()
Note
Keep in mind, the used struct #page_header must be "packed", e.g. no gaps between its members
Todo:

Try to handle the copy feature of this printer. Is it relevant? Is it true, the printer's firmware supports it?

The members .pwidth and .plength carries always the real medium size in dots of the page, but always at 300 DPI (in the original Samsung driver).

◆ drv_spl2_write_band_header()

static int drv_spl2_write_band_header ( unsigned  band_no,
unsigned  dots,
size_t  data_size,
FILE *  outstream 
)
static

Write a "band header", a data structure leading one band of data

Parameters
[in]band_noNumber of this band
[in]dotsDot count in a line
[in]data_sizeSize in bytes of the following compressed band data
[in]outstreamWhere to send the data to
Returns
0 on success, negative errno else

◆ drv_spl2_page_footer_write()

static int drv_spl2_page_footer_write ( unsigned  copies,
FILE *  outstream 
)
static

Write a "page footer", a data structure trailing a full page's data

Parameters
[in]copiesCopy count of this page (max. USHRT_MAX)
[in]outstreamWhere to send the data to
Return values
0On success
negativeError codes from fwrite()
-EBADFThe printer device seems gone offline
Note
This will really flush the data in the stream's buffer to the printer.
The printer can make copies by its own. If the copies member of the footer is greater than 1, the printer repeats this page.

◆ drv_spl2_band_exit()

static void drv_spl2_band_exit ( struct spl2_band_buffer band)
static

Free resources for band processing

Parameters
[out]bandStructure to free

◆ drv_spl2_line_create()

static void drv_spl2_line_create ( size_t  dcnt,
uint8_t  dst[dcnt],
size_t  scnt,
const uint8_t  src[scnt],
size_t  skip 
)
static

Create a line of dots matching the printer's head requirements

Parameters
[in]dcntBuffer size in bytes for the print head data in dst
[out]dstBuffer for the print head data
[in]scntBuffer size in bytes for the source line in src
[in]srcBuffer with the source line data
[in]skipBytes to skip in src

dcnt should be the amout of bytes the driver expects for one line of dots (620 byte at 600 DPI for example)

Todo:
Printing real smaller media (A5 for example), needs a different approach, because the print head still requires 4960 dots, but the real content must be centered in the line in this case.

◆ drv_spl2_cb_fill()

static void drv_spl2_cb_fill ( struct band_info bi,
struct caps_drv drvi,
unsigned  band_no 
)
static

Fill the band info's band with LINES_IN_ONE_BAND from the raster image

Parameters
[out]biThe band info to fill (its band's input buffer)
[in]drviFull job description
[in]band_noNumber of the band to fill

This routine ensures there are always LINES_IN_ONE_BAND in the input buffer. If the raster image has less lines than required to fill a full band, the missing lines are padded with empty data (e.g. white dots, not printed).

Precondition
The band must be already prepared by a call to drv_spl2_buffer_prepare()
Todo:

Consider the non-printable offset at the left medium edge (depending on the format, line size and resolution!)

Consider the max. line length (depending on the resolution)

◆ to_worker_info()

static struct worker_info * to_worker_info ( void *  d)
static

◆ to_band_info()

static struct band_info * to_band_info ( struct worker_info wi,
unsigned  no 
)
static

◆ drv_spl2_buffer_prepare()

static void drv_spl2_buffer_prepare ( struct band_info bi)
static

Allocate the required memory to fill and rotate one band's data

Parameters
[in,out]biBand info to work on

Only the input buffer and the rotation buffer are allocated here, as they are always required. The compression buffer is optional for empty bands.

Note
Does not return in case of memory failure
Precondition
The bi must be already prepared by a call to drv_spl2_page_bis_create()

◆ spl2_drv_cb_band_process()

static int spl2_drv_cb_band_process ( void *  anonymous_data,
unsigned  band_no 
)
static

Do all required steps to process one band

Parameters
[in,out]anonymous_dataOur worker info
[in]band_noThe band to process in this step
Return values
0On success (here: always)

Callback from a worker thread

Memory optimized band processing. Memory is only allocated on demand and freed again as early as possible (valid only for the input and rotation buffer).

◆ spl2_drv_cb_band_is_ready()

static int spl2_drv_cb_band_is_ready ( void *  anonymous_data,
unsigned  band_no 
)
static

Check if a band is processed already

Parameters
[in,out]anonymous_dataOur worker info
[in]band_noThe band to process in this step
Return values
0This band isn't processed yet
1Band is already processed

Callback from a worker thread. It is called everytime one of the worker threads signal a band as processed. If the band is already processed, this worker thread will call spl2_drv_cb_send() in the next step.

◆ spl2_drv_cb_send()

static int spl2_drv_cb_send ( void *  anonymous_data,
unsigned  band_no 
)
static

Send the data of one band to the printer

Parameters
[in,out]anonymous_dataOur worker info
[in]band_noThe band to process in this step

Callback from a worker thread

Precondition
The bi->band.compressed data must already contain a comp_data_header

◆ drv_spl2_page_bis_create()

static struct band_info * drv_spl2_page_bis_create ( size_t  cnt,
unsigned  hw,
unsigned  dots_per_line,
unsigned  skip 
)
static

Create the band info structures for the whole page

Parameters
[in]cntBand count on this page (rounded up)
[in]hwPrint head width in monochrome dots
[in]dots_per_lineMonochrome raster dots in one source line (from the CAPS framework)
[in]skipSkip monochrome dots from the left of each source line

Creates an array of band_info structures in order to process them in parallel. A minimal set of variables are initialized, everything else happens in the threads later on (memory allocation aso.).

◆ drv_spl2_page_bis_destroy()

static void drv_spl2_page_bis_destroy ( size_t  cnt,
struct band_info  band_list[cnt] 
)
static

◆ ml1640_driver_page_print()

int ml1640_driver_page_print ( struct caps_drv drvi,
void *  d 
)

Convert one raw page and print it.

Parameters
[in]drviFull job description
[in]dThe info structure
Return values
0On success
negativeErrno else
-EBADFThe device seems gone offline

The image to process is expected as a monochrome bitmap, 8 pixel in one byte.

Precondition
For monochrome raster image data only (e.g. pixel size = 1)
A to be printed pixel must have its corresponding bit = 0, e,g, CAPS_RSTR_MONOCHROME0

Variable Documentation

◆ worker

const struct caps_worker_idx worker
static
Initial value:
= {
.idx_process = spl2_drv_cb_band_process,
.idx_is_ready = spl2_drv_cb_band_is_ready,
.idx_send = spl2_drv_cb_send,
}
static int spl2_drv_cb_band_is_ready(void *anonymous_data, unsigned band_no)
Definition: samsung-spl2-protocol.c:432
static int spl2_drv_cb_send(void *anonymous_data, unsigned band_no)
Definition: samsung-spl2-protocol.c:452
static int spl2_drv_cb_band_process(void *anonymous_data, unsigned band_no)
Definition: samsung-spl2-protocol.c:366