I need help with my code?

Discussion in 'Java' started by LiverLad, Feb 8, 2005.

  1. LiverLad

    LiverLad Guest

    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: (Sorry there are some
    quotes and i don't know why its all in green text)


    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

    *---------------------------------*
    Posted at: http://www.GroupSrv.com
    *---------------------------------*

    Posted Via Usenet.com Premium Usenet Newsgroup Services
    ----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
    ----------------------------------------------------------
    http://www.usenet.com
    LiverLad, Feb 8, 2005
    #1
    1. Advertising

  2. On 8 Feb 2005 12:26:44 -0600, LiverLad wrote:

    > Hi i have a large piece of code ..


    But no question, apparently. That is odd, very odd.

    > ..Here is the part of the code which deals with this task:


    But if you manage to frame a question, you might try posting a self
    contained example that does not line wrap (keep your lines under 72
    chars, avoid posting 'tabs'). For further tips..
    <http://www.physci.org/codes/sscce.jsp>

    --
    Andrew Thompson
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.PhySci.org/ Open-source software suite
    http://www.1point1C.org/ Science & Technology
    http://www.LensEscapes.com/ Images that escape the mundane
    Andrew Thompson, Feb 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    1
    Views:
    2,447
    Edward
    Jun 18, 2004
  2. Teep
    Replies:
    2
    Views:
    750
    Larry Marburger
    Jun 21, 2004
  3. John
    Replies:
    1
    Views:
    380
    John C. Bollinger
    Aug 19, 2004
  4. =?Utf-8?B?Q2hyaXM=?=

    Help Help. I really need some help with this

    =?Utf-8?B?Q2hyaXM=?=, Jan 31, 2007, in forum: ASP .Net
    Replies:
    3
    Views:
    535
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=
    Jan 31, 2007
  5. ElementX
    Replies:
    9
    Views:
    470
    RedGrittyBrick
    Oct 1, 2008
Loading...

Share This Page