Skip to content

Refactor duplicated JPEG segment parsing logic#81

Merged
shibukawa merged 1 commit intomasterfrom
codex/refactor-code-to-reduce-duplication
Mar 3, 2026
Merged

Refactor duplicated JPEG segment parsing logic#81
shibukawa merged 1 commit intomasterfrom
codex/refactor-code-to-reduce-duplication

Conversation

@shibukawa
Copy link
Copy Markdown
Owner

Motivation

  • JPEG marker-scanning logic was duplicated across _get_size, _get_dpi, and _get_channels, making the code harder to maintain and reason about.
  • Consolidate JPEG segment parsing to reduce duplication and centralize error handling for robustness.

Description

  • Introduced _JPEG_NO_SOF_MARKERS to list JPEG markers that are not SOF markers and used it in SOF detection.
  • Added helper def _read_jpeg_segment_header(fhandle) to read a JPEG segment header and validate its size.
  • Added helper def _seek_to_jpeg_sof(fhandle) to seek to the next SOF marker, replacing inline marker-scanning loops.
  • Replaced duplicated loops in _get_size, _get_dpi, and _get_channels to call the new helpers and unified JPEG-related exception handling to raise ValueError on parse errors.

Testing

  • Ran the full test suite with python -m pytest -q and all tests passed (82 passed).
  • No regressions observed in image parsing behavior according to the existing tests.

Codex Task

@shibukawa shibukawa merged commit 53eff2e into master Mar 3, 2026
5 checks passed
@shibukawa shibukawa deleted the codex/refactor-code-to-reduce-duplication branch March 3, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant