Skip to content

Commit

Permalink
Updated graphics output for new java-based display
Browse files Browse the repository at this point in the history
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@138 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Feb 1, 2008
1 parent 34431e0 commit ac4e0cf
Show file tree
Hide file tree
Showing 31 changed files with 350 additions and 223 deletions.
6 changes: 3 additions & 3 deletions ccstruct/blobbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ class BLOBNBOX:public ELIST_LINK

#ifndef GRAPHICS_DISABLED
void plot( //draw one
WINDOW window, //window to draw in
COLOUR blob_colour, //for outer bits
COLOUR child_colour) { //for holes
ScrollView* window, //window to draw in
ScrollView::Color blob_colour, //for outer bits
ScrollView::Color child_colour) { //for holes
if (blob_ptr != NULL)
blob_ptr->plot (window, blob_colour, child_colour);
if (cblob_ptr != NULL)
Expand Down
59 changes: 29 additions & 30 deletions ccstruct/callcpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#endif
#include <time.h>
#include "memry.h"
#include "grphics.h"
#include "evnts.h"
#include "scrollview.h"
//#include "evnts.h"
#include "varable.h"
#include "callcpp.h"
#include "tprintf.h"
Expand Down Expand Up @@ -179,69 +179,68 @@ void *c_create_window( /*create a window */
double ymin, /*getting lost in */
double ymax /*empty space */
) {
return create_window (name, SCROLLINGWIN, xpos, ypos, xsize, ysize,
xmin, xmax, ymin, ymax, TRUE, FALSE, FALSE, TRUE);
return new ScrollView(name, xpos, ypos, xsize, ysize, xmax - xmin, ymax - ymin, true);
}


void c_line_color_index( /*set color */
void *win,
C_COL index) {
WINDOW window = (WINDOW) win;

// ASSERT_HOST(index>=0 && index<=48);
if (index < 0 || index > 48)
index = (C_COL) 1;
window->Line_color_index ((COLOUR) index);
// The colors are the same as the SV ones except that SV has COLOR:NONE --> offset of 1
ScrollView* window = (ScrollView*) win;
window->Pen((ScrollView::Color) (index + 1));
}


void c_move( /*move pen */
void *win,
double x,
double y) {
WINDOW window = (WINDOW) win;

window->Move2d (x, y);
ScrollView* window = (ScrollView*) win;
window->SetCursor((int) x, (int) y);
}


void c_draw( /*move pen */
void *win,
double x,
double y) {
WINDOW window = (WINDOW) win;

window->Draw2d (x, y);
ScrollView* window = (ScrollView*) win;
window->DrawTo((int) x, (int) y);
}


void c_make_current( /*move pen */
void *win) {
WINDOW window = (WINDOW) win;

window->Make_picture_current ();
ScrollView* window = (ScrollView*) win;
window->Update();
}


void c_clear_window( /*move pen */
void *win) {
WINDOW window = (WINDOW) win;

window->Clear_view_surface ();
ScrollView* window = (ScrollView*) win;
window->Clear();
}


char window_wait( /*move pen */
void *win) {
WINDOW window = (WINDOW) win;
GRAPHICS_EVENT event;

await_event(window, TRUE, ANY_EVENT, &event);
if (event.type == KEYPRESS_EVENT)
return event.key;
else
return '\0';
ScrollView* window = (ScrollView*) win;
SVEvent* ev;

// Wait till an input event (all others are thrown away)
char ret = '\0';
SVEventType ev_type = SVET_ANY;
do {
ev = window->AwaitEvent(SVET_ANY);
ev_type = ev->type;
if (ev_type == SVET_INPUT) {
ret = ev->parameter[0];
}
delete ev;
} while (ev_type != SVET_INPUT && ev_type != SVET_CLICK);
return ret;
}
#endif

Expand Down
65 changes: 38 additions & 27 deletions ccstruct/coutln.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**********************************************************************
* File: coutln.c (Formerly coutline.c)
* Description: Code for the C_OUTLINE class.
* Author: Ray Smith
* Created: Mon Oct 07 16:01:57 BST 1991
* Author: Ray Smith
* Created: Mon Oct 07 16:01:57 BST 1991
*
* (C) Copyright 1991, Hewlett-Packard Ltd.
** Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -45,8 +45,12 @@ ICOORD top_right, INT16 length //length of loop
CRACKEDGE *edgept; //current point

stepcount = length; //no of steps
if (length == 0) {
steps = NULL;
return;
}
//get memory
steps = (UINT8 *) alloc_mem (step_mem());
steps = (UINT8 *) alloc_mem (step_mem());
memset(steps, 0, step_mem());
edgept = startpt;

Expand Down Expand Up @@ -82,7 +86,7 @@ INT16 length //length of loop
stepcount = length; //no of steps
//get memory
steps = (UINT8 *) alloc_mem (step_mem());
memset(steps, 0, step_mem());
memset(steps, 0, step_mem());

lastdir = new_steps[length - 1];
prevdir = lastdir;
Expand All @@ -91,8 +95,8 @@ INT16 length //length of loop
new_box = BOX (pos, pos);
box += new_box;
//copy steps
dir = new_steps[srcindex];
set_step(stepindex, dir);
dir = new_steps[srcindex];
set_step(stepindex, dir);
dirdiff = dir - prevdir;
pos += step (stepindex);
if ((dirdiff == 64 || dirdiff == -64) && stepindex > 0) {
Expand All @@ -107,8 +111,8 @@ INT16 length //length of loop
dirdiff = step_dir (stepindex - 1) - step_dir (0);
if (dirdiff == 64 || dirdiff == -64) {
start += step (0);
stepindex -= 2; //cancel there-and-back
for (int i = 0; i < stepindex; ++i)
stepindex -= 2; //cancel there-and-back
for (int i = 0; i < stepindex; ++i)
set_step(i, step_dir(i + 1));
}
}
Expand Down Expand Up @@ -141,12 +145,12 @@ C_OUTLINE::C_OUTLINE( //constructor
stepcount = srcline->stepcount * 2;
//get memory
steps = (UINT8 *) alloc_mem (step_mem());
memset(steps, 0, step_mem());
memset(steps, 0, step_mem());

for (int iteration = 0; iteration < 2; ++iteration) {
DIR128 round1 = iteration == 0 ? 32 : 0;
DIR128 round2 = iteration != 0 ? 32 : 0;
pos = srcline->start;
for (int iteration = 0; iteration < 2; ++iteration) {
DIR128 round1 = iteration == 0 ? 32 : 0;
DIR128 round2 = iteration != 0 ? 32 : 0;
pos = srcline->start;
prevpos = pos;
prevpos.rotate (rotation);
start = prevpos;
Expand All @@ -160,20 +164,20 @@ C_OUTLINE::C_OUTLINE( //constructor
dir = DIR128 (FCOORD (destpos - prevpos));
dir += 64; //turn to step style
new_step = dir.get_dir ();
if (new_step & 31) {
if (new_step & 31) {
set_step(destindex++, dir + round1);
if (destindex < 2
|| (dirdiff =
|| ((dirdiff =
step_dir (destindex - 1) - step_dir (destindex - 2)) !=
-64 && dirdiff != 64)
set_step(destindex++, dir + round2);
-64 && dirdiff != 64))
set_step(destindex++, dir + round2);
else {
set_step(destindex - 1, dir + round2);
set_step(destindex++, dir + round1);
}
}
else {
set_step(destindex++, dir);
set_step(destindex++, dir);
if (destindex >= 2
&&
((dirdiff =
Expand All @@ -191,12 +195,12 @@ C_OUTLINE::C_OUTLINE( //constructor
while ((dirdiff == 64 || dirdiff == -64) && destindex > 1) {
start += step (0);
destindex -= 2;
for (int i = 0; i < destindex; ++i)
set_step(i, step_dir(i + 1));
for (int i = 0; i < destindex; ++i)
set_step(i, step_dir(i + 1));
dirdiff = step_dir (destindex - 1) - step_dir (0);
}
if (destindex >= 4)
break;
if (destindex >= 4)
break;
}
stepcount = destindex;
destpos = start;
Expand Down Expand Up @@ -255,6 +259,8 @@ INT32 C_OUTLINE::outer_area() { //winding number

pos = start_pos ();
total_steps = pathlength ();
if (total_steps == 0)
return box.area();
total = 0;
for (stepindex = 0; stepindex < total_steps; stepindex++) {
//all intersected
Expand Down Expand Up @@ -415,6 +421,8 @@ const C_OUTLINE & other //other outline

if (!box.overlap (other.box))
return FALSE; //can't be contained
if (stepcount == 0)
return other.box.contains(this->box);

pos = start;
for (stepindex = 0; stepindex < stepcount
Expand Down Expand Up @@ -486,6 +494,8 @@ INT16 C_OUTLINE::turn_direction() const { //winding number
INT8 dirdiff; //direction difference
INT16 count; //winding count

if (stepcount == 0)
return 128;
count = 0;
prevdir = step_dir (stepcount - 1);
for (stepindex = 0; stepindex < stepcount; stepindex++) {
Expand Down Expand Up @@ -550,17 +560,18 @@ void C_OUTLINE::move( // reposition OUTLINE

#ifndef GRAPHICS_DISABLED
void C_OUTLINE::plot( //draw it
WINDOW window, //window to draw in
COLOUR colour //colour to draw in
ScrollView* window, //window to draw in
ScrollView::Color colour //colour to draw in
) const {
INT16 stepindex; //index to cstep
ICOORD pos; //current position
DIR128 stepdir; //direction of step
DIR128 oldstepdir; //previous stepdir

pos = start; //current position
line_color_index(window, colour);
move2d (window, pos.x (), pos.y ());
window->Pen(colour);
window->SetCursor(pos.x(), pos.y());

stepindex = 0;
stepdir = step_dir (0); //get direction
while (stepindex < stepcount) {
Expand All @@ -574,7 +585,7 @@ void C_OUTLINE::plot( //draw it
while (stepindex < stepcount
&& oldstepdir.get_dir () == stepdir.get_dir ());
//merge straight lines
draw2d (window, pos.x (), pos.y ());
window->DrawTo(pos.x(), pos.y());
}
}
#endif
Expand Down
20 changes: 10 additions & 10 deletions ccstruct/coutln.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
#ifndef COUTLN_H
#define COUTLN_H

#include "grphics.h"
#include "crakedge.h"
#include "mod128.h"
#include "bits16.h"
#include "rect.h"
#include "blckerr.h"
#include "scrollview.h"

#define INTERSECTING MAX_INT16//no winding number

Expand Down Expand Up @@ -82,10 +82,10 @@ class DLLSYM C_OUTLINE:public ELIST_LINK
}
void set_step( //set a step
INT16 stepindex, //index of step
INT8 stepdir) { //chain code
int shift = stepindex%4 * 2;
INT8 stepdir) { //chain code
int shift = stepindex%4 * 2;
UINT8 mask = 3 << shift;
steps[stepindex/4] = ((stepdir << shift) & mask) |
steps[stepindex/4] = ((stepdir << shift) & mask) |
(steps[stepindex/4] & ~mask);
//squeeze 4 into byte
}
Expand All @@ -105,10 +105,10 @@ class DLLSYM C_OUTLINE:public ELIST_LINK
}
INT32 pathlength() const { //get path length
return stepcount;
}
}
// Return step at a given index as a DIR128.
DIR128 step_dir(INT16 index) const {
return DIR128((INT16)(((steps[index/4] >> (index%4 * 2)) & STEP_MASK) <<
return DIR128((INT16)(((steps[index/4] >> (index%4 * 2)) & STEP_MASK) <<
(DIRBITS - 2)));
}
// Return the step vector for the given outline position.
Expand Down Expand Up @@ -138,8 +138,8 @@ class DLLSYM C_OUTLINE:public ELIST_LINK
const ICOORD vec); // by vector

void plot( //draw one
WINDOW window, //window to draw in
COLOUR colour) const; //colour to draw it
ScrollView* window, //window to draw in
ScrollView::Color colour) const; //colour to draw it

void prep_serialise() { //set ptrs to counts
children.prep_serialise ();
Expand All @@ -162,8 +162,8 @@ class DLLSYM C_OUTLINE:public ELIST_LINK
make_serialise (C_OUTLINE) C_OUTLINE & operator= (
const C_OUTLINE & source); //from this

private:
int step_mem() const { return (stepcount+3) / 4; }
private:
int step_mem() const { return (stepcount+3) / 4; }

BOX box; //boudning box
ICOORD start; //start coord
Expand Down
10 changes: 5 additions & 5 deletions ccstruct/lmedsq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,14 +437,14 @@ float LMS::compute_quadratic_errors( //fit sample

#ifndef GRAPHICS_DISABLED
void LMS::plot( //plot fit
WINDOW win, //window
COLOUR colour //colour to draw in
ScrollView* win, //window
ScrollView::Color colour //colour to draw in
) {
if (fitted) {
line_color_index(win, colour);
move2d (win, samples[0].x (),
win->Pen(colour);
win->SetCursor(samples[0].x (),
c + samples[0].x () * (m + samples[0].x () * a));
draw2d (win, samples[samplecount - 1].x (),
win->DrawTo(samples[samplecount - 1].x (),
c + samples[samplecount - 1].x () * (m +
samples[samplecount -
1].x () * a));
Expand Down
6 changes: 3 additions & 3 deletions ccstruct/lmedsq.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "points.h"
#include "varable.h"
#include "grphics.h"
#include "scrollview.h"
#include "notdll.h"

class LMS
Expand All @@ -46,8 +46,8 @@ class LMS
float &b, //x
float &c); //constant
void plot( //plot fit
WINDOW win, //window
COLOUR colour); //colour to draw in
ScrollView* win, //window
ScrollView::Color colour); //colour to draw in
float error() { //get error
return fitted ? line_error : -1;
}
Expand Down
Loading

0 comments on commit ac4e0cf

Please sign in to comment.