kopia lustrzana https://gitlab.com/sane-project/backends
rts8891: gamma-correct image in find_origin and find_margin
Apply gamma correction to image in find_origin and find_margin to allow correct detection with cold lamp. Also find 4 consecutive white pixels (instead of one) in find_margin.734-support-for-canon-i-sensys-mf657cdw-mf650c-series
rodzic
4e4180c459
commit
464dfeb5c6
|
@ -1619,7 +1619,7 @@ libsane_rts8891_la_LIBADD = $(COMMON_LIBS) \
|
|||
sane_strstatus.lo \
|
||||
../sanei/sanei_scsi.lo \
|
||||
../sanei/sanei_usb.lo \
|
||||
$(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) $(RESMGR_LIBS)
|
||||
$(MATH_LIB) $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS) $(RESMGR_LIBS)
|
||||
EXTRA_DIST += rts8891.conf.in
|
||||
# TODO: Why are these distributed but not compiled?
|
||||
EXTRA_DIST += rts8891_devices.c rts8891_low.c rts8891_low.h
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
@ -2937,6 +2938,15 @@ average_area (int color, SANE_Byte * data, int width, int height,
|
|||
return global;
|
||||
}
|
||||
|
||||
static void
|
||||
gamma_correction (unsigned char *data, int length, float gamma)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
data[i] = 255 * pow(data[i] / 255.0, 1/gamma);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets lamp brightness (hum, maybe some timing before light off)
|
||||
|
@ -3286,6 +3296,16 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed)
|
|||
write_gray_data (data, "find_origin.pnm", width, height);
|
||||
}
|
||||
|
||||
/* strong gamma correction (16) for reliable detection with cold lamp */
|
||||
if (dev->sensor == SENSOR_TYPE_UMAX)
|
||||
{
|
||||
gamma_correction(data, total, 16);
|
||||
if (DBG_LEVEL > DBG_io2)
|
||||
{
|
||||
write_gray_data (data, "find_origin_gamma.pnm", width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/* now we have the data, search for the black area so that we can */
|
||||
/* deduce start of scan area */
|
||||
/* we apply an Y direction sobel filter to get reliable edge detection */
|
||||
|
@ -3398,6 +3418,7 @@ find_origin (struct Rts8891_Device *dev, SANE_Bool * changed)
|
|||
}
|
||||
|
||||
/* move by a fixed amount relative to the 'top' of the scanner */
|
||||
DBG (DBG_info, "find_origin: moving back %d lines\n", height - sum + 10);
|
||||
sanei_rts88xx_set_scan_area (dev->regs, height - sum + 10,
|
||||
height - sum + 11, 637, 893);
|
||||
rts8891_write_all (dev->devnum, dev->regs, dev->reg_count);
|
||||
|
@ -3629,11 +3650,28 @@ find_margin (struct Rts8891_Device *dev)
|
|||
write_gray_data (data, "find_margin.pnm", width, height);
|
||||
}
|
||||
|
||||
/* we search from left to right the first white pixel */
|
||||
/* gamma correction (2) for reliable detection with cold lamp */
|
||||
if (dev->sensor == SENSOR_TYPE_UMAX)
|
||||
{
|
||||
gamma_correction(data, total, 2);
|
||||
if (DBG_LEVEL > DBG_io2)
|
||||
{
|
||||
write_gray_data (data, "find_margin_gamma.pnm", width, height);
|
||||
}
|
||||
}
|
||||
|
||||
/* search from left for the first white pixel (4 consecutive for UMAX) */
|
||||
x = 0;
|
||||
while (x < width && data[x] < margin_level)
|
||||
x++;
|
||||
if (x == width)
|
||||
if (dev->sensor == SENSOR_TYPE_UMAX)
|
||||
while (x < width - 3 && (data[x] < margin_level ||
|
||||
data[x + 1] < margin_level ||
|
||||
data[x + 2] < margin_level ||
|
||||
data[x + 3] < margin_level))
|
||||
x++;
|
||||
else
|
||||
while (x < width && data[x] < margin_level)
|
||||
x++;
|
||||
if (x == width || (dev->sensor == SENSOR_TYPE_UMAX && x == width - 3))
|
||||
{
|
||||
DBG (DBG_warn, "find_margin: failed to find left margin!\n");
|
||||
DBG (DBG_warn, "find_margin: using default...\n");
|
||||
|
|
Ładowanie…
Reference in New Issue