Esempio n. 1
0
int OCRPrep :: edge(SIPImage *src, SIPImage *dst){
	int	x,y,width,height;
	uchar	*p,*dp,*pu,*pd;
	SIPImage	*tmpimage;
	width  = src->width;
	height = src->height;
	if ( 0 == (tmpimage = sip_CreateImage(width +2, height +2,8)) )  return(-1);
	sip_ClearImage(tmpimage,0);
	for ( y=0 ; y<height ; y++ ){
		p = (uchar *)sip_getimgptr(src,y);
		dp = (uchar *)sip_getimgptr(tmpimage,y+1) +1;
		memcpy((void *)dp,(void *)p,width);
	}
	sip_ClearImage(dst,0);
	for ( y=0 ; y<height ; y++ ){
		pu = (uchar *)sip_getimgptr(tmpimage,y);
		p = (uchar *)sip_getimgptr(tmpimage,y+1);
		pd = (uchar *)sip_getimgptr(tmpimage,y+2);
		dp = (uchar *)sip_getimgptr(dst,y);
		for ( x=0 ; x<width ; x++ ){
			if ( p[x+1] != 0 ){
				if ( p[x  ] == 0 )  dp[x] |= 0xff;
				if ( p[x+2] == 0 )  dp[x] |= 0xff;
				if ( pu[x+1] == 0 )  dp[x] |= 0xff;
				if ( pd[x+1] == 0 )  dp[x] |= 0xff;
			}
		}
	}
	sip_DestroyImage(tmpimage);
	return(0);
}
Esempio n. 2
0
int sip_rotate8(SIPImage *src,SIPImage *dst,int x0,int y0,double angle,int mode){
					/* mode = BOP_XXX */
	int	sx,sy,dx,dy;
	int	sx0,sy0;
	int	dx1,dy1,dx2,dy2;
	double	rc,rs,rsy,rcy;
	double	*ctbl,*stbl;
	uchar	*dstp;
	int	lnlen;
	if ( src->depth != 8 )  return(-1);
	if ( dst->depth != 8 )  return(-1);
	rc = cos(-angle);
	rs = sin(-angle);
	sx0 = (unsigned int)(src->width  +1) /2;
	sy0 = (unsigned int)(src->height +1) /2;
	dx2 = (int)((double)sx0 * fabs(rc) + (double)sy0 * fabs(rs));
	if ( 0 > (dx1 = x0 - dx2) )  dx1 = 0;
	if ( dst->width <= (dx2 += x0) )  dx2 = dst->width -1;
	dy2 = (int)((double)sx0 * fabs(rs) + (double)sy0 * fabs(rc));
	if ( 0 > (dy1 = y0 - dy2) )  dy1 = 0;
	if ( dst->height <= (dy2 += y0) )  dy2 = dst->height -1;
	dx1 -= x0;	dx2 -= x0;
	lnlen = dx2 - dx1 +1;
	if ( NULL == (ctbl = (double *)malloc(2 * lnlen * sizeof(double))) )  return(-1);
	stbl = ctbl + lnlen;
	for ( dx=0 ; dx<lnlen ; dx++ ){
		ctbl[dx] = rc * (double)(dx + dx1);
		stbl[dx] = rs * (double)(dx + dx1);
	}
	for ( dy=dy1 ; dy<=dy2 ; dy++ ){
		dstp = (uchar *)sip_getimgptr(dst,dy) + x0 + dx1;
		rsy = rs * (double)(dy - y0);
		rcy = rc * (double)(dy - y0);
		switch ( mode ){
		    case BOP_PUT:
			for ( dx=0 ; dx<lnlen ; dx++ ){
				sx = sx0 + (int)(ctbl[dx] + rsy);
				if ( sx < 0 )  continue;
				if ( sx >= src->width  )  continue;
				sy = sy0 - (int)(stbl[dx] - rcy);
				if ( sy < 0 )  continue;
				if ( sy >= src->height )  continue;
				dstp[dx] = sip_getimgptr(src,sy)[sx];
			}
			break;
		    case BOP_OR:
			for ( dx=0 ; dx<lnlen ; dx++ ){
				sx = sx0 + (int)(ctbl[dx] + rsy);
				if ( sx < 0 )  continue;
				if ( sx >= src->width  )  continue;
				sy = sy0 - (int)(stbl[dx] - rcy);
				if ( sy < 0 )  continue;
				if ( sy >= src->height )  continue;
				dstp[dx] |= sip_getimgptr(src,sy)[sx];
			}
			break;
		    case BOP_AND:
			for ( dx=0 ; dx<lnlen ; dx++ ){
				sx = sx0 + (int)(ctbl[dx] + rsy);
				if ( sx < 0 )  continue;
				if ( sx >= src->width  )  continue;
				sy = sy0 - (int)(stbl[dx] - rcy);
				if ( sy < 0 )  continue;
				if ( sy >= src->height )  continue;
				dstp[dx] &= sip_getimgptr(src,sy)[sx];
			}
			break;
		}
	}
	free((char *)ctbl);
	return(0);
}