Documentation
¶
Overview ¶
Package renderutil contains the size calculations and pixel helpers that are shared between the cgo and the webassembly implementation of the render methods.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateImageSize ¶
func CalculateImageSize(widthInPoints, heightInPoints float64, width, height int) (int, int, float64)
CalculateImageSize calculates the pixel size of a box of the given size in points when it has to fit inside the given maximum width and/or height. A maximum of 0 means that the value is calculated from the other maximum and the aspect ratio of the box. It returns the width, the height and the scale in pixels per point.
func CompositeOnWhiteInPlace ¶ added in v1.20.1
CompositeOnWhiteInPlace flattens straight-alpha (non-premultiplied) RGBA pixels onto an opaque white background, writing the result back into img.Pix. PDFium's FPDFBitmap_BGRA output has straight alpha.
Blending in place avoids allocating a second full-size image. For the webassembly implementation this also keeps the pixel data inside the guest bitmap, so the JPEG encoder can borrow it instead of copying it back into WASM memory.
The integer arithmetic reproduces image/draw's NRGBA-over-RGBA path with a white destination exactly, so the result is bit-identical to drawing the image with draw.Over onto a white image.NewRGBA. This matters because the render golden hashes depend on it. The equivalence is checked against the image/draw implementation in composite_test.go.
func RenderSize ¶
RenderSize returns the size in pixels of a full page render at the given scale in pixels per point. This is the size that a crop is positioned against, it is not the size of the resulting image when cropping.
func ValidateCrop ¶
func ValidateCrop(crop requests.RenderPageCrop) error
ValidateCrop checks whether a crop region can be rendered at all. It is separate from CalculateCrop because a render that is given a maximum width or height derives its scale from the size of the region, so the region has to be checked before there is a scale to calculate the pixel bounds with.
Types ¶
type Crop ¶
type Crop struct {
OffsetX int // The X offset of the region inside the full page render, in pixels.
OffsetY int // The Y offset of the region inside the full page render, in pixels.
Width int // The width of the cropped image in pixels.
Height int // The height of the cropped image in pixels.
}
Crop is the pixel representation of a requests.RenderPageCrop for a specific render scale.
func CalculateCrop ¶
func CalculateCrop(crop requests.RenderPageCrop, scale float64) (*Crop, error)
CalculateCrop calculates the pixel bounds of a crop region for a render with the given scale in pixels per point.
The bounds are calculated as pixel edges on the grid of the full page render at the same scale, instead of by scaling the size of the region itself. That gives two guarantees that a tiling caller depends on: a cropped render contains the same pixels as the matching region of a full page render, and two regions that share an edge in points also share that edge in pixels, so tiles fit together without a seam, a gap or an overlap.