Pixmap#
A Pixmap object contains a color raster image (short for pixel map). The components in a pixel in the Pixmap are all byte values, with the transparency as the last component.
A Pixmap also has a location (x, y) in addition to its size; so that they can easily be used to represent tiles of a page.
CONSTRUCTOR METHODS
- Pixmap(colorspace: ColorSpace, bbox?: Rect, alpha: boolean = false)#
Create a new Pixmap. Note: The pixel data is not initialized.
- Parameters:
colorspace – ColorSpace.
bbox – Rect.
alpha –
boolean
.
- Returns:
EXAMPLE
var pixmap = new mupdfjs.Pixmap(mupdfjs.ColorSpace.DeviceRGB, [0,0,100,100], true);
INSTANCE METHODS
- clear(value?: number)#
Clear the pixels to the specified value. Pass
255
for white,0
for black, or omit for transparent.- Parameters:
value –
number
.
EXAMPLE
pixmap.clear(255);
- getWidth()#
- Returns:
number
. The width value.
EXAMPLE
var w = pixmap.getWidth();
- getHeight()#
- Returns:
number
. The height value.
EXAMPLE
var h = pixmap.getHeight();
- getNumberOfComponents()#
Number of colors; plus one if an alpha channel is present.
- Returns:
number
. Number of color components.
EXAMPLE
var num = pixmap.getNumberOfComponents();
- getAlpha()#
True if alpha channel is present.
- Returns:
boolean
.
EXAMPLE
var alpha = pixmap.getAlpha();
- getStride()#
Number of bytes per row.
- Returns:
number
.
EXAMPLE
var stride = pixmap.getStride();
- getColorSpace()#
Returns the ColorSpace for the Pixmap.
- Returns:
EXAMPLE
var cs = pixmap.getColorSpace();
- setResolution(x: number, y: number)#
Set
x
&y
resolution.- Parameters:
x –
number
. X resolution in dots per inch.y –
number
. Y resolution in dots per inch.
EXAMPLE
pixmap.setResolution(300, 300);
- getXResolution()#
Returns the
x
resolution for the Pixmap.- Returns:
number
. Resolution in dots per inch.
EXAMPLE
var xRes = pixmap.getXResolution();
- getYResolution()#
Returns the
y
resolution for the Pixmap.- Returns:
number
. Resolution in dots per inch.
EXAMPLE
var yRes = pixmap.getYResolution();
- invert()#
Invert all pixels. All components are processed, except alpha which is unchanged.
EXAMPLE
pixmap.invert();
- invertLuminance()#
Transform all pixels so that luminance of each pixel is inverted, and the chrominance remains as unchanged as possible. All components are processed, except alpha which is unchanged.
EXAMPLE
pixmap.invertLuminance();
- gamma(p: number)#
Apply gamma correction to Pixmap. All components are processed, except alpha which is unchanged.
Values
>= 0.1 & < 1
= darken,> 1 & < 10
= lighten.- Parameters:
p –
number
.
EXAMPLE
pixmap.gamma(3.5);
- tint(black: number | Color, white: number | Color)#
- Tint all pixels in a RGB, BGR or Gray Pixmap.
Map black and white respectively to the given hex RGB values.
EXAMPLE
pixmap.tint(0xffff00, 0xffff00);
- warp(points: Point[], width: number, height: number)#
Return a warped subsection of the Pixmap, where the result has the requested dimensions.
- Parameters:
- Returns:
EXAMPLE
var warpedPixmap = pixmap.warp([[0,0], [100,100], [130,170], [150,200]],200,200);
- convertToColorSpace(colorspace: ColorSpace, keepAlpha: boolean = false)#
Convert pixmap into a new pixmap of a desired colorspace. A proofing colorspace, a set of default colorspaces and color parameters used during conversion may be specified. Finally a boolean indicates if alpha should be preserved (default is to not preserve alpha).
- Parameters:
colorspace –
Colorspace
.keepAlpha –
boolean
.
- Returns:
- getPixels()#
Returns an array of pixels for the Pixmap.
- Returns:
[...]
.
EXAMPLE
var pixels = pixmap.getPixels();
- asJPEG(quality: number, invert_cmyk: boolean)#
Returns a buffer of the Pixmap as a JPEG. Note, if the Pixmap has an alpha channel then an exception will be thrown.
- Parameters:
quality –
number
. Should be between0 - 100
.invert_cmyk –
boolean
.
- Returns:
EXAMPLE
var buffer = pixmap.asJPEG(80, false);
Code samples
Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:
import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"