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

Function PSL_plotcolorimage

src/postscriptlight.c:3848–3932  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3846}
3847
3848int PSL_plotcolorimage (struct PSL_CTRL *PSL, double x, double y, double xsize, double ysize, int justify, unsigned char *buffer, int nx, int ny, int nbits) {
3849 /* Plots a 24-bit color image in Grayscale, RGB or CMYK mode.
3850 * When the number of unique colors does not exceed PSL_MAX_COLORS, the routine will index
3851 * 24-bit RGB images and then attempt to reduce the depth of the indexed image to 1, 2 or 4 bits.
3852 *
3853 * x, y : lower left position of image in plot units
3854 * xsize, ysize : image size in units (if 0, adjust to keep the original aspect ratio)
3855 * justify : indicates what corner x,y refers to (see graphic below)
3856 * buffer : contains the bytes for the image
3857 * nx, ny : pixel dimension
3858 * nbits : number of bits per pixel (1, 2, 4, 8, 24)
3859 *
3860 * Special cases:
3861 * nx < 0 : 8- or 24-bit image contains a color mask (first 1 or 3 bytes)
3862 * nbits < 0 : "Hardware" interpolation requested
3863 *
3864 * 9 10 11
3865 * |----------------|
3866 * 5 <image> 7
3867 * |----------------|
3868 * 1 2 3
3869 */
3870 int id, it;
3871 const char *colorspace[3] = {"Gray", "RGB", "CMYK"}; /* What kind of image we are writing */
3872 const char *decode[3] = {"0 1", "0 1 0 1 0 1", "0 1 0 1 0 1 0 1"}; /* What kind of color decoding */
3873 const char *type[3] = {"1", "4 /MaskColor[0]", "1 /Interpolate true"};
3874 psl_indexed_image_t image;
3875
3876 /* If one of [xy]size is 0, keep the aspect ratio */
3877 if (PSL_eq (xsize, 0.0)) xsize = (ysize * nx) / ny;
3878 if (PSL_eq (ysize, 0.0)) ysize = (xsize * ny) / nx;
3879
3880 /* Correct origin (x,y) in case of justification */
3881 if (justify > 1) { /* Move the new origin so (0,0) is lower left of box */
3882 x -= 0.5 * ((justify + 3) % 4) * xsize;
3883 y -= 0.5 * (int)(justify / 4) * ysize;
3884 }
3885
3886 /* Gray scale, CMYK or RGB encoding/colorspace */
3887 id = (PSL->internal.color_mode == PSL_GRAY || abs (nbits) < 24) ? 0 : (PSL->internal.color_mode == PSL_CMYK ? 2 : 1);
3888 /* Colormask or interpolate */
3889 it = nx < 0 ? 1 : (nbits < 0 ? 2 : 0);
3890
3891 if (PSL->internal.color_mode != PSL_GRAY && (image = psl_makecolormap (PSL, buffer, nx, ny, nbits))) {
3892 /* Creation of colormap was successful */
3893 nbits = psl_bitreduce (PSL, image->buffer, nx, ny, image->colormap->ncolors);
3894
3895 PSL_comment (PSL, "Start of indexed %s image [%d bit]\n", colorspace[id], nbits);
3896 PSL_command (PSL, "V N %d %d T %d %d scale [/Indexed /Device%s %" PRIuS " <\n", psl_ix(PSL, x), psl_iy(PSL, y), psl_iz (PSL, xsize), psl_iz (PSL, ysize), colorspace[id], image->colormap->ncolors - 1);
3897 psl_stream_dump (PSL, &image->colormap->colors[0][0], (int)image->colormap->ncolors, 1, 24, 0, PSL_HEX, 2);
3898 PSL_command (PSL, ">] setcolorspace\n<< /ImageType %s /Decode [0 %d] ", type[it], (1<<nbits)-1);
3899 psl_stream_dump (PSL, image->buffer, nx, ny, nbits, PSL->internal.compress, PSL_ASCII85, 0);
3900 PSL_command (PSL, "U\n");
3901 PSL_comment (PSL, "End of indexed %s image\n", colorspace[id]);
3902
3903 /* Clear the newly created image buffer and colormap */
3904 PSL_free (image->buffer);
3905 PSL_free (image->colormap);

Callers 7

gmtplot_timestampFunction · 0.85
GMT_grdviewFunction · 0.85
PSL_plotcolorimage_Function · 0.85
psscale_draw_colorbarFunction · 0.85
GMT_grdimageFunction · 0.85
GMT_psimageFunction · 0.85
mainFunction · 0.85

Calls 8

psl_makecolormapFunction · 0.85
psl_bitreduceFunction · 0.85
PSL_commentFunction · 0.85
PSL_commandFunction · 0.85
psl_ixFunction · 0.85
psl_iyFunction · 0.85
psl_izFunction · 0.85
psl_stream_dumpFunction · 0.85

Tested by

no test coverage detected