From b26e58fcd809c7a52a3a91927fc79fc5cf821aaa Mon Sep 17 00:00:00 2001 From: micio Date: Sun, 20 Sep 2009 14:55:01 +0000 Subject: [PATCH] Bazaar:Leptonica - added image rectangular markers git-svn-id: svn://ultimatepp.org/upp/trunk@1577 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/PixRaster/Marker.cpp | 321 +++++++++++++++ bazaar/PixRaster/Marker.h | 103 +++++ bazaar/PixRaster/PixRaster.cpp | 22 +- bazaar/PixRaster/PixRaster.h | 16 +- bazaar/PixRaster/PixRaster.upp | 4 +- bazaar/PixRaster/PolyMarker.cpp | 216 ---------- bazaar/PixRaster/PolyMarker.h | 76 ---- bazaar/PixRaster/src.tpp/Pix$en-us.tpp | 291 ++++++++++++++ bazaar/PixRaster/src.tpp/PixBase$en-us.tpp | 159 ++++++++ bazaar/PixRasterCtrl/ImageCache.cpp | 3 + bazaar/PixRasterCtrl/ImageCache.h | 4 +- bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp | 391 +++++++++++++++++-- bazaar/PixRasterCtrl/PixRasterBaseCtrl.h | 55 ++- bazaar/PixRasterCtrl/PixRasterCtrl.cpp | 3 + bazaar/PixRasterCtrl/PixRasterCtrl.h | 4 +- bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp | 11 +- bazaar/PixRasterCtrl/PixRasterThumbsCtrl.h | 6 +- bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp | 4 + bazaar/PixRasterCtrl/PixRasterViewCtrl.h | 4 +- bazaar/TestLeptonica/PageLayout.cpp | 2 +- bazaar/TestLeptonica/PageMarkers.cpp | 40 ++ bazaar/TestLeptonica/TestLeptonica.h | 1 + bazaar/TestLeptonica/TestLeptonica.lay | 3 +- bazaar/TestLeptonica/TestLeptonica.upp | 1 + bazaar/TestLeptonica/main.cpp | 1 + 25 files changed, 1378 insertions(+), 363 deletions(-) create mode 100644 bazaar/PixRaster/Marker.cpp create mode 100644 bazaar/PixRaster/Marker.h delete mode 100644 bazaar/PixRaster/PolyMarker.cpp delete mode 100644 bazaar/PixRaster/PolyMarker.h create mode 100644 bazaar/PixRaster/src.tpp/Pix$en-us.tpp create mode 100644 bazaar/PixRaster/src.tpp/PixBase$en-us.tpp create mode 100644 bazaar/TestLeptonica/PageMarkers.cpp diff --git a/bazaar/PixRaster/Marker.cpp b/bazaar/PixRaster/Marker.cpp new file mode 100644 index 000000000..9a3ef90ac --- /dev/null +++ b/bazaar/PixRaster/Marker.cpp @@ -0,0 +1,321 @@ +#include "Marker.h" + +NAMESPACE_UPP + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// constructors +Marker::Marker() +{ + kind = EmptyMarker; + borderThickness = 2; + borderColor = Blue; + borderLineType = 0; + fillColor = WhiteGray(); + selBorderThickness = 2; + selBorderColor = LtBlue; + selBorderLineType = 0; + selFillColor = LtGray(); + closed = false; + +} // END Constructor class Marker + +// construct a rectangular Marker +Marker::Marker(Point const &p1, Point const &p2) +{ + kind = RectMarker; + borderThickness = 2; + borderColor = Blue; + borderLineType = 0; + fillColor = WhiteGray(); + selBorderThickness = 2; + selBorderColor = LtBlue; + selBorderLineType = 0; + selFillColor = LtGray(); + closed = true; + points.Add(Point(min(p1.x, p2.x), min(p1.y, p2.y))); + points.Add(Point(max(p1.x, p2.x), max(p1.y, p2.y))); + +} // END Constructor class Marker + +// construct a polygonal Marker +Marker::Marker(Vector const &pts) +{ + kind = PolyMarker; + borderThickness = 2; + borderColor = Blue; + borderLineType = 0; + fillColor = WhiteGray(); + selBorderThickness = 2; + selBorderColor = LtBlue; + selBorderLineType = 0; + selFillColor = LtGray(); + closed = true; + points <<= pts; + +} // END Constructor class Marker + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +Marker::Marker(const Marker &m) +{ + kind = m.GetKind(); + borderThickness = m.GetBorderThickness(); + borderColor = m.GetBorderColor(); + borderLineType = m.GetBorderLineType(); + fillColor = m.GetFillColor(); + selBorderThickness = m.GetSelBorderThickness(); + selBorderColor = m.GetSelBorderColor(); + selBorderLineType = m.GetSelBorderLineType(); + selFillColor = m.GetSelFillColor(); + closed = m.IsClosed(); + points <<= m.GetPoints(); + +} // END Constructor class Marker + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// sets the marker to a rectangular area +void Marker::Set(const Point &p1, const Point &p2) +{ + kind = RectMarker; + points.Clear(); + points.Add(Point(min(p1.x, p2.x), min(p1.y, p2.y))); + points.Add(Point(max(p1.x, p2.x), max(p1.y, p2.y))); + +} // END Marker::Set() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// sets the marker to be a polygonal area +void Marker::Set(const Vector &pts) +{ + kind = PolyMarker; + points <<= pts; + +} // END Marker::Set() + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// test for point hit +Marker::HitKind Marker::Hit(const Point &p, int minDist, int &hitIndex) +{ + + switch(kind) + { + case EmptyMarker: + return Miss; + + case RectMarker: + { + Point p1 = points[0]; + Point p2 = points[1]; + if(abs(p1.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) + return TopLeft; + if(abs(p2.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) + return TopRight; + if(abs(p1.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) + return BottomLeft; + if(abs(p2.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) + return BottomRight; + if(abs(p1.y - p.y) <= minDist && p.x >= p1.x && p.x <= p2.x) + return Top; + if(abs(p2.y - p.y) <= minDist && p.x >= p1.x && p.x <= p2.x) + return Bottom; + if(abs(p1.x - p.x) <= minDist && p.y >= p1.y && p.y <= p2.y) + return Left; + if(abs(p2.x - p.x) <= minDist && p.y >= p1.y && p.y <= p2.y) + return Right; + if(p.x > p1.x && p.x < p2.x && p.y > p1.y && p.y < p2.y) + return Inside; + return Miss; + } + + case PolyMarker: + // FIXME -- support polygon + default: + NEVER(); + } // switch +} + + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// open/close the polygon (invalid for rectangle markers) +void Marker::Open() +{ + closed = false; + +} + +void Marker::Close() +{ + closed = true; + +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// clears the marker +void Marker::Clear(void) +{ + points.Clear(); + kind = EmptyMarker; + closed = false; +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// gets rectangular bounding box of marker +Rect Marker::GetBoundingBox() const +{ + switch(kind) + { + case EmptyMarker: + return Rect(0, 0, 0, 0); + + case RectMarker: + return Rect(points[0], points[1]); + + case PolyMarker: + { + int minX = INT_MAX; + int maxX = INT_MIN; + int minY = INT_MAX; + int maxY = INT_MIN; + for(int i = 0; i < points.GetCount(); i++) + { + Point p = points[i]; + if(p.x < minX) minX = p.x; + if(p.x > maxX) maxX = p.x; + if(p.y < minY) minY = p.y; + if(p.y > maxY) maxY = p.y; + } + return Rect(minX, minY, maxX, maxY); + } + + default: + NEVER(); + } + +} + +///////////////////////////////////////////////////////////////////////////////////////////////////////////// +// gets vertexs of marker +Vector Marker::GetPoints() const +{ + Vector res; + + switch(kind) + { + case RectMarker: + res.Add(points[0]); + res.Add(Point(points[1].x, points[0].y)); + res.Add(points[1]); + res.Add(Point(points[0].x, points[1].y)); + return res; + + case PolyMarker: + return Vector(points, 1); + + default: + return Vector(); + } +} + +// gets dragged outline +Vector Marker::DragOutline(Point const &startPt, Point const &endPt, int minDist) +{ + // if empty marker, just return empty polygon + if(kind == EmptyMarker) + return Vector(); + + // find kind of hit on start point + int index = 0; + HitKind hitKind = Hit(startPt, minDist, index); + if(hitKind == Miss) + return Vector(); + + int dx = endPt.x - startPt.x; + int dy = endPt.y - startPt.y; + switch(kind) + { + case RectMarker: + { + int x1 = points[0].x; + int y1 = points[0].y; + int x2 = points[1].x; + int y2 = points[1].y; + Vector res; + switch(hitKind) + { + case TopLeft: + x1 += dx; + y1 += dy; + break; + case TopRight: + x2 += dx; + y1 += dy; + break; + case BottomLeft: + x1 += dx; + y2 += dy; + break; + case BottomRight: + x2 += dx; + y2 += dy; + break; + case Top: + y1 += dy; + break; + case Bottom: + y2 += dy; + break; + case Left: + x1 += dx; + break; + case Right: + x2 += dx; + break; + default: // inside + x1 += dx; y1 += dy; + x2 += dx; y2 += dy; + break; + } + res.Add(Point(x1, y1)); + res.Add(Point(x2, y1)); + res.Add(Point(x2, y2)); + res.Add(Point(x1, y2)); + return res; + } + + case PolyMarker: + // FIXME -- support polygon + + default: + NEVER(); + + } // switch(kind) + + +} // END Marker::DragOutline() + +// drag the marker to final position +void Marker::Drag(Point const &startPt, Point const &endPt, int minDist) +{ + if(kind == EmptyMarker) + return; + + Vector pts = DragOutline(startPt, endPt, minDist); + switch(kind) + { + case RectMarker: + { + points[0] = pts[0]; + points[1] = pts[2]; + break; + } + + case PolyMarker: + points = pts; + break; + + default: + NEVER(); + } + +} // END Marker::Drag() + +END_UPP_NAMESPACE diff --git a/bazaar/PixRaster/Marker.h b/bazaar/PixRaster/Marker.h new file mode 100644 index 000000000..8b3a44df0 --- /dev/null +++ b/bazaar/PixRaster/Marker.h @@ -0,0 +1,103 @@ +#ifndef _Marker_h_ +#define _Marker_h_ + +#include + +NAMESPACE_UPP + +// Image Marker class +// supports rectangular and polygonal areas +class Marker +{ + public: + typedef Marker CLASSNAME; + + enum HitKind { Miss, PolyVertex, PolySide, Left, Right, Top, Bottom, TopLeft, TopRight, BottomLeft, BottomRight, Inside }; + enum MarkerKind { EmptyMarker, RectMarker, PolyMarker }; + + protected: + + MarkerKind kind; + bool closed; + + int borderThickness; + Color borderColor; + int borderLineType; + RGBA fillColor; + + int selBorderThickness; + Color selBorderColor; + int selBorderLineType; + RGBA selFillColor; + + Vector points; + + public: + + // construct an empty marker + Marker(); + + // construct a rectangular Marker + Marker(Point const &p1, Point const &p2); + + // construct a polygonal Marker + Marker(Vector const &pts); + + // copy constructor + Marker(Marker const &m); + + // sets the marker to a rectangular area + void Set(const Point &p1, const Point &p2); + + // sets the marker to be a polygonal area + void Set(const Vector &pts); + + // empties the marker + void Clear(); + + // opens/closes the marker + void Open(); + void Close(); + + // test for point hit + // hitIndex is only for polygons, gives vertex's index of selected vertex + HitKind Hit(const Point &p, int minDist, int &hitIndex); + + // member read access + virtual MarkerKind GetKind() const { return kind; } + bool IsClosed() const { return closed; } + Color GetBorderColor() const { return borderColor; } + int GetBorderLineType() const { return borderLineType; } + int GetBorderThickness() const { return borderThickness; } + RGBA GetFillColor() const { return fillColor; } + Color GetSelBorderColor() const { return selBorderColor; } + int GetSelBorderLineType() const { return selBorderLineType; } + int GetSelBorderThickness() const { return selBorderThickness; } + RGBA GetSelFillColor() const { return selFillColor; } + Rect GetBoundingBox() const; + Vector GetPoints() const; + + // member write access + void SetKind(MarkerKind k); + void SetBorderColor(Color c); + void SetBorderLineType(int lt); + void SetBorderThickness(int th); + RGBA SetFillColor(RGBA const &rgba); + void SetSelBorderColor(Color c); + void SetSelBorderLineType(int lt); + void SetSelBorderThickness(int th); + RGBA SetSelFillColor(RGBA const &rgba); + + // gets dragged outline + VectorDragOutline(Point const &startPt, Point const &endPt, int minDist); + + // drag the marker to final position + void Drag(Point const &startPt, Point const &endPt, int minDist); + +}; // END Class Marker + +typedef Array Markers; + +END_UPP_NAMESPACE + +#endif diff --git a/bazaar/PixRaster/PixRaster.cpp b/bazaar/PixRaster/PixRaster.cpp index 0a3c32a1f..2f296331c 100644 --- a/bazaar/PixRaster/PixRaster.cpp +++ b/bazaar/PixRaster/PixRaster.cpp @@ -31,7 +31,7 @@ void Pix::Destroy() delete[] localPalette; localPalette = NULL; } - polyMarkers.Clear(); + markers.Clear(); } // END Pix::Destroy() @@ -408,7 +408,7 @@ Pix::Pix() pix = NULL; rasterFormat = NULL; localPalette = NULL; - polyMarkers.Clear(); + markers.Clear(); } // END Pix::Pix() @@ -423,7 +423,7 @@ Pix::Pix(int width, int height, int depth, RGBA *colorTable) } rasterFormat = NULL; localPalette = NULL; - polyMarkers.Clear(); + markers.Clear(); } // END Pix::Pix() @@ -436,7 +436,7 @@ Pix::Pix(PIX **_pix) *_pix = NULL; rasterFormat = NULL; localPalette = NULL; - polyMarkers.Clear(); + markers.Clear(); } // END Pix::Pix() @@ -447,7 +447,7 @@ Pix::Pix(Pix const &_pix) pix = pixClone((Pix &)_pix); rasterFormat = NULL; localPalette = NULL; - polyMarkers <<= _pix.polyMarkers; + markers <<= _pix.markers; } // END Pix::Pix() @@ -458,7 +458,7 @@ Pix::Pix(Pix const &_pix, int i) pix = pixCopy(NULL, (Pix &)_pix); rasterFormat = NULL; localPalette = NULL; - polyMarkers <<= _pix.polyMarkers; + markers <<= _pix.markers; } // END Pix::Pix() @@ -505,7 +505,7 @@ Pix &Pix::operator=(Pix &_pix) pix = pixClone(_pix); rasterFormat = NULL; localPalette = NULL; - polyMarkers <<= _pix.polyMarkers; + markers <<= _pix.markers; return *this; } // END Pix::operator=() @@ -521,7 +521,7 @@ Pix &Pix::operator <<=(Pix &_pix) pix = pixCopy(NULL, _pix); rasterFormat = NULL; localPalette = NULL; - polyMarkers <<= _pix.polyMarkers; + markers <<= _pix.markers; return *this; } // END Pix::operator <<=() @@ -536,7 +536,7 @@ Pix &Pix::DeepCopy(Pix &_pix) pix = pixCopy(NULL, _pix); rasterFormat = NULL; localPalette = NULL; - polyMarkers <<= _pix.polyMarkers; + markers <<= _pix.markers; return *this; } // END Pix::DeepCopy() @@ -1113,7 +1113,7 @@ const RasterFormat *PixRaster::GetFormatEx(int page) ///////////////////////////////////////////////////////////////////////////////////////////////////////////// // read page polymarkers -PolyMarkers *PixRaster::GetPolyMarkersEx(int page) +Markers *PixRaster::GetMarkersEx(int page) { if (IsEmpty()) return NULL; @@ -1121,7 +1121,7 @@ PolyMarkers *PixRaster::GetPolyMarkersEx(int page) // gets true page number page = getTruePage(page); - return At(page).GetPolyMarkers(); + return At(page).GetMarkers(); } // END PixRaster::GetPolyMarkersEx() diff --git a/bazaar/PixRaster/PixRaster.h b/bazaar/PixRaster/PixRaster.h index 63b11443d..0007d790b 100644 --- a/bazaar/PixRaster/PixRaster.h +++ b/bazaar/PixRaster/PixRaster.h @@ -7,7 +7,7 @@ #include "lib/allheaders.h" #undef Pix -#include "PolyMarker.h" +#include "Marker.h" NAMESPACE_UPP @@ -51,7 +51,7 @@ class PixBase : public Raster virtual const RasterFormat *GetFormat() { return GetFormatEx(PIXRASTER_CURPAGE); } virtual int GetWidth() { return GetSize().cx; } virtual int GetHeight() { return GetSize().cy; } - virtual PolyMarkers *GetPolyMarkers() { return GetPolyMarkersEx(PIXRASTER_CURPAGE); } + virtual Markers *GetMarkers() { return GetMarkersEx(PIXRASTER_CURPAGE); } // extended Raster functions -- they allow to query @@ -64,7 +64,7 @@ class PixBase : public Raster virtual const RasterFormat *GetFormatEx(int page) = 0; virtual int GetWidthEx(int page) { return GetSizeEx(page).cx; } virtual int GetHeightEx(int page) { return GetSizeEx(page).cy; } - virtual PolyMarkers *GetPolyMarkersEx(int page) = 0; + virtual Markers *GetMarkersEx(int page) = 0; virtual bool IsEmpty() = 0; operator bool() { return !IsEmpty(); } @@ -96,7 +96,7 @@ class Pix : public PixBase RGBA *localPalette; // polygon markers - ArraypolyMarkers; + Markers markers; protected: @@ -198,8 +198,8 @@ class Pix : public PixBase virtual const RasterFormat *GetFormatEx(int page); // gets polygon markers - virtual PolyMarkers *GetPolyMarkers() { return &polyMarkers; } - virtual PolyMarkers *GetPolyMarkersEx(int) { return &polyMarkers; } + virtual Markers *GetMarkers() { return &markers; } + virtual Markers *GetMarkersEx(int) { return &markers; } // file I/O bool Load(FileIn &fs, int page = 0); @@ -366,8 +366,8 @@ class PixRaster : public PixBase virtual const RasterFormat *GetFormatEx(int page); // gets polygon markers - virtual PolyMarkers *GetPolyMarkers() { return GetPolyMarkersEx(PIXRASTER_CURPAGE); } - virtual PolyMarkers *GetPolyMarkersEx(int page); + virtual Markers *GetMarkers() { return GetMarkersEx(PIXRASTER_CURPAGE); } + virtual Markers *GetMarkersEx(int page); // check whether pixraster has images bool IsEmpty(void) { return !pages.GetCount(); }; diff --git a/bazaar/PixRaster/PixRaster.upp b/bazaar/PixRaster/PixRaster.upp index 191d16523..fe317bbf1 100644 --- a/bazaar/PixRaster/PixRaster.upp +++ b/bazaar/PixRaster/PixRaster.upp @@ -173,8 +173,8 @@ file PixRaster.h, PixRasterLoad.cpp, PixRaster.cpp, - PolyMarker.h, - PolyMarker.cpp, + Marker.h, + Marker.cpp, TiffIo.cpp, UppLept.cpp, Lept-Skew.cpp, diff --git a/bazaar/PixRaster/PolyMarker.cpp b/bazaar/PixRaster/PolyMarker.cpp deleted file mode 100644 index 6fa114ec0..000000000 --- a/bazaar/PixRaster/PolyMarker.cpp +++ /dev/null @@ -1,216 +0,0 @@ -#include "PolyMarker.h" - -using namespace Upp; - -// constructors -PolyMarker::PolyMarker() -{ - kind = Empty; - borderThickness = 0; - borderColor = Black; - borderLineType = 0; - fillColor.a = 0; - fillColor.r = 0; - fillColor.g = 0; - fillColor.b = 0; - closed = false; -} - -PolyMarker::PolyMarker(const PolyMarker &pm) -{ - kind = pm.GetKind(); - borderThickness = pm.GetBorderThickness(); - borderColor = pm.GetBorderColor(); - borderLineType = pm.GetBorderLineType(); - fillColor = pm.GetFillColor(); - closed = pm.IsClosed(); - -} - -// test for point hit -PolyMarker::HitKind PolyMarker::Hit(const Point &p, int minDist) -{ - - switch(kind) - { - case Empty: - return Miss; - - case Rectangle: - { - Point p1 = points[0]; - Point p2 = points[1]; - int x1 = min(p1.x, p2.x); - int y1 = min(p1.y, p2.y); - int x2 = max(p1.x, p2.x); - int y2 = max(p1.y, p2.y); - if(abs(p1.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) - return Vertex; - if(abs(p2.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) - return Vertex; - if(abs(p1.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) - return Side; - if(abs(p2.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) - return Side; - if(abs(p1.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= y2 + minDist) - return Side; - if(abs(p2.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= y2 + minDist) - return Side; - if(p.x > x1 && p.x < x2 && p.y > y1 && p.y < y2) - return Inside; - return Miss; - } - - case Polygon: - // FIXME -- support polygon - default: - NEVER(); - } // switch -} - -// gets vertex or side on point -One const PolyMarker::VertexAt(const Point &p, int minDist) -{ - switch(kind) - { - case Empty: - return One(); - - case Rectangle: - { - Point p1 = points[0]; - Point p2 = points[1]; - int x1 = min(p1.x, p2.x); - int y1 = min(p1.y, p2.y); - int x2 = max(p1.x, p2.x); - int y2 = max(p1.y, p2.y); - if(abs(p1.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) - return One(new Point(p1.x, p1.y)); - else if(abs(p2.x - p.x) <= minDist && abs(p1.y - p.y) <= minDist) - return One(new Point(p2.x, p1.y)); - else if(abs(p2.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) - return One(new Point(p2.x, p2.y)); - else if(abs(p1.x - p.x) <= minDist && abs(p2.y - p.y) <= minDist) - return One(new Point(p1.x, p2.y)); - return One(); - } - - case Polygon: - { - for(int i = 0; i < points.GetCount(); i++) - { - Point pi = points[i]; - if(abs(pi.x - p.x) <= minDist && abs(pi.y - p.y) <= minDist) - return One(new Point(pi)); - } - return One(); - } - - default: - return One(); - } // switch kind -} - -One const PolyMarker::SideAt(const Point &p, int minDist) -{ - switch(kind) - { - case Empty: - return One(); - - case Rectangle: - { - Point p1 = points[0]; - Point p2 = points[1]; - int x1 = min(p1.x, p2.x); - int y1 = min(p1.y, p2.y); - int x2 = max(p1.x, p2.x); - int y2 = max(p1.y, p2.y); - if(abs(p1.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) - return One(new Rect(Point(p1.x, y1), Point(p1.x, y2))); - else if(abs(p2.x - p.x) < minDist && p.y >= y1 - minDist && p.y <= y2 + minDist) - return One(new Rect(Point(p2.x, y1), Point(p2.x, y2))); - else if(abs(p1.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= x2 + minDist) - return One(new Rect(Point(x1, p1.y), Point(x2, p1.y))); - else if(abs(p2.y - p.y) < minDist && p.x >= x1 - minDist && p.x <= x2 + minDist) - return One(new Rect(Point(x1, p2.y), Point(x2, p2.y))); - return One(); - } - - case Polygon: - // fixme : add support - - default: - return One(); - - } // switch kind -} - - -// open/close the polygon (invalid for rectangle markers) -bool PolyMarker::Open(void) -{ - closed = false; - -} - -bool PolyMarker::Close(void) - -{ - closed = true; - -} - -// adds a vertex to the polygon (invalid for rectangle markers) -bool PolyMarker::AddVertex(const Point &p) -{ - if(closed || kind == Rectangle) - return false; - points.Add(p); - return true; - -} - -bool PolyMarker::AddVertex(const Array &ap) -{ - if(closed || kind == Rectangle || !ap.GetCount()) - return false; - for(int i = 0; i < ap.GetCount(); i++) - points.Add(ap[i]); - return true; -} - -void PolyMarker::MakeRect(const Point &p1, const Point &p2) -{ - points.Clear(); - points.Add(p1); - points.Add(p1); - kind = Rectangle; - closed = true; -} - -// clears the marker -void PolyMarker::Clear(void) -{ - points.Clear(); - kind = Empty; - closed = false; -} - -// gets a dragged PolyMarker giving start and end point -PolyMarker PolyMarker::Drag(const Point &startP, const Point &endP) -{ - -} - -// changes the PolyMarker at end of drag ops -void PolyMarker::DoDrag(const Point &startP, const Point &endP) -{ - -} - -// paint the PolyMarker on a given viewport -void PolyMarker::Paint(const Rect &vport) -{ - -} diff --git a/bazaar/PixRaster/PolyMarker.h b/bazaar/PixRaster/PolyMarker.h deleted file mode 100644 index 424b906e0..000000000 --- a/bazaar/PixRaster/PolyMarker.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef _PolyMarker_h_ -#define _PolyMarker_h_ - -#include - -NAMESPACE_UPP - -class PolyMarker -{ - public: - typedef PolyMarker CLASSNAME; - - enum HitKind { Miss, Vertex, Side, Inside }; - enum PolyKind { Empty, Rectangle, Polygon }; - - protected: - - PolyKind kind; - Array points; - int borderThickness; - Color borderColor; - int borderLineType; - RGBA fillColor; - bool closed; - - public: - - // constructors - PolyMarker(); - PolyMarker(const PolyMarker &pm); - - // test for point hit - HitKind Hit(const Point &p, int minDist); - - // gets nearest vertex or side to point - One const VertexAt(const Point &p, int minDist); - One const SideAt(const Point &p, int minDist); - - // open/close the polygon (invalid for rectangle markers) - bool Open(void); - bool Close(void); - - // adds a vertex to the polygon (invalid for rectangle markers) - bool AddVertex(const Point &p); - bool AddVertex(const Array &ap); - void MakeRect(const Point &p1, const Point &p2); - - // clears the marker - void Clear(void); - - // member read access - PolyKind GetKind(void) const { return kind; } - bool IsClosed(void) const { return closed; } - Color GetBorderColor(void) const { return borderColor; } - int GetBorderLineType(void) const { return borderLineType; } - int GetBorderThickness(void) const { return borderThickness; } - RGBA GetFillColor(void) const { return fillColor; } - Rect const &GetBoundingBox(void); - Array const &GetPoints(void); - - // gets a dragged PolyMarker giving start and end point - PolyMarker Drag(const Point &startP, const Point &endP); - - // changes the PolyMarker at end of drag ops - void DoDrag(const Point &startP, const Point &endP); - - // paint the PolyMarker on a given viewport - void Paint(const Rect &vport); - -} ; // END Class PolyMarker - -typedef Array PolyMarkers; - -END_UPP_NAMESPACE - -#endif diff --git a/bazaar/PixRaster/src.tpp/Pix$en-us.tpp b/bazaar/PixRaster/src.tpp/Pix$en-us.tpp new file mode 100644 index 000000000..2e5410a9b --- /dev/null +++ b/bazaar/PixRaster/src.tpp/Pix$en-us.tpp @@ -0,0 +1,291 @@ +topic "class Pix : public PixBase"; +[ $$0,0#00000000000000000000000000000000:Default] +[i448;a25;kKO9; $$1,0#37138531426314131252341829483380:structitem] +[l288;2 $$2,0#27521748481378242620020725143825:desc] +[0 $$3,0#96390100711032703541132217272105:end] +[H6;0 $$4,0#05600065144404261032431302351956:begin] +[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:codeitem] +[{_} +[s1;:Pix`:`:class: [@(0.0.255) class]_[* Pix]_:_[@(0.0.255) public]_[*@3 PixBase]&] +[s2;%% Single page Leptonica raster object.&] +[s2;%% It encapsulates [* Pix] single`-page Leptonica raster objects&] +[s2;%% &] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Public enums]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:PIXRASTER`_BRING`_IN`_WHITE: [@(0.0.255) enum]_[* BringInModes]&] +[s2;%% &] +[s2; Color filling mode in operations that adds parts to images, +for example rotations :&] +[s0; &] +[s5; -|[* PIXRASTER`_BRING`_IN`_WHITE]-|Fills new parts with white color&] +[s5; -|[* PIXRASTER`_BRING`_IN`_BLACK]-|Fills new parts with black color&] +[s2;%% &] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Constructors, destructor and assignment operator]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:Pix`(`): [* Pix]()&] +[s2;%% Constructs an empty [* Pix].&] +[s3; &] +[s4; &] +[s5;:Pix`:`:Pix`(int`,int`,int`,RGBA`*`): [* Pix]([@(0.0.255) int]_[*@3 width], +[@(0.0.255) int]_[*@3 height], [@(0.0.255) int]_[*@3 depth], [_^RGBA^ RGBA]_`*[*@3 colorTable +]_`=_NULL)&] +[s2;%% Constructs and initializes Pix of [%-*@3 width] , [%-*@3 height] +and [%-*@3 depth] .&] +[s2;%% Optionally sets its [%-*@3 colorTable] if available.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(PIX`*`*`): [* Pix]([_^PIX^ PIX]_`*`*[*@3 `_pix])&] +[s2;%% Constructs [* Pix] from the Leptonica [* PIX] [%-*@3 `_pix] object.&] +[s2;%% To avoid mis`-use of owned [* PIX], it clears source pointer; +beware to double indirection when using.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(Pix const`&`): [* Pix]([* Pix]_[@(0.0.255) const]_`&[*@3 `_pix])&] +[s2;%% Copy constructor. Initializes [* Pix] object from a source one +[%-*@3 `_pix].&] +[s2;%% Source is [* reference copied], so any change on copy will reflect +on original object.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(Pix const`&`,int`): [* Pix]([* Pix]_[@(0.0.255) const]_`&[*@3 `_pix], +[@(0.0.255) int]_[*@3 i])&] +[s2;%% Deep copy constructor. Initializes [* Pix] object from a source +one [%-*@3 `_pix].&] +[s2;%% Source is [* deep copied], so any change on copy will [* NOT] +reflect on original object.&] +[s2;%% &] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(Raster`&`,bool`,int`): [* Pix]([_^Raster^ Raster]_`&[*@3 raster], +[@(0.0.255) bool]_[*@3 deepCopy]_`=_[@(0.0.255) false], [@(0.0.255) int]_[*@3 page]_`=_PIXR +ASTER`_CURPAGE)&] +[s2;%% Constructs [* Pix] from [%-*@3 page] in source [%-*@3 raster] with +optional [%-*@3 deepCopy] &] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(FileIn`&`,int`): [* Pix]([_^FileIn^ FileIn]_`&[*@3 fs], +[@(0.0.255) int]_[*@3 page]_`=_[@3 0])&] +[s2;%% Constructs [* Pix] reading its content from opened stream [%-*@3 fs] +; if fs supports multipaged images, an optional argument [%-*@3 page] +can select one of them.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Pix`(String const`&`,int`): [* Pix]([_^String^ String]_[@(0.0.255) const]_`&[*@3 f +ileName], [@(0.0.255) int]_[*@3 page]_`=_[@3 0])&] +[s2;%% Constructs [* Pix] reading its content from [%-*@3 fileName] file; +if file format supports multipaged images, an optional argument +[%-*@3 page] can select one of them&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:`~Pix`(`): [@(0.0.255) `~][* Pix]()&] +[s2;%% Frees underlying PIX decrementing its reference counter and +deleting it if needed.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:operator`=`(Pix`&`): [_^Pix^ Pix]_`&[* operator`=]([_^Pix^ Pix]_`&[*@3 pix])&] +[s2;%% Assignment operator. [%-*@3 pix] is [* referenced], NOT copied, +so any change on destination [* Pix] will reflect on original one.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:operator`<`<`=`(Pix`&`): [_^Pix^ Pix]_`&[@(0.0.255) operator]_<<`=([_^Pix^ Pix]_ +`&[*@3 pix])&] +[s2;%% Assignment operator. [%-*@3 pix] is [* deep copied], NOT referenced, +so any change on destination [* Pix] will [* NOT ]reflect on original +one.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:DeepCopy`(Pix`&`): [_^Pix^ Pix]_`&[* DeepCopy]([_^Pix^ Pix]_`&[*@3 pix])&] +[s2;%% Return a [* deep copy] of [%-*@3 pix].&] +[s3;%% &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Internal handling of Leptonica objects]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:GetPIX`(int`): [@(0.0.255) virtual] [_^PIX^ PIX]_`*[* GetPIX]([@(0.0.255) int]_[*@3 p +age]_`=_PIXRASTER`_CURPAGE)&] +[s2;%% Gets underlying Leptonica [* PIX ]object for [%-*@3 page]. As +[* Pix] is single`-paged, just returns the underlying [* PIX] object.&] +[s2;%% [* WARNING], [* Pix] owns [* PIX ]object, so don`'t free it.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:operator PIX`*`(`): [* operator_PIX`*]()&] +[s2;%% Gets underlying Leptonica [* PIX ]object.&] +[s2;%% [* WARNING], [* Pix] owns [* PIX ]object, so don`'t free it.&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Page handling functions]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:SeekPage`(int`): [@(0.0.255) virtual] [@(0.0.255) void]_[* SeekPage]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Sets active [%-*@3 page]. As Pix object is single`-paged, does +nothing.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetPageCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPageCount]()&] +[s2;%% Gets number of images on PixRaster. As Pix object is single`-paged, +returns 1.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetActivePage`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetActivePage]()&] +[s2;%% Gets number of currently active page. As Pix object is single`-paged, +returns 0.&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Miscellaneous Raster functions]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:GetSize`(`): [@(0.0.255) virtual] [_^Size^ Size]_[* GetSize]()&] +[s2;%% Returns the size of Raster`'s active page in pixels.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetSizeEx`(int`): [@(0.0.255) virtual] [_^Size^ Size]_[* GetSizeEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the size of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetWidth`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetWidth]()&] +[s2;%% Returns the width of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetWidthEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetWidthEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the width of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetHeight`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetHeight]()&] +[s2;%% Returns the height of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetHeightEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetHeightEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the height of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetInfo`(`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_[* GetInfo]()&] +[s2;%% Returns the information about Raster`'s active page.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetInfoEx`(int`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_[* GetInfoEx(][@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the information about Raster for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetLine`(int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_[* GetLine]([@(0.0.255) i +nt]_[@3 line])&] +[s2;%% Reads a single scanline [%-*@3 line] from the raster`'s active +page. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetLineEx`(int`,int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_[* GetLine +Ex]([@(0.0.255) int]_[@3 line], [@(0.0.255) int]_[@3 page])&] +[s2;%% Reads a single scanline [%-*@3 line] from [%-*@3 page] ot the +raster. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetPaletteCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPaletteCount]( +)&] +[s2;%% Returns the size of palette for raster`'s active page. If +there is no palette, returns 0&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetPaletteCountEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPaletteCo +untEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the size of palette for raster`'s [%-*@3 page]. If there +is no palette, returns 0..&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetPalette`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_`*[* GetPa +lette]()&] +[s2;%% Returns active pages`'current palette, NULL if there is no +palette.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetPaletteEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_`*[* G +etPaletteEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns [%-*@3 page][%- `'s ]current palette, NULL if there is +no palette &] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:GetFormat`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ RasterF +ormat]_`*[* GetFormat]()&] +[s2;%% Returns the format of Raster`'s active page, can return NULL +if format is RGBA.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetFormatEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ Ra +sterFormat]_`*[* GetFormatEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the format of Raster`'s [%-*@3 page], can return NULL +if format is RGBA.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:IsEmpty`(`): [@(0.0.255) bool]_[* IsEmpty]()&] +[s2;%% Returns [%-@(0.0.255) true] if raster contains no images.&] +[s3; &] +[s4; &] +[s5;:Pix`:`:operator bool`(`): [* operator_bool]()&] +[s2;%% Returns true if raster has some content, false otherwise&] +[s3; &] +[s4; &] +[s5;:Pix`:`:Clear`(`): [@(0.0.255) virtual] [@(0.0.255) void]_[* Clear]()_`=_[@3 0]&] +[s2;%% Clears raster content&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Polygon markers access]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:GetPolyMarkers`(`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarkers]_`*[* GetP +olyMarkers]()&] +[s2;%% Returns array of polygon markers for current raster page&] +[s3; &] +[s4; &] +[s5;:Pix`:`:GetPolyMarkersEx`(int`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarkers]_`* +[* GetPolyMarkersEx]([@(0.0.255) int]_[@3 page])&] +[s2; [%% Returns array of polygon markers for raster ][@3 page]&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Conversion and file I/O functions]]}}&] +[s0; &] +[s4; &] +[s5;:Pix`:`:Load`(Raster`&`,bool`,int`): [@(0.0.255) void]_[* Load]([_^Raster^ Raster][@(0.0.255) `& +]_[*@3 raster], [@(0.0.255) bool]_[*@3 deepCopy]_`=_[@(0.0.255) false], +[@(0.0.255) int]_[*@3 page]_`=_PIXRASTER`_CURPAGE)&] +[s2;%% Initializes [* Pix] from [%-*@3 page] in source [%-*@3 raster] with +optional [%-*@3 deepCopy] &] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Load`(FileIn`&`,int`): [@(0.0.255) bool]_[* Load]([_^FileIn^ FileIn]_`&[*@3 fs], +[@(0.0.255) int]_[*@3 page]_`=_[@3 0])&] +[s2;%% Initializes [* Pix] reading its content from opened stream [%-*@3 fs] +; if fs supports multipaged images, an optional argument [%-*@3 page] +can select one of them.&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Load`(String`,int`): [@(0.0.255) bool]_[* Load]([_^String^ String]_[*@3 fileName], + [@(0.0.255) int]_[*@3 page]_`=_[@3 0])&] +[s2;%% Initializes [* Pix] reading its content from [%-*@3 fileName] +file; if file format supports multipaged images, an optional +argument [%-*@3 page] can select one of them&] +[s3;%% &] +[s4; &] +[s5;:Pix`:`:Save`(String`): [@(0.0.255) bool]_[* Save]([_^String^ String]_[*@3 fileName])&] +[s2;%% Stores Pix into [%-*@3 fileName] named file.&] +[s3;%% &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Leptonica functions wrappers]]}}&] +[s0; &] +[s2; [*^topic`:`/`/Leptonica`/src`/PixRaster`$en`-us`#PixRaster`:`:class^ Pix] +provides wrappers to many Leptonica image handling functions; +as the list is huge it has been divided by cathegories; see Leptonica +wrappers index.&] +[s0; ] \ No newline at end of file diff --git a/bazaar/PixRaster/src.tpp/PixBase$en-us.tpp b/bazaar/PixRaster/src.tpp/PixBase$en-us.tpp new file mode 100644 index 000000000..730e674ff --- /dev/null +++ b/bazaar/PixRaster/src.tpp/PixBase$en-us.tpp @@ -0,0 +1,159 @@ +topic "class PixBase : public Raster"; +[ $$0,0#00000000000000000000000000000000:Default] +[i448;a25;kKO9; $$1,0#37138531426314131252341829483380:structitem] +[l288;2 $$2,0#27521748481378242620020725143825:desc] +[0 $$3,0#96390100711032703541132217272105:end] +[H6;0 $$4,0#05600065144404261032431302351956:begin] +[i448;a25;kKO9;2 $$5,0#37138531426314131252341829483370:codeitem] +[{_} +[s1;:PixBase`:`:class: [@(0.0.255) class]_[* PixBase]_:_[@(0.0.255) public]_[*@3 Raster]&] +[s2;%% This is the base class of Leptonica raster objects, Pix and +PixRaster.&] +[s2;%% It has the sole purpose to provide a common base class for +Leptonica raster pointers,&] +[s2;%% with some common function prototypes for pointer access.&] +[s2;%% Used mainly inside PixRasterCtrl&] +[s2;%% PixBase is an abstract class and cannot be instantiated.&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Internal handling of Leptonica objects]]}}&] +[s0; &] +[s4; &] +[s5;:PixBase`:`:GetPIX`(int`): [@(0.0.255) virtual] [_^PIX^ PIX]_`*[* GetPIX]([@(0.0.255) int +]_[*@3 page]_`=_PIXRASTER`_CURPAGE)_`=_[@3 0]&] +[s2;%% Gets underlying Leptonica PIX object for [%-*@3 page].&] +[s3;%% &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Page handling functions]]}}&] +[s0; &] +[s4; &] +[s5;:PixBase`:`:SeekPage`(int`): [@(0.0.255) virtual] [@(0.0.255) void]_[* SeekPage]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Sets active [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetPageCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPageCount]()&] +[s2;%% Gets number of images on PixRaster&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetActivePage`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetActivePage]( +)&] +[s2;%% Gets number of currently active page&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Miscellaneous Raster functions]]}}&] +[s0; &] +[s4; &] +[s5;:PixBase`:`:GetSize`(`): [@(0.0.255) virtual] [_^Size^ Size]_[* GetSize]()&] +[s2;%% Returns the size of Raster`'s active page in pixels.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetSizeEx`(int`): [@(0.0.255) virtual] [_^Size^ Size]_[* GetSizeEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the size of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetWidth`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetWidth]()&] +[s2;%% Returns the width of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetWidthEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetWidthEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the width of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetHeight`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetHeight]()&] +[s2;%% Returns the height of Raster in pixels for active page.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetHeightEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetHeightEx]([@(0.0.255) i +nt]_[@3 page])&] +[s2;%% Returns the height of Raster in pixels for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetInfo`(`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_[* GetInfo]()&] +[s2;%% Returns the information about Raster`'s active page.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetInfoEx`(int`): [@(0.0.255) virtual] [_^Raster`:`:Info^ Info]_[* GetInfoE +x(][@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the information about Raster for [%-*@3 page].&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetLine`(int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_[* GetLine]([@(0.0.255) i +nt]_[@3 line])&] +[s2;%% Reads a single scanline [%-*@3 line] from the raster`'s active +page. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetLineEx`(int`,int`): [@(0.0.255) virtual] [_^Raster`:`:Line^ Line]_[* Get +LineEx]([@(0.0.255) int]_[@3 line], [@(0.0.255) int]_[@3 page])&] +[s2;%% Reads a single scanline [%-*@3 line] from [%-*@3 page] ot the +raster. If possible, Raster should be optimized for reading scanlines +in ascending order `- this what most processing functions (should) +require.&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetPaletteCount`(`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPaletteCou +nt]()&] +[s2;%% Returns the size of palette for raster`'s active page. If +there is no palette, returns 0&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetPaletteCountEx`(int`): [@(0.0.255) virtual] [@(0.0.255) int]_[* GetPalet +teCountEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the size of palette for raster`'s [%-*@3 page]. If there +is no palette, returns 0..&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetPalette`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_`*[* G +etPalette]()&] +[s2;%% Returns active pages`'current palette, NULL if there is no +palette.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetPaletteEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RGBA^ RGBA]_ +`*[* GetPaletteEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns [%-*@3 page][%- `'s ]current palette, NULL if there is +no palette &] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:GetFormat`(`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ Ras +terFormat]_`*[* GetFormat]()&] +[s2;%% Returns the format of Raster`'s active page, can return NULL +if format is RGBA.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetFormatEx`(int`): [@(0.0.255) virtual] [@(0.0.255) const]_[_^RasterFormat^ R +asterFormat]_`*[* GetFormatEx]([@(0.0.255) int]_[@3 page])&] +[s2;%% Returns the format of Raster`'s [%-*@3 page], can return NULL +if format is RGBA.&] +[s3;%% &] +[s4; &] +[s5;:PixBase`:`:IsEmpty`(`): [@(0.0.255) bool]_[* IsEmpty]()&] +[s2;%% Returns [%-@(0.0.255) true] if raster contains no images.&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:operator bool`(`): [* operator_bool]()&] +[s2;%% Returns true if raster has some content, false otherwise&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:Clear`(`): [@(0.0.255) virtual] [@(0.0.255) void]_[* Clear]()_`=_[@3 0]&] +[s2;%% Clears raster content&] +[s3; &] +[s0; &] +[ {{10000F(128)G(128)@1 [s0;%% [* Polygon markers access]]}}&] +[s0; &] +[s4; &] +[s5;:PixBase`:`:GetPolyMarkers`(`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarkers]_`*[* G +etPolyMarkers]()&] +[s2;%% Returns array of polygon markers for current raster page&] +[s3; &] +[s4; &] +[s5;:PixBase`:`:GetPolyMarkersEx`(int`): [@(0.0.255) virtual] [_^PolyMarkers^ PolyMarkers +]_`*[* GetPolyMarkersEx]([@(0.0.255) int]_[@3 page])&] +[s2; [%% Returns array of polygon markers for raster ][@3 page]&] +[s3; &] +[s0; ] \ No newline at end of file diff --git a/bazaar/PixRasterCtrl/ImageCache.cpp b/bazaar/PixRasterCtrl/ImageCache.cpp index 72ed77b5c..8081ff92b 100644 --- a/bazaar/PixRasterCtrl/ImageCache.cpp +++ b/bazaar/PixRasterCtrl/ImageCache.cpp @@ -1,5 +1,6 @@ #include "ImageCache.h" +NAMESPACE_UPP /////////////////////////////////////////////////////////////////////////////////////////////// // constructor @@ -356,3 +357,5 @@ Size const ImageCache::GetSize(void) return imageBuffer.GetSize(); } // EBND ImageCache::GetSize() + +END_UPP_NAMESPACE diff --git a/bazaar/PixRasterCtrl/ImageCache.h b/bazaar/PixRasterCtrl/ImageCache.h index d865dcfae..6a4fef7d9 100644 --- a/bazaar/PixRasterCtrl/ImageCache.h +++ b/bazaar/PixRasterCtrl/ImageCache.h @@ -3,7 +3,7 @@ #include -using namespace Upp; +NAMESPACE_UPP class ImageCache { @@ -59,4 +59,6 @@ class ImageCache }; // END Class ImageCache +END_UPP_NAMESPACE + #endif diff --git a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp index 0b92d6150..8dd872360 100644 --- a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.cpp @@ -1,6 +1,8 @@ #include "PixRasterBaseCtrl.h" #include "PixRasterCtrl.h" +NAMESPACE_UPP + #define BackColor SColorFace() /////////////////////////////////////////////////////////////////////////////////////////////// @@ -29,6 +31,11 @@ PixRasterBaseCtrl::PixRasterBaseCtrl(PixRasterCtrl *t, bool hScroll, bool vScrol // marks cache as invalid imageCache.SetValid(false); + // no marker selected + selectedMarker = NULL; + highlightMarker = NULL; + dragPolygon.Clear(); + } // END constructor class PixRasterBaseCtrl /////////////////////////////////////////////////////////////////////////////////////////////// @@ -37,6 +44,167 @@ PixRasterBaseCtrl::~PixRasterBaseCtrl() { } // END destructor class PixRasterBaseCtrl +/////////////////////////////////////////////////////////////////////////////////////////////// +// converts a page and an array of page points into an array of view points +Vector PixRasterBaseCtrl::PointsToView(int page, Vector const &pts) +{ + // gets the PixRaster object + PixBase *pixBase = pixRasterCtrl->GetPixBase(); + + // calculate view position inside the full tiff image + // in page coords + int viewLeft, viewTop; + if(hScrollBar.IsVisible()) + viewLeft = ScaleToPage(hScrollBar.Get()); + else + viewLeft = 0; + if(vScrollBar.IsVisible()) + viewTop = ScaleToPage(vScrollBar.Get()); + else + viewTop = 0; + + // gets requested page position (in page coordinates) + int pageTop = 0; + int gapSize = ScaleToPage(10); + for(int i = 0; i < page; i++) + pageTop += pixBase->GetHeightEx(i) + gapSize; + + // if page not visible, just return an empty array + int pageBottom = pageTop + pixBase->GetHeightEx(page); + int viewBottom = viewTop + ScaleToPage(GetSize().cy); + if(viewBottom < pageTop || viewTop > pageBottom) + return Vector(); + + // horizontal gap if page width < ctrl width + int viewWidth = ScaleToPage(GetSize().cx); + int pageWidth = pixBase->GetWidthEx(page); + int hGap; + if(pageWidth < viewWidth) + hGap = (viewWidth - pageWidth) / 2; + else + hGap = 0; + + // calculates the offset of points in page coordinates + int dx = -viewLeft + hGap; + int dy = -viewTop + pageTop; + + // creates the new array scaling the coordinates + Vectorres(pts, 1); + for(int iPoint = 0; iPoint < res.GetCount(); iPoint++) + { + res[iPoint].x = ScaleToView(res[iPoint].x + dx); + res[iPoint].y = ScaleToView(res[iPoint].y + dy); + } + return res; + +} // END PixRasterBaseCtrl::PointsToView() + +/////////////////////////////////////////////////////////////////////////////////////////////// +// converts a view point into page + page point +bool PixRasterBaseCtrl::PointToPage(Point const &srcPt, int &page, Point &destPt) +{ + if(!pixRasterCtrl) + return false; + + // gets the PixRaster object + PixBase *pixBase = pixRasterCtrl->GetPixBase(); + if(!pixBase || !pixBase->GetPageCount()) + return false; + + // gets point position in raster coordinates + int yPos = ScaleToPage(vScrollBar.Get() + srcPt.y); + + // gets gap size between pages + int gapSize = ScaleToPage(10); + + // iterates through page positions to find the requested one + int top = 0; + for(int iPage = 0; iPage < pixBase->GetPageCount(); iPage++) + { + int pageWidth = pixBase->GetWidthEx(iPage); + int pageHeight = pixBase->GetHeightEx(iPage); + int bottom = top + pageHeight; + + if(yPos >= top && yPos <= bottom) + { + int xPos; + if(ScaleToView(pageWidth) >= GetSize().cx) + xPos = ScaleToPage(srcPt.x); + else + xPos = ScaleToPage(srcPt.x) - (ScaleToPage(GetSize().cx) - pageWidth) / 2; + if(xPos < 0 || xPos > pageWidth) + return false; + destPt = Point(xPos, yPos - top); + page = iPage; + return true; + } + top += pageHeight + gapSize; + } + +} // END PixRasterBaseCtrl::PointToPage() + +/////////////////////////////////////////////////////////////////////////////////////////////// +// left mouse button handlers +void PixRasterBaseCtrl::LeftDown(Point p, dword keyflags) +{ + // translates mouse coordinate in page and page coordinates + int page; + Point pagePt; + if(!PointToPage(p, page, pagePt)) + return; + + // found a page on point, scan it to get the marker on it (if any) + + // gets the PixRaster object + PixBase *pixBase = pixRasterCtrl->GetPixBase(); + + int minDist = ScaleToPage(5); + Markers *markers = pixBase->GetMarkersEx(page); + for(int i = 0; i < markers->GetCount(); i++) + { + Marker &marker = (*markers)[i]; + int index; + Marker::HitKind hitKind = marker.Hit(pagePt, minDist, index); + if(hitKind == Marker::Miss) + continue; + + // found a marker on cursor -- start drag op + dragPolygon = PointsToView(page, marker.DragOutline(pagePt, pagePt, minDist)); + selectedMarker = ▮ + dragPoint = pagePt; + dragPage = page; + } + + +} // END PixRasterBaseCtrl::LeftDown() + +void PixRasterBaseCtrl::LeftUp(Point p, dword keyflags) +{ + Point endDragPoint; + int endDragPage; + + // if dragging a marker, stop and update it + if(selectedMarker) + { + int minDist = ScaleToPage(5); + PointToPage(p, endDragPage, endDragPoint); + // if dest point still on page, complete dragging op + // otherwise abort it + if(endDragPage == dragPage) + selectedMarker->Drag(dragPoint, endDragPoint, minDist); + selectedMarker = NULL; + pixRasterCtrl->Refresh(); + } + +} // END PixRasterBaseCtrl::LeftDown() + +/////////////////////////////////////////////////////////////////////////////////////////////// +// right mouse button handlers +void PixRasterBaseCtrl::RightDown(Point p, dword keyflags) +{ + +} // END PixRasterBaseCtrl::RightDown() + /////////////////////////////////////////////////////////////////////////////////////////////// // middle mouse button pan handlers void PixRasterBaseCtrl::MiddleDown(Point p, dword keyflags) @@ -49,27 +217,77 @@ void PixRasterBaseCtrl::MiddleDown(Point p, dword keyflags) void PixRasterBaseCtrl::MouseMove(Point p, dword keyflags) { - // reacts only to moves with middle button pressed - if(!(keyflags & K_MOUSEMIDDLE)) + Point endDragPoint; + int endDragPage; + + if(!pixRasterCtrl || !pixRasterCtrl->GetPixBase()) return; - // gets distance between current and pan point - int dx = panPoint.x - p.x + panHScroll; - int dy = panPoint.y - p.y + panVScroll; - - // gets max scrolling values - int hMax = hScrollBar.GetTotal(); - int vMax = vScrollBar.GetTotal(); + // check what we're dragging.... + if(keyflags & K_MOUSEMIDDLE) + { + // moves with middle button pressed -- panning image + + // gets distance between current and pan point + int dx = panPoint.x - p.x + panHScroll; + int dy = panPoint.y - p.y + panVScroll; - // sets new pan position - if(dx < 0) dx = 0; - if(dx > hMax) dx = hMax; - if(dy < 0) dy = 0; - if(dy > vMax) dy = vMax; - hScrollBar.Set(dx); - vScrollBar.Set(dy); + // gets max scrolling values + int hMax = hScrollBar.GetTotal(); + int vMax = vScrollBar.GetTotal(); + + // sets new pan position + if(dx < 0) dx = 0; + if(dx > hMax) dx = hMax; + if(dy < 0) dy = 0; + if(dy > vMax) dy = vMax; + hScrollBar.Set(dx); + vScrollBar.Set(dy); + + Refresh(); + } + else if((keyflags & K_MOUSELEFT) && selectedMarker) + { + // dragging a marker + + int minDist = ScaleToPage(5); + PointToPage(p, endDragPage, endDragPoint); - Refresh(); + if(endDragPage == dragPage) + dragPolygon = PointsToView(dragPage, selectedMarker->DragOutline(dragPoint, endDragPoint, minDist)); + else + dragPolygon.Clear(); + pixRasterCtrl->Refresh(); + } + else + { + // nothing else, just highlight marker under cursor + // and set the appropriate cursor + int page; + Point pagePt; + int minDist = ScaleToPage(5); + Marker *newMarker = NULL; + if(PointToPage(p, page, pagePt)) + { + PixBase *pixBase = pixRasterCtrl->GetPixBase(); + Markers *markers = pixBase->GetMarkersEx(page); + for(int iMarker = 0; iMarker < markers->GetCount(); iMarker++) + { + Marker &marker = (*markers)[iMarker]; + int index; + if(marker.Hit(pagePt, minDist, index) != Marker::Miss) + { + newMarker = ▮ + break; + } + } + } + if(highlightMarker != newMarker) + { + highlightMarker = newMarker; + pixRasterCtrl->Refresh(); + } + } } // END PixRasterBaseCtrl::MouseMove() @@ -181,14 +399,14 @@ void PixRasterBaseCtrl::PaintCache() pixBase->SeekPage(i); // translates current top of page in view coordinates - int viewCurrentTop = iscale(currentTop, imageScale, 1000); + int viewCurrentTop = ScaleToView(currentTop); // gets current page size and translates it in view coordinates Rect viewPageRect( -cacheLeft, -cacheTop + viewCurrentTop, - iscale(pixBase->GetSize().cx, imageScale, 1000) - cacheLeft, - iscale(pixBase->GetSize().cy, imageScale, 1000) - cacheTop + viewCurrentTop + ScaleToView(pixBase->GetSize().cx) - cacheLeft, + ScaleToView(pixBase->GetSize().cy) - cacheTop + viewCurrentTop ); // now scans the rectangles that must be repainted @@ -206,10 +424,10 @@ void PixRasterBaseCtrl::PaintCache() { // gets back the tiff rectangle Rect tiffRect( - iscale(rect.left + cacheLeft, 1000, imageScale), - iscale(rect.top + cacheTop, 1000, imageScale) - currentTop, - iscale(rect.right + cacheLeft, 1000, imageScale), - iscale(rect.bottom + cacheTop, 1000, imageScale) -currentTop + ScaleToPage(rect.left + cacheLeft), + ScaleToPage(rect.top + cacheTop) - currentTop, + ScaleToPage(rect.right + cacheLeft), + ScaleToPage(rect.bottom + cacheTop) -currentTop ); // rescales the image area @@ -223,7 +441,7 @@ void PixRasterBaseCtrl::PaintCache() imageCache.Copy(Point(rect.left, rect.top), Rect(0, 0, img.GetWidth(), img.GetHeight()), img); } } - currentTop += pixBase->GetHeight() + iscale(10, 1000, imageScale); + currentTop += pixBase->GetHeight() + ScaleToPage(10); } // restore PixRaster's active page @@ -234,8 +452,105 @@ void PixRasterBaseCtrl::PaintCache() /////////////////////////////////////////////////////////////////////////////////////////////// // repaint polygon markers over the images -void PixRasterBaseCtrl::PaintMarkers(void) +void PixRasterBaseCtrl::PaintMarkers(Draw &d) { + // if no associated PixRaster object, do nothing + if(!pixRasterCtrl || !pixRasterCtrl->GetPixBase()) + return; + + // gets associated PixRaster object + PixBase *pixBase = pixRasterCtrl->GetPixBase(); + + // calculate view position inside the full tiff image + int left, top; + if(hScrollBar.IsVisible()) + left = hScrollBar.Get(); + else + left = 0; + if(vScrollBar.IsVisible()) + top = vScrollBar.Get(); + else + top = 0; + + // loop for all pages, to see which of them fits the view + int currentTop = 0; + int currentPage = pixBase->GetActivePage(); + for(int i = 0 ; i < pixBase->GetPageCount() ; i++) + { + // sets the active page + pixBase->SeekPage(i); + + // translates current top of page in view coordinates + int viewCurrentTop = ScaleToView(currentTop); + + // gets current page size and translates it in view coordinates + Rect viewPageRect( + -left, + -top + viewCurrentTop, + ScaleToView(pixBase->GetSize().cx) - left, + ScaleToView(pixBase->GetSize().cy) - top + viewCurrentTop + ); + + // this is when page view is smaller than ctrl view + int hGap; + int pw = viewPageRect.right - viewPageRect.left; + if(pw >= GetSize().cx) + hGap = 0; + else + hGap = (GetSize().cx - pw) / 2; + + // checks wether the page fits the view.. + viewPageRect.Intersect(GetView()); + if(!viewPageRect.IsEmpty()) + { + + // this page is inside view, let's take its markers + Markers &markers = *pixBase->GetMarkers(); + for(int iMarker = 0; iMarker < markers.GetCount(); iMarker++) + { + Marker &marker = markers[iMarker]; + + // don't paint marker being dragged... it will be done by + // drag routine itself + if(&marker == selectedMarker) + continue; + + switch(marker.GetKind()) + { + case Marker::EmptyMarker: + continue; + + default: + Vector pts = marker.GetPoints(); + Point points[pts.GetCount()]; + for(int i = 0; i < pts.GetCount(); i++) + { + points[i].x = ScaleToView(pts[i].x) - left + hGap; + points[i].y = ScaleToView(pts[i].y) - top + viewCurrentTop; + } + if(&marker != highlightMarker) + d.DrawPolygon(points, pts.GetCount(), + marker.GetFillColor(), + marker.GetBorderThickness(), + marker.GetBorderColor(), + marker.GetBorderLineType(), + White); + else + d.DrawPolygon(points, pts.GetCount(), + marker.GetSelFillColor(), + marker.GetSelBorderThickness(), + marker.GetSelBorderColor(), + marker.GetSelBorderLineType(), + White); + break; + } + } + } + currentTop += pixBase->GetHeight() + ScaleToPage(10); + } + + // restore PixRaster's active page + pixBase->SeekPage(currentPage); } // END PixRasterBaseCtrl::PaintMarkers() @@ -258,6 +573,20 @@ void PixRasterBaseCtrl::Paint(Draw &d) imageCache.Paint(d, Point(0, 0)); else imageCache.Paint(d, Point((GetSize().cx - imageCache.GetWidth()) / 2, 0)); + + // paints markers inside control + PaintMarkers(d); + + // if dragging, paints rubber banded polygon + if(selectedMarker && dragPolygon.GetCount()) + { + d.DrawPolygon(dragPolygon, dragPolygon.GetCount(), + selectedMarker->GetFillColor(), + selectedMarker->GetBorderThickness(), + selectedMarker->GetBorderColor(), + PEN_DOT, + White); + } } // END LeptonicaBaseCtrl::Paint() @@ -334,14 +663,14 @@ void PixRasterBaseCtrl::Layout(void) } // now calculate gaps to be exactly 10 pixels in every zoom factor - int gapSize = iscale(10, 1000, imageScale); + int gapSize = ScaleToPage(10); // adds total gaps sizes to total height rasterHeight += (pageCount -1) * gapSize; // and finally, sets up scrollbars and shows them // and calculate cache sizes - int scaledRasterHeight = iscale(rasterHeight, imageScale, 1000); + int scaledRasterHeight = ScaleToView(rasterHeight); int cacheHeight; vScrollBar.SetPage(GetSize().cy); vScrollBar.SetTotal(scaledRasterHeight); @@ -360,7 +689,7 @@ void PixRasterBaseCtrl::Layout(void) vScrollBar.Hide(); cacheHeight = scaledRasterHeight; } - int scaledRasterWidth = iscale(rasterWidth, imageScale, 1000); + int scaledRasterWidth = ScaleToView(rasterWidth); int cacheWidth; hScrollBar.SetPage(GetSize().cx); hScrollBar.SetTotal(scaledRasterWidth); @@ -389,4 +718,6 @@ void PixRasterBaseCtrl::Layout(void) // mark layout terminated inside = false; -} // END LeptonicaBaseCtrl::Layout() +} // END PixRasterBaseCtrl::Layout() + +END_UPP_NAMESPACE diff --git a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h index 8458bbcbb..47f5a3695 100644 --- a/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterBaseCtrl.h @@ -5,16 +5,17 @@ #include "ImageCache.h" -using namespace Upp; +NAMESPACE_UPP; // types of zoom inside view enum ZoomTypes { ZOOM_NORMAL, ZOOM_WIDTH, ZOOM_PAGE }; -// forward declaration +// forward declarations class PixRasterCtrl; +class Marker; // Tiff view ctrl class -class PixRasterBaseCtrl : public Ctrl +class PixRasterBaseCtrl : public LocalLoop { public : typedef PixRasterBaseCtrl CLASSNAME; @@ -34,9 +35,21 @@ class PixRasterBaseCtrl : public Ctrl // calculates image scale factor // pure virtual function, MUST be redefined on derived classes virtual int CalcScale(int imageScale, int rasterWidth, int maxPageHeight) = 0; + + // scales a coordinate from page to view + inline int ScaleToView(int x) { return iscale(x, imageScale, 1000); } + + // scales a coordinate from view to page + inline int ScaleToPage(int x) { return iscale(x, 1000, imageScale); } + + // converts a page and an array of page points into an array of view points + Vector PointsToView(int page, Vector const &pts); + + // converts a view point into page + page point + bool PointToPage(Point const &srcPt, int &page, Point &destPt); // scrollbar handler - virtual void OnScroll(void); + virtual void OnScroll(); // paint routine virtual void Paint(Draw &d); @@ -46,24 +59,42 @@ class PixRasterBaseCtrl : public Ctrl int cacheLeft, cacheTop; // repaint images on image cache - virtual void PaintCache(void); + virtual void PaintCache(); // repaint polygon markers over the images - virtual void PaintMarkers(void); + virtual void PaintMarkers(Draw &d); + + // mouse button handlers + virtual void LeftDown(Point p, dword keyflags); + virtual void LeftUp(Point p, dword keyflags); + virtual void MiddleDown(Point p, dword keyflags); + virtual void RightDown(Point p, dword keyflags); + virtual void MouseMove(Point p, dword keyflags); // mouse wheel handler virtual void MouseWheel(Point p, int zdelta, dword keyflags); - // pan point on middle mouse button pan operations + // point for pan operations Point panPoint; int panHScroll, panVScroll; - // mouse button pan handlers - virtual void MiddleDown(Point p, dword keyflags); - virtual void MouseMove(Point p, dword keyflags); - virtual Image CursorImage(Point p, dword keyflags); + // highlighted marker (under mouse cursor) + Marker *highlightMarker; + + // selected marker and drag mode + Marker *selectedMarker; + + // page on which dragging is done + int dragPage; + + // starting drag point + Point dragPoint; + + // current polygon in dragging ops + VectordragPolygon; + public : // constructor @@ -77,4 +108,6 @@ class PixRasterBaseCtrl : public Ctrl } ; // END class PixRasterBaseCtrl +END_UPP_NAMESPACE + #endif diff --git a/bazaar/PixRasterCtrl/PixRasterCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterCtrl.cpp index 30b24c78c..5a1752eb6 100644 --- a/bazaar/PixRasterCtrl/PixRasterCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterCtrl.cpp @@ -3,6 +3,8 @@ #include "PixRasterThumbsCtrl.h" #include "PixRasterViewCtrl.h" +NAMESPACE_UPP + // initialize the control void PixRasterCtrl::Create(PixBase *_pixBase) { @@ -152,3 +154,4 @@ void PixRasterCtrl::Reload(void) view->Layout(); } +END_UPP_NAMESPACE diff --git a/bazaar/PixRasterCtrl/PixRasterCtrl.h b/bazaar/PixRasterCtrl/PixRasterCtrl.h index 5ae56c685..77d3a4d1a 100644 --- a/bazaar/PixRasterCtrl/PixRasterCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterCtrl.h @@ -7,7 +7,7 @@ #include "PixRasterBaseCtrl.h" -using namespace Upp; +NAMESPACE_UPP class PixRasterThumbsCtrl; class PixRasterViewCtrl; @@ -84,4 +84,6 @@ class PixRasterCtrl : public Ctrl } ; // END Class PixRasterCtrl +END_UPP_NAMESPACE + #endif diff --git a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp index ab6a53d53..a361cc749 100644 --- a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.cpp @@ -1,6 +1,8 @@ #include "PixRasterThumbsCtrl.h" #include "PixRasterCtrl.h" +NAMESPACE_UPP + // Scale factor between pane size and thumbs sizes const int THUMBS_HSIZE_MUL = 9; const int THUMBS_HSIZE_DIV = 10; @@ -36,10 +38,10 @@ void PixRasterThumbsCtrl::LeftDown(Point p, dword keyflags) { // gets point position in raster coordinates int clickPos = vScrollBar.Get() + iscale(p.y, vScrollBar.GetPage(), GetView().GetHeight()); - clickPos = iscale(clickPos, 1000, imageScale); + clickPos = ScaleToPage(clickPos); // gets gap size between pages - int gapSize = iscale(10, 1000, imageScale); + int gapSize = ScaleToPage(10); // gets the PixRaster object PixBase *pixBase = pixRasterCtrl->GetPixBase(); @@ -58,4 +60,9 @@ void PixRasterThumbsCtrl::LeftDown(Point p, dword keyflags) top += pixBase->GetHeightEx(iPage) + gapSize; } + // calls base class handler -- used for dragging + PixRasterBaseCtrl::LeftDown(p, keyflags); + } // END PixRasterThumbsCtrl::LeftDown() + +END_UPP_NAMESPACE diff --git a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.h b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.h index e460f0858..1d5fec489 100644 --- a/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterThumbsCtrl.h @@ -7,7 +7,7 @@ #include "PixRasterBaseCtrl.h" -using namespace Upp; +NAMESPACE_UPP // forward declaration class PixRasterCtrl; @@ -31,8 +31,10 @@ class PixRasterThumbsCtrl : public PixRasterBaseCtrl ~PixRasterThumbsCtrl(); // left click handler --> shows requested page in viewer - void LeftDown(Point p, dword keyflags); + virtual void LeftDown(Point p, dword keyflags); } ; // END class PixRasterThumbsCtrl +END_UPP_NAMESPACE + #endif diff --git a/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp b/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp index f7c445d98..a895d8686 100644 --- a/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp +++ b/bazaar/PixRasterCtrl/PixRasterViewCtrl.cpp @@ -1,6 +1,8 @@ #include "PixRasterViewCtrl.h" #include "PixRasterCtrl.h" +NAMESPACE_UPP + #define BackColor SColorFace() /////////////////////////////////////////////////////////////////////////////////////////////// @@ -188,3 +190,5 @@ void PixRasterViewCtrl::SetPage(int page) Layout(); } // END PixRasterViewCtrl::SetPage() + +END_UPP_NAMESPACE diff --git a/bazaar/PixRasterCtrl/PixRasterViewCtrl.h b/bazaar/PixRasterCtrl/PixRasterViewCtrl.h index 24c27d403..20128c823 100644 --- a/bazaar/PixRasterCtrl/PixRasterViewCtrl.h +++ b/bazaar/PixRasterCtrl/PixRasterViewCtrl.h @@ -5,7 +5,7 @@ #include "PixRasterBaseCtrl.h" -using namespace Upp; +NAMESPACE_UPP // Tiff view ctrl class class PixRasterViewCtrl : public PixRasterBaseCtrl @@ -53,4 +53,6 @@ class PixRasterViewCtrl : public PixRasterBaseCtrl } ; // END class PixRasterViewCtrl +END_UPP_NAMESPACE + #endif diff --git a/bazaar/TestLeptonica/PageLayout.cpp b/bazaar/TestLeptonica/PageLayout.cpp index 5e835f224..95d118de6 100644 --- a/bazaar/TestLeptonica/PageLayout.cpp +++ b/bazaar/TestLeptonica/PageLayout.cpp @@ -5,7 +5,7 @@ static void PageLayout(Pix &source, PixRaster &pixRaster) pixRaster.Add(source); PixRaster regions = source.GetRegionsBinary(); CHECKR(regions, "Error getting page layout"); - pixRaster.Add(regions); + pixRaster.Add(regions); } void TestLeptonica::onPageLayout() diff --git a/bazaar/TestLeptonica/PageMarkers.cpp b/bazaar/TestLeptonica/PageMarkers.cpp new file mode 100644 index 000000000..98e5069f4 --- /dev/null +++ b/bazaar/TestLeptonica/PageMarkers.cpp @@ -0,0 +1,40 @@ +#include "TestLeptonica.h" + +static void PageMarkers(Pix & source, PixRaster &pixRaster) +{ + Markers *markers; + + pixRaster.Add(source, true); + pixRaster.Add(source, true); + + markers = pixRaster[0].GetMarkers(); + markers->Add(new Marker(Point(100, 100), Point(300, 400))); + markers->Add(new Marker(Point(0, 500), Point(300, 800))); + markers = pixRaster[1].GetMarkers(); + markers->Add(new Marker(Point(0, 0), Point(200, 100))); + markers->Add(new Marker(Point(400, 500), Point(900, 600))); + +} + +void TestLeptonica::onPageMarkers() +{ + String fileName; + FileSelector fs; + + Pix source; + + FileIn s("/home/massimo/tmp/TestLept1.tif"); + + // Loads pixraster from source raster + CHECKR(source.Load(s), "Error loading image"); + s.Close(); + + // apply line removal algothithm + pixRaster.Clear(); + PageMarkers(source, pixRaster); + + // refresh the PixRasterCtrl control with the new image contents + pixRasterCtrl.Reload(); + pixRasterCtrl.SetPage(0); + +} diff --git a/bazaar/TestLeptonica/TestLeptonica.h b/bazaar/TestLeptonica/TestLeptonica.h index 13757c117..4fa12d84e 100644 --- a/bazaar/TestLeptonica/TestLeptonica.h +++ b/bazaar/TestLeptonica/TestLeptonica.h @@ -29,6 +29,7 @@ class TestLeptonica : public WithTestLeptonicaLayout void onLineRemoval(void); void onPageLayout(void); void onBaseLine(void); + void onPageMarkers(void); void onQuit(void); // PIX raster diff --git a/bazaar/TestLeptonica/TestLeptonica.lay b/bazaar/TestLeptonica/TestLeptonica.lay index 02b13e1b5..a8e912368 100644 --- a/bazaar/TestLeptonica/TestLeptonica.lay +++ b/bazaar/TestLeptonica/TestLeptonica.lay @@ -1,8 +1,9 @@ LAYOUT(TestLeptonicaLayout, 640, 400) - ITEM(Button, BaseLineButton, SetLabel(t_("Baseline test")).Tip(t_("Find baseline of text lines of a scanned page")).LeftPosZ(8, 92).TopPosZ(56, 15)) + ITEM(Button, PageMarkersButton, SetLabel(t_("Page markers")).Tip(t_("Test page area marking")).LeftPosZ(8, 92).TopPosZ(80, 15)) ITEM(Button, QuitButton, SetLabel(t_("\aQuit")).LeftPosZ(8, 92).BottomPosZ(9, 15)) ITEM(PixRasterCtrl, pixRasterCtrl, SetFrame(InsetFrame()).HSizePosZ(108, 8).VSizePosZ(8, 8)) ITEM(Button, LineRemovalButton, SetLabel(t_("Line removal test")).Tip(t_("Removes horizontal lines from a scanned paper drawing")).LeftPosZ(8, 92).TopPosZ(8, 15)) ITEM(Button, PageLayoutButton, SetLabel(t_("Page layout test")).Tip(t_("Finds the layout of a page, separating graphics from text")).LeftPosZ(8, 92).TopPosZ(32, 15)) + ITEM(Button, BaseLineButton, SetLabel(t_("Baseline test")).Tip(t_("Find baseline of text lines of a scanned page")).LeftPosZ(8, 92).TopPosZ(56, 15)) END_LAYOUT diff --git a/bazaar/TestLeptonica/TestLeptonica.upp b/bazaar/TestLeptonica/TestLeptonica.upp index 2768d7129..31a3c6502 100644 --- a/bazaar/TestLeptonica/TestLeptonica.upp +++ b/bazaar/TestLeptonica/TestLeptonica.upp @@ -9,6 +9,7 @@ file LineRemoval.cpp, PageLayout.cpp, BaseLine.cpp, + PageMarkers.cpp, main.cpp; mainconfig diff --git a/bazaar/TestLeptonica/main.cpp b/bazaar/TestLeptonica/main.cpp index ab4004ec1..e16864321 100644 --- a/bazaar/TestLeptonica/main.cpp +++ b/bazaar/TestLeptonica/main.cpp @@ -17,6 +17,7 @@ TestLeptonica::TestLeptonica() LineRemovalButton <<= THISBACK(onLineRemoval); PageLayoutButton <<= THISBACK(onPageLayout); BaseLineButton <<= THISBACK(onBaseLine); + PageMarkersButton <<= THISBACK(onPageMarkers); QuitButton <<= THISBACK(onQuit); }