SANEI 1.3.1.76-0750
Functions
sanei_magic.h File Reference

This file provides an interface to simple image post-processing functions. More...

Go to the source code of this file.

Functions

void sanei_magic_init (void)
 Initialize sanei_magic. More...
 
SANE_Status sanei_magic_despeck (SANE_Parameters *params, SANE_Byte *buffer, SANE_Int diam)
 Update the image buffer, replacing dots with surrounding background color. More...
 
SANE_Status sanei_magic_findSkew (SANE_Parameters *params, SANE_Byte *buffer, int dpiX, int dpiY, int *centerX, int *centerY, double *finSlope)
 Find the skew of the media inside the image, via edge detection. More...
 
SANE_Status sanei_magic_rotate (SANE_Parameters *params, SANE_Byte *buffer, int centerX, int centerY, double slope, int bg_color)
 Correct the skew of the media inside the image, via simple rotation. More...
 
SANE_Status sanei_magic_findEdges (SANE_Parameters *params, SANE_Byte *buffer, int dpiX, int dpiY, int *top, int *bot, int *left, int *right)
 Find the edges of the media inside the image, parallel to image edges. More...
 
SANE_Status sanei_magic_crop (SANE_Parameters *params, SANE_Byte *buffer, int top, int bot, int left, int right)
 Crop the image, parallel to image edges. More...
 
SANE_Status sanei_magic_isBlank (SANE_Parameters *params, SANE_Byte *buffer, double thresh)
 Determine if image is blank. More...
 
SANE_Status sanei_magic_isBlank2 (SANE_Parameters *params, SANE_Byte *buffer, int dpiX, int dpiY, double thresh)
 Determine if image is blank, enhanced version. More...
 
SANE_Status sanei_magic_findTurn (SANE_Parameters *params, SANE_Byte *buffer, int dpiX, int dpiY, int *angle)
 Determine coarse image rotation (90 degree increments) More...
 
SANE_Status sanei_magic_turn (SANE_Parameters *params, SANE_Byte *buffer, int angle)
 Coarse image rotation (90 degree increments) More...
 

Detailed Description

This file provides an interface to simple image post-processing functions.

Currently, three operations are provided:

Note that these functions are simplistic, and are expected to change. Patches and suggestions are welcome.

Function Documentation

◆ sanei_magic_init()

void sanei_magic_init ( void  )

Initialize sanei_magic.

Call this before any other sanei_magic function.

◆ sanei_magic_despeck()

SANE_Status sanei_magic_despeck ( SANE_Parameters *  params,
SANE_Byte *  buffer,
SANE_Int  diam 
)

Update the image buffer, replacing dots with surrounding background color.

Parameters
paramsdescribes image
buffercontains image data
diammaximum dot diameter to remove
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_findSkew()

SANE_Status sanei_magic_findSkew ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  dpiX,
int  dpiY,
int *  centerX,
int *  centerY,
double *  finSlope 
)

Find the skew of the media inside the image, via edge detection.

Parameters
paramsdescribes image
buffercontains image data
dpiXhorizontal resolution
dpiYvertical resolution
[out]centerXhorizontal coordinate of center of rotation
[out]centerYvertical coordinate of center of rotation
[out]finSlopeslope of rotation
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters
  • SANE_STATUS_UNSUPPORTED - slope angle too shallow to detect

◆ sanei_magic_rotate()

SANE_Status sanei_magic_rotate ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  centerX,
int  centerY,
double  slope,
int  bg_color 
)

Correct the skew of the media inside the image, via simple rotation.

Parameters
paramsdescribes image
buffercontains image data
centerXhorizontal coordinate of center of rotation
centerYvertical coordinate of center of rotation
slopeslope of rotation
bg_colorthe replacement color for edges exposed by rotation
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_findEdges()

SANE_Status sanei_magic_findEdges ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  dpiX,
int  dpiY,
int *  top,
int *  bot,
int *  left,
int *  right 
)

Find the edges of the media inside the image, parallel to image edges.

Parameters
paramsdescribes image
buffercontains image data
dpiXhorizontal resolution
dpiYvertical resolution
[out]topvertical offset to upper edge of media
[out]botvertical offset to lower edge of media
[out]lefthorizontal offset to left edge of media
[out]righthorizontal offset to right edge of media
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_UNSUPPORTED - edges could not be detected

◆ sanei_magic_crop()

SANE_Status sanei_magic_crop ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  top,
int  bot,
int  left,
int  right 
)

Crop the image, parallel to image edges.

Parameters
paramsdescribes image
buffercontains image data
topvertical offset to upper edge of crop
botvertical offset to lower edge of crop
lefthorizontal offset to left edge of crop
righthorizontal offset to right edge of crop
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_isBlank()

SANE_Status sanei_magic_isBlank ( SANE_Parameters *  params,
SANE_Byte *  buffer,
double  thresh 
)

Determine if image is blank.

Parameters
paramsdescribes image
buffercontains image data
threshmaximum % density for blankness (0-100)
Returns
  • SANE_STATUS_GOOD - page is not blank
  • SANE_STATUS_NO_DOCS - page is blank
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_isBlank2()

SANE_Status sanei_magic_isBlank2 ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  dpiX,
int  dpiY,
double  thresh 
)

Determine if image is blank, enhanced version.

Parameters
paramsdescribes image
buffercontains image data
dpiXhorizontal resolution
dpiYvertical resolution
threshmaximum % density for blankness (0-100)
Returns
  • SANE_STATUS_GOOD - page is not blank
  • SANE_STATUS_NO_DOCS - page is blank
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_findTurn()

SANE_Status sanei_magic_findTurn ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  dpiX,
int  dpiY,
int *  angle 
)

Determine coarse image rotation (90 degree increments)

Parameters
paramsdescribes image
buffercontains image data
dpiXhorizontal resolution
dpiYvertical resolution
[out]angleamount of rotation recommended
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image parameters

◆ sanei_magic_turn()

SANE_Status sanei_magic_turn ( SANE_Parameters *  params,
SANE_Byte *  buffer,
int  angle 
)

Coarse image rotation (90 degree increments)

Parameters
paramsdescribes image
buffercontains image data
angleamount of rotation requested (multiple of 90)
Returns
  • SANE_STATUS_GOOD - success
  • SANE_STATUS_NO_MEM - not enough memory
  • SANE_STATUS_INVAL - invalid image or angle parameters