?? frontend.c
字號:
{
line_data[jj] = 127;
}
else
{
line_data[jj] = 0;
}
}
if ( debug)
{
printf("End smooth line \n");
}
}
/**************************************************************************
* line_fast *
* gets a line using Bresenham's line-drawing algorithm, which uses *
* no multiplication or division. *
* gets data from pixel array and puts in line_data *
**************************************************************************/
void line_fast(int x1, int y1, int x2, int y2)
{
int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
dx=x2-x1; /* the horizontal distance of the line */
dy=y2-y1; /* the vertical distance of the line */
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;
pixel_cnt = 0;
get_pixel(px,py);
if (dxabs>=dyabs) /* the line is more horizontal than vertical */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
get_pixel(px,py);
}
}
else /* the line is more vertical than horizontal */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
get_pixel(px,py);
}
}
}
/**************************************************************************
* line_fast_post *
* gets a line using Bresenham's line-drawing algorithm, which uses *
* no multiplication or division. *
* get data from the pix_out and puts it in post_line_data *
**************************************************************************/
void line_fast_post(int x1, int y1, int x2, int y2)
{
int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
dx=x2-x1; /* the horizontal distance of the line */
dy=y2-y1; /* the vertical distance of the line */
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;
post_pixel_cnt = 0;
get_pixel_post(px,py);
if (dxabs>=dyabs) /* the line is more horizontal than vertical */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
get_pixel_post(px,py);
}
}
else /* the line is more vertical than horizontal */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
get_pixel_post(px,py);
}
}
}
/**************************************************************************
* line_fast norm *
* gets a line using Bresenham's line-drawing algorithm, which uses *
* no multiplication or division. *
* gets data from pixel_array but puts result in norm_line_data *
**************************************************************************/
void line_fast_norm(int x1, int y1, int x2, int y2)
{
int i,dx,dy,sdx,sdy,dxabs,dyabs,x,y,px,py;
dx=x2-x1; /* the horizontal distance of the line */
dy=y2-y1; /* the vertical distance of the line */
dxabs=abs(dx);
dyabs=abs(dy);
sdx=sgn(dx);
sdy=sgn(dy);
x=dyabs>>1;
y=dxabs>>1;
px=x1;
py=y1;
pixel_cnt = 0;
get_pixel_norm(px,py);
if (dxabs>=dyabs) /* the line is more horizontal than vertical */
{
for(i=0;i<dxabs;i++)
{
y+=dyabs;
if (y>=dxabs)
{
y-=dxabs;
py+=sdy;
}
px+=sdx;
get_pixel_norm(px,py);
}
}
else /* the line is more vertical than horizontal */
{
for(i=0;i<dyabs;i++)
{
x+=dxabs;
if (x>=dyabs)
{
x-=dyabs;
px+=sdx;
}
py+=sdy;
get_pixel_norm(px,py);
}
}
}
// draw a normal at a point
void draw_normal(int nx, int ny, int nslope, int ndir, int ylen)
{
int ii;
int xinc, yinc;
int dark_percent;
int bits_on_cnt;
int num_dark;
int first_dark;
int first_dark_ind;
int debug;
debug = 0;
if (debug)
{
printf("In draw normal , x,y = %d %d \n",nx, ny );
printf("Slope = %d \n", nslope);
printf("ylen = %d \n", ylen);
printf("dir = %d \n",ndir);
}
if ( ndir == 1) // positive x and positive y incr
{
yinc = (ylen);
xinc = (((ylen) * slope) / 100);
line_fast_norm(nx, ny, nx + xinc, ny+yinc);
}
if ( ndir == -1) // negative x incr and positive y incr
{
yinc = (ylen);
xinc = 0- (( (ylen) * slope) / 100);
line_fast_norm(nx, ny, nx + xinc, ny+yinc);
}
num_dark = 0;
first_dark = FALSE;
first_dark_ind = -1;
for ( ii = 0; ii < pixel_cnt; ii += 1)
{
if ( norm_line_data[ii] > dark_threshold)
{
if ( first_dark == FALSE)
{
first_dark = TRUE;
first_dark_ind = ii;
}
num_dark += 1;
}
if (debug) { printf("norm line %d = %d \n",ii, norm_line_data[ii]); }
}
if (debug)
{
printf("num_dark = %d \n",num_dark);
printf("First dark at = %d \n",first_dark_ind);
}
dark_percent = (num_dark * 100) / pixel_cnt;
if (debug) { printf("Dark percent = %d \n", dark_percent); }
norm_fdark_ind = first_dark_ind;
}
// use a binary search to find the index in the
// bit_array of the pdf barcode
//
int find_index( long inbits, int code_in, int column, int row)
{
int ii;
int found_index;
int bit_index;
int bit_increment;
int found;
int less_than_flag;
int debug;
bit_index = 1392;
bit_increment = 696;
found = FALSE;
less_than_flag = FALSE;
debug = 0;
if ( debug) { printf("Inbits = %x \n", inbits); }
while (( found == FALSE ) && (bit_increment > 11 ))
{
if (debug)
{
printf(" bit_array val = %x , inbits = %x \n",
bit_array[bit_index], inbits);
}
if (bit_array[bit_index] > inbits)
{
bit_index = bit_index - bit_increment;
less_than_flag = FALSE;
}
else
{
if (bit_array[bit_index] == inbits)
{
found = TRUE;
found_index = bit_index;
}
else // less than
{
bit_index = bit_index + bit_increment;
less_than_flag = TRUE;
}
}
bit_increment = bit_increment / 2;
if (debug)
{
printf("In find loop , bit_increment = %d \n", bit_increment);
printf("In find loop , bit_index = %d \n", bit_index);
}
}
if ( found == FALSE)
{
ii = 0;
if ( debug) { printf("no less than flag , bit_index = %d \n",bit_index); }
while (( found == FALSE) && ( ii < 25) && ( bit_index < 2759))
{
if (bit_array[bit_index + ii] == inbits)
{
found = TRUE;
found_index = bit_index + ii;
}
ii += 1;
}
}
if ( found == FALSE)
{
ii = 0;
if (debug) { printf("less than flag , bit_index = %d \n",bit_index); }
while (( found == FALSE) && ( ii > -25) && ( bit_index > 26))
{
if ( bit_index + ii > 0)
{
if (bit_array[bit_index + ii] == inbits)
{
found = TRUE;
found_index = bit_index + ii;
}
}
ii -= 1;
}
}
if (found == FALSE)
{
// do an exhaustive search
ii = 0;
if (debug) { printf("Doing exhaustive search \n"); }
while ( ( ii < 2784 ) && (found == FALSE))
{
if ( bit_array[ii] == inbits)
{
found = TRUE;
found_index = ii;
}
ii += 1;
}
}
if (found == FALSE)
{
if (code_in == 0)
{
printf(" Top left module not found in bit_array = 0x%x \n", inbits);
}
if (code_in == 1)
{
printf(" Bottom left module not found in bit_array = 0x%x \n", inbits);
}
if (code_in == 2)
{
if ( debug)
{
printf(" Column,row module not found in bit_array = 0x%x \n", inbits);
printf(" Column = %d row = %d\n", column, row);
}
}
return(-1);
}
else
{
return( found_index );
}
}
// find the differences in the x ( row ) grey values
// for each y location in pix_col data
//
void do_pixcol_diffy(int inwidth, int inheight)
{
int ii;
int jj;
int kk;
int diff_data[OUT_MAX_X_PIXEL];
int diff_tots[OUT_MAX_X_PIXEL];
int first_deriv[OUT_MAX_X_PIXEL];
int diff_tots_sorted[OUT_MAX_X_PIXEL];
int total_diff;
int prev_total;
long cum_total;
long avg_total;
int prev_line;
int x_space;
int est_bar_width;
int debug;
debug = 0;
diff_data[0] = 0;
diff_data[1] = 0;
diff_data[2] = 0;
cum_total = 0;
total_diff = 0;
prev_total = 0;
if (debug)
{
printf(" In do pix_col_diffy, inwidth, inheight = %d %d \n",
inwidth, inheight);
}
for ( jj = 3; jj < inwidth; jj += 1)
{
total_diff = 0;
for ( ii = 0; ii < inheight ; ii += 1)
{
diff_data[ii] = abs(pix_cols[jj][ii].greyval - pix_cols[jj-3][ii].greyval);
total_diff = total_diff + diff_data[ii];
}
diff_tots[jj]= total_diff;
cum_total = total_diff + cum_total;
first_deriv[jj] = total_diff - prev_total;
prev_total = total_diff;
}
if ( inwidth != 0)
{
avg_total = cum_total/inwidth;
}
else
{
printf("In pixcol_diff_y, inwidth = 0 , internal error \n");
exit(0);
}
if (debug)
{ printf("avg total = %d \n", avg_total); }
for ( jj = 0; jj < inwidth; jj += 1)
{
if (debug)
{
printf(" jj = %d diff_tots = %d 1st deriv = %d \n",jj, diff_tots[jj],
first_deriv[jj]);
}
}
kk = 0;
prev_line = 0;
for ( jj = 5; jj < inwidth; jj += 1)
{
if (( first_deriv[jj] > 0) && ( first_deriv[jj+1] < 0))
{
if ( (long) diff_tots[jj] > (avg_total/2 ))
{
if ( kk < MAX_LINES_X)
{
if ( kk > 0)
{
if (( jj - pix_col_xline[kk-1]) > (int) (best_onewf /2))
{
pix_col_xline[kk] = jj;
x_space = jj - prev_line;
prev_line = jj;
kk += 1;
}
}
else
{
if ( jj > (int) (best_onewf /2))
{
pix_col_xline[kk] = jj;
x_space = jj - prev_line;
prev_line = jj;
kk += 1;
}
}
}
else
{
printf("Too many vertical lines in pix_col \n");
}
if (debug)
{
printf("Candidate at jj = %d x_space = %d \n",jj, x_space);
}
}
}
}
vert_line_cnt = kk;
if ( kk != 0)
{
est_bar_width = (inwidth * 10 )/ kk;
}
else
{
est_bar_width = 1;
}
if (debug)
{
printf("est_bar_width = %d \n", est_bar_width);
for ( kk = 0; kk < vert_line_cnt; kk += 1)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -