1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
|
/*
Copyright (c) 1993-2008, Cognitive Technologies
All rights reserved.
Разрешается повторное распространение и использование как в виде исходного кода,
так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
* При повторном распространении исходного кода должны оставаться указанное
выше уведомление об авторском праве, этот список условий и последующий
отказ от гарантий.
* При повторном распространении двоичного кода в документации и/или в
других материалах, поставляемых при распространении, должны сохраняться
указанная выше информация об авторском праве, этот список условий и
последующий отказ от гарантий.
* Ни название Cognitive Technologies, ни имена ее сотрудников не могут
быть использованы в качестве средства поддержки и/или продвижения
продуктов, основанных на этом ПО, без предварительного письменного
разрешения.
ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the Cognitive Technologies nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
//////////////////////////////////////////////////////
// Rotation routines:
//
// inline Point32& Deskew( Point32& pt, int32_t skew1024);
// inline Point16& Deskew( Point16& pt, int32_t skew1024);
//
// NOTE: POSITIVE SKEW == CLOCKWISE
//////////////////////////////////////////////////////
#ifdef __cplusplus
#ifndef __SKEW1024_H
#define __SKEW1024_H
#ifndef __CTTYPES_H
#include "cttypes.h"
#endif
inline Point32& Deskew( Point32& pt, int32_t skew1024)
{
long phi_sq = (skew1024*skew1024);
long dx = ( (skew1024*pt.y+0x200) >> 10 );
long dy = ( (skew1024*pt.x+0x200) >> 10 );
long ddx =( (phi_sq*pt.x+0x100000) >> 21 );
long ddy =( (phi_sq*pt.y+0x100000) >> 21 );
pt.x -= dx;
pt.x -= ddx;
pt.y += dy;
pt.y -= ddy;
return pt;
}
inline Point16& Deskew( Point16& pt, int32_t skew1024)
{
long phi_sq = (skew1024*skew1024);
long dx = ( (skew1024*(long)pt.y+0x200) >> 10 );
long dy = ( (skew1024*(long)pt.x+0x200) >> 10 );
long ddx =( (phi_sq*(long)pt.x+0x100000) >> 21 );
long ddy =( (phi_sq*(long)pt.y+0x100000) >> 21 );
pt.x -= (int16_t)dx;
pt.x -= (int16_t)ddx;
pt.y += (int16_t)dy;
pt.y -= (int16_t)ddy;
return pt;
}
inline Point32& DeskewRel( Point32& pt, int32_t skew1024, Point32& rel )
{
pt.x -= rel.x;
pt.y -= rel.y;
Deskew( pt, skew1024 );
pt.x += rel.x;
pt.y += rel.y;
return pt;
}
inline Point16& DeskewRel( Point16& pt, int32_t skew1024, Point16& rel )
{
pt.x -= rel.x;
pt.y -= rel.y;
Deskew( pt, skew1024 );
pt.x += rel.x;
pt.y += rel.y;
return pt;
}
inline Point32& GetCenter( const Rect32& rc, Point32& center)
{
center.x = (rc.left+rc.right)>>1;
center.y = (rc.top+rc.bottom)>>1;
return center;
}
inline Point16& GetCenter( const Rect16& rc, Point16& center)
{
center.x = (rc.left+rc.right)>>1;
center.y = (rc.top+rc.bottom)>>1;
return center;
}
inline Point32& Copy(Point32& dst, Point16& src)
{
dst.x=src.x; dst.y=src.y;
return dst;
}
inline Point16& Copy(Point16& dst, Point32& src)
{
dst.x=(int16_t)src.x; dst.y=(int16_t)src.y;
return dst;
}
inline Rect32& Copy(Rect32& dst, Rect16& src)
{
dst.left = src.left; dst.right = src.right;
dst.top = src.top; dst.bottom = src.bottom;
return dst;
}
inline Rect16& Copy(Rect16& dst, Rect32& src)
{
dst.left = (int16_t)src.left; dst.right = (int16_t)src.right;
dst.top = (int16_t)src.top; dst.bottom = (int16_t)src.bottom;
return dst;
}
//////////////////////////////////////////////////////////
// diagonal points => rect
inline Rect32& Pt2Rc(Rect32& dst, Point16& a, Point16& b )
{
dst.left = a.x; dst.right = b.x;
dst.top = a.y; dst.bottom = b.y;
return dst;
}
inline Rect16& Pt2Rc(Rect16& dst, Point16& a, Point16& b )
{
dst.left = a.x; dst.right = b.x;
dst.top = a.y; dst.bottom = b.y;
return dst;
}
inline Rect32& Pt2Rc(Rect32& dst, Point32& a, Point32& b )
{
dst.left = a.x; dst.right = b.x;
dst.top = a.y; dst.bottom = b.y;
return dst;
}
inline Rect16& Pt2Rc(Rect16& dst, Point32& a, Point32& b )
{
dst.left = (int16_t)a.x; dst.right = (int16_t)b.x;
dst.top = (int16_t)a.y; dst.bottom = (int16_t)b.y;
return dst;
}
////////////////////////////////////////////////////
// movements ( -=, += )
inline Rect32& operator -=(Rect32& rc, Point32& pt)
{
rc.left -= pt.x; rc.right -= pt.x;
rc.top -= pt.y; rc.bottom-= pt.y;
return rc;
}
inline Rect16& operator -=(Rect16& rc, Point16& pt)
{
rc.left -= pt.x; rc.right -= pt.x;
rc.top -= pt.y; rc.bottom-= pt.y;
return rc;
}
inline Rect32& operator +=(Rect32& rc, Point32& pt)
{
rc.left += pt.x; rc.right += pt.x;
rc.top += pt.y; rc.bottom+= pt.y;
return rc;
}
inline Rect16& operator +=(Rect16& rc, Point16& pt)
{
rc.left += pt.x; rc.right += pt.x;
rc.top += pt.y; rc.bottom+= pt.y;
return rc;
}
inline Point32& operator -=(Point32& pt, Point32& pt1)
{
pt.x -= pt1.x; pt.y -= pt1.y;
return pt;
}
inline Point16& operator -=(Point16& pt, Point16& pt1)
{
pt.x -= pt1.x; pt.y -= pt1.y;
return pt;
}
inline Point32& operator +=(Point32& pt, Point32& pt1)
{
pt.x += pt1.x; pt.y += pt1.y;
return pt;
}
inline Point16& operator +=(Point16& pt, Point16& pt1)
{
pt.x += pt1.x; pt.y += pt1.y;
return pt;
}
inline Rect32& DeskewCenter( Rect32& rc, int32_t skew1024)
{
Point32 center; GetCenter(rc, center);
Point32 old_center = center;
Deskew( center, skew1024 );
center -= old_center; // diff
rc += center;
return rc;
}
inline Rect16& DeskewCenter( Rect16& rc, int32_t skew1024)
{
Point16 center; GetCenter(rc, center);
Point16 old_center = center;
Deskew( center, skew1024 );
center -= old_center; // diff
rc += center;
return rc;
}
inline Rect16& Expand( Rect16& rc, int16_t delta )
{
rc.left -= delta; rc.top -= delta;
rc.right+= delta; rc.bottom+= delta;
return rc;
}
inline Rect32& Expand( Rect32& rc, int32_t delta )
{
rc.left -= delta; rc.top -= delta;
rc.right+= delta; rc.bottom+= delta;
return rc;
}
// make points: lt & rb (main diag) or rt & lb (other)
inline void GetDiag1( Rect32& rc, Point32& lt, Point32& rb )
{ lt.x = rc.left; lt.y = rc.top; rb.x = rc.right;rb.y = rc.bottom; }
inline void GetDiag1( Rect16& rc, Point16& lt, Point16& rb )
{ lt.x = rc.left; lt.y = rc.top; rb.x = rc.right;rb.y = rc.bottom; }
inline void GetDiag2( Rect32& rc, Point32& rt, Point32& lb )
{ rt.x = rc.right; rt.y = rc.top; lb.x = rc.left;lb.y = rc.bottom; }
inline void GetDiag2( Rect16& rc, Point16& rt, Point16& lb )
{ rt.x = rc.right; rt.y = rc.top; lb.x = rc.left;lb.y = rc.bottom; }
inline Rect32& GetBounding( Rect32& rc_src, Rect32& rc_dest, int32_t skew1024 )
// dest rect can be the same as source
{
Point32 lt, rb; GetDiag1(rc_src, lt, rb);
Deskew(lt, skew1024); Deskew(rb, skew1024);
Point32 rt, lb; GetDiag2(rc_src, rt, lb);
Deskew(rt, skew1024); Deskew(lb, skew1024);
if (skew1024 < 0)
{
rc_dest.left = lt.x;
rc_dest.right = rb.x;
rc_dest.top = rt.y;
rc_dest.bottom= lb.y;
}
else
{
rc_dest.left = lb.x;
rc_dest.right = rt.x;
rc_dest.top = lt.y;
rc_dest.bottom= rb.y;
};
return rc_dest;
}
inline Rect16& GetBounding( Rect16& rc_src, Rect16& rc_dest, int32_t skew1024 )
// dest rect can be the same as source
{
Point16 lt, rb; GetDiag1(rc_src, lt, rb);
Deskew(lt, skew1024); Deskew(rb, skew1024);
Point16 rt, lb; GetDiag2(rc_src, rt, lb);
Deskew(rt, skew1024); Deskew(lb, skew1024);
if (skew1024 < 0)
{
rc_dest.left = lt.x;
rc_dest.right = rb.x;
rc_dest.top = rt.y;
rc_dest.bottom= lb.y;
}
else
{
rc_dest.left = lb.x;
rc_dest.right = rt.x;
rc_dest.top = lt.y;
rc_dest.bottom= rb.y;
};
return rc_dest;
}
///////////////////////////////////////////////////////////////
// 22.03.97 17:48, V.P
inline Bool operator !(const Rect16 & r) { return (r.left > r.right)||(r.top > r.bottom); }
inline Bool operator !(const Rect32 & r) { return (r.left > r.right)||(r.top > r.bottom); }
inline Bool Not(const Rect16 & r) { return (r.left > r.right)||(r.top > r.bottom); }
inline Bool Not(const Rect32 & r) { return (r.left > r.right)||(r.top > r.bottom); }
#define SetMax( a, b ) { if ((a) < (b)) (a) = (b); }
#define SetMin( a, b ) { if ((a) > (b)) (a) = (b); }
inline Rect32& operator |=(Rect32& rc, const Rect32& r)
{ SetMin( rc.left, r.left ); SetMin( rc.top , r.top );
SetMax( rc.right, r.right); SetMax( rc.bottom, r.bottom );
return rc;
}
inline Rect16& operator |=(Rect16& rc, const Rect16& r)
{ SetMin( rc.left, r.left ); SetMin( rc.top , r.top );
SetMax( rc.right, r.right); SetMax( rc.bottom, r.bottom );
return rc;
}
inline Rect32& operator &=(Rect32& rc, const Rect32& r)
{ SetMax( rc.left, r.left ); SetMax( rc.top , r.top );
SetMin( rc.right, r.right); SetMin( rc.bottom, r.bottom );
return rc;
}
inline Rect16& operator &=(Rect16& rc, const Rect16& r)
{ SetMax( rc.left, r.left ); SetMax( rc.top , r.top );
SetMin( rc.right, r.right); SetMin( rc.bottom, r.bottom );
return rc;
}
inline Rect16& Set( Rect16& r, int left, int top, int right, int bottom )
{ r.left=left; r.top=top; r.right=right; r.bottom=bottom; return r; }
inline Rect32& Set( Rect32& r, int left, int top, int right, int bottom )
{ r.left=left; r.top=top; r.right=right; r.bottom=bottom; return r; }
inline Rect16& Check( Rect16& r )
{
if (r.left>r.right) {int x=r.left; r.left=r.right; r.right=x; };
if (r.top>r.bottom) {int x=r.top; r.top=r.bottom; r.bottom=x; }
return r;
}
inline Rect32& Check( Rect32& r )
{
if (r.left>r.right) {int32_t x=r.left; r.left=r.right; r.right=x; };
if (r.top>r.bottom) {int32_t x=r.top; r.top=r.bottom; r.bottom=x; }
return r;
}
inline Point16& Set( Point16& p, int x, int y ){ p.x=x; p.y=y; return p; }
inline Point32& Set( Point32& p, int x, int y ){ p.x=x; p.y=y; return p; }
inline int width( const Rect16& rc ) { return rc.right-rc.left+1; }
inline int width( const Rect32& rc ) { return rc.right-rc.left+1; }
inline int height( const Rect16& rc ) { return rc.bottom-rc.top+1; }
inline int height( const Rect32& rc ) { return rc.bottom-rc.top+1; }
inline Bool Overlap( const Rect16& r1, const Rect16& r2 )
{ return !( (r1.left > r2.right)||(r1.top > r2.bottom) ||
(r2.left > r1.right)||(r2.top > r1.bottom)
);
}
inline Bool Overlap( const Rect32& r1, const Rect32& r2 )
{ return !( (r1.left > r2.right)||(r1.top > r2.bottom) ||
(r2.left > r1.right)||(r2.top > r1.bottom)
);
}
inline Bool Inside( const Rect16& r, const Point16 & p)
{ return !( (p.x < r.left)||(p.x > r.right )||
(p.x < r.top) ||(p.x > r.bottom)
);
}
inline Bool Inside( const Rect32& r, const Point32 & p)
{ return !( (p.x < r.left)||(p.x > r.right )||
(p.x < r.top) ||(p.x > r.bottom)
);
}
inline Bool Overlap( int a1, int a2, int b1, int b2 ) // two ranges intersection
{ // assumed that a1 <= a2; b1 <= b2
return !( (a2 < b1) || (b2 < a1) );
}
#endif
#endif // __cplusplus
|