00001 #include "sadie.h"
00002 #include "sadie_byte.h"
00003 #include "mosaic.h"
00004
00005
00006
00007
00008
00009
00010
00011
00012 void MOSAIC_BYTE_EXTRACT (
00013 IMAGE_BYTE *in,
00014 MOSAIC_INDEX *index,
00015 int jbgn,
00016 int jend,
00017 int kbgn,
00018 int kend,
00019 PIXEL fill,
00020 IMAGE **out
00021
00022 ) { register int j, k;
00023 char msg[SLEN];
00024
00025 printf("extracting (%d,%d) to (%d,%d)\n",kbgn,jbgn,kend,jend);
00026
00027
00028 if (!CHECKIMG_BYTE(in)) {
00029 printf("Can't identify mosaic index.\n");
00030 MESSAGE('E'," Can't identify mosaic image.");
00031 goto the_end;
00032 } else if (!CHECKIMG_MOSAIC_INDEX(index)) {
00033 printf("Can't identify mosaic index\n");
00034 MESSAGE('E'," Can't identify mosaic index.");
00035 goto the_end;
00036 } else if (index->npix != in->npix) {
00037 printf("index->npix = %d, in->npix = %d\n",index->npix, in->npix);
00038 printf("Size of mosaic image and mosaic index do not match.\n");
00039 MESSAGE('E'," Size of mosaic image and mosaic index do not match.");
00040 goto the_end;
00041 } else if (in->nbnd > 1) {
00042 printf("Image must be single-band.\n");
00043 MESSAGE('E'," Image must be single-band.");
00044 goto the_end;
00045 } else if (jbgn > jend) {
00046 printf("Start line must be before end line.\n");
00047 MESSAGE('E'," Start line must be before end line.");
00048 goto the_end;
00049 } else if (kbgn > kend) {
00050 printf("Start pixel must be before end pixel.\n");
00051 MESSAGE('E'," Start pixel must be before end pixel.");
00052 goto the_end;
00053 }
00054
00055
00056 if (NAMES) {
00057 MESSAGE('I',"");
00058 MESSAGE('I',"MOSAIC_BYTE_EXTRACT");
00059 MESSAGE('I',"");
00060 sprintf(msg," Input image: %s",in->text);
00061 MESSAGE('I',msg);
00062 sprintf(msg," Start line: %d",jbgn);
00063 MESSAGE('I',msg);
00064 sprintf(msg," End line: %d",jend);
00065 MESSAGE('I',msg);
00066 sprintf(msg," Start pixel: %d",kbgn);
00067 MESSAGE('I',msg);
00068 sprintf(msg," End pixel: %d",kend);
00069 MESSAGE('I',msg);
00070 MESSAGE('I'," ...............");
00071 }
00072
00073
00074
00075 if (!CHECKIMG(*out)) GETMEM(1,(jend-jbgn)+1,(kend-kbgn)+1,out);
00076 if (!*out) goto the_end;
00077
00078 for (j=0; j<(*out)->nlin; j++) {
00079 for (k=0; k<(*out)->npix; k++) {
00080 (*out)->data[0][j][k] = (PIXEL)fill;
00081 }
00082 }
00083
00084 for (k=kbgn; k<=kend; k++) {
00085 if (k>0 && k<in->npix) {
00086 for (j=jbgn-index->voffset[k]; j<=jend-index->voffset[k]; j++) {
00087 if (j>0 && j<index->vheight[k]) {
00088 (*out)->data[0][j-(jbgn-index->voffset[k])][k-kbgn] = (PIXEL)in->data[0][j][k];
00089 }
00090 }
00091 }
00092 }
00093
00094 the_end:
00095 return;
00096
00097 }