epjitsu: introduce & use MAX() & MIN()

This change simplifies some expressions, and hence
allows for easier understanding of the intention.

Signed-off-by: Peter Marschall <peter@adpm.de>
pixma-add-canon-ts-3400-series
Peter Marschall 2014-03-04 12:09:17 +01:00 zatwierdzone przez Povilas Kanapickas
rodzic b183f6a055
commit 36b59bd2c1
1 zmienionych plików z 23 dodań i 32 usunięć

Wyświetl plik

@ -205,6 +205,12 @@
#define DEBUG 1 #define DEBUG 1
#define BUILD 31 #define BUILD 31
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MAX3 #ifndef MAX3
#define MAX3(a,b,c) ((a) > (b) ? ((a) > (c) ? a : c) : ((b) > (c) ? b : c)) #define MAX3(a,b,c) ((a) > (b) ? ((a) > (c) ? a : c) : ((b) > (c) ? b : c))
#endif #endif
@ -2042,14 +2048,12 @@ change_params(struct scanner *s)
/* height */ /* height */
if (s->tl_y > s->max_y - s->min_y) if (s->tl_y > s->max_y - s->min_y)
s->tl_y = s->max_y - s->min_y - s->adf_height_padding; s->tl_y = s->max_y - s->min_y - s->adf_height_padding;
if (s->tl_y + s->page_height > s->max_y - s->adf_height_padding) s->page_height = MIN(s->page_height, s->max_y - s->adf_height_padding - s->tl_y);
s->page_height = s->max_y - s->adf_height_padding - s->tl_y; if (s->page_height > 0)
if (s->page_height < s->min_y && s->page_height > 0) s->page_height = MAX(s->page_height, s->min_y);
s->page_height = s->min_y;
if (s->tl_y + s->page_height > s->max_y) if (s->tl_y + s->page_height > s->max_y)
s->tl_y = s->max_y - s->adf_height_padding - s->page_height; s->tl_y = s->max_y - s->adf_height_padding - s->page_height;
if (s->tl_y < 0) s->tl_y = MAX(s->tl_y, 0);
s->tl_y = 0;
if (s->page_height > 0) { if (s->page_height > 0) {
s->br_y = s->tl_y + s->page_height; s->br_y = s->tl_y + s->page_height;
@ -2059,10 +2063,9 @@ change_params(struct scanner *s)
} }
/*width*/ /*width*/
if (s->page_width > s->max_x) s->page_width = MIN(s->page_width, s->max_x);
s->page_width = s->max_x; s->page_width = MAX(s->page_width, s->min_x);
else if (s->page_width < s->min_x)
s->page_width = s->min_x;
s->tl_x = (s->max_x - s->page_width)/2; s->tl_x = (s->max_x - s->page_width)/2;
s->br_x = (s->max_x + s->page_width)/2; s->br_x = (s->max_x + s->page_width)/2;
@ -2310,12 +2313,8 @@ load_lut (unsigned char * lut,
for(i=0;i<=max_in_val;i++){ for(i=0;i<=max_in_val;i++){
j = rise*i + shift; j = rise*i + shift;
if(j<out_min){ j = MAX(j, out_min);
j=out_min; j = MIN(j, out_max);
}
else if(j>out_max){
j=out_max;
}
*lut_p=j; *lut_p=j;
lut_p++; lut_p++;
@ -3385,8 +3384,8 @@ finecal(struct scanner *s)
else else
s->sendcal.buffer[idx * 2 + 1] = newgain; s->sendcal.buffer[idx * 2 + 1] = newgain;
/* update statistics */ /* update statistics */
if (pixvalue < min_value[i][k]) min_value[i][k] = pixvalue; min_value[i][k] = MIN(min_value[i][k], pixvalue);
if (pixvalue > max_value[i][k]) max_value[i][k] = pixvalue; max_value[i][k] = MAX(max_value[i][k], pixvalue);
avg_value[i][k] += pixerror; avg_value[i][k] += pixerror;
variance[i][k] += (pixerror * pixerror); variance[i][k] += (pixerror * pixerror);
idx++; idx++;
@ -3658,13 +3657,8 @@ send_lut (struct scanner *s)
for(i=0;i<width;i++){ for(i=0;i<width;i++){
j=slope*i + offset + b; j=slope*i + offset + b;
if(j<0){ j = MAX(j, 0);
j=0; j = MIN(j, height-1);
}
if(j>(height-1)){
j=height-1;
}
if (s->model == MODEL_S1100){ if (s->model == MODEL_S1100){
/*only one table, be order*/ /*only one table, be order*/
@ -4078,9 +4072,7 @@ sane_read (SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int * len
} }
*len = page->bytes_scanned - page->bytes_read; *len = page->bytes_scanned - page->bytes_read;
if(*len > max_len){ *len = MIN(*len, max_len);
*len = max_len;
}
if(*len){ if(*len){
DBG (10, "sane_read: copy rx:%d tx:%d tot:%d len:%d\n", DBG (10, "sane_read: copy rx:%d tx:%d tot:%d len:%d\n",
@ -4341,8 +4333,8 @@ read_from_scanner(struct scanner *s, struct transfer * tp)
size_t bufLen; size_t bufLen;
/* determine amount to ask for, S1300i wants big requests */ /* determine amount to ask for, S1300i wants big requests */
if(bytes > remainBlock && s->model != MODEL_S1300i){ if(s->model != MODEL_S1300i){
bytes = remainBlock; bytes = MIN(bytes, remainBlock);
} }
if (tp->image == NULL) if (tp->image == NULL)
@ -4932,8 +4924,7 @@ maxStringSize (const SANE_String_Const strings[])
for (i = 0; strings[i]; ++i) { for (i = 0; strings[i]; ++i) {
size = strlen (strings[i]) + 1; size = strlen (strings[i]) + 1;
if (size > max_size) max_size = MAX(max_size, size);
max_size = size;
} }
return max_size; return max_size;