~ubuntu-branches/ubuntu/edgy/djvulibre/edgy

« back to all changes in this revision

Viewing changes to libdjvu/GRect.h

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-07-03 11:38:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113823-un2te7742kk04c63
Tags: 3.5.17-1ubuntu1
* Sync with Debian
* debian/rules:
  - use dh_iconcache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
53
53
// 
54
 
// $Id: GRect.h,v 1.9 2003/11/07 22:08:21 leonb Exp $
55
 
// $Name: debian_version_3_5_16-1 $
 
54
// $Id: GRect.h,v 1.11 2006/02/21 16:10:29 docbill Exp $
 
55
// $Name: debian_version_3_5_17-1 $
56
56
 
57
57
#ifndef _GRECT_H_
58
58
#define _GRECT_H_
75
75
    @author
76
76
    L\'eon Bottou <leonb@research.att.com> -- initial implementation.
77
77
    @version
78
 
    #$Id: GRect.h,v 1.9 2003/11/07 22:08:21 leonb Exp $# */
 
78
    #$Id: GRect.h,v 1.11 2006/02/21 16:10:29 docbill Exp $# */
79
79
//@{
80
80
 
81
81
#include "DjVuGlobal.h"
88
88
#endif
89
89
 
90
90
 
 
91
/* Flag to indicate that this djvulibre version
 
92
   gets rid of all the crap about orientation bits.
 
93
   All rotation code has been fixed and consistently
 
94
   implements counter-clockwise rotations. */
 
95
 
 
96
#define GRECT_WITHOUT_ORIENTATION_BITS 1
 
97
 
91
98
 
92
99
/** @name Point Coordinates vs. Pixel Coordinates
93
100
 
132
139
class GRect 
133
140
{
134
141
public:
135
 
  /** #OrientationBits# defines 3 mutually exclusive
136
 
     bits to indicate the image orientation.
137
 
 
138
 
     There are four possible rotation values for an image
139
 
     which are 0 degrees, 90 degrees, 180 degrees, and 270 degrees.
140
 
     In addition the image can be mirrored backwards in any of these
141
 
     orientations, giving a possible of 8 orientations.  To sanely deal
142
 
     with these orientations, we have defined 3 mutually exclusive
143
 
     bits.  These are BOTTOM_UP, MIRROR, and ROTATE90_CW.
144
 
  */
145
 
  enum OrientationBits
146
 
  {
147
 
    BOTTOM_UP=0x1,  /* Upside down */
148
 
    MIRROR=0x2,     /* Written backwards. (right to left) */
149
 
    ROTATE90_CW=0x4 /* rotated 90 degrees */
150
 
  };
151
 
 
152
 
  /**  #Orientations# defines all 8 possible orientations, using
153
 
   the three \Ref{OrientationBits}.
154
 
   \begin{itemize}
155
 
   \item {\em TDLRNR} for Top Down, Left to Right, No Rotation.
156
 
   \item {\em BULRNR} for Bottom Up, Left to Right, No Rotation.
157
 
   \item {\em TDRLNR} for Top Down, Right to Left, No Rotation.
158
 
   \item {\em BURLNR} for Bottom Up, Right to Left, No Rotation.
159
 
   \item {\em TDLRCW} for Top Down, Left to Right, 90 degree CW rotation.
160
 
   \item {\em BULRCW} for Bottom Up, Left to Right, 90 degree CW rotation.
161
 
   \item {\em TDRLCW} for Top Down, Right to Left, 90 degree CW rotation.
162
 
   \item {\em BURLCW} for Bottom Up, Right to Left, 90 degree CW rotation.
163
 
   \end{itemize}
164
 
  */
165
 
  enum Orientations
166
 
  {
167
 
    TDLRNR=0,                                     /* normal orientation */
168
 
    BULRNR=BOTTOM_UP,                               /* upside down */
169
 
    TDRLNR=MIRROR,                    /* backwards (right to left) */
170
 
    BURLNR=MIRROR|BOTTOM_UP,                    /* rotate 180 */
171
 
    TDLRCW=ROTATE90_CW,                              /* rotated 90 */
172
 
    BULRCW=ROTATE90_CW|BOTTOM_UP, /* backwards and rotate 180 */
173
 
    TDRLCW=ROTATE90_CW|MIRROR,     /* backwards and rotate 90 */
174
 
    BURLCW=ROTATE90_CW|MIRROR|BOTTOM_UP    /* rotate 270 */
175
 
  };
176
 
 
177
 
  static Orientations
178
 
  rotate(const int angle,Orientations orientation)
179
 
  {
180
 
    for(int a=(((angle)%360)+405)%360;a>90;a-=90)
181
 
      orientation=(Orientations)((int)orientation^(int)(orientation&ROTATE90_CW)?BURLCW:TDLRCW);
182
 
    return orientation;
183
 
  }
184
 
 
185
 
  static int
186
 
  findangle(const Orientations orientation)
187
 
  {
188
 
    int a=270;
189
 
    while(a&&(rotate(a,BURLNR)!=orientation)&&(rotate(a,TDRLNR)!=orientation))
190
 
      a-=90;
191
 
    return a;
192
 
  }
193
 
 
194
142
  /** Constructs an empty rectangle */
195
143
  GRect();
196
144
  /** Constructs a rectangle given its minimal coordinates #xmin# and #ymin#,
204
152
  /** Returns the area of the rectangle. */
205
153
  int  area() const;
206
154
  /** Returns true if the rectangle is empty. */
207
 
  int  isempty() const;
 
155
  bool  isempty() const;
208
156
  /** Returns true if the rectangle contains pixel (#x#,#y#).  A rectangle
209
157
      contains all pixels with horizontal pixel coordinates in range #xmin#
210
158
      (inclusive) to #xmax# (exclusive) and vertical coordinates #ymin#
315
263
      corners in the canonical rectangle representation.  Variable #rect# is
316
264
      overwritten with the new rectangle coordinates. */
317
265
  void unmap(GRect &rect);
318
 
private:
 
266
public:
319
267
  // GRatio
320
268
  struct GRatio {
321
269
    GRatio ();
323
271
    int p;
324
272
    int q;
325
273
  };
 
274
private:
326
275
  // Data
327
276
  GRect rectFrom;
328
277
  GRect rectTo;
366
315
  return ymax - ymin;
367
316
}
368
317
 
369
 
inline int 
 
318
inline bool 
370
319
GRect::isempty() const
371
320
{
372
321
  return (xmin>=xmax || ymin>=ymax);