HGetDImage (see figure 5.9) combines HGetComp (section “HGetComp”) and HGetImage (section “HGetImage”). It reads the data of the gray value component channel of the image object specified by the database key obj_key and returns it in the Himage structure (image).
Note that HGetDImage automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HGetDImage yourself.
Himage image; Hcpar row,col,gray; ... HGetSPar(proc_handle,1,LONG_PAR,&row,1); /* row */ HGetSPar(proc_handle,2,LONG_PAR,&col,1); /* column */ coord = HLinCoor(row.par.l,col.par.l,image.width); HGetDImage(proc_handle,obj_key,IMAGE_INDEX,&image); /* processing (in general this should be done calling an action proc.) */ switch (image.kind) { case BYTE_IMAGE: gray.par.l = image.pixel.b[coord]; gray.type = LONG_PAR; break; case FLOAT_IMAGE: gray.par.d = image.pixel.f[coord]; gray.type = DOUBLE_PAR; break; default: return(H_ERR_WIT); /* wrong image type */ } HPutCPar(proc_handle,1,&gray,1);
Figure 5.13: Application of HGetDImage: Return the gray value at position (row,col) in the first channel of the input iconic object obj_key.
For the sake of efficiency, only a pointer to the image matrix is copied to image, instead of copying the data itself. So, only read access to the image data is recommended in order to avoid unpredictable side effects. Figure 5.13 shows an application of HGetDImage.