From 030c7fa122dccca2f47c949ca46a5972efca20b8 Mon Sep 17 00:00:00 2001 From: Jan Hauffa Date: Sun, 6 Mar 2011 16:55:39 +0100 Subject: [PATCH] Remove redundant code from mustek_usb2_high.c. --- backend/mustek_usb2_high.c | 334 +----------------------------- backend/mustek_usb2_high.h | 33 +++ backend/mustek_usb2_reflective.c | 25 +-- backend/mustek_usb2_transparent.c | 25 +-- 4 files changed, 57 insertions(+), 360 deletions(-) diff --git a/backend/mustek_usb2_high.c b/backend/mustek_usb2_high.c index e43c04fa9..dfe34a477 100644 --- a/backend/mustek_usb2_high.c +++ b/backend/mustek_usb2_high.c @@ -59,7 +59,6 @@ static SANE_Bool g_bOpened; static SANE_Bool g_bPrepared; static SANE_Bool g_isCanceled; -static SANE_Bool g_bSharpen; static SANE_Bool g_bFirstReadImage; static SANE_Bool g_isScanning; static SANE_Bool g_isSelfGamma; @@ -67,8 +66,7 @@ static SANE_Bool g_isSelfGamma; static SANE_Byte g_bScanBits; static SANE_Byte *g_lpReadImageHead; -static unsigned short s_wOpticalYDpi[] = { 1200, 600, 300, 150, 75, 0 }; -static unsigned short s_wOpticalXDpi[] = { 1200, 600, 300, 150, 75, 0 }; +static const unsigned short s_wOpticalDpi[] = { 1200, 600, 300, 150, 75, 0 }; static unsigned short g_X; static unsigned short g_Y; static unsigned short g_Width; @@ -80,10 +78,6 @@ static unsigned short g_SWHeight; static unsigned short g_wPixelDistance; /*even & odd sensor problem */ static unsigned short g_wLineDistance; static unsigned short g_wScanLinesPerBlock; -static unsigned short g_wReadedLines; -static unsigned short g_wReadImageLines; -static unsigned short g_wReadyShadingLine; -static unsigned short g_wStartShadingLinePos; static unsigned short g_wLineartThreshold; static unsigned int g_wtheReadyLines; @@ -126,51 +120,6 @@ static SANE_Byte * g_lpBefLineImageData = NULL; static SANE_Bool g_bIsFirstReadBefData = TRUE; static unsigned int g_dwAlreadyGetLines = 0; -static SANE_Bool MustScanner_Init (void); -static SANE_Bool MustScanner_GetScannerState (void); -static SANE_Bool MustScanner_PowerControl (SANE_Bool isLampOn, SANE_Bool isTALampOn); -static SANE_Bool MustScanner_BackHome (void); -static SANE_Bool MustScanner_Prepare (SCANSOURCE ssScanSource); -#ifdef SANE_UNUSED -static SANE_Bool MustScanner_AdjustOffset (int nTimes, SANE_Bool * bDirection, SANE_Byte * bOffset, - SANE_Byte * bLastMin, SANE_Byte * bLastOffset, - unsigned short * wMinValue, SANE_Byte * bOffsetUpperBound, - SANE_Byte * bOffsetLowerBound, unsigned short wStdMinLevel, - unsigned short wStdMaxLevel); -static SANE_Bool MustScanner_SecondAdjustOffset (int nTimes, SANE_Bool * bDirection, - SANE_Byte * bOffset, SANE_Byte * bLastMin, - SANE_Byte * bLastOffset, unsigned short * wMinValue, - SANE_Byte * bOffsetUpperBound, - SANE_Byte * bOffsetLowerBound, - unsigned short wStdMinLevel, unsigned short wStdMaxLevel); -#endif -static unsigned short MustScanner_FiltLower (unsigned short * pSort, unsigned short TotalCount, unsigned short LowCount, - unsigned short HighCount); -static SANE_Bool MustScanner_GetRgb48BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetRgb48BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetRgb24BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetRgb24BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono16BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono16BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono8BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono8BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono1BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static SANE_Bool MustScanner_GetMono1BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, - unsigned short * wLinesCount); -static void *MustScanner_ReadDataFromScanner (void * dummy); -static void MustScanner_PrepareCalculateMaxMin (unsigned short wResolution); -static void MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue, - unsigned short * lpMinValue, unsigned short wResolution); - static SANE_Byte QBET4 (SANE_Byte A, SANE_Byte B); static unsigned int GetScannedLines (void); static unsigned int GetReadyLines (void); @@ -216,7 +165,6 @@ MustScanner_Init () g_bFirstReadImage = TRUE; g_bOpened = FALSE; g_bPrepared = FALSE; - g_bSharpen = FALSE; g_isScanning = FALSE; g_isSelfGamma = FALSE; @@ -240,17 +188,14 @@ Return value: static SANE_Bool MustScanner_GetScannerState () { - if (STATUS_GOOD != Asic_Open (&g_chip)) { DBG (DBG_FUNC, "MustScanner_GetScannerState: Asic_Open return error\n"); return FALSE; } - else - { - Asic_Close (&g_chip); - return TRUE; - } + + Asic_Close (&g_chip); + return TRUE; } /********************************************************************** @@ -352,8 +297,6 @@ MustScanner_Prepare (SCANSOURCE ssScanSource) DBG (DBG_FUNC, "MustScanner_Prepare: call in\n"); if (STATUS_GOOD != Asic_Open (&g_chip)) - - { DBG (DBG_FUNC, "MustScanner_Prepare: Asic_Open return error\n"); return FALSE; @@ -422,275 +365,6 @@ MustScanner_Prepare (SCANSOURCE ssScanSource) return TRUE; } -#ifdef SANE_UNUSED -/********************************************************************** - Adjust the offset -Parameters: - nTimes: Adjust offset the times - bDirection: whether direction - bOffset: the data of offset - bLastMin: the last min data - bLastOffset: the last offset data - wMinValue: the min value of offset - bOffsetUpperBound: the upper bound of offset - bOffsetLowerBound: the lower bound of offset - wStdMinLevel: the min level of offset - wStdMaxLevel: the max level of offset -Return value: - TRUE if the operation is success, FALSE otherwise -***********************************************************************/ -static SANE_Bool -MustScanner_AdjustOffset (int nTimes, SANE_Bool * bDirection, SANE_Byte * bOffset, - SANE_Byte * bLastMin, SANE_Byte * bLastOffset, - unsigned short * wMinValue, SANE_Byte * bOffsetUpperBound, - SANE_Byte * bOffsetLowerBound, unsigned short wStdMinLevel, - unsigned short wStdMaxLevel) -{ - if ((*wMinValue <= wStdMaxLevel) && (*wMinValue >= wStdMinLevel)) - { - return TRUE; - } - - if (nTimes == 0) - { - *bLastMin = LOSANE_Byte (*wMinValue); - *bLastOffset = *bOffset; - - if (*wMinValue == 255) - { - *bOffset = 0; - } - else - { - *bOffset = 255; - } - } - - if (nTimes == 1) - { - if (*wMinValue > *bLastMin) - { - if (*wMinValue > wStdMaxLevel && *bLastMin > wStdMaxLevel) - { - *bDirection = !(*bDirection); - return TRUE; - } - - if (*wMinValue < wStdMinLevel && *bLastMin < wStdMinLevel) - return TRUE; - } - - if (*wMinValue < *bLastMin) - { - if (*wMinValue < wStdMinLevel && *bLastMin < wStdMinLevel) - *bDirection = !(*bDirection); - - if (*wMinValue > wStdMaxLevel && *bLastMin > wStdMaxLevel) - return TRUE; - } - } - - if (nTimes > 1) - { - if (*wMinValue > *bLastMin) - { - SANE_Byte bTemp; - - bTemp = *bOffset; - - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - - if (nTimes > 2) - { - if (*wMinValue > wStdMaxLevel) - if (bDirection) - *bOffsetLowerBound = bTemp; - else - *bOffsetUpperBound = bTemp; - - - else if (bDirection) - *bOffsetUpperBound = bTemp; - else - *bOffsetLowerBound = bTemp; - } - - *bLastOffset = bTemp; - *bLastMin = (SANE_Byte) * wMinValue; - } - else - { - SANE_Byte bTemp; - - bTemp = *bOffset; - - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - - if (nTimes > 2) - { - if (*wMinValue == *bLastMin) - { - if (*wMinValue > wStdMaxLevel) - { - if (!bDirection) - *bOffsetUpperBound = bTemp; - else - *bOffsetLowerBound = bTemp; - } - else - { - if (!bDirection) - *bOffsetLowerBound = bTemp; - else - *bOffsetUpperBound = bTemp; - } - } - else - { - if (*wMinValue > wStdMaxLevel) - { - if (bDirection) - *bOffsetUpperBound = bTemp; - else - *bOffsetLowerBound = bTemp; - } - else - { - if (bDirection) - *bOffsetLowerBound = bTemp; - else - *bOffsetUpperBound = bTemp; - } - } - } - - *bLastOffset = bTemp; - *bLastMin = (SANE_Byte) * wMinValue; - - } - } /* end of if(nTimes > 1) */ - - return TRUE; -} -#endif - -#ifdef SANE_UNUSED -/********************************************************************** - Adjust the offset second times -Parameters: - nTimes: Adjust offset the times - bDirection: whether direction - bOffset: the data of offset - bLastMin: the last min data - bLastOffset: the last offset data - wMinValue: the min value of offset - bOffsetUpperBound: the upper bound of offset - bOffsetLowerBound: the lower bound of offset - wStdMinLevel: the min level of offset - wStdMaxLevel: the max level of offset -Return value: - TRUE if the operation is success, FALSE otherwise -***********************************************************************/ -static SANE_Bool -MustScanner_SecondAdjustOffset (int nTimes, SANE_Bool * bDirection, SANE_Byte * bOffset, - SANE_Byte * bLastMin, SANE_Byte * bLastOffset, - unsigned short * wMinValue, SANE_Byte * bOffsetUpperBound, - SANE_Byte * bOffsetLowerBound, unsigned short wStdMinLevel, - unsigned short wStdMaxLevel) -{ - if ((*wMinValue <= wStdMaxLevel) && (*wMinValue >= wStdMinLevel)) - { - return TRUE; - } - if (nTimes == 0) - { - *bLastMin = LOSANE_Byte (*wMinValue); - *bLastOffset = *bOffset; - - if (*bDirection == 0) - { - *bOffsetUpperBound = *bLastOffset; - *bOffsetLowerBound = 0; - *bOffset = 0; - } - else - { - *bOffsetUpperBound = 255; - *bOffsetLowerBound = *bLastOffset; - *bOffset = 255; - } - } - - if (nTimes >= 1) - { - if (*wMinValue > wStdMaxLevel) - { - if (*wMinValue > *bLastMin) - { - if (*bDirection == 0) - { - *bOffsetUpperBound = *bOffset; - } - else - { - *bOffsetLowerBound = *bOffset; - } - - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - else - { - if (*bDirection == 1) - { - *bOffsetUpperBound = *bOffset; - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - else - { - *bOffsetLowerBound = *bOffset; - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - } - } /*end of if(*wMinValue > MAX_OFFSET) */ - - - if (*wMinValue < wStdMinLevel) - { - if (*wMinValue > *bLastMin) - { - if (*bDirection == 0) - { - *bOffsetLowerBound = *bOffset; - } - else - { - *bOffsetUpperBound = *bOffset; - } - - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - else - { - if (*bDirection == 1) - { - *bOffsetUpperBound = *bOffset; - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - else - { - *bOffsetLowerBound = *bOffset; - *bOffset = (*bOffsetUpperBound + *bOffsetLowerBound) / 2; - } - } - } /*end of if(*wMinValue > MIN_OFFSET) */ - *bLastMin = (SANE_Byte) * wMinValue; - } /*end of if(nTimes >= 1) */ - - /* HOLD: missing return value! Correct? */ - return FALSE; -} -#endif - /********************************************************************** Filter the data Parameters: diff --git a/backend/mustek_usb2_high.h b/backend/mustek_usb2_high.h index f7d233abb..da262e710 100644 --- a/backend/mustek_usb2_high.h +++ b/backend/mustek_usb2_high.h @@ -196,4 +196,37 @@ typedef struct tagSUGGESTSETTING /*#define DEBUG_SAVE_IMAGE*/ +static SANE_Bool MustScanner_Init (void); +static SANE_Bool MustScanner_GetScannerState (void); +static SANE_Bool MustScanner_PowerControl (SANE_Bool isLampOn, SANE_Bool isTALampOn); +static SANE_Bool MustScanner_BackHome (void); +static SANE_Bool MustScanner_Prepare (SCANSOURCE ssScanSource); +static unsigned short MustScanner_FiltLower (unsigned short * pSort, unsigned short TotalCount, unsigned short LowCount, + unsigned short HighCount); +static SANE_Bool MustScanner_GetRgb48BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetRgb48BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetRgb24BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetRgb24BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono16BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono16BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono8BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono8BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono1BitLine (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static SANE_Bool MustScanner_GetMono1BitLine1200DPI (SANE_Byte * lpLine, SANE_Bool isOrderInvert, + unsigned short * wLinesCount); +static void *MustScanner_ReadDataFromScanner (void * dummy); +static void MustScanner_PrepareCalculateMaxMin (unsigned short wResolution); +static void MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue, + unsigned short * lpMinValue, unsigned short wResolution); + + #endif diff --git a/backend/mustek_usb2_reflective.c b/backend/mustek_usb2_reflective.c index 19a344243..91fd59445 100644 --- a/backend/mustek_usb2_reflective.c +++ b/backend/mustek_usb2_reflective.c @@ -144,33 +144,33 @@ Reflective_ScanSuggest (PTARGETIMAGE pTarget, PSUGGESTSETTING pSuggest) } /*1. Looking up Optical Y Resolution */ - for (i = 0; s_wOpticalYDpi[i] != 0; i++) + for (i = 0; s_wOpticalDpi[i] != 0; i++) { - if (s_wOpticalYDpi[i] <= pTarget->wDpi) + if (s_wOpticalDpi[i] <= pTarget->wDpi) { - pSuggest->wYDpi = s_wOpticalYDpi[i]; + pSuggest->wYDpi = s_wOpticalDpi[i]; break; } } - if (s_wOpticalYDpi[i] == 0) + if (s_wOpticalDpi[i] == 0) { i--; - pSuggest->wYDpi = s_wOpticalYDpi[i]; + pSuggest->wYDpi = s_wOpticalDpi[i]; } /*2. Looking up Optical X Resolution */ - for (i = 0; s_wOpticalXDpi[i] != 0; i++) + for (i = 0; s_wOpticalDpi[i] != 0; i++) { - if (s_wOpticalXDpi[i] <= pTarget->wDpi) + if (s_wOpticalDpi[i] <= pTarget->wDpi) { - pSuggest->wXDpi = s_wOpticalXDpi[i]; + pSuggest->wXDpi = s_wOpticalDpi[i]; break; } } - if (s_wOpticalXDpi[i] == 0) + if (s_wOpticalDpi[i] == 0) { i--; - pSuggest->wXDpi = s_wOpticalXDpi[i]; + pSuggest->wXDpi = s_wOpticalDpi[i]; } DBG (DBG_FUNC, "Reflective_ScanSuggest: pTarget->wDpi = %d\n", @@ -1703,12 +1703,7 @@ Reflective_PrepareScan () g_isCanceled = FALSE; g_dwScannedTotalLines = 0; - g_wReadedLines = 0; g_wtheReadyLines = 0; - g_wReadImageLines = 0; - - g_wReadyShadingLine = 0; - g_wStartShadingLinePos = 0; switch (g_ScanMode) { diff --git a/backend/mustek_usb2_transparent.c b/backend/mustek_usb2_transparent.c index 76a70061d..daeeb83b6 100644 --- a/backend/mustek_usb2_transparent.c +++ b/backend/mustek_usb2_transparent.c @@ -136,32 +136,32 @@ Transparent_ScanSuggest (PTARGETIMAGE pTarget, PSUGGESTSETTING pSuggest) DBG (DBG_FUNC, "Transparent_ScanSuggest: call in\n"); - for (i = 0; s_wOpticalYDpi[i] != 0; i++) + for (i = 0; s_wOpticalDpi[i] != 0; i++) { - if (s_wOpticalYDpi[i] <= pTarget->wDpi) + if (s_wOpticalDpi[i] <= pTarget->wDpi) { - pSuggest->wYDpi = s_wOpticalYDpi[i]; + pSuggest->wYDpi = s_wOpticalDpi[i]; break; } } - if (s_wOpticalYDpi[i] == 0) + if (s_wOpticalDpi[i] == 0) { i--; - pSuggest->wYDpi = s_wOpticalYDpi[i]; + pSuggest->wYDpi = s_wOpticalDpi[i]; } - for (i = 0; s_wOpticalXDpi[i] != 0; i++) + for (i = 0; s_wOpticalDpi[i] != 0; i++) { - if (s_wOpticalXDpi[i] <= pTarget->wDpi) + if (s_wOpticalDpi[i] <= pTarget->wDpi) { - pSuggest->wXDpi = s_wOpticalXDpi[i]; + pSuggest->wXDpi = s_wOpticalDpi[i]; break; } } - if (s_wOpticalXDpi[i] == 0) + if (s_wOpticalDpi[i] == 0) { i--; - pSuggest->wXDpi = s_wOpticalXDpi[i]; + pSuggest->wXDpi = s_wOpticalDpi[i]; } pSuggest->wX = @@ -1614,12 +1614,7 @@ Transparent_PrepareScan () g_isCanceled = FALSE; g_dwScannedTotalLines = 0; - g_wReadedLines = 0; g_wtheReadyLines = 0; - g_wReadImageLines = 0; - - g_wReadyShadingLine = 0; - g_wStartShadingLinePos = 0; switch (g_ScanMode) {