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

Function gmtapi_export_palette

src/gmt_api.c:3515–3587  ·  view source on GitHub ↗

! . */

Source from the content-addressed store, hash-verified

3513
3514/*! . */
3515GMT_LOCAL int gmtapi_export_palette (struct GMTAPI_CTRL *API, int object_ID, unsigned int mode, struct GMT_PALETTE *P_obj) {
3516 /* Does the actual work of writing out the specified CPT to a destination.
3517 * The mode controls how the back, for, NaN color entries are handled.
3518 */
3519 int item, error;
3520 unsigned int kind;
3521 struct GMTAPI_DATA_OBJECT *S_obj = NULL;
3522 struct GMT_PALETTE *P_copy = NULL;
3523 struct GMT_PALETTE_HIDDEN *PH = NULL;
3524 struct GMT_CTRL *GMT = API->GMT;
3525
3526 GMT_Report (API, GMT_MSG_DEBUG, "gmtapi_export_palette: Passed ID = %d and mode = %d\n", object_ID, mode);
3527
3528 if (object_ID == GMT_NOTSET) return (gmtlib_report_error (API, GMT_OUTPUT_NOT_SET));
3529 if ((item = gmtlib_validate_id (API, GMT_IS_PALETTE, object_ID, GMT_OUT, GMT_NOTSET)) == GMT_NOTSET) return (gmtlib_report_error (API, API->error));
3530
3531 S_obj = API->object[item]; /* This is the API object for the output destination */
3532 if (S_obj->status != GMT_IS_UNUSED && !(mode & GMT_IO_RESET)) { /* Only allow writing of a data set once, unless we override by resetting the mode */
3533 return (gmtlib_report_error (API, GMT_WRITTEN_ONCE));
3534 }
3535 if (mode & GMT_IO_RESET) mode -= GMT_IO_RESET;
3536
3537 /* Passed sanity and allowed to write */
3538
3539 /* If need to assign non-default BFN do it now so external interfaces can access that too */
3540 if (mode & GMT_CPT_EXTEND_BNF) { /* Use low and high colors as back and foreground */
3541 gmt_M_rgb_copy (P_obj->bfn[GMT_BGD].rgb, P_obj->data[0].rgb_low);
3542 gmt_M_rgb_copy (P_obj->bfn[GMT_FGD].rgb, P_obj->data[P_obj->n_colors-1].rgb_high);
3543 gmt_M_rgb_copy (P_obj->bfn[GMT_BGD].hsv, P_obj->data[0].hsv_low);
3544 gmt_M_rgb_copy (P_obj->bfn[GMT_FGD].hsv, P_obj->data[P_obj->n_colors-1].hsv_high);
3545 }
3546
3547 switch (S_obj->method) { /* File, array, stream etc ? */
3548 case GMT_IS_FILE:
3549 /* gmtlib_write_cpt will report where it is writing from if level is GMT_MSG_INFORMATION */
3550 GMT_Report (API, GMT_MSG_INFORMATION, "Write CPT to %s %s\n", gmtapi_method (S_obj->method), S_obj->filename);
3551 if ((error = gmtlib_write_cpt (GMT, S_obj->filename, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error));
3552 break;
3553 case GMT_IS_STREAM:
3554 /* gmtlib_write_cpt will report where it is writing from if level is GMT_MSG_INFORMATION */
3555 kind = (S_obj->fp == GMT->session.std[GMT_OUT]) ? 0 : 1; /* 0 if stdout, 1 otherwise for user pointer */
3556 GMT_Report (API, GMT_MSG_INFORMATION, "Write CPT to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]);
3557 if ((error = gmtlib_write_cpt (GMT, S_obj->fp, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error));
3558 break;
3559 case GMT_IS_FDESC:
3560 /* gmtlib_write_cpt will report where it is writing from if level is GMT_MSG_INFORMATION */
3561 kind = (*((int *)S_obj->fp) == GMT_OUT) ? 0 : 1; /* 0 if stdout, 1 otherwise for user pointer */
3562 GMT_Report (API, GMT_MSG_INFORMATION, "Write CPT to %s %s output stream\n", gmtapi_method (S_obj->method), GMT_stream[kind]);
3563 if ((error = gmtlib_write_cpt (GMT, S_obj->fp, S_obj->method, mode, P_obj))) return (gmtlib_report_error (API, error));
3564 break;
3565 case GMT_IS_DUPLICATE: /* Duplicate the input cpt */
3566 if (S_obj->resource) return (gmtlib_report_error (API, GMT_PTR_NOT_NULL)); /* The output resource must be NULL */
3567 GMT_Report (API, GMT_MSG_INFORMATION, "Duplicating CPT to GMT_PALETTE memory location\n");
3568 P_copy = gmtlib_create_palette (GMT, P_obj->n_colors);
3569 gmtlib_copy_palette (GMT, P_copy, P_obj);
3570 S_obj->resource = P_copy; /* Set resource pointer from object to this palette */
3571 break;
3572 case GMT_IS_REFERENCE: /* Just pass memory location */

Callers 1

gmtapi_export_dataFunction · 0.85

Calls 8

GMT_ReportFunction · 0.85
gmtlib_report_errorFunction · 0.85
gmtlib_validate_idFunction · 0.85
gmtapi_methodFunction · 0.85
gmtlib_write_cptFunction · 0.85
gmtlib_create_paletteFunction · 0.85
gmtlib_copy_paletteFunction · 0.85
gmt_get_C_hiddenFunction · 0.85

Tested by

no test coverage detected