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

Function PSL_loadeps

src/postscriptlight.c:6068–6148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6066#define Return2(x) {code = x; fclose (fp); remove (tmp_file); return (code);}
6067
6068int PSL_loadeps (struct PSL_CTRL *PSL, char *file, struct imageinfo *h, unsigned char **picture) {
6069 /* PSL_loadeps reads an Encapsulated PostScript file, If picture == NULL we just return h. */
6070
6071 int n, p, llx, lly, trx, try, BLOCKSIZE=4096;
6072 int32_t value;
6073 unsigned char *buffer = NULL;
6074 FILE *fp = NULL;
6075
6076 /* Open PostScript file in binary mode; see below for reverting on Windows for gets reads */
6077
6078 if ((fp = fopen (file, "rb")) == NULL) {
6079 PSL_message (PSL, PSL_MSG_ERROR, "Error: Cannot open image file %s!\n", file);
6080 return (PSL_READ_FAILURE);
6081 }
6082
6083 /* Check magic key */
6084
6085 if (fread (&value, sizeof (int32_t), 1, fp) != 1) {
6086 PSL_message (PSL, PSL_MSG_ERROR, "Error: Failure reading EPS magic key from %s\n", file);
6087 fclose (fp);
6088 return (-1);
6089 }
6090#ifndef WORDS_BIGENDIAN
6091 value = bswap32 (value);
6092#endif
6093 if (value != EPS_MAGIC) {
6094 PSL_message (PSL, PSL_MSG_ERROR, "Error: Could not find EPS magic key in %s\n", file);
6095 fclose (fp);
6096 return (-1);
6097 }
6098 h->magic = (int)value;
6099
6100 /* Scan for BoundingBox */
6101
6102#ifdef _WIN32
6103 /* Reset I/O to text mode since we are using gets in psl_get_boundingbox */
6104 if ( _setmode(_fileno(stdin), _O_TEXT) == -1 ) {
6105 PSL_message (PSL, PSL_MSG_WARNING, "Could not set text mode for %s.\n", file);
6106 return 0;
6107 }
6108#endif
6109
6110 psl_get_boundingbox (PSL, fp, &llx, &lly, &trx, &try, &h->llx, &h->lly, &h->trx, &h->try);
6111
6112 /* Fill header struct with appropriate values */
6113 h->magic = EPS_MAGIC;
6114 h->width = trx - llx;
6115 h->height = try - lly;
6116 h->depth = 0;
6117 h->length = 0; /* Not read yet */
6118 h->type = RT_EPS;
6119 h->maptype = RMT_NONE;
6120 h->maplength = 0;
6121 h->xorigin = llx;
6122 h->yorigin = lly;
6123
6124 if (picture == NULL) {
6125 fclose (fp);

Callers 4

gmtplot_latex_epsFunction · 0.85
PSL_loadeps_Function · 0.85
GMT_psimageFunction · 0.85

Calls 2

PSL_messageFunction · 0.85
psl_get_boundingboxFunction · 0.85

Tested by

no test coverage detected