CAPS Universe documentation  1.0.4
All you need to know to be successful
Macros | Functions
emulation-and-restore.c File Reference

Emulate the unsupported colour formats and restore the raster. More...

Macros

#define MONOCHROME0_WHITE   0xff
 
#define MONOCHROME1_WHITE   0x00
 
#define LUMINANCE_WHITE   0xff
 
#define RGB_WHITE   0xff
 
#define CMYK_WHITE   0x00
 

Functions

static void monochome_dots_wipe_out_left (size_t cnt, struct caps_dot_monochrome *buf, uint8_t nodot)
 
static void monochome_dots_wipe_out_right (size_t cnt, struct caps_dot_monochrome *buf, uint8_t nodot)
 
static void grey_dots_wipe_out (size_t cnt, struct caps_dot_grey buf[cnt])
 
static void rgb_dots_wipe_out (size_t cnt, struct caps_dot_rgb *buf)
 
static void cmyk_dots_wipe_out (size_t cnt, struct caps_dot_cmyk *buf)
 
static void * empty_line (size_t dots_per_line, void *buf, enum caps_colour_format cf)
 
static void * line_buffer_allocate (void *buf, unsigned dots_per_line, enum caps_colour_format cf)
 
static void line_buffer_poisoning (void *buf, enum caps_colour_format cf, unsigned dot_cnt)
 
const void * caps_drv_raw_raster_line_get (struct caps_drv *cdrv, unsigned line_no)
 
void * caps_drv_raster_line_copy_get (struct caps_drv *cdrv, void *line_buf, unsigned line_no)
 
void caps_drv_emulation_stop (struct caps_drv *cdrv)
 
static void alloc_monochrome_buffer (struct caps_drv *cdrv)
 
static void read_and_store (struct caps_dot_monochrome *buf, struct drv_halftone_converter *htc, unsigned ll, unsigned no, unsigned expected_width, enum caps_colour_format cf)
 
static void monochrome_buffer_convert (struct caps_drv *cdrv, struct drv_halftone_converter *htc)
 
static void tweak_monochrome_position (struct caps_rstr_raster *desc)
 
int caps_drv_emulation_setup (struct caps_drv *cdrv)
 

Detailed Description

Author
Jürgen Borleis
Warning
Use as experimental

Drivers rely on the fact, they get a ready-to-use raster to convert and send it to the printer. But sometimes libcapsraster hasn't support for the requested colour format for example. Or the source (the document) hasn't the same format as the target medium.

Both adaptions shouldn't be done by the driver itself. That's the job of the framework.

This file provides the corresponding routines.

Macro Definition Documentation

◆ MONOCHROME0_WHITE

#define MONOCHROME0_WHITE   0xff

No-dot value for CAPS_CF_MONOCHROME0

◆ MONOCHROME1_WHITE

#define MONOCHROME1_WHITE   0x00

No-dot value for CAPS_CF_MONOCHROME1

◆ LUMINANCE_WHITE

#define LUMINANCE_WHITE   0xff

No-dot value for CAPS_CF_GREY

Luminance=0xff => white, e.g. no dot

◆ RGB_WHITE

#define RGB_WHITE   0xff

No-dot value for CAPS_CF_RGB

Red=0xff, Green=0xff, Blue=0xff => white, e.g. no dot

◆ CMYK_WHITE

#define CMYK_WHITE   0x00

No-dot value for CAPS_CF_CMYK

Cyan=0, Mangenta=0, Yellow=0, Key=0 => white, e.g. no dot

Function Documentation

◆ monochome_dots_wipe_out_left()

static void monochome_dots_wipe_out_left ( size_t  cnt,
struct caps_dot_monochrome buf,
uint8_t  nodot 
)
static

Wipe-out an amount of monochrome dots beginning at the given buffer

Parameters
[in]cntAmount of dots to wipe-out
[in,out]bufWhere to start changing dots
[in]nodotWipe-out value (0xff or 0x00)

For CAPS_CF_MONOCHROME0 let val = 0xff, for CAPS_CF_MONOCHROME1 let val = 0x00

Precondition
Bit 7 in each byte is the leftmost dot on the paper
Note
This only handles monochrome modes (e.g. one bit per dot)

◆ monochome_dots_wipe_out_right()

static void monochome_dots_wipe_out_right ( size_t  cnt,
struct caps_dot_monochrome buf,
uint8_t  nodot 
)
static

Wipe-out an amount of dots in the given buffer from right to left

Parameters
[in]cntAmount of dots to wipe-out
[in,out]bufWhere to stop changing dots (e.g. last byte in the buffer)
[in]nodotWipe-out value (0xff or 0x00)

For CAPS_CF_MONOCHROME0 let val = 0xff, for CAPS_CF_MONOCHROME1 let val = 0x00

Precondition
Bit 7 in each byte is the leftmost dot on the paper
Attention
The dot count must always start at the right most dot, e.g. bit 0 in *buf
Note
This only handles monochrome modes (e.g. one bit per dot)

◆ grey_dots_wipe_out()

static void grey_dots_wipe_out ( size_t  cnt,
struct caps_dot_grey  buf[cnt] 
)
static

Wipe-out an amount of grey dots beginning at the given buffer

Parameters
[in]cntAmount of dots to wipe-out
[in,out]bufWhere to start changing dots

Uses LUMINANCE_WHITE for each dot

◆ rgb_dots_wipe_out()

static void rgb_dots_wipe_out ( size_t  cnt,
struct caps_dot_rgb buf 
)
static

Wipe-out an amount of RGB dots beginning at the given buffer

Parameters
[in]cntAmount of dots to wipe-out
[in,out]bufWhere to start changing dots

Uses RGB_WHITE for all three colour components for each dot

◆ cmyk_dots_wipe_out()

static void cmyk_dots_wipe_out ( size_t  cnt,
struct caps_dot_cmyk buf 
)
static

Wipe-out an amount of CMYK dots beginning at the given buffer

Parameters
[in,out]bufWhere to start changing dots
[in]cntAmount of dots to wipe-out

Used CMYK_WHITE for all four colour components for each dot

◆ empty_line()

static void * empty_line ( size_t  dots_per_line,
void *  buf,
enum caps_colour_format  cf 
)
static

Provide an empty line in the corresponding colour format

Parameters
[in]dots_per_lineDots in the line in the corresponding colour format
[in,out]bufWhere the line to be wiped-out starts
[in]cfColour format
Returns
buf
Todo:
Should be optimzed and only wiped out if not already done. Lines at high resolutions can be large! But the driver can modify the data, it is free to do so!

◆ line_buffer_allocate()

static void * line_buffer_allocate ( void *  buf,
unsigned  dots_per_line,
enum caps_colour_format  cf 
)
static

Allocate a line buffer on demand for the emulated colour format

Parameters
[in]bufThe current buffer pointer (can be NULL)
[in]dots_per_lineDot count of one line
[in]cfThe colour format of the dots to emulate
Return values
bufIf a buffer is already available
PointerA line buffer of the correct length

If buf is NULL a correct sized buffer is returned. This buffer can be used on further calls as buf again.

◆ line_buffer_poisoning()

static void line_buffer_poisoning ( void *  buf,
enum caps_colour_format  cf,
unsigned  dot_cnt 
)
static

Poison the line buffer to discover bad margin/offset handling

This is only made when DEBUG is enabled. Let the compiler sort it out if not used

◆ caps_drv_emulation_stop()

void caps_drv_emulation_stop ( struct caps_drv cdrv)

Clean up the emulated data

◆ alloc_monochrome_buffer()

static void alloc_monochrome_buffer ( struct caps_drv cdrv)
static

Allocate once per page a buffer for the halftone raster

Unless the buffer is freed, no new buffer is allocated, instead the existing one from the previous page is re-used.

Precondition
caps_drv::raster_desc must be valid
Postcondition
caps_drv_emulation_stop() frees the buffer at the end of the job
The halftone raster has the dimension of the source raster from the rasterizer (regarding dots)

◆ read_and_store()

static void read_and_store ( struct caps_dot_monochrome buf,
struct drv_halftone_converter htc,
unsigned  ll,
unsigned  no,
unsigned  expected_width,
enum caps_colour_format  cf 
)
static

Read one line from a halftone converter and store it into the emulation raster buffer

Parameters
[in,out]bufThe emulation buffer to store the line to (its base address)
[in]htcThe halftone converter to read a line from
[in]llFull line length in buf
[in]noLine number in buf to write the line to
[in]expected_widthExpected width in pixel per line (e.g. <= ll) for error cecking
[in]cfColour format in which the line should be stored in buf
Precondition
buf is expected to have the size to store an ll long line at line no.

◆ monochrome_buffer_convert()

static void monochrome_buffer_convert ( struct caps_drv cdrv,
struct drv_halftone_converter htc 
)
static

Dither the input grey scale raster with the given halftone converter

Parameters
[in,out]cdrvlibcapsdriver handle
[in]htcHalftone converter to use for the conversion
Precondition
Input raster must be in format grey scale

When the routine returns, there is a second raster buffer with the requested monochrome data format in caps_drv::mono_buf. It is used as long caps_drv::emulate is one of the monochrome pixel formats instead of CAPS_CF_NONE.

This buffer is created when the first page of a document should be converted and re-used on every next page if possible and freed at the end when emulation is stopped (caps_drv_emulation_stop())

◆ tweak_monochrome_position()

static void tweak_monochrome_position ( struct caps_rstr_raster desc)
static

Tweak the horizontal position of the monochrome raster

Parameters
[in,out]descThe raster description to tweak

When we copy the monochrome line into the full line buffer in caps_drv_raster_line_copy_get() we have a little problem with positions which aren't a multiple of eight. Due to the implementation in caps_drv_raster_line_copy_get() the start of the line is exact or up to 7 bits left. These up to 7 bits must be added at the right border to wipe them out.

◆ caps_drv_emulation_setup()

int caps_drv_emulation_setup ( struct caps_drv cdrv)

Convert the rasterized image on demand

Return values
0Always

For the case, we need to emulate some colour format, we do it here

Note
This increases the amount of required memory, since the raw raster and the emulated raster exists at the same time.
Precondition
caps_drv::raster_desc must be valid
Todo:
Think about to free the raw raster, when the emulated raster has been created. This might conflict with printing more than one copies of the current page!