summaryrefslogtreecommitdiffstats
path: root/kooka/kookaimage.h
blob: b56c086b6e23f4b4849bd5d7d22f83da1b5f3bde (plain)
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
/***************************************************************************
                          kookaimage.h  - Kooka's Image
                             -------------------
    begin                : Thu Nov 20 2001
    copyright            : (C) 1999 by Klaas Freitag
    email                : freitag@suse.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *  This file may be distributed and/or modified under the terms of the    *
 *  GNU General Public License version 2 as published by the Free Software *
 *  Foundation and appearing in the file COPYING included in the           *
 *  packaging of this file.                                                *
 *
 *  As a special exception, permission is given to link this program       *
 *  with any version of the KADMOS ocr/icr engine of reRecognition GmbH,   *
 *  Kreuzlingen and distribute the resulting executable without            *
 *  including the source code for KADMOS in the source distribution.       *
 *
 *  As a special exception, permission is given to link this program       *
 *  with any edition of TQt, and distribute the resulting executable,       *
 *  without including the source code for TQt in the source distribution.   *
 *                                                                         *
 ***************************************************************************/



#ifndef KOOKAIMAGE_H
#define KOOKAIMAGE_H
#include <kurl.h>
#include <tqimage.h>
#include <tqptrlist.h>
#include <tqvaluevector.h>
#include <tqrect.h>

#include <kfilemetainfo.h>

class KFileItem;

/**
  * @author Klaas Freitag
  *
  * class that represents an image, very much as TQImage. But this one can contain
  * multiple pages.
  */

typedef enum { MaxCut, MediumCut } TileMode;

class KookaImage: public TQImage
{
public:

    KookaImage( );
    /**
     * creating a subimage for a parent image.
     * @param subNo contains the sequence number of subimages to create.
     * @param p is the parent image.
     */
    KookaImage(  int subNo, KookaImage *p );
    KookaImage( 	const TQImage& img );

    KookaImage& operator=(const KookaImage& );
    KookaImage& operator=(const TQImage& );
    /**
     * load an image from a KURL. This method reads the entire file and sets
     * the values for subimage count.
     */
    bool         loadFromUrl( const KURL& );

    ~KookaImage();

    /**
     * the amount of subimages. This is 0 if there are no subimages.
     */
    int         	subImagesCount() const;

    /**
     * the parent image.
     */
    KookaImage*  parentImage() const;

    /**
     * returns true if this is a subimage.
     */
    bool         isSubImage() const;

    /**
     * extracts the correct subimage according to the number given in the constructor.
     */
    void         extractNow();

    KURL         url() const;
    TQString      localFileName( ) const;

    /**
     *  Set and get the KFileItem of the image. Note that the KFileItem pointer returned
     *  may be zero.
     */
    KFileItem*   fileItem() const;
    void         setFileItem( KFileItem* );

    /**
     * @return the KFileMetaInfo
     **/
    const KFileMetaInfo fileMetaInfo( );

    /**
     * set the url of the kooka image. Note that loadFromUrl sets this
     * url automatically.
     */
    void setUrl( const KURL& url )
        { m_url = url; }

    /**
     * checks if the image is file bound ie. was loaded from file. If this
     * method returns false, fileMetaInfo and FileItem are undefined.
     */
    bool isFileBound()const { return m_fileBound; }

    /**
     * Create tiles on the given image. That is just cut the image in parts
     * while non of the parts is larger than maxSize and store the rect list.
     * The parameters rows and cols contain the number of rows and cols after
     * tiling. If both are one, the image is smaller than maxSize, thus the
     * left-top tile is index 1,1.
     * Use getTile() to read the TQRect list.
     */
    int cutToTiles( const TQSize maxSize, int& rows, int& cols, TileMode mode = MaxCut );

    /**
     * read tiles from the tile list. The image needs to be tiled by method
     * cutToTiles before.
     */
    TQRect getTileRect( int rowPos, int colPos ) const;

    /**
     * retrieve the sub number of this image.
     */
    int subNumber() const { return m_subNo; }

private:
    int 		m_subImages;
    bool                loadTiffDir( const TQString&, int );

    /* if subNo is 0, the image is the one and only. If it is larger than 0, the
     * parent contains the filename */
    int                 m_subNo;

    /* In case being a subimage */
    KookaImage          *m_parent;
    KURL                m_url;
    /* Fileitem if available */
    KFileItem           *m_fileItem;
    bool                m_fileBound;

    TQValueVector<TQRect> m_tileVector;
    int                 m_tileCols;  /* number of tile columns  */
};


class KookaImageList: public TQPtrList<KookaImage>
{
public:
   KookaImageList() {}
   ~KookaImageList() {}
};


#endif