SERDISP_TOOLS

Drawing functions

void sdtools_generic_rotate (serdisp_t *dd)
 rotates the display buffer More...
 
void sdtools_generic_setsdpixel (serdisp_t *dd, int x, int y, SDCol sdcol)
 changes a pixel into the display buffer More...
 
SDCol sdtools_generic_getsdpixel (serdisp_t *dd, int x, int y)
 gets a pixel from the display buffer More...
 
void sdtools_generic_setsdpixel_greyhoriz (serdisp_t *dd, int x, int y, SDCol sdcol)
 changes a pixel into the display buffer (horizontally organised w/o pages) More...
 
SDCol sdtools_generic_getsdpixel_greyhoriz (serdisp_t *dd, int x, int y)
 gets a pixel from the display buffer (horizontally organised w/o pages) More...
 

System functions

void sdtools_nsleep (long ns)
 sleeps for the specified number of nanoseconds More...
 
void * sdtools_malloc (size_t size)
 zero-byte save malloc More...
 
byte sdtools_reversebits (byte b)
 swaps bits in a byte More...
 

Conversion functions

int sdtools_contrast_norm2hw (serdisp_t *dd, int normval)
 convert normalised contrast value to hardware contrast value More...
 
int sdtools_contrast_hw2norm (serdisp_t *dd, int hwval)
 convert hardware contrast value to normalised contrast value More...
 
int sdtools_rotate_deg2intern (serdisp_t *dd, int degval)
 convert rotation radius in degrees to rotation value in internal representation More...
 
int sdtools_rotate_intern2deg (serdisp_t *dd, int irepval)
 convert rotation value in internal representation to radius value in degrees More...
 
byte sdtools_dec2bcd (byte num)
 convert a decimal number to BCD representation More...
 

String processing

char * sdtools_strncpy (char *dest, const char *src, size_t n)
 workaround for error-prone strncpy More...
 
char * sdtools_strlefttrim (const char *str)
 trims a string More...
 
int sdtools_isinelemlist (const char *elemlist, const char *str, int len)
 tests of a string is part of a comma-separated list More...
 
char * sdtools_nextpattern (const char *str, char delim, int *len, int *border)
 searches next pattern in a string More...
 
int sdtools_ismatching (const char *str1, int len1, const char *str2, int len2)
 compares two strings if they're matching More...
 
int sdtools_strtrimmedlen (const char *str, int len)
 length of a string without trailing spaces or tabulators More...
 
int sdtools_strtol (const char *str, char delim, int base, long *value)
 reads a long value until delimiter or end of string More...
 
int sdtools_strtosd (const char *str, char delim, double *value)
 reads a simple double value until delimiter or end of string More...
 

Calculation functions

void sdtools_init_bbox (serdisp_t *dd, int value)
 initialises or sets the bounding box data More...
 
int sdtools_calc_bbox (serdisp_t *dd, int *xt, int *yt, int *xb, int *yb)
 calculates bounding box containing changed display information More...
 

Math function replacements which do not require math.h nor -lm

double sdtools_exp (double x)
 base-e exponential function More...
 
double sdtools_log (double x)
 calculates the natural logarithm of x More...
 
double sdtools_logN (double x, double base)
 calculates the logarithm of x to base y More...
 
double sdtools_pow (double x, double y)
 power function More...
 

Backward compatibility functions

void sdtools_generic_setpixel (serdisp_t *dd, int x, int y, long colour)
 
long sdtools_generic_getpixel (serdisp_t *dd, int x, int y)
 
void sdtools_generic_setpixel_greyhoriz (serdisp_t *dd, int x, int y, long colour)
 
long sdtools_generic_getpixel_greyhoriz (serdisp_t *dd, int x, int y)
 

Detailed Description

Introduction

serdisp_tools.h provides common routines that are used in different parts of serdisplib.

Attention
These functions are NOT part of the API of serdisplib.
Programs should use functions defined in serdisp_control.h.

Function Documentation

int sdtools_calc_bbox ( serdisp_t *  dd,
int *  xt,
int *  yt,
int *  xb,
int *  yb 
)
Parameters
dddevice descriptor
xtx top-left
yty top-left
xbx bottom-left
yby bottom-left
Return values
0no changed display information found in current bounding box
1changes detected, new bbox calculated
Since
2.00
int sdtools_contrast_hw2norm ( serdisp_t *  dd,
int  hwval 
)
Parameters
dddevice descriptor
hwvalcontrast value used by the hardware (in [min_contrast, max_contrast])
Returns
normalised contrast value (in [0,MAX_CONTRASTSTEP])
Since
1.97.8
int sdtools_contrast_norm2hw ( serdisp_t *  dd,
int  normval 
)
Parameters
dddevice descriptor
normvalnormalised contrast value (in [0,MAX_CONTRASTSTEP])
Returns
contrast value used by the hardware (in [min_contrast, max_contrast])
Since
1.97.8
byte sdtools_dec2bcd ( byte  num)
Parameters
numdecimal number (in [0, 99])
Returns
BCD (binary coded decimal) representation
Since
1.97.8
double sdtools_exp ( double  x)

calculates the value of e raised to the power of x without requiring math.h nor libm.

Attention
this function is not optimised for speed and only usable and accurate for simple usages like calculating a grey value table or an expontential contrast table.
Parameters
xvalue
Returns
e raised to the power of x
Since
1.97.9
SDCol sdtools_generic_getsdpixel ( serdisp_t *  dd,
int  x,
int  y 
)
Parameters
dddevice descriptor
xx-position
yy-position
Returns
hardware-dependent grey-level or colour information at (x/y)
SDCol sdtools_generic_getsdpixel_greyhoriz ( serdisp_t *  dd,
int  x,
int  y 
)
Parameters
dddevice descriptor
xx-position
yy-position
Returns
hardware-dependent grey-level or colour information at (x/y)
void sdtools_generic_rotate ( serdisp_t *  dd)

rotates the display buffer (and updates the display)

Parameters
dddevice descriptor
Since
1.97.2
void sdtools_generic_setsdpixel ( serdisp_t *  dd,
int  x,
int  y,
SDCol  sdcol 
)
Parameters
dddevice descriptor
xx-position
yy-position
sdcolmonochrome: 0: clear (white), <>0: set (black); else: grey value (supported depths: 1, 2, 4)
void sdtools_generic_setsdpixel_greyhoriz ( serdisp_t *  dd,
int  x,
int  y,
SDCol  sdcol 
)
Parameters
dddevice descriptor
xx-position
yy-position
sdcolmonochrome: 0: clear (white), <>0: set (black); else: grey value (dependent on display)
void sdtools_init_bbox ( serdisp_t *  dd,
int  value 
)
Parameters
dddevice descriptor
value0: clears bounding box, 1: sets whole display area to dirty
Since
2.00
int sdtools_isinelemlist ( const char *  elemlist,
const char *  str,
int  len 
)

tests if string str is part of the comma-separated list elemlist.
leading and trailing spaces and tabs are ignored. commas are interpreted as separators and are NOT valid in elements!

Parameters
elemlistcomma-separated element list
strstring to be searched
lenmax. number of characters to be processed (or -1 if unlimited)
Return values
-1string str is not part of the element list
>=0str is the n-th element in the element list

Examples:

     sdtools_isinelemlist(" xyz , abc,cde ", "xyz", -1);   ->  0 will be returned
     sdtools_isinelemlist(" xyz , abc,cde ", "abc", -1);   ->  1 will be returned
     sdtools_isinelemlist(" xyz , abc,cde ", " cde", -1);  ->  2 will be returned (trailing spaces will be ignored)
     sdtools_isinelemlist(" xyz , abc,cde ", "ijk", -1);   -> -1 will be returned
     sdtools_isinelemlist(" xyz , abc,cde ", "c,c", -1);   -> -1 will be returned (',' is a separator but no valid character)
\since   1.95
int sdtools_ismatching ( const char *  str1,
int  len1,
const char *  str2,
int  len2 
)

compares two strings whether they match or not. case, leading spaces, and tabs are ignored.

Parameters
str1string 1
len1length of string 1 (all characters after len1 are ignored)
str2string 2
len2length of string 2 (all characters after len2 are ignored)
Return values
1strings match
0strings don't match
Since
1.95
double sdtools_log ( double  x)

calculates the natural logarithm of x in a simple way without requiring math.h nor libm.

Attention
this function is not optimised for speed and only usable and accurate for simple usages like calculating a grey value table or an expontential contrast table.
this function cannot calculate log(0). the result will simply be 0 which is incorrect. (because we don't have NaN of inf because we don't include math.h)
Parameters
xvalue
Returns
natural logarithm of x
Since
1.97.9
double sdtools_logN ( double  x,
double  base 
)

calculates the logarithm of x to base y in a simple way without requiring math.h nor libm.

Attention
this function is not optimised for speed and only usable and accurate for simple usages like calculating a grey value table or an expontential contrast table.
this function cannot calculate logN(0, base) nor a result for x < 1.0 and base < 1.0. the result will simply be 0 which is incorrect (there is no NaN or inf available because we don't include math.h).
Parameters
xvalue
basebase of logarithm
Returns
logarithm of x with base y
Since
1.97.9
void* sdtools_malloc ( size_t  size)

zero-byte save malloc (some versions of malloc are defective when size is zero

Parameters
sizeamount of bytes to allocate
Returns
pointer to allocated memory (or NULL if requested memory could not be allocated)
Since
1.97
char* sdtools_nextpattern ( const char *  str,
char  delim,
int *  len,
int *  border 
)

searches the next pattern delimited with delim or \0, leading spaces or tabs are ignored.

len will contain the length of this pattern without any trainling spaces or tabs.
for the first pattern, len has to be set to -1 and, if a pattern can be found, will be changed to its length.

border contains the maximum characters to take care of. all characters above border are ignored.
if a new pattern was found, border will be adapted.

Parameters
[in]strstring to be searched
[in]delimdelimiter (eg: ',' or ';')
[in,out]lenlength of found pattern (w/o leading and trailing spaces or tabulators)
[in,out]borderamount of characters that are valid for searching patterns
Return values
NULLno more patterns available
!NULLpointer to the found pattern (with leading spaces and tabulators eliminated)

Examples:

     str = "elem1=val1, elem2= val2 ,  elem3=val3   ;  xyz=abc, def = ghi ";
     border = 40;  -> ';' and all following characters are ignored
     len = -1;     -> start with -1 to get first parameter

     pattern = sdtools_nextpattern(str, ',', &len, &border);
     -> pattern will contain "elem1=........", len = 10; border = 40; so pattern => "elem1=val1"

     pattern = sdtools_nextpattern(str, ',', &len, &border);
     -> pattern will contain "elem2=........", len = 11; border = 22; so pattern => "elem2= val2"

     pattern = sdtools_nextpattern(str, ',', &len, &border);
     -> pattern will contain "elem3=........", len = 10; border = 13; so pattern => "elem3=val3"

     pattern = sdtools_nextpattern(str, ',', &len, &border);
     -> pattern will contain 0, because the border was exceeded
\since   1.95
void sdtools_nsleep ( long  ns)
Parameters
nsamount of nanoseconds to sleep
ns = 0: no delay (do nothing)
ns = 1: do a simple delay (one call of gettimeofday())
ns > 1: delay ns nanoseconds
Attention
no scheduling or priority-calls are used because these might cause errors in MPEG-PES streaming of VDR.
another fact to keep in mind: time spent for scheduling and task-switching usually is much longer than one nanosecond. thus sdtools_nsleep() cannot be accurate.
Since
1.93
double sdtools_pow ( double  x,
double  y 
)

calculates x raised to the power of y without requiring math.h nor libm.

Attention
this function is not optimised for speed and only usable and accurate for simple usages like calculating a grey value table or an expontential contrast table.
Parameters
xvalue
ypower
Returns
x raised to the power of y
Since
1.97.9
byte sdtools_reversebits ( byte  b)

swaps all bits in a byte: bit7 becomes bit0, bit6 becomes bit1 and so on.
a predefined table containing all 256 dupels is used for faster execution.

Source: graphlcd-plugin: glcddrivers/common.c: ReverseBits()
http://projects.vdr-developer.org/projects/graphlcd

Parameters
binput byte
Returns
swapped byte
Since
1.94
int sdtools_rotate_deg2intern ( serdisp_t *  dd,
int  degval 
)
Parameters
dddevice descriptor
degvalradius in degrees (1==180) (or special case degree=2: toggle 0 <-> 180 or 90 <-> 270)
Returns
rotation value in internal representation
Since
1.97.8
int sdtools_rotate_intern2deg ( serdisp_t *  dd,
int  irepval 
)
Parameters
dddevice descriptor
irepvalrotation value in internal representation
Returns
rotation radius in degrees
Since
1.97.8
char* sdtools_strlefttrim ( const char *  str)

returns a char-pointer to the first non-space/tabulator character in string str.
if no leading spaces/tabulators: str is returned as is.
no extra memory is allocated.

Parameters
strstring that should be trimmed
Returns
left-trimmed string
Since
1.95
char* sdtools_strncpy ( char *  dest,
const char *  src,
size_t  n 
)

strncpy with workarounds avoiding strncpy-bugs found on solaris10 and/or glibc-linked programs

Parameters
destdestination string
srcsource string
namount of characters to be copied
Returns
pointer to the destination string
Since
1.95
int sdtools_strtol ( const char *  str,
char  delim,
int  base,
long *  value 
)

tries to read a long value in a string. reads until end of string or until given delimiter. if the string representation contains invalid characters, the value is invalid.

Parameters
strstring containing long value
delimprocessing is stopped if delimiter is found
basenumerical base (10 for decimal, 16 for hexadecimal, 0 for auto)
valuepointer to value
Return values
1value is valid
0value is invalid (contains invalid characters)
Since
2.00
int sdtools_strtosd ( const char *  str,
char  delim,
double *  value 
)

tries to read a simple double value in a string. reads until end of string or until given delimiter. if the string representation contains invalid characters, the value is invalid. if a decimal point character is given it always has to be '.'. no other characters (like ',') are allowed. exponents are NOT supported.

Parameters
strstring containing long value
delimprocessing is stopped if delimiter is found (delim must not be '.')
valuepointer to value
Return values
1value is valid
0value is invalid (contains invalid characters)
Since
2.00
int sdtools_strtrimmedlen ( const char *  str,
int  len 
)

returns length of string str without any trailing spaces or tabulators (only len characters of str are used for this operation). leading spaces and tabulators are ignored.
if no trailing spaces/tabulators is found: len will be returned.

Parameters
strstring
lenmax. number of characters to be processed
Returns
length of string str without trailing spaces or tabulators

Examples:

 sdtools_strtimmedlen("test  ", 6);       -> 4 will be returned
 sdtools_strtimmedlen(" test ", 6);       -> 5 will be returned
 sdtools_strtimmedlen("test   ,xyz", 6);  -> 4 will be returned
 sdtools_strtimmedlen("test   ,xyz", 8);  -> 8 will be returned 
Since
1.95