Skip to content

Implement JPEG output backend with extracted raster graphics functionality #36

@krystophny

Description

@krystophny

Summary

Implement JPEG output backend similar to the existing PNG backend, following single responsibility principle by extracting common raster graphics functionality.

Background

Currently we have a PNG backend that works well for animation streaming and static image output. We need to add JPEG support while maintaining clean architecture.

Requirements

  1. JPEG Backend Implementation

    • Create fortplot_jpeg.f90 module similar to fortplot_png.f90
    • Support JPEG compression with quality settings
    • Maintain same API pattern as PNG backend (create_jpeg_canvas, get_jpeg_data)
  2. Extract Common Raster Functionality (Single Responsibility Principle)

    • Current PNG backend has raster-specific code mixed with PNG-specific code
    • Extract common raster operations into shared module
    • Both PNG and JPEG backends should use shared raster base
  3. Architecture Requirements

    • Follow existing pattern in fortplot_animation.f90 for backend-agnostic rendering
    • Support memory-based JPEG generation for animation streaming
    • Maintain compatibility with existing PNG functionality

Proposed Structure

src/fortplot_raster_base.f90    # Common raster operations
src/fortplot_png.f90            # PNG-specific encoding (refactored)
src/fortplot_jpeg.f90           # New JPEG encoding

Reference Implementation

Use STB image library as reference for JPEG encoding:
https://github.com/nothings/stb/blob/master/stb_image.h

STB provides a clean, single-header implementation that can guide our Fortran JPEG encoder.

Implementation Notes

  • Use libjpeg or similar for JPEG compression
  • Maintain same quality as PNG for scientific visualization
  • Follow TDD approach with tests first
  • Reference matplotlib JPEG backend for quality standards

Acceptance Criteria

  • JPEG backend creates valid JPEG files
  • Animation streaming works with JPEG frames
  • Common raster functionality extracted to shared module
  • All existing PNG functionality remains working
  • Tests cover JPEG output quality and correctness

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions