How BitBlt, scaling, and matrices work
The bitblt family is the library’s main image-composition tool. If polygons and text create pixels, bitblt decides how one image is copied, transformed, colour-converted, and merged into another image.
What a bitblt does
At the simplest level, a bitblt copies pixels from a source image into a destination image.
In this library the same call can also:
- crop a source rectangle,
- place it at a new destination position,
- resize it,
- rotate it in 90 degree steps,
- apply an arbitrary affine matrix,
- convert between colour spaces using an ICC transform,
- treat white as transparent for greyscale mask-style work,
- blend using an alpha channel,
- respect the destination clip rectangle.
The normal rectangular pipeline
The rectangle-based overloads of jett::bitblt() broadly work like this:
- Choose the destination pixel being written.
- Map that pixel back to the corresponding source position.
- Decide how to sample the source position.
- Optionally run the sampled colour through a colour transform.
- Optionally blend with the destination pixel.
- Write the result.
The key mental model is to walk over the destination and ask where each destination pixel should read from in the source.
Scaling
Nearest-neighbour scaling
bitblt_nn_scaling is the default. It picks the nearest source pixel and copies it.
Advantages:
- very fast,
- preserves hard pixel edges,
- ideal for masks, previews, and already-dithered imagery.
Drawbacks:
- enlarged images look blocky,
- reduced images can shimmer or alias.
Cubic scaling
bitblt_cubic_scaling samples a 4 by 4 neighbourhood and uses cubic interpolation to estimate a smoother value.
Advantages:
- smoother enlargement,
- better detail retention when resizing photographs and artwork,
- more natural-looking composition when placing source art at a different size.
Drawbacks:
- slower than nearest-neighbour,
- near image edges the implementation falls back to a simpler sample when there is not a full neighbourhood available.
Rotation
The flag-based rotation path supports bitblt_rotate_0, bitblt_rotate_90, bitblt_rotate_180, and bitblt_rotate_270.
These are exact quarter turns. They are efficient and ideal for label, page, and print layout work where the asset only needs to be turned upright or sideways.
If you need an arbitrary angle, use the matrix overload instead.
Matrix-based bitblt
The matrix overload of jett::bitblt() lets you apply a full affine transform. The matrix stored by jett_matrix is:
x' = a*x + c*y + e
y' = b*x + d*y + f
This means:
eandftranslate the image,aanddcontrol scale when the off-diagonal terms are zero,bandcintroduce rotation or shear depending on the combination.
Affine transforms matter because one matrix can combine multiple effects without producing intermediate images.
Matrix composition and inversion
jett_matrix::append() multiplies the current matrix by another one. In practice the order matters: rotating and then translating is not the same as translating and then rotating.
jett_matrix::invert() returns the inverse transform when one exists. If the matrix collapses area, for example by scaling one axis to zero, inversion fails and the library throws JETT_MATRIX_CANNOT_INVERT.
Colour transforms during bitblt
If you pass a non-null jett_transform, bitblt converts the sampled source pixel into the destination colour space while copying.
That means one call can resize an RGB image, convert it into CMYK with an ICC profile, and place it into a destination layout in one pass.
Transparency and alpha
White-as-transparent
bitblt_white_is_transparent treats white source pixels as empty background while darker values act like coverage. This is useful for mask-style monochrome overlays.
Alpha blending
bitblt_use_alpha uses the source alpha channel when the source image has one. This is the normal choice for PNG-style compositing where soft edges need to blend into the destination.
Clipping
bitblt respects the clip rectangle of the destination image. Clipping is a property of where you draw into, not where you read from.
Choosing the right overload
Use the simple overloads when you want to copy a whole source image, place it at one location, resize into a destination rectangle, or do quarter-turn rotation.
Use the matrix overload when you want arbitrary rotation, combined scale and rotation, shear, or placement through a transform you already share with text or geometry.
Common beginner patterns
- Photo into print layout: cubic scaling plus a colour transform.
- Logo with transparent background: alpha blending plus an optional colour transform.
- Simple mask overlay: white-is-transparent.
- Rotated product icon: matrix
bitblt.