/***************************************************************/ /* */ /* prepare_client_data - Prepare the client_data structure. */ /* The client_data structure */ /* communicates pixel data between the */ /* SE_stream_execute function and your */ /* callback function. */ /* */ /* arguments: */ /* */ /* client_data - Pointer to the */ /* client data */ /* structure. */ /* pixel_type - The pixel bit depth. */ /* pixelwidth - The width of the image */ /* specified in pixels. */ /* filename - The name of the BSQ file. */ /* */ /***************************************************************/ void prepare_client_data ( CLIENT_DATA *client_data, LONG pixel_type, LONG pixelwidth, CHAR *filename) { LONG bits_per_pixel, bufferbytes, bitmaskbytes; CHAR *bsqfilename; /* Set the number of bits each pixel will contain. In this case 8. */ bits_per_pixel = SE_PIXEL_TYPE_GET_DEPTH (pixel_type); /* Number of bytes per scanline. In this case 256 bytes. */ bufferbytes = (pixelwidth * bits_per_pixel + 7) / 8; /* Number of bytes in the bitmask */ bitmaskbytes = (pixelwidth + 7) / 8; /* Populate the CLIENT_DATA structure. This structure is passed between */ /* the SE_stream_execute function and the raster attribute callback function. */ /* Allocate the data buffer */ client_data->buffer = (CHAR *) calloc (bufferbytes, sizeof(CHAR)); /* Set the data buffer length. In this case the data buffer length is set to a */ /* single scanline, but since the raster being loaded is 8-bit, the length could */ /* have been set to a multiple of the scanline, even the entire image provided */ /* the memory resources are available. */ client_data->length = bufferbytes; /* Allocate the nodata bitmap buffer */ client_data->bitmaskbuffer = (CHAR *) calloc (bitmaskbytes, sizeof(CHAR)); /* Set the bitmaskbuffer length */ client_data->bitmasklength = bitmaskbytes; /* Set the file descriptor on the BSQ image file opened for read-only access, from which */ /* the pixel values will be read in band sequential order. The file will be read by the */ /* call back function which will be called iteratively by SE_stream_execute, until the */ /* image file is exhausted. SE_stream_execute will insert the pixels of the image into */ /* the SDE_BLK_ table. */ /* create the BSQ filename */ bsqfilename = (CHAR *) malloc (sizeof(CHAR) * (strlen(filename) + 5)); sprintf(bsqfilename,"%s.bsq",filename); client_data->fd = fopen (bsqfilename, "rb"); /* Release the bsqfilename */ free(bsqfilename); return; } /* prepare_client_data */