parallax/jsPDF · error · Error
Not enough pixels for the frame size.
Error message
Not enough pixels for the frame size.
What it means
Thrown by GifWriter.addFrame when indexed_pixels.length < w * h. Each frame must supply at least one palette index per pixel covering its declared dimensions, otherwise the LZW encoder would read out of bounds.
Source
Thrown at src/libs/omggif.js:151
this.addFrame = function(x, y, w, h, indexed_pixels, opts) {
if (ended === true) {
--p;
ended = false;
} // Un-end.
opts = opts === undefined ? {} : opts;
// TODO(deanm): Bounds check x, y. Do they need to be within the virtual
// canvas width/height, I imagine?
if (x < 0 || y < 0 || x > 65535 || y > 65535)
throw new Error("x/y invalid.");
if (w <= 0 || h <= 0 || w > 65535 || h > 65535)
throw new Error("Width/Height invalid.");
if (indexed_pixels.length < w * h)
throw new Error("Not enough pixels for the frame size.");
var using_local_palette = true;
var palette = opts.palette;
if (palette === undefined || palette === null) {
using_local_palette = false;
palette = global_palette;
}
if (palette === undefined || palette === null)
throw new Error("Must supply either a local or global palette.");
var num_colors = check_palette_and_num_colors(palette);
// Compute the min_code_size (power of 2), destroying num_colors.
var min_code_size = 0;
while ((num_colors >>= 1)) ++min_code_size;
num_colors = 1 << min_code_size; // Now we can easily get it back.
View on GitHub (pinned to a3930ce03a)
Solutions
- Ensure indexed_pixels has exactly w * h entries (one byte per pixel).
- Recompute the pixel buffer from the same w, h passed to addFrame.
- Add an assertion: if (pixels.length < w*h) before calling.
Example fix
// before
gw.addFrame(x, y, w, h, partialPixels);
// after
var needed = w * h;
if (partialPixels.length < needed) throw new Error('frame underrun');
gw.addFrame(x, y, w, h, partialPixels); Defensive patterns
Strategy: validation
Validate before calling
if (indexed_pixels.length >= w * h) gw.addFrame(x, y, w, h, indexed_pixels); else throw new Error('pixel underrun'); Type guard
function hasEnoughPixels(px, w, h){ return px && px.length >= w * h; } Try / catch
try { gw.addFrame(x, y, w, h, pixels); } catch (e) { if (/Not enough pixels/.test(e.message)) { /* rebuild pixel buffer */ } else throw e; } Prevention
- Recompute pixel buffer from the same w,h passed to addFrame
- Assert buffer length equals w*h before encoding
When it happens
Trigger: Passing a pixel buffer computed for a smaller region than (w, h); forgetting to include all rows; mismatch between declared frame size and the extracted pixel array length.
Common situations: Crop/resize producing fewer pixels than expected; off-by-one in row stride; reusing a previous frame's shorter pixel buffer for a larger frame.
Related errors
- Loop count invalid.
- x/y invalid.
- Must supply either a local or global palette.
- Disposal out of range.
- Transparent color index.
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/71fcb8c8d8f3d1d8.
Report an issue: GitHub.