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

Function psl_pattern_init

src/postscriptlight.c:2575–2619  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2573}
2574
2575static int psl_pattern_init (struct PSL_CTRL *PSL, int image_no, char *imagefile, unsigned char *image, unsigned int width, unsigned int height, unsigned int depth) {
2576 int k, i;
2577 unsigned char *picture = NULL;
2578 /* image_no is 1-90 (PSL_N_PATTERNS) if a standard PSL pattern, else we examine imagefile.
2579 * User images are numbered PSL_N_PATTERNS+1,2,3 etc. */
2580 k = image_no - 1; /* Array index */
2581 if ((image_no > 0 && image_no <= PSL_N_PATTERNS)) { /* Premade pattern yet not used, assign settings */
2582 if (PSL->internal.pattern[k].status) return (image_no); /* Already initialized this pattern once, just return */
2583 picture = PSL_pattern[k];
2584 }
2585 else { /* User image, check to see if already used */
2586 if (imagefile == NULL) {
2587 PSL_message (PSL, PSL_MSG_ERROR, "Error: Gave NULL as imagefile name\n");
2588 return (-1);
2589 }
2590 i = psl_search_userimages (PSL, imagefile); /* i = 0 is the first user image */
2591 if (i >= 0) return (PSL_N_PATTERNS + i + 1); /* Already registered, just return number */
2592 if (PSL->internal.n_userimages > (PSL_N_PATTERNS-1)) {
2593 PSL_message (PSL, PSL_MSG_ERROR, "Error: Already maintaining %d user images and cannot accept any more\n", PSL->internal.n_userimages+1);
2594 return (-1);
2595 }
2596 /* Must initialize a previously unused image */
2597 PSL->internal.user_image[PSL->internal.n_userimages] = PSL_memory (PSL, NULL, strlen (imagefile)+1, char);
2598 strcpy (PSL->internal.user_image[PSL->internal.n_userimages], imagefile);
2599 PSL->internal.n_userimages++;
2600 image_no = PSL_N_PATTERNS + PSL->internal.n_userimages;
2601 k = image_no - 1; /* Array index */
2602 picture = image;
2603 }
2604
2605 /* Store size, depth and bogus DPI setting */
2606 PSL->internal.pattern[k].nx = width;
2607 PSL->internal.pattern[k].ny = height;
2608 PSL->internal.pattern[k].depth = depth;
2609 PSL->internal.pattern[k].status = 1;
2610 PSL->internal.pattern[k].dpi = -999;
2611
2612 PSL_comment (PSL, "Define pattern %d\n", image_no);
2613
2614 PSL_command (PSL, "/image%d {<~\n", image_no);
2615 psl_stream_dump (PSL, picture, PSL->internal.pattern[k].nx, PSL->internal.pattern[k].ny, PSL->internal.pattern[k].depth, PSL->internal.compress, PSL_ASCII85, 2);
2616 PSL_command (PSL, "} def\n");
2617
2618 return (image_no);
2619}
2620
2621#ifdef PSL_WITH_GMT4_SUPPORT
2622/* This code is included so we may offer backwards compatibility with GMT 4 old-school

Callers 1

PSL_setimageFunction · 0.85

Calls 5

PSL_messageFunction · 0.85
psl_search_userimagesFunction · 0.85
PSL_commentFunction · 0.85
PSL_commandFunction · 0.85
psl_stream_dumpFunction · 0.85

Tested by

no test coverage detected