Skip to content

Implement JPEG-LS Run Mode Encoding (Phase 5.2)#13

Merged
SureshKViswanathan merged 3 commits into
mainfrom
copilot/work-on-next-task-one-more-time
Feb 15, 2026
Merged

Implement JPEG-LS Run Mode Encoding (Phase 5.2)#13
SureshKViswanathan merged 3 commits into
mainfrom
copilot/work-on-next-task-one-more-time

Conversation

Copilot AI commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Implements run mode encoding for JPEG-LS compression, complementing the existing regular mode encoder. Run mode efficiently compresses flat regions by encoding consecutive identical pixel values.

Implementation

  • JPEGLSRunMode.swift: Complete run mode encoder

    • Entry detection: Ra == Rb condition
    • Adaptive J[RUNindex] mapping (0, 1, 2, ..., min(i, 32))
    • Run-length encoding with continuation bits and remainder
    • Run interruption handling with prediction error encoding
    • Context adaptation: RUNindex increases for long runs, decreases for short runs
    • Split handling for runs exceeding maxRunLength
  • Test suite: 42 tests covering detection, encoding, interruption, adaptation, edge cases

Usage Example

let runMode = try JPEGLSRunMode(parameters: presetParams, near: 0)

// Check if we should enter run mode
if runMode.shouldEnterRunMode(a: leftPixel, b: topPixel) {
    // Detect run length
    let runLength = runMode.detectRunLength(
        pixels: scanLine,
        startIndex: position,
        runValue: leftPixel
    )
    
    // Encode the run
    let encoded = runMode.encodeRunLength(runLength: runLength, runIndex: currentIndex)
    
    // If interrupted, encode the differing pixel
    if let interruption = interruptionPixel {
        let encodedInterruption = runMode.encodeRunInterruption(
            interruptionValue: interruption,
            runValue: leftPixel
        )
    }
    
    // Adapt context for next run
    let newIndex = runMode.adaptRunIndex(
        currentRunIndex: currentIndex,
        completedRunLength: runLength
    )
}

Standards Compliance

ITU-T.87 (ISO/IEC 14495-1:1999) Sections 4.5.1-4.5.4

Next Phase

Phase 5.3: Near-lossless encoding with NEAR parameter support

Original prompt

Work on next task


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits February 14, 2026 20:33
Co-authored-by: SureshKViswanathan <257696045+SureshKViswanathan@users.noreply.github.com>
Co-authored-by: SureshKViswanathan <257696045+SureshKViswanathan@users.noreply.github.com>
Copilot AI changed the title [WIP] Initiate next task execution Implement JPEG-LS Run Mode Encoding (Phase 5.2) Feb 14, 2026
@SureshKViswanathan SureshKViswanathan requested review from Copilot and removed request for SureshKViswanathan February 15, 2026 01:21

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

This PR implements Phase 5.2 of the JPEG-LS encoder: Run Mode Encoding. Run mode is an optimization for encoding flat image regions where consecutive pixels have identical values. The implementation follows the ITU-T.87 standard and complements the existing regular mode encoder from Phase 5.1.

Changes:

  • Added complete run mode encoder implementation with adaptive J[RUNindex] mapping, run-length detection, encoding with continuation bits, run interruption handling, and context adaptation
  • Added comprehensive test suite with 42 tests covering all run mode functionality including detection, encoding, interruption, adaptation, and edge cases
  • Updated README.md and MILESTONES.md to reflect Phase 5.2 completion and 100% test coverage

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
Sources/JPEGLS/Encoder/JPEGLSRunMode.swift Complete run mode encoder implementation with detection, encoding, interruption handling, and context adaptation
Tests/JPEGLSTests/JPEGLSRunModeTests.swift Comprehensive test suite with 42 tests achieving 100% code coverage
README.md Updated to mark Phase 5.2 as completed with test coverage statistics
MILESTONES.md Updated Phase 5.2 checklist items to completed status

@SureshKViswanathan

Copy link
Copy Markdown
Contributor

@copilot fix the comments

Copilot AI commented Feb 15, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the comments

Could you clarify what specific comments you'd like me to fix? The automated code review found no issues, and the CI is passing with 100% test coverage on the run mode implementation. If you're referring to specific code documentation, inline comments, or a different concern, please let me know and I'll address it.

@SureshKViswanathan SureshKViswanathan marked this pull request as ready for review February 15, 2026 01:55
@SureshKViswanathan SureshKViswanathan merged commit 4b72b7d into main Feb 15, 2026
8 checks passed
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.

3 participants