00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void MOSAIC (
00013 IMAGE **in,
00014
00015 short nimg,
00016 short nlin,
00017 short npix,
00018 short *jbgn,
00019
00020 short *kbgn,
00021
00022 PIXEL glev,
00023 IMAGE **out
00024
00025 ) { register short i, j, k, l, nbnd, elin, epix;
00026 char msg[SLEN];
00027
00028 if (TIMES) TIMING(T_MOSAIC);
00029 if (NAMES) {
00030 MESSAGE('I',"");
00031 MESSAGE('I',"MOSAIC");
00032 MESSAGE('I',"");
00033 sprintf(msg," Number of input images: %d",nimg);
00034 MESSAGE('I',msg);
00035 sprintf(msg," Image size: lines: %d",nlin);
00036 MESSAGE('I',msg);
00037 sprintf(msg," pixels: %d",npix);
00038 MESSAGE('I',msg);
00039 for (i=0; i<nimg; i++) {
00040 sprintf(msg," Image: %s Offset: lines: %-4d pixels: %-4d",in[i]->text,jbgn[i],kbgn[i]);
00041 MESSAGE('I',msg);
00042 }
00043 sprintf(msg," Fill graylevel: %12.4e",glev);
00044 MESSAGE('I',msg);
00045 MESSAGE('I'," ...............");
00046 }
00047
00048
00049 for (i=0; i<nimg; i++) {
00050 if (!CHECKIMG(in[i])) {
00051 MESSAGE('E'," Can't identify input image(s).");
00052 goto the_end;
00053 }
00054 }
00055 for (nbnd=in[0]->nbnd,i=1; i<nimg; i++) {
00056 if (nbnd != in[i]->nbnd) {
00057 MESSAGE('E'," Number of bands must be identical in all images.");
00058 goto the_end;
00059 }
00060 }
00061 for (i=0; i<nimg; i++) {
00062 if (0 > jbgn[i] || jbgn[i]+in[i]->nlin > nlin) {
00063 MESSAGE('E'," Input image(s) must be located completely inside output image in the line dimension.");
00064 goto the_end;
00065 } else if (0 > kbgn[i] || kbgn[i]+in[i]->npix > npix) {
00066 MESSAGE('E'," Input image(s) must be located completely inside output image in the pixel dimension.");
00067 goto the_end;
00068 }
00069 }
00070
00071
00072 if (!CHECKIMG(*out)) GETMEM(nbnd,nlin,npix,out);
00073 if (!*out) goto the_end;
00074
00075
00076 for (i=0; i<nbnd; i++) {
00077 for (j=0; j<nlin; j++) {
00078 for (k=0; k<npix; k++) {
00079 (*out)->data[i][j][k] = glev;
00080 }
00081 }
00082 }
00083
00084
00085 for (i=0; i<nbnd; i++) {
00086 for (l=0; l<nimg; l++) {
00087 elin = min(jbgn[l]+in[l]->nlin,nlin);
00088 epix = min(kbgn[l]+in[l]->npix,npix);
00089 for (j=jbgn[l]; j<elin; j++) {
00090 for (k=kbgn[l]; k<epix; k++) {
00091 (*out)->data[i][j][k] = in[l]->data[i][j-jbgn[l]][k-kbgn[l]];
00092 }
00093 }
00094 }
00095 }
00096
00097 the_end:
00098 if (TIMES) TIMING(T_EXIT);
00099 }