MCPcopy Create free account
hub / github.com/GenericMappingTools/gmt / gmtapi_import_image

Function gmtapi_import_image

src/gmt_api.c:4746–5057  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4744
4745/*! . */
4746GMT_LOCAL struct GMT_IMAGE *gmtapi_import_image (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_IMAGE *image) {
4747 /* Handles the reading of a 2-D image given in one of several ways.
4748 * Get the entire image:
4749 * mode = GMT_CONTAINER_AND_DATA reads both header and image;
4750 * Get a subset of the image: Call gmtapi_import_image twice:
4751 * 1. first with mode = GMT_CONTAINER_ONLY which reads header only. Then, pass
4752 * the new S_obj-> wesn to match your desired subregion
4753 * 2. 2nd with mode = GMT_DATA_ONLY, which reads image based on header's settings
4754 * If the image->data array is NULL it will be allocated for you.
4755 */
4756
4757 int item, new_item, new_ID;
4758 bool done = true, via = false, must_be_image = true, no_index = false, bc_not_set = true, new = false, have_CRS = false;
4759 uint64_t ij, ij_orig;
4760 openmp_int row, col, i0, i1, j0, j1;
4761 unsigned int both_set = (GMT_CONTAINER_ONLY | GMT_DATA_ONLY);
4762 size_t size;
4763 double dx, dy, d;
4764 p_func_uint64_t GMT_2D_to_index = NULL;
4765 GMT_getfunction api_get_val = NULL;
4766 struct GMT_IMAGE *I_obj = NULL, *I_orig = NULL;
4767 struct GMT_MATRIX *M_obj = NULL;
4768 struct GMT_MATRIX_HIDDEN *MH = NULL;
4769 struct GMT_IMAGE_HIDDEN *IH = NULL;
4770 struct GMT_GRID_HEADER_HIDDEN *HH = NULL;
4771 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
4772 struct GMT_CTRL *GMT = API->GMT;
4773 struct GMT_IMAGE *Irgb = NULL;
4774
4775 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_import_image: Passed ID = %d and mode = %d\n", object_ID, mode);
4776
4777 if ((item = gmtlib_validate_id (API, GMT_IS_IMAGE, object_ID, GMT_IN, GMT_NOTSET)) == GMT_NOTSET) return_null (API, API->error);
4778
4779 S_obj = API->object[item]; /* Current data object */
4780 if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET))
4781 return_null (API, GMT_READ_ONCE); /* Already read this resources before, so fail unless overridden by mode */
4782 if ((mode & GMT_IMAGE_NO_INDEX)) no_index = true, mode -= GMT_IMAGE_NO_INDEX; /* Must expand any index to rgb */
4783 if ((mode & both_set) == both_set) mode -= both_set; /* Allow users to have set GMT_CONTAINER_ONLY | GMT_DATA_ONLY; reset to GMT_CONTAINER_AND_DATA */
4784 if ((mode & GMT_GRID_IS_IMAGE) == GMT_GRID_IS_IMAGE) { /* Only allowed when fishing the image header and it may in fact be a grid */
4785 if (mode & GMT_DATA_ONLY) {
4786 GMT_Report (API, GMT_MSG_ERROR, "Cannot pass mode = GMT_GRID_IS_IMAGE when reading the image for file %s\n", S_obj->filename);
4787 return_null (API, GMT_IMAGE_READ_ERROR);
4788 }
4789 mode -= GMT_GRID_IS_IMAGE;
4790 must_be_image = false;
4791 }
4792
4793 switch (S_obj->method) {
4794 case GMT_IS_FILE: /* Name of an image file on disk */
4795 if (image == NULL) { /* Only allocate image struct when not already allocated */
4796 if (mode & GMT_DATA_ONLY) return_null (API, GMT_NO_GRDHEADER); /* For mode & GMT_DATA_ONLY image must already be allocated */
4797 I_obj = gmtlib_create_image (GMT);
4798 new = true;
4799 }
4800 else
4801 I_obj = image; /* We are passing in an image already allocated */
4802 HH = gmt_get_H_hidden (I_obj->header);
4803 I_obj->header->complex_mode = (mode & GMT_GRID_IS_COMPLEX_MASK); /* Pass on any bitflags */

Callers 1

gmtapi_import_dataFunction · 0.85

Calls 15

GMT_ReportFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmtlib_create_imageFunction · 0.85
gmt_get_H_hiddenFunction · 0.85
gmtapi_import_ppm_headerFunction · 0.85
gmtlib_read_image_infoFunction · 0.85
gmtlib_free_imageFunction · 0.85
gmtapi_set_grdarray_sizeFunction · 0.85
gmtapi_import_ppmFunction · 0.85
gmtlib_read_imageFunction · 0.85
gmtlib_image_BC_setFunction · 0.85
gmt_get_I_hiddenFunction · 0.85

Tested by

no test coverage detected