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
|
/*
** vic.c - load a VICAR Image file for use inside xloadimage
**
** Khalid Soofi (August 1992)
*/
#define TRUE 1
#define FALSE 0
#define DEPTH 8
#define LBLSIZE label[0]
#define LINES label[8]
#define SAMPLES label[6]
#include <stdio.h>
#include "image.h"
#include <sys/types.h>
FILE *fp,*fopen();
int label[10];
char labstr[80];
int flag=0;
/*
** vicarIdent
**
** Identify passed file a VICAR Image
** return 1 for true
** return 0 otherwise
**
*/
unsigned int vicarIdent (fullname, name)
char *fullname, *name;
{
int i=0;
char IDENT[7];
char c;
if ( ! (fp = fopen(fullname,"r")) )
return(0);
/* identify the VICAR IMAGE */
if ( fscanf(fp,"%6s",IDENT) < 1 ||
strcmp(IDENT,"LBLSIZ") == 0 ) {
printf("%s is a VICAR Image: ",fullname);
fclose(fp);
}
else
return(0);
/* Fill up the label block of image */
fp = fopen(fullname,"r");
while ( i < 10) {
if ( fscanf(fp,"%c",&c) < 1 || c == '=' ||
fscanf(fp,"%d",&label[i]) < 1)
label[i] = 0;
++i;
}
printf("%d lines and %d samples\n", LINES , SAMPLES );
fclose(fp);
return(1);
}
/* vicHeader - print the history record */
static void vicarHeader(ptr)
char *ptr;
{
int i;
int prflag;
int rtflag;
printf("\n ---HISTORY RECORD------------------------------------\n");
for ( i=0, prflag=FALSE, rtflag=0 ; i < LBLSIZE ; i++ ) {
if ( *(ptr++) == '\'' ) {
prflag = !prflag;
rtflag++;
}
if ( prflag && (char)(*ptr) != '\'' )
printf("%c",(char)(*ptr));
if ( rtflag == 2 ) {
printf("\n");
rtflag = 0;
}
}
printf("\n -----------------------------------------------------\n");
}
/*
** vicarLoad
**
** Load Vicar image into an Image structure.
**
** Return pointer to allocated struct if successful, NULL otherwise
**
*/
Image *vicarLoad(fullname, name, verbose)
char *fullname, *name;
unsigned int verbose;
{
int i;
unsigned int mapsize, size;
Image *image;
byte *lineptr;
byte *map;
byte *mapred,*mapgreen,*mapblue;
ZFILE *zf;
if ( vicarIdent(fullname,name,verbose) == 0 )
return(0);
/* define the image structure */
image = newRGBImage( SAMPLES , LINES , DEPTH );
image->width = SAMPLES ;
image->height = LINES ;
image->depth = DEPTH ;
image->title = dupString(name);
/*
* Set up the grey scale lookup table:-
* From Jim frost 09.27.89 (sunraster.c)
* Copyright 1989, 1991 Jim Frost.
* See included file "copyright.h" for complete copyright information.
*/
mapsize = 256*3;
map= lmalloc(mapsize);
for (i = 0; i < 256; i += 1) {
map[i] = map[256+i] = map[2*256+i] = i;
}
mapsize /= 3;
mapred= map;
mapgreen= mapred + mapsize;
mapblue= mapgreen + mapsize;
if (image->rgb.size == 0)
newRGBMapData(&image->rgb, mapsize);
for (i= 0; i < mapsize; i++) {
*(image->rgb.red + i)= (*(mapred++) << 8);
*(image->rgb.green + i)= (*(mapgreen++) << 8);
*(image->rgb.blue + i)= (*(mapblue++) << 8);
}
lfree(map);
image->rgb.used= mapsize;
/*
* Finally start the image data
*/
lineptr = image->data;
if ( !(zf=zopen(fullname))) {
perror(fullname);
zclose(zf);
exit(1);
}
if ( verbose ){
zread(zf,lineptr,LBLSIZE); /* dump label */
vicarHeader(lineptr);
}
else
zread(zf,lineptr,LBLSIZE); /* skip label */
size = image->width * image->height;
if (zread(zf,lineptr,size) != size)
fprintf(stderr, "%s: Warning, image data was missing\n", fullname);
zclose(zf);
return(image);
}
|