Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 9th, 2005, 10:36 AM   #1
LiverLad
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 LiverLad is on a distinguished road
Help with code please

Hi i have a large piece of code and i am trying to improve one part. The code looks at a scanned image and calculates how many lines are on the image and will section them off the the page is viewed.
But sometimes the lines are not sectioned i think it has something to do with the values i have put in for certain variables. Here is the part of the code which deals with this task (This is only part of the code and program if necessary i can attach the other code as a .zip file if you ask) Thank you for your time.
Mark

private static void splitTextArea(boolean leftPage) throws IOException
	{
	int left = 0,
	    right = 0 ;
	if (leftPage)
	    {
	    left = textEdge ;
	    right = leftEdge + cropWidth ;
	    }
	else
	    {
	    left = leftEdge ;
	    right = textEdge ;
	    }
	int rowWidth = right - left ;
 
	// int backcolour1 = 253 ;
	int backcolour1 = 245,
	    max_light_lines = 4,
	    max_dark_lines = 8,
	    lightLineCounter = 0,
	    darkLineCounter = 0 ;
	boolean inLightZone = true,
		inTextZone = false ;
	int lastY = topEdge,
	    descender_space = 3 ;
	// PrintWriter pout2 = new PrintWriter(new FileWriter(outDirectory1 +
	//				File.separator + "xxx.txt")) ;
	noOfRows = 0 ;JAVA 
	int clearance = 40 ;
	for (int i = topEdge + clearance ; i < topEdge + cropHeight - clearance ; i++)
	    {
	    int colour = getRowColour(left, right, i) ;
	// pout2.println(i + ", " + colour) ;
            if (colour >= backcolour1)
		{
		lightLineCounter++ ;
		darkLineCounter-- ;
		}
	    else
		{
		darkLineCounter++ ;
		lightLineCounter-- ;
		}
	    if (lightLineCounter > max_light_lines)
	        lightLineCounter = max_light_lines ;
	    if (lightLineCounter < 0)
	        lightLineCounter = 0 ;
	    if (darkLineCounter > max_dark_lines)
	        darkLineCounter = max_dark_lines ;
	    if (darkLineCounter < 0)
	        darkLineCounter = 0 ;
 
	    if ((lightLineCounter == max_light_lines) && (inTextZone))
		{
		inLightZone = true ;
		inTextZone = false ;
		int line = noOfRows + 1 ;
		int rowHeight = i + descender_space - lastY ;
		// message("(" + left + ", " + lastY + ", " + rowWidth + ", " +
		//			rowHeight + ")") ;
		pout1.println("(" + left + ", " + lastY + ", " + rowWidth +
					", " + rowHeight + ")") ;
		rows[noOfRows] = new IntegerQuad(left, lastY, rowWidth, rowHeight) ;
		noOfRows++ ;
		lastY = i + descender_space ;
		}
	    else if ((darkLineCounter == max_dark_lines) && (inLightZone))
		{
		inLightZone = false ;
		inTextZone = true ;
		}
    	    }
	// pout2.close() ;
	message("no of lines = " + noOfRows) ;
	pout1.println("No of Lines = " + noOfRows) ;
	pout1.println() ;
	} // end of method splitTextArea
 
    private static void splitGlossArea(boolean leftPage)
	{
	int left = 0,
	    right = 0 ;
	if (leftPage)
	    {
	    left = leftEdge ;
	    right = textEdge ;
	    }
	else
	    {
	    left = textEdge ;
	    right = leftEdge + cropWidth ;
	    }
	int rowWidth = right - left ;
	if (rowWidth == 0)
	    {
	    message("WARNING: no gloss area found") ;
	    noOfGlossRows = 0 ;
	    return ;
	    }
 
	// int backcolour1 = 253,
	int backcolour1 = 245,
	    max_light_lines = 20,
	    max_dark_lines = 10,
	    lightLineCounter = 0,
	    darkLineCounter = 0 ;
	boolean inLightZone = true,
		inTextZone = false ;
	int lastY = topEdge,
	    descender_space = 17,
	    ascender_space = 20 ;
	noOfGlossRows = 0 ;
	int clearance = 40 ;
	for (int i = topEdge + clearance ; i < topEdge + cropHeight - clearance ; i++)
	    {
	    int colour = getRowColour(left, right, i) ;
	    if (colour >= backcolour1)
	        {
	        lightLineCounter++ ;
	        darkLineCounter-- ;
	        }
	    else
	        {
		darkLineCounter++ ;
		lightLineCounter-- ;
		}
	    if (lightLineCounter > max_light_lines)
	        lightLineCounter = max_light_lines ;
	    if (lightLineCounter < 0)
	        lightLineCounter = 0 ;
	    if (darkLineCounter > max_dark_lines)
	        darkLineCounter = max_dark_lines ;
	    if (darkLineCounter < 0)
	        darkLineCounter = 0 ;
 
	    if ((lightLineCounter == max_light_lines) && (inTextZone))
	        {
	        inLightZone = true ;
		inTextZone = false ;
		int line = noOfGlossRows + 1 ;
		int rowHeight = i + descender_space - lastY ;
		// message("(" + left + ", " + lastY + ", " + rowWidth + ", " +
		//		rowHeight + ")") ;
		pout1.println("(" + left + ", " + lastY + ", " + rowWidth +
				", " + rowHeight + ")") ;
		glossRows[noOfGlossRows] = new IntegerQuad(left, lastY, rowWidth,
				rowHeight) ;
		noOfGlossRows++ ;
	        lastY = i + descender_space ;
		}
	    else if ((darkLineCounter == max_dark_lines) && (inLightZone))
	    	{
		inLightZone = false ;
		inTextZone = true ;
		// this overrides other values of lastY,
		// 	to eliminate gloss whitespace
		lastY = i - max_dark_lines - ascender_space ;
		}
    	    }
 
	message("no of glosses = " + noOfGlossRows) ;
	pout1.println("No of Glosses = " + noOfGlossRows) ;
        pout1.close() ;
        } // end of method splitGlossArea
LiverLad is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:19 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC