From 76a23c3bc4c80f91f223f29ae8cc5c91a1a8e4f8 Mon Sep 17 00:00:00 2001 From: Jan Hauffa Date: Sun, 6 Mar 2011 20:31:48 +0100 Subject: [PATCH] Remove dead "auto level" code, sanitize key handling. --- backend/mustek_usb2.c | 532 +------------------------------------ backend/mustek_usb2_asic.c | 8 +- 2 files changed, 15 insertions(+), 525 deletions(-) diff --git a/backend/mustek_usb2.c b/backend/mustek_usb2.c index 7543e53c2..8863cc7ed 100644 --- a/backend/mustek_usb2.c +++ b/backend/mustek_usb2.c @@ -973,7 +973,6 @@ static SANE_Bool GetKeyStatus (SANE_Byte * pKey) { SANE_Byte pKeyTemp = 0x00; - STATUS status = Asic_CheckFunctionKey (&g_chip, &pKeyTemp); DBG (DBG_FUNC, "GetKeyStatus: start\n"); if (STATUS_GOOD != Asic_Open (&g_chip)) @@ -982,33 +981,22 @@ GetKeyStatus (SANE_Byte * pKey) return FALSE; } - if (STATUS_GOOD != status) + if (STATUS_GOOD != Asic_CheckFunctionKey (&g_chip, &pKeyTemp)) { DBG (DBG_ERR, "GetKeyStatus: Asic_CheckFunctionKey is fail\n"); return FALSE; } if (0x01 == pKeyTemp) - { - *pKey = 0x01; /*Scan key pressed */ - } - - if (0x02 == pKeyTemp) - { - *pKey = 0x02; /*Copy key pressed */ - } - if (0x04 == pKeyTemp) - { - *pKey = 0x03; /*Fax key pressed */ - } - if (0x08 == pKeyTemp) - { - *pKey = 0x04; /*Email key pressed */ - } - if (0x10 == pKeyTemp) - { - *pKey = 0x05; /*Panel key pressed */ - } + *pKey = 0x01; /* Scan key pressed */ + else if (0x02 == pKeyTemp) + *pKey = 0x02; /* Copy key pressed */ + else if (0x04 == pKeyTemp) + *pKey = 0x03; /* Fax key pressed */ + else if (0x08 == pKeyTemp) + *pKey = 0x04; /* Email key pressed */ + else if (0x10 == pKeyTemp) + *pKey = 0x05; /* Panel key pressed */ if (STATUS_GOOD != Asic_Close (&g_chip)) { @@ -1020,6 +1008,7 @@ GetKeyStatus (SANE_Byte * pKey) return TRUE; } #endif + /********************************************************************** Deal with the image with auto level Parameters: @@ -1273,505 +1262,6 @@ AutoLevel (SANE_Byte *lpSource, COLORMODE colorMode, unsigned short ScanLines, return; } -#ifdef SANE_UNUSED -/********************************************************************** - Deal with image with auto level -Parameters: - pDIB: the data of image - ImageWidth: the width of image - ImageHeight: the height of image -***********************************************************************/ -static void -QBETDetectAutoLevel (void *pDIB, unsigned int ImageWidth, unsigned int ImageHeight) -{ - unsigned short *pbmpdata; - float fRPercent = 0.0; - float fGPercent = 0.0; - float fBPercent = 0.0; - float fRSum, fGSum, fBSum; - - int i, j; - unsigned int tLines, CountPixels, TotalImgSize; - unsigned short R, G, B, max_R, max_G, max_B, min_R, min_G, min_B; - unsigned short wIndexR, wIndexG, wIndexB; - float fmax_R, fmax_G, fmax_B; - unsigned int sum_R = 0, sum_G = 0, sum_B = 0; - unsigned int hisgram_R[1024], hisgram_G[1024], hisgram_B[1024]; - - if (!pDIB) - { - return; - } - - pbmpdata = (unsigned short *) pDIB; - - CountPixels = 0; - TotalImgSize = ImageWidth * ImageHeight; - - - for (i = 0; i < 1024; i++) - { - - hisgram_R[i] = 0; - hisgram_G[i] = 0; - hisgram_B[i] = 0; - } - - - /*Find min , max, mean */ - max_R = max_G = max_B = 0; - min_R = min_G = min_B = 1023; - tLines = 0; - - for (j = 0; j < (int) ImageHeight; j++) - { - tLines = j * ImageWidth * 3; - for (i = 0; i < (int) ImageWidth; i++) - { - R = *(pbmpdata + (tLines + i * 3 + 2)); - G = *(pbmpdata + (tLines + i * 3 + 1)); - B = *(pbmpdata + (tLines + i * 3)); - - max_R = _MAX (R, max_R); - max_G = _MAX (G, max_G); - max_B = _MAX (B, max_B); - - min_R = _MIN (R, min_R); - min_G = _MIN (G, min_G); - min_B = _MIN (B, min_B); - - hisgram_R[R]++; - hisgram_G[G]++; - hisgram_B[B]++; - - sum_R += R; - sum_G += G; - sum_B += B; - - *(pbmpdata + (tLines + i * 3 + 2)) = R; - *(pbmpdata + (tLines + i * 3 + 1)) = G; - *(pbmpdata + (tLines + i * 3)) = B; - - CountPixels++; - } - - } - - - fRSum = 0.0; - fGSum = 0.0; - fBSum = 0.0; - - wIndexR = 511; - wIndexG = 511; - wIndexB = 511; - - for (i = 0; i < 1024; i++) - { - fRSum += (float) hisgram_R[i]; - fRPercent = (fRSum / CountPixels) * 100; - if (fRPercent > 50) - { - wIndexR = i; - break; - } - - } - - for (i = 0; i < 1024; i++) - { - fGSum += (float) hisgram_G[i]; - fGPercent = (fGSum / CountPixels) * 100; - if (fGPercent > 50) - { - wIndexG = i; - break; - } - } - - for (i = 0; i < 1024; i++) - { - fBSum += (float) hisgram_B[i]; - fBPercent = (fBSum / CountPixels) * 100; - if (fBPercent > 50) - { - wIndexB = i; - break; - } - - } - - - fRSum = 0.0; - - for (i = wIndexR; i >= 0; i--) - { - fRSum += (float) hisgram_R[i]; - fRPercent = (fRSum / CountPixels) * 100; - if (fRPercent >= 48) - { - min_R = i; - break; - } - - } - - fRSum = 0.0; - for (i = wIndexR; i < 1024; i++) - { - fRSum += (float) hisgram_R[i]; - fRPercent = (fRSum / CountPixels) * 100; - if (fRPercent >= 47) - { - max_R = i; - break; - } - - } - - - fGSum = 0.0; - for (i = wIndexG; i >= 0; i--) - { - fGSum += (float) hisgram_G[i]; - fGPercent = (fGSum / CountPixels) * 100; - if (fGPercent >= 48) - { - min_G = i; - break; - } - - } - - fGSum = 0.0; - for (i = wIndexG; i < 1024; i++) - { - fGSum += (float) hisgram_G[i]; - fGPercent = (fGSum / CountPixels) * 100; - if (fGPercent >= 47) - { - max_G = i; - break; - } - - } - - fBSum = 0.0; - for (i = wIndexB; i >= 0; i--) - { - fBSum += (float) hisgram_B[i]; - fBPercent = (fBSum / CountPixels) * 100; - if (fBPercent >= 46) - { - min_B = i; - break; - } - - } - - fBSum = 0.0; - for (i = wIndexB; i < 1024; i++) - { - fBSum += (float) hisgram_B[i]; - fBPercent = (fBSum / CountPixels) * 100; - if (fBPercent >= 47) - { - max_B = i; - break; - } - - } - - - /*Autolevel: */ - sum_R = max_R - min_R; - sum_G = max_G - min_G; - sum_B = max_B - min_B; - - for (j = 0; j < (int) ImageHeight; j++) - { - tLines = j * ImageWidth * 3; - for (i = 0; i < (int) ImageWidth; i++) - { - R = *(pbmpdata + (tLines + i * 3 + 2)); - G = *(pbmpdata + (tLines + i * 3 + 1)); - B = *(pbmpdata + (tLines + i * 3)); - - - /*R*/ if (sum_R == 0) - R = max_R; - else if (R < min_R) - { - - R = 0; - } - else if ((R >= min_R) && (R <= 1023)) - { - fmax_R = ((float) ((R - min_R) * 923) / (float) sum_R) + 100; - R = (unsigned short) fmax_R; - fmax_R = (fmax_R - R) * 10; - if (fmax_R >= 5) - R++; - } - if (R > 1023) - R = 1023; - - /*G*/ if (sum_G == 0) - G = max_G; - else if (G < min_G) - { - - G = 0; - } - else if ((G >= min_G) && (G <= 1023)) - { - fmax_G = ((float) ((G - min_G) * 923) / (float) sum_G) + 100; - G = (unsigned short) fmax_G; - fmax_G = (fmax_G - G) * 10; - if (fmax_G >= 5) - G++; - } - if (G > 1023) - G = 1023; - - /*B*/ if (sum_B == 0) - B = max_B; - else if (B < min_R) - { - - B = 0; - } - else if ((B >= min_B) && (R <= 1023)) - { - fmax_B = ((float) (B - min_B) * 923 / (float) sum_B) + 100; - - B = (unsigned short) fmax_B; - fmax_B = (fmax_B - B) * 10; - if (fmax_B >= 5) - B++; - } - if (B > 1023) - B = 1023; - - *(pbmpdata + (tLines + i * 3 + 2)) = R; - *(pbmpdata + (tLines + i * 3 + 1)) = G; - *(pbmpdata + (tLines + i * 3)) = B; - - } - } - - return; -} -#endif - -#ifdef SANE_UNUSED -/********************************************************************** - Change the image data and deal with auto level -Parameters: - lpSource: the data of image - colorMode: the color mode - ScanLines: the rows of image - BytesPerLine: the bytes of per line -***********************************************************************/ -static void -QBetChange (SANE_Byte *lpSource, COLORMODE colorMode, unsigned short ScanLines, - unsigned int BytesPerLine) -{ - unsigned short i, j; - unsigned int tLines, TotalImgSize; - unsigned short R1, G1, B1, R, G, B, R2, G2, B2, QBET_RGB = 0, PointF, PointB; - unsigned short *pwRGB; - - int k; - - unsigned int ImageWidth = BytesPerLine / 3; - unsigned int ImageHeight = ScanLines; - SANE_Byte *pbmpdata = (SANE_Byte *) lpSource; - - if (colorMode != CM_RGB24ext) - { - return; - } - - - TotalImgSize = ImageWidth * ImageHeight * 3 * 2; - if ((pwRGB = (unsigned short *) malloc (TotalImgSize)) == NULL) - { - return; - } - - - for (j = 0; j < ImageHeight; j++) - { - tLines = j * ImageWidth * 3; - for (i = 0; i < ImageWidth; i++) - { - if (i == 0) - { - R1 = R = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 2)); - G1 = G = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 1)); - B1 = B = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3)); - R2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3 + 2)); - G2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3 + 1)); - B2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3)); - } - else if (i == (ImageWidth - 1)) - { - R1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3 + 2)); - G1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3 + 1)); - B1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3)); - R2 = R = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 2)); - G2 = G = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 1)); - B2 = B = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3)); - } - else - { - R1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3 + 2)); - G1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3 + 1)); - B1 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i - 1) * 3)); - - R = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 2)); - G = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3 + 1)); - B = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + i * 3)); - - R2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3 + 2)); - G2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3 + 1)); - B2 = (unsigned short) (SANE_Byte) * (pbmpdata + (tLines + (i + 1) * 3)); - } - - R1 = R1 & 0x0003; - G1 = G1 & 0x0003; - B1 = B1 & 0x0003; - - R2 = R2 & 0x0003; - G2 = G2 & 0x0003; - B2 = B2 & 0x0003; - for (k = 0; k < 3; k++) - { - if (k == 0) - { - PointF = R1; - PointB = R2; - } - else if (k == 1) - { - PointF = G1; - PointB = G2; - } - else if (k == 2) - { - PointF = B1; - PointB = B2; - } - - switch (PointF) - { - case 0: - case 1: - if (PointB == 0) - QBET_RGB = 0xFFFC; - else if (PointB == 1) - QBET_RGB = 0xFFFC; - else if (PointB == 2) - QBET_RGB = 0xFFFD; - else if (PointB == 3) - QBET_RGB = 0xFFFE; - break; - case 2: - if (PointB == 0) - QBET_RGB = 0xFFFD; - else if (PointB == 1) - QBET_RGB = 0xFFFD; - else if (PointB == 2) - QBET_RGB = 0xFFFF; - else if (PointB == 3) - QBET_RGB = 0xFFFF; - break; - case 3: - if (PointB == 0) - QBET_RGB = 0xFFFE; - else if (PointB == 1) - QBET_RGB = 0xFFFE; - else if (PointB == 2) - QBET_RGB = 0xFFFF; - else if (PointB == 3) - QBET_RGB = 0xFFFF; - break; - default: - break; - } - - if (k == 0) - { - R = R << 2; - R = R + 0x0003; - R = R & QBET_RGB; - } - else if (k == 1) - { - G = G << 2; - G = G + 0x0003; - G = G & QBET_RGB; - } - else if (k == 2) - { - B = B << 2; - B = B + 0x0003; - B = B & QBET_RGB; - } - - } - - *(pwRGB + (tLines + i * 3 + 2)) = R; - *(pwRGB + (tLines + i * 3 + 1)) = G; - *(pwRGB + (tLines + i * 3)) = B; - - } - - } - - - QBETDetectAutoLevel (pwRGB, ImageWidth, ImageHeight); - - - for (j = 0; j < ImageHeight; j++) - { - tLines = j * ImageWidth * 3; - - for (i = 0; i < ImageWidth; i++) - { - R = *(pwRGB + (tLines + i * 3 + 2)); - G = *(pwRGB + (tLines + i * 3 + 1)); - B = *(pwRGB + (tLines + i * 3)); - - R = R >> 2; - G = G >> 2; - - B = B >> 2; - if (R > 255) - R = 255; - if (G > 255) - G = 255; - if (B > 255) - B = 255; - - *(pbmpdata + (tLines + i * 3 + 2)) = (SANE_Byte) R; - *(pbmpdata + (tLines + i * 3 + 1)) = (SANE_Byte) G; - *(pbmpdata + (tLines + i * 3)) = (SANE_Byte) B; - - } - - } - - - if (pwRGB != NULL) - { - free (pwRGB); - } - - return; -} -#endif /****************************** SANE API functions *****************************/ diff --git a/backend/mustek_usb2_asic.c b/backend/mustek_usb2_asic.c index c06436e0d..325064c6b 100644 --- a/backend/mustek_usb2_asic.c +++ b/backend/mustek_usb2_asic.c @@ -3974,13 +3974,13 @@ Asic_CheckFunctionKey (PAsic chip, SANE_Byte * key) if (((0xff - bBuffer_1) & 0x10) == 0x10) *key = 0x01; - if (((0xff - bBuffer_1) & 0x01) == 0x01) + else if (((0xff - bBuffer_1) & 0x01) == 0x01) *key = 0x02; - if (((0xff - bBuffer_1) & 0x04) == 0x04) + else if (((0xff - bBuffer_1) & 0x04) == 0x04) *key = 0x04; - if (((0xff - bBuffer_2) & 0x08) == 0x08) + else if (((0xff - bBuffer_2) & 0x08) == 0x08) *key = 0x08; - if (((0xff - bBuffer_1) & 0x02) == 0x02) + else if (((0xff - bBuffer_1) & 0x02) == 0x02) *key = 0x10; DBG (DBG_ASIC, "CheckFunctionKey=%d\n", *key);