Skip to content

Phase 4.2 - Refactor JPEG parsing to support progressive frames and improve error handling - #1

Merged
romulocrj merged 1 commit into
mainfrom
fix/jpeg
Aug 6, 2026
Merged

Phase 4.2 - Refactor JPEG parsing to support progressive frames and improve error handling#1
romulocrj merged 1 commit into
mainfrom
fix/jpeg

Conversation

@romulocrj

Copy link
Copy Markdown
Owner
  • Updated JPEG parsing logic to recognize and accept progressive JPEG metadata.
  • Changed variable names for clarity, replacing 'foundBaseline' with 'foundFrame'.
  • Enhanced error messages for unsupported frame markers and component data.
  • Adjusted tests to validate progressive JPEG handling and ensure proper rejection of unsupported formats.

…mprove error handling

- Updated JPEG parsing logic to recognize and accept progressive JPEG metadata.
- Changed variable names for clarity, replacing 'foundBaseline' with 'foundFrame'.
- Enhanced error messages for unsupported frame markers and component data.
- Adjusted tests to validate progressive JPEG handling and ensure proper rejection of unsupported formats.
Copilot AI lite review requested due to automatic review settings August 6, 2026 13:13
@romulocrj
romulocrj merged commit f44ea01 into main Aug 6, 2026
1 check passed
@romulocrj
romulocrj deleted the fix/jpeg branch August 6, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the JPEG metadata parser so the library can embed more JPEG variants (notably progressive) by recognizing additional SOF frame markers, and updates tests/docs/examples accordingly.

Changes:

  • Extend parseJpeg to accept DCT-based SOF markers (SOF0/SOF1/SOF2) and improve unsupported-frame error messaging.
  • Add/adjust tests and examples to exercise progressive JPEG handling and updated error expectations.
  • Update roadmap/porting status documentation and regenerate distribution/type artifacts.

Reviewed changes

Copilot reviewed 6 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
test/jpeg_phase_4_2.test.mjs Adds progressive JPEG fixture coverage and updates rejection expectations.
src/pdf/image/jpeg.ts Expands accepted SOF markers to include progressive/extended sequential and updates error handling.
examples/jpeg-phase-4.2.mjs Updates the phase 4.2 demo to render baseline/extended/progressive JPEG cards.
examples/generation-results.json Updates generation timestamp metadata.
docs/ROADMAP.md Updates phase 4.2 description to reflect progressive support.
docs/PORTING-STATUS.md Updates porting status text for JPEG parsing scope.
dist/types/pdf/image/jpeg.d.ts Updates public typings docstring to match new JPEG scope.
dist/js_pdf.mjs Regenerated bundle reflecting updated JPEG parsing logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +33 to +42
function replaceFrameMarker(bytes, from, to) {
const copy = bytes.slice();
for (let index = 2; index + 1 < copy.length; index++) {
if (copy[index] === 0xff && copy[index + 1] === from) {
copy[index + 1] = to;
return copy;
}
}
throw new RangeError(`JPEG frame marker 0x${from.toString(16)} was not found`);
}
Comment on lines +70 to 85
test('parseJpeg accepts progressive JPEG metadata', () => {
assert.deepEqual(Pdf.parseJpeg(PROGRESSIVE), {
width: 2,
height: 2,
bitsPerComponent: 8,
components: 3,
colorSpace: 'rgb',
inverted: false
});
});

test('parseJpeg rejects unsupported frames, truncated data and unsupported components', () => {
assert.throws(() => Pdf.parseJpeg(jpeg(sof(0xc3, 10, 10, 3))), /frame marker/);
assert.throws(() => Pdf.parseJpeg(Uint8Array.from([0xff, 0xd8, 0xff, 0xe0, 0, 20])), /truncated/i);
assert.throws(() => Pdf.parseJpeg(jpeg(sof(0xc0, 10, 10, 2))), /component/);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants