Improved readability of functions in mustek_usb2_high.c.

merge-requests/1/head
Jan Hauffa 2011-03-11 00:07:43 +01:00 zatwierdzone przez m. allan noah
rodzic ca1e0db16f
commit 77ea9b01c3
1 zmienionych plików z 27 dodań i 40 usunięć

Wyświetl plik

@ -2262,8 +2262,8 @@ MustScanner_PrepareCalculateMaxMin (unsigned short wResolution)
g_wDarkCalWidth = 52; g_wDarkCalWidth = 52;
if (wResolution <= 600) if (wResolution <= 600)
{ {
g_wCalWidth = ((5120 * wResolution / 600 + 511) >> 9) << 9; g_wCalWidth = (5120 * wResolution / 600 + 511) & ~511;
g_wDarkCalWidth = g_wDarkCalWidth / (1200 / wResolution); g_wDarkCalWidth *= wResolution / 1200;
if (wResolution < 200) if (wResolution < 200)
{ {
@ -2307,7 +2307,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue,
unsigned short *wSecData = NULL, *wDarkSecData = NULL; unsigned short *wSecData = NULL, *wDarkSecData = NULL;
int i, j; int i, j;
wSecData = malloc (sizeof (unsigned short) * g_nSecNum); wSecData = malloc (g_nSecNum * sizeof (unsigned short));
if (wSecData == NULL) if (wSecData == NULL)
return; return;
memset (wSecData, 0, g_nSecNum * sizeof (unsigned short)); memset (wSecData, 0, g_nSecNum * sizeof (unsigned short));
@ -2315,7 +2315,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue,
for (i = 0; i < g_nSecNum; i++) for (i = 0; i < g_nSecNum; i++)
{ {
for (j = 0; j < g_nSecLength; j++) for (j = 0; j < g_nSecLength; j++)
wSecData[i] += *(pBuffer + g_wStartPosition + i * g_nSecLength + j); wSecData[i] += pBuffer[g_wStartPosition + i * g_nSecLength + j];
wSecData[i] >>= g_nPowerNum; wSecData[i] >>= g_nPowerNum;
} }
@ -2327,7 +2327,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue,
} }
free (wSecData); free (wSecData);
wDarkSecData = malloc (sizeof (unsigned short) * g_nDarkSecNum); wDarkSecData = malloc (g_nDarkSecNum * sizeof (unsigned short));
if (wDarkSecData == NULL) if (wDarkSecData == NULL)
return; return;
memset (wDarkSecData, 0, g_nDarkSecNum * sizeof (unsigned short)); memset (wDarkSecData, 0, g_nDarkSecNum * sizeof (unsigned short));
@ -2335,9 +2335,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue,
for (i = 0; i < g_nDarkSecNum; i++) for (i = 0; i < g_nDarkSecNum; i++)
{ {
for (j = 0; j < g_nDarkSecLength; j++) for (j = 0; j < g_nDarkSecLength; j++)
wDarkSecData[i] += wDarkSecData[i] += pBuffer[g_wStartPosition + i * g_nDarkSecLength + j];
*(pBuffer + g_wStartPosition + i * g_nDarkSecLength + j);
wDarkSecData[i] /= g_nDarkSecLength; wDarkSecData[i] /= g_nDarkSecLength;
} }
@ -2352,7 +2350,7 @@ MustScanner_CalculateMaxMin (SANE_Byte * pBuffer, unsigned short * lpMaxValue,
static void * static void *
MustScanner_ReadDataFromScanner (void * dummy) MustScanner_ReadDataFromScanner (void __sane_unused__ * dummy)
{ {
unsigned short wTotalReadImageLines = 0; unsigned short wTotalReadImageLines = 0;
unsigned short wWantedLines = g_Height; unsigned short wWantedLines = g_Height;
@ -2363,24 +2361,20 @@ MustScanner_ReadDataFromScanner (void * dummy)
unsigned short wScanLinesThisBlock; unsigned short wScanLinesThisBlock;
unsigned short wBufferLines = g_wLineDistance * 2 + g_wPixelDistance; unsigned short wBufferLines = g_wLineDistance * 2 + g_wPixelDistance;
dummy = dummy;
DBG (DBG_FUNC, DBG (DBG_FUNC,
"MustScanner_ReadDataFromScanner: call in, and in new thread\n"); "MustScanner_ReadDataFromScanner: call in, and in new thread\n");
while (wTotalReadImageLines < wWantedLines && g_lpReadImageHead) while (wTotalReadImageLines < wWantedLines)
{ {
if (!isWaitImageLineDiff) if (!isWaitImageLineDiff)
{ {
wScanLinesThisBlock = wScanLinesThisBlock =
(wWantedLines - wTotalReadImageLines) < (wWantedLines - wTotalReadImageLines) < g_wScanLinesPerBlock ?
g_wScanLinesPerBlock ? (wWantedLines - (wWantedLines - wTotalReadImageLines) : g_wScanLinesPerBlock;
wTotalReadImageLines) :
g_wScanLinesPerBlock;
DBG (DBG_FUNC, DBG (DBG_FUNC,
"MustScanner_ReadDataFromScanner: wWantedLines=%d\n", "MustScanner_ReadDataFromScanner: wWantedLines=%d\n",
wWantedLines); wWantedLines);
DBG (DBG_FUNC, DBG (DBG_FUNC,
"MustScanner_ReadDataFromScanner: wScanLinesThisBlock=%d\n", "MustScanner_ReadDataFromScanner: wScanLinesThisBlock=%d\n",
wScanLinesThisBlock); wScanLinesThisBlock);
@ -2396,11 +2390,8 @@ MustScanner_ReadDataFromScanner (void * dummy)
/* has read in memory buffer */ /* has read in memory buffer */
wReadImageLines += wScanLinesThisBlock; wReadImageLines += wScanLinesThisBlock;
AddScannedLines (wScanLinesThisBlock); AddScannedLines (wScanLinesThisBlock);
wTotalReadImageLines += wScanLinesThisBlock; wTotalReadImageLines += wScanLinesThisBlock;
lpReadImage += wScanLinesThisBlock * g_BytesPerRow; lpReadImage += wScanLinesThisBlock * g_BytesPerRow;
/* buffer is full */ /* buffer is full */
@ -2410,9 +2401,9 @@ MustScanner_ReadDataFromScanner (void * dummy)
wReadImageLines = 0; wReadImageLines = 0;
} }
if ((g_dwScannedTotalLines - GetReadyLines ()) if ((g_dwScannedTotalLines - GetReadyLines ()) >=
>= (wMaxScanLines - (wBufferLines + g_wScanLinesPerBlock)) (wMaxScanLines - (wBufferLines + g_wScanLinesPerBlock)) &&
&& g_dwScannedTotalLines > GetReadyLines ()) g_dwScannedTotalLines > GetReadyLines ())
{ {
isWaitImageLineDiff = TRUE; isWaitImageLineDiff = TRUE;
} }
@ -2461,9 +2452,7 @@ static void
AddScannedLines (unsigned short wAddLines) AddScannedLines (unsigned short wAddLines)
{ {
pthread_mutex_lock (&g_scannedLinesMutex); pthread_mutex_lock (&g_scannedLinesMutex);
g_dwScannedTotalLines += wAddLines; g_dwScannedTotalLines += wAddLines;
pthread_mutex_unlock (&g_scannedLinesMutex); pthread_mutex_unlock (&g_scannedLinesMutex);
} }
@ -2480,29 +2469,29 @@ ModifyLinePoint (SANE_Byte * lpImageData, SANE_Byte * lpImageDataBefore,
unsigned int dwBytesPerLine, unsigned int dwLinesCount, unsigned int dwBytesPerLine, unsigned int dwLinesCount,
unsigned short wPixDistance, unsigned short wModPtCount) unsigned short wPixDistance, unsigned short wModPtCount)
{ {
unsigned short i = 0; unsigned short i, j;
unsigned short j = 0; unsigned short wLines;
unsigned short wLines = 0;
unsigned int dwWidth = dwBytesPerLine / wPixDistance; unsigned int dwWidth = dwBytesPerLine / wPixDistance;
for (i = wModPtCount; i > 0; i--) for (i = wModPtCount; i > 0; i--)
{ {
for (j = 0; j < wPixDistance; j++) for (j = 0; j < wPixDistance; j++)
{ {
unsigned int lineOffset = (dwWidth - i) * wPixDistance + j;
unsigned int prevLineOffset = (dwWidth - i - 1) * wPixDistance + j;
/* modify the first line */ /* modify the first line */
*(lpImageData + (dwWidth - i) * wPixDistance + j) = lpImageData[lineOffset] =
(*(lpImageData + (dwWidth - i - 1) * wPixDistance + j) + (lpImageData[prevLineOffset] +
*(lpImageDataBefore + (dwWidth - i) * wPixDistance + j)) / 2; lpImageDataBefore[prevLineOffset]) / 2;
/* modify other lines */ /* modify other lines */
for (wLines = 1; wLines < dwLinesCount; wLines++) for (wLines = 1; wLines < dwLinesCount; wLines++)
{ {
unsigned int dwBytesBefor = (wLines - 1) * dwBytesPerLine; unsigned int dwBytesBefore = (wLines - 1) * dwBytesPerLine;
unsigned int dwBytes = wLines * dwBytesPerLine; unsigned int dwBytes = wLines * dwBytesPerLine;
*(lpImageData + dwBytes + (dwWidth - i) * wPixDistance + j) = lpImageData[dwBytes + lineOffset] =
(* (lpImageData[dwBytes + prevLineOffset] +
(lpImageData + dwBytes + (dwWidth - i - 1) * wPixDistance + lpImageData[dwBytesBefore + prevLineOffset]) / 2;
j) + *(lpImageData + dwBytesBefor + (dwWidth -
i) * wPixDistance +
j)) / 2;
} }
} }
} }
@ -2530,9 +2519,7 @@ QBET4 (SANE_Byte A, SANE_Byte B)
{9, 9, 9, 9, 11, 11, 11, 11, 14, 14, 14, 14, 15, 15, 15, 15} {9, 9, 9, 9, 11, 11, 11, 11, 14, 14, 14, 14, 15, 15, 15, 15}
}; };
A = A & 0x0f; return bQBET[A & 0x0f][B & 0x0f];
B = B & 0x0f;
return bQBET[A][B];
} }
static SANE_Bool static SANE_Bool