/*---------------------------------------------------------------------------*/ /* Program: imzcat.c */ /* */ /* Purpose: This programs combines a collection of 2D KUIM format images */ /* into a single 3D image of type BYTE or PSEUDO. */ /* */ /* Author: John Gauch / Chunyen Liu */ /* */ /* Date: September 20, 1996 */ /* */ /* Note: Copyright (C) The University of Kansas, 1996 */ /*---------------------------------------------------------------------------*/ #include /*---------------------------------------------------------------------------*/ /* Purpose: This is the main program. */ /*---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { /* Image variables */ char Name1[50]; char Name2[50]; IM_TYPE *Image1; IM_TYPE *Image2; BYTE_TYPE *Data1; PSEUDO_TYPE *Data0; int PixType, Xdim, Ydim, Zdim, DimCnt; int NewPixType, NewXdim, NewYdim, NewZdim; unsigned char Red[nCMAP]; unsigned char Green[nCMAP]; unsigned char Blue[nCMAP]; /* Program variables */ int Debug = FALSE; int i = 0, j, x; int Offset = 0; /* Interpret program options */ printf("IMZCAT Program - KUIM Version 2.0\n\n"); while ((++i < argc) && (argv[i][0] == '-')) switch (argv[i][1]) { case 'd': Debug = TRUE; break; default: Error("Invalid option encountered"); break; } /* Check number of file names */ if (argc - i < 3) { fprintf(stderr, "Usage: imzcat [options] outfile infile1 infile2 ...\n"); fprintf(stderr, " [-d] Print debugging information\n"); exit(1); } /* Get output image file name */ if (sscanf(argv[i++], "%s", Name1) == 0) Error("Could not get output file name"); /* Check input image dimensions */ for (j = i; j < argc; j++) { if (sscanf(argv[j], "%s", Name2) == 0) Error("Could not get output file name"); Image2 = im_open(Name2, &PixType, &Xdim, &Ydim, &Zdim, &DimCnt); if (Debug == TRUE) printf("%s dimensions %d %d %d\n", Name2, Xdim, Ydim, Zdim); if (j == i) { NewPixType = PixType; NewXdim = Xdim; NewYdim = Ydim; NewZdim = Zdim; } else if ((NewXdim == Xdim) && (NewYdim == Ydim)) NewZdim += Zdim; else Error("Input image dimensions do not match"); } /* Special case for combining 1D signals */ if (NewYdim == 1) { NewYdim = NewZdim; NewZdim = 1; } /* Create output image */ if (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB) NewPixType = PSEUDO; else NewPixType = BYTE; Image1 = im_create(Name1, NewPixType, NewXdim, NewYdim, NewZdim); if (Debug == TRUE) printf("%s dimensions %d %d %d\n", Name1, NewXdim, NewYdim, NewZdim); if (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB) Data0 = (PSEUDO_TYPE *) im_alloc1D(Image1, PSEUDO); else Data1 = (BYTE_TYPE *) im_alloc1D(Image1, BYTE); /* Read and copy input images */ Offset = 0; for (j = i; j < argc; j++) { if (sscanf(argv[j], "%s", Name2) == 0) Error("Could not get output file name"); Image2 = im_open(Name2, &PixType, &Xdim, &Ydim, &Zdim, &DimCnt); if (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB) im_read(Image2, PSEUDO, (char *) &(Data0[Offset])); else im_read(Image2, BYTE, (char *) &(Data1[Offset])); if ((j == i) && (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB)) { im_get_cmap(Image2, Red, Green, Blue); if (Debug) for (x = 0; x < 256; x++) printf("color %d: %d %d %d\n", x, Red[x], Green[x], Blue[x]); } Offset += Xdim * Ydim * Zdim; } /* Write output image */ if (PixType == COLOR || PixType == PSEUDO || PixType == JPEG_RGB) { im_put_cmap(Image1, Red, Green, Blue); im_write(Image1, PSEUDO, (char *) Data0); im_free1D((char *) Data0); } else { im_write(Image1, BYTE, (char *) Data1); im_free1D((char *) Data1); } return (0); }