File: rawImage.cxx

package info (click to toggle)
imview 1.1.8-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,052 kB
  • ctags: 3,797
  • sloc: cpp: 29,842; sh: 2,620; ansic: 1,835; makefile: 756; exp: 112; python: 88
file content (301 lines) | stat: -rw-r--r-- 6,923 bytes parent folder | download
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
/*
 * $Id: rawImage.cxx,v 4.1 2003/05/13 14:55:26 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.
 * */

/*------------------------------------------------------------------------
 *
 * A panel for reading arbitrary uncompressed images.
 *
 * Hugues Talbot	 8 Apr 2000
 *
 * A wish from the Perth group.
 *      
 *-----------------------------------------------------------------------*/

#include "imnmspc.hxx"

#include <stdio.h>
#include <assert.h>
#include <time.h>
#include <sys/stat.h>
#include <map> // STL
#include "imunistd.h"
#include "imview.hxx"
#include "imageIO.hxx"
#include "rawImage.hxx"
#include "menubar.hxx" // for openimage
#include "machine.hxx"

extern imageIO *IOBlackBox;

extern std::map <string, RAWFILE_HEADER> rawfilemap;

// we use a global static array so that the
// callbacks can see it.
static pixtype pixtype_match[NBTYPES] = {
    IM_UINT1, IM_INT2, IM_UINT2,
    IM_INT4, IM_UINT4, IM_INT8,
    IM_UINT8, IM_FLOAT, IM_DOUBLE
};

rawimage::rawimage()
{
    dbgprintf("Raw image panel constructed\n");
    rawimageWindow = 0; // fluid depends on this
    return;
}

void rawimage::setDefaults(void)
{
    // explanatory text
    bannerOutput->value("If you know the image data is uncompressed and you know the image\n"
			"dimensions, you can enter them below; otherwise press Cancel.");
    
    xInput->value("1");
    yInput->value("1");
    zInput->value("1");

    nbBandsInput->value("1");
    bandTypeChoice->deactivate(); // no need if there is only one band
    assignButton->deactivate(); // same

    headerSizeInput->value("0");
    filesizeOutput->value("0");

    // consistent corresponding values
    nx = ny = nz = 1;
    spp = 1;
    interleave = 0; // default from fluid
    byteOrder = 0; // sameg
    ptype = IM_UINT1; // same
    dataSize = headerSize = 0;
    
    dataSize = 0;
    filename = 0; 
}

void rawimage::show()
{
    rebuildBoxTitle();
    rawimageWindow->show();
    return;
}

void rawimage::hide()
{
    rawimageWindow->hide();
    return;
}

void rawimage::recomputeHeader(void)
{
    int header;

    header = computeSkip();

    if (header < 0) {
	headerSizeInput->textcolor(FL_RED);
	OKButton->deactivate();
    } else {
	headerSizeInput->textcolor(FL_BLACK);
	OKButton->activate();
    }

    if (spp > 1) {
	bandTypeChoice->activate();
	assignButton->activate();
    } else {
	bandTypeChoice->deactivate();
	assignButton->deactivate();
    }
    
}

int rawimage::computeSkip(void)
{
    int totaldata;
    
    totaldata = nx*ny*nz*spp * IOBlackBox->typeSize(ptype);
    headerSize = dataSize - totaldata;


    return headerSize;
}

void rawimage::setHeaderInput(void)
{
    char buf[100];
    int v = computeSkip();

    snprintf(buf, 100, "%d", v);
    headerSizeInput->value(buf);
}

void rawimage::saveHeader(void)
{
    RAWFILE_HEADER rfh;

    rfh.nx = nx;
    rfh.ny = ny;
    rfh.nz = nz;
    rfh.spp = spp;
    rfh.byo = byteOrder;
    rfh.itl = interleave;
    rfh.pixt = ptype;
    rfh.filesize = dataSize;
    rfh.skip = headerSize;

    rawfilemap[filename] = rfh; 
}

void rawimage::tryReading(void)
{
    // try reading the file again...
    openimage(filename);
}

// work out the file size as well...
void rawimage::rebuildBoxTitle(void)
{
    static char newTitle[100], fst[20];
    struct stat  statbuf;
    
    assert(filename != 0);
    snprintf(newTitle, 100, "%s: format not recognized", myBaseName(filename));
    titleBox->label(newTitle);

    
    if (stat(filename, &statbuf) == 0)
	dataSize =  statbuf.st_size;
    else
	dataSize = 0;
    
    snprintf(fst, 20, "%d", dataSize);

    filesizeOutput->value(fst);
    
}
//------- callbacks --------
void xinput_cb(Fl_Int_Input *i, rawimage *panel)
{
    int nx;

    nx = atoi(i->value());
    panel->setnx(nx);
}

void yinput_cb(Fl_Int_Input *i, rawimage *panel)
{
    int ny;

    ny = atoi(i->value());
    panel->setny(ny);
}

void zinput_cb(Fl_Int_Input *i, rawimage *panel)
{
    int nz;

    nz = atoi(i->value());
    panel->setnz(nz);
}

void nbband_cb(Fl_Int_Input *i, rawimage *panel)
{
    int spp;

    spp = atoi(i->value());
    panel->setspp(spp);
}

void pixeltype_cb(Fl_Choice *c, rawimage *panel)
{
    int rp = c->value();

    dbgprintf("pixel type callback: chosen %d\n", rp);
    assert((rp >= 0) && (rp < NBTYPES));
    panel->setPixType(pixtype_match[rp]);
}

void interleave_cb(Fl_Choice *c, rawimage *panel)
{
    int leav = c->value();

    dbgprintf("Interleave callback: %d\n", leav);
    assert((leav >= 0) && (leav < NBINTER));
    panel->setInterleave(leav);
	   
}

void byteorder_cb(Fl_Choice *c, rawimage *panel)
{
    int bo = c->value();

    dbgprintf("Byte order callback: %d\n", bo);
    assert((bo >= 0) && (bo < NBBYORD));
    panel->setByteOrder(bo);
    
}

void computeskip_cb(Fl_Button *, rawimage *panel)
{
    panel->setHeaderInput();
}

void headersize_cb(Fl_Int_Input *i, rawimage *panel)
{
    int hs = atoi(i->value());
    dbgprintf("Header size changed to %d\n", hs);
    panel->setHeaderSize(hs);
}

void helpbutton_cb(Fl_Button *, rawimage *panel)
{
    dbgprintf("Help on rawimage called\n");
    return;
}

void cancelbutton_cb(Fl_Button *, rawimage *panel)
{
    panel->hide();
}

void okbutton_cb(Fl_Button *, rawimage *panel)
{
    dbgprintf("OK Button pressed, saving the structure... \n");
    panel->saveHeader();
    panel->tryReading();
    //panel->hide();
}