genesys: Make sanei_genesys_search_reference_point() non-destructive

merge-requests/118/head
Povilas Kanapickas 2019-08-04 02:48:28 +03:00
rodzic d0dbfa6ec3
commit 91b20fb268
2 zmienionych plików z 32 dodań i 31 usunięć

Wyświetl plik

@ -1053,8 +1053,8 @@ void sanei_genesys_init_shading_data(Genesys_Device* dev, const Genesys_Sensor&
// Find the position of the reference point: takes gray level 8 bits data and find
// first CCD usable pixel and top of scanning area
void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& sensor,
uint8_t* data, int start_pixel, int dpi, int width,
int height)
const uint8_t* src_data, int start_pixel, int dpi,
int width, int height)
{
DBG_HELPER(dbg);
int x, y;
@ -1069,22 +1069,25 @@ void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& s
/* transformed image data */
size = width * height;
std::vector<uint8_t> image2(size, 0);
std::vector<uint8_t> image(size, 0);
/* laplace filter to denoise picture */
memcpy(image.data(), data, size); // to initialize unprocessed part of the image buffer
for (y = 1; y < height - 1; y++)
for (x = 1; x < width - 1; x++)
{
image[y * width + x] =
(data[(y - 1) * width + x + 1] + 2 * data[(y - 1) * width + x] +
data[(y - 1) * width + x - 1] + 2 * data[y * width + x + 1] +
4 * data[y * width + x] + 2 * data[y * width + x - 1] +
data[(y + 1) * width + x + 1] + 2 * data[(y + 1) * width + x] +
data[(y + 1) * width + x - 1]) / 16;
}
std::memcpy(image2.data(), src_data, size);
std::memcpy(image.data(), src_data, size); // to initialize unprocessed part of the image buffer
memcpy (data, image.data(), size);
for (y = 1; y < height - 1; y++) {
for (x = 1; x < width - 1; x++) {
image[y * width + x] =
(image2[(y - 1) * width + x + 1] + 2 * image2[(y - 1) * width + x] +
image2[(y - 1) * width + x - 1] + 2 * image2[y * width + x + 1] +
4 * image2[y * width + x] + 2 * image2[y * width + x - 1] +
image2[(y + 1) * width + x + 1] + 2 * image2[(y + 1) * width + x] +
image2[(y + 1) * width + x - 1]) / 16;
}
}
image2 = image;
if (DBG_LEVEL >= DBG_data)
sanei_genesys_write_pnm_file("gl_laplace.pnm", image.data(), 8, 1, width, height);
@ -1095,13 +1098,11 @@ void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& s
and finds threshold level
*/
level = 0;
for (y = 2; y < height - 2; y++)
for (x = 2; x < width - 2; x++)
{
current =
data[(y - 1) * width + x + 1] - data[(y - 1) * width + x - 1] +
2 * data[y * width + x + 1] - 2 * data[y * width + x - 1] +
data[(y + 1) * width + x + 1] - data[(y + 1) * width + x - 1];
for (y = 2; y < height - 2; y++) {
for (x = 2; x < width - 2; x++) {
current = image2[(y - 1) * width + x + 1] - image2[(y - 1) * width + x - 1] +
2 * image2[y * width + x + 1] - 2 * image2[y * width + x - 1] +
image2[(y + 1) * width + x + 1] - image2[(y + 1) * width + x - 1];
if (current < 0)
current = -current;
if (current > 255)
@ -1109,7 +1110,8 @@ void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& s
image[y * width + x] = current;
if (current > level)
level = current;
}
}
}
if (DBG_LEVEL >= DBG_data)
sanei_genesys_write_pnm_file("gl_xsobel.pnm", image.data(), 8, 1, width, height);
@ -1146,13 +1148,11 @@ void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& s
1 2 1
*/
level = 0;
for (y = 2; y < height - 2; y++)
for (x = 2; x < width - 2; x++)
{
current =
-data[(y - 1) * width + x + 1] - 2 * data[(y - 1) * width + x] -
data[(y - 1) * width + x - 1] + data[(y + 1) * width + x + 1] +
2 * data[(y + 1) * width + x] + data[(y + 1) * width + x - 1];
for (y = 2; y < height - 2; y++) {
for (x = 2; x < width - 2; x++) {
current = -image2[(y - 1) * width + x + 1] - 2 * image2[(y - 1) * width + x] -
image2[(y - 1) * width + x - 1] + image2[(y + 1) * width + x + 1] +
2 * image2[(y + 1) * width + x] + image2[(y + 1) * width + x - 1];
if (current < 0)
current = -current;
if (current > 255)
@ -1161,6 +1161,7 @@ void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& s
if (current > level)
level = current;
}
}
if (DBG_LEVEL >= DBG_data)
sanei_genesys_write_pnm_file("gl_ysobel.pnm", image.data(), 8, 1, width, height);

Wyświetl plik

@ -525,8 +525,8 @@ void sanei_genesys_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& s
extern void sanei_genesys_stop_motor(Genesys_Device* dev);
extern void sanei_genesys_search_reference_point(Genesys_Device* dev, Genesys_Sensor& sensor,
uint8_t* data, int start_pixel, int dpi, int width,
int height);
const uint8_t* src_data, int start_pixel, int dpi,
int width, int height);
extern void sanei_genesys_write_file(const char* filename, uint8_t* data, size_t length);