File: imview.hxx

package info (click to toggle)
imview 1.1.9c-7
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,076 kB
  • ctags: 4,780
  • sloc: cpp: 28,836; sh: 2,624; ansic: 1,818; makefile: 731; exp: 112; python: 88
file content (372 lines) | stat: -rw-r--r-- 11,236 bytes parent folder | download | duplicates (5)
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
/*
 * $Id: imview.hxx,v 4.5 2007/11/19 18:17:55 hut66au Exp $
 *
 * Imview, the portable image analysis application
 * http://www.cmis.csiro.au/Hugues.Talbot/imview
 * ----------------------------------------------------------
 *
 *  Imview is an attempt to provide an image display application
 *  suitable for professional image analysis. It was started in
 *  1997 and is mostly the result of the efforts of Hugues Talbot,
 *  Image Analysis Project, CSIRO Mathematical and Information
 *  Sciences, with help from others (see the CREDITS files for
 *  more information)
 *
 *  Imview is Copyrighted (C) 1997-2001 by Hugues Talbot and was
 *  supported in parts by the Australian Commonwealth Science and 
 *  Industry Research Organisation. Please see the COPYRIGHT file 
 *  for full details. Imview also includes the contributions of 
 *  many others. Please see the CREDITS file for full details.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
 * */

/*------------------------------------------------------------------------
 *
 * Main include file for imview, an application for displaying image
 * under X11 and the Windows (tm) GDI.
 *
 * Hugues Talbot	26 Oct 1997
 *
 * Usage is free of charge for anyone under no guarantee whatsoever,
 * expressed or implied.
 *
 *-----------------------------------------------------------------------*/

#ifndef IMVIEW_H
#define IMVIEW_H

#include <imcfg.h> // defines all sorts of things...

#include <string>

#include <FL/Fl.H>
#include <FL/Fl_Menu.H>
#include <FL/Fl_Menu_Bar.H>

#ifndef WIN32
//#include <vector> // OK, a header that defines  needs to be included 
//using namespace std;
#endif

using std::string;

// Constants
#define SHEIGHT 400
#define SWIDTH  600
#define MINHEIGHT  100
#define MINWIDTH   280
#define MAXWIDTH   1024
#define MAXHEIGHT  768
#define MENUHEIGHT 30
#define TBOXWIDTH 460
#define TBOXHEIGHT 100

#define DFLTSTRLEN     1024
#define SMALSTRLEN     128

#define MAX_FL_COLOURS 292 // a weird number, but heh.

// Installation path
#if !defined(PrefPath)
#define PrefPath  "/usr/local/share/imview"
#endif


#ifdef WIN32
// win32 doesn't have basename(), so we do the bit by hand
#  define IMVIEW        "imview"
#  define PATHSEP       ','   // Windows/DOS path use :, as in D:\mydir
#  define SLASH         '\\'
#else
#  define PATHSEP       ':'   // traditionally, Unix path use : as separators
#  define SLASH         '/'   // POSIX directory slash
#endif

// prefix to debug messages
#define DEBUGPROMPT  "Imview> "
#define SRVDBGPRMPT  "Server Imview> "
#define SRVIDBGPRMPT "Server Internal> "
#define ERRORPROMPT  "**error** Imview> "

// default point file name
#define DEFAULTPF   "pointfile"
#define ANNOTEHDR   "# annotation: "

// overlay image marker
#define OVERLAY_MARKER "<overlay>"

// default port file name
#define DEFAULT_PORT_FILE "portfile"
#define PF_MAX_LEN        1023  // max length of port file name

#define CLUT_SUFFIX ".lut"

// trivial macros
#ifndef trivmin
#define trivmin(x,y) ((x) > (y)) ? (y):(x)
#endif

#ifndef trivmax
#define trivmax(x,y) ((x) < (y)) ? (y):(x)
#endif

// page sizes 
// needed by both io/cpostscript.cxx and io/readps.cxx
typedef enum {
    PAGESIZE_AUTO = 0,
    PAGESIZE_A5,
    PAGESIZE_B5,
    PAGESIZE_A4,
    PAGESIZE_LETTER,
    PAGESIZE_LEGAL,
    PAGESIZE_A3,
    PAGESIZE_NB /* size of array needed */
} page_size;

// image types and pixel types

typedef enum {
    IM_INVALID = 0,
    IM_BINARY=10,
    IM_CHAR=31,    IM_INT1 = 31, IM_UINT1 = 30,
    IM_SHORT = 35, IM_INT2 = 35, IM_UINT2 = 37,
    IM_INT = 40,   IM_INT4 = 40, IM_UINT4 = 42,
    IM_INT8 = 43,  IM_UINT8 = 44, 
    IM_FLOAT=45,   IM_DOUBLE=50
} pixtype;

/*-- Multi-component image types --*/
typedef enum { IM_ERROR=0, IM_UNSPEC, IM_SINGLE, IM_SPECTRUM, IM_RGB, IM_HLS } imgtype;

/* the colour used in the bivariate histogram */
typedef enum {BHPBlack = FL_BLACK,
	      BHPRed=FL_RED,
	      BHPGreen=FL_GREEN,
	      BHPYellow=FL_YELLOW,
	      BHPBlue=FL_BLUE,
	      BHPMagenta=FL_MAGENTA,
	      BHPCyan=FL_CYAN
	     } BHPColour;

// the valid image  formats

typedef enum {
    TIFF_FMT = 0,
    ZIMAGE_FMT = 1,
    EURO_FMT = 2,
    PNG_FMT = 3,
    JPG_FMT = 4,
    LAST_FMT = 5
} imgfmt;

// panel IDS
typedef enum{SPECTRAPANEL=0, PROFILEPANEL} paneltype;

// orientations
typedef enum {
    STR_NE=0,
    STR_SE,
    STR_SW,
    STR_NW,
    STR_QUAD_MAX
} str_quadrant;

// endianness
typedef enum {
    ENDIAN_DEFAULT=0,
    ENDIAN_BIG,
    ENDIAN_LITTLE,
    ENDIAN_UNKNOWN
} endianness;


// filemap

class image_psfile {
public:
    image_psfile(void) {}
    image_psfile(const image_psfile &i) {filename_ = i.getfilename(); hash_ = i.gethash();}
    image_psfile(const string &fn, const string &hh) {filename_ = fn; hash_ = hh;}
    image_psfile& operator=(image_psfile &i) {
        if (this == &i)
            return *this; // nothing more
        filename_ = i.getfilename();
        hash_ = i.gethash();
    }
    const string getfilename(void) const {return filename_;}
    void setfilename(const string &s) {filename_ = s;}
    const string gethash() const {return hash_;}
    void sethash(const string &s) {hash_ = s;}
private:
    string filename_;
    string hash_;
};


// simple useful typedefs
typedef unsigned char uchar;

// this structure is used to store extra information
// about the images in the image list.
typedef struct image_parm {
    char             *itempath;  // used to index the structure...
    char             *clutpath;  // path to the CLUT used by the image
    char             *ovlpath;   // path to overlay, if any
    char             *pfpath;    // path to pointfile, if any
    int               zslice;    // 3rd dimension slice to display
    int               comp;      // component to show
    int               frame;     // frame to show
    int               nbframes;  // total number of frames in image
    float             gamma;     // gamma factor to be used
    float             contrast;  // contrast to use
    float             brightness; // same for brightness
    double            Rgamma, Rbrightness, Rcontrast; // RGB version 
    double            Ggamma, Gbrightness, Gcontrast; 
    double            Bgamma, Bbrightness, Bcontrast; 
    float             angle;      // Remember the angle
    char              mirror;     // Remember the mirror state (0 or 1)
    struct item_xtra *next;      // next in list
} IMAGEPARM;

// image header, useful when receiving raw binary data
typedef struct imagecomp_header {
    int             nx, ny, nz;              // size
    int             ox, oy, oz;              // offset
    imgtype         imgt;                    // types 
    pixtype         pixt;                    // ....
    int             spp;                     // samples per pixel
    void          **buffp;                   // array of buffers (one per spectrum.)
} IMAGECOMP_HEADER;

typedef struct image_header {
    char                *label;                   // image name or label
    unsigned int         unique_id;               // necessary to find the right buffer, assumed to be 4 bytes
    unsigned int         previous_id;             // ID of previous buffer
    unsigned int         expected_size;
    bool                 needswap;                // if the data comes from a diffent-endian machine
    int                  nbc;                     // nb of components
    void                *rawdata;                 // pointer to raw data, needed when freed.
    IMAGECOMP_HEADER    *comp;                    // array of components
} IMAGE_HEADER;


// this structure is sufficiently different from the `socket' raw data
// that it warrants its own type.
typedef struct rawfile_header {
    int            nx, ny, nz;
    int            spp;
    endianness    byo;  // sample per pixels = nb of bands; byo = byte ordering
    int            itl;       // interleave type
    pixtype        pixt;
    int            filesize;  // if changed!
    int            skip;      // need to remember this too!
} RAWFILE_HEADER;

// the `bivariate histogram point' class. Has to be small
class BHPoint {
public:
    BHPoint(void) { return;}
    BHPoint(BHPColour c, int i, double dx, double dy) {
	colour = c;
	imgOffset = i;
	Xvalue = dx;
	Yvalue = dy;
    }
    BHPColour colour;          // 255 different colours should be enough
    int       imgOffset;       // offset in the original image. Enough for a cube 1600 pixels aside.
    double    Xvalue, Yvalue;  // values of the point in both components.
};

// this predicate class to be used to sort the points
class cmpBHPoints {
public:
    bool operator() (const BHPoint &a, const BHPoint &b) const;
};

// this structure for rectangle selection
typedef struct SelectionRectangle {
		int x, y, w, h;
} SELRECT;

// prototypes for C-like functions

void run(void);
Fl_Menu_Bar *makeMenu(void);
// this functions checks the argument and return an image list.
void huntCLUT(const char **clutpathlist);
void checkArgs(int argc, char **argv, char ***imlist, char ***lutlist);
void showSimpleBanner(void);
void removeSimpleBanner(void);
void displayImages(char **imageList, char **lutList);

void filechooser_cb(const char *name);
int arg_cb(int argc, char **argv, int &i);

// server startup function
void start_server(void);
// exit/cleanup function
void imview_exit(int status, bool abort = false);

// debugging function
int dbgprintf(const char *msg, ...);
int stderrprintf(const char *msg, ...);
int srv_dbgprintf(const char *msg, ...);
int srv_internal_dbgprintf(const char *msg, ...);
int srv_printf(const char * msg,...);
// error printing function
int errprintf(const char *msg, ...);
// warning printing function
int warnprintf(const char * msg,...);

// utility colour function
Fl_Color fl_closest_colour(uchar r, uchar g, uchar b);
Fl_Color fl_closest_index(int i);

// from the FL directory
// defines the very important snprintf
#if !HAVE_SNPRINTF
#include <stdio.h>
#include <stdarg.h>
extern "C" {
int snprintf(char* str, size_t size, const char* fmt, ...);
}
#endif /* !HAVE_SNPRINTF */

#if !HAVE_VSNPRINTF
#include <stdio.h>
#include <stdarg.h>
extern "C" {
int vsnprintf(char* str, size_t size, const char* fmt, va_list ap);
}
#endif /* !HAVE_VSNPRINTF */


// puzzling missing prototype
// not missing anymore in RH >= 5.0
// missing againg in 6.1
//#ifdef Linux
//extern "C" {
//    const char *basename(const char *name);
//}
//#endif

#if defined(Solaris) || defined(Linux)
#include <libgen.h> // isn't that totally incredible?
#endif



#endif