Conversation
romulocrj
commented
Aug 6, 2026
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.
There was a problem hiding this comment.
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
parseJpegto 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/); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.