From c0895a858db7c9a59925067071db2362adc1c025 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Fri, 24 Apr 2020 18:05:22 +0200
Subject: [PATCH] etes603: Return TOO_SHORT retry error for small images

If the image height is less than the sensor horizontal resolution, then
return a retry error rather than trying to submit the image for further
processing.

Related to: #251
---
 libfprint/drivers/etes603.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/libfprint/drivers/etes603.c b/libfprint/drivers/etes603.c
index f798f5b..fcece3c 100644
--- a/libfprint/drivers/etes603.c
+++ b/libfprint/drivers/etes603.c
@@ -859,21 +859,29 @@ m_capture_state (FpiSsm *ssm, FpDevice *dev)
         }
       else
         {
-          FpImage *img;
-          unsigned int img_size;
           /* Remove empty parts 2 times for the 2 frames */
           process_removefpi_end (self);
           process_removefpi_end (self);
-          img_size = self->fp_height * FE_WIDTH;
-          img = fp_image_new (FE_WIDTH, self->fp_height);
-          /* Images received are white on black, so invert it. */
-          /* TODO detect sweep direction */
-          img->flags = FPI_IMAGE_COLORS_INVERTED | FPI_IMAGE_V_FLIPPED;
-          img->height = self->fp_height;
-          process_4to8_bpp (self->fp, img_size / 2, img->data);
-          fp_dbg ("Sending the raw fingerprint image (%dx%d)",
-                  img->width, img->height);
-          fpi_image_device_image_captured (idev, img);
+
+          if (self->fp_height >= FE_WIDTH)
+            {
+              FpImage *img = fp_image_new (FE_WIDTH, self->fp_height);
+              unsigned int img_size = self->fp_height * FE_WIDTH;
+
+              /* Images received are white on black, so invert it. */
+              /* TODO detect sweep direction */
+              img->flags = FPI_IMAGE_COLORS_INVERTED | FPI_IMAGE_V_FLIPPED;
+              img->height = self->fp_height;
+              process_4to8_bpp (self->fp, img_size / 2, img->data);
+              fp_dbg ("Sending the raw fingerprint image (%dx%d)",
+                      img->width, img->height);
+              fpi_image_device_image_captured (idev, img);
+            }
+          else
+            {
+              fpi_image_device_retry_scan (idev, FP_DEVICE_RETRY_TOO_SHORT);
+            }
+
           fpi_image_device_report_finger_status (idev, FALSE);
           fpi_ssm_mark_completed (ssm);
         }