Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

cinderblocks/CoreJ2K

 
 

Repository files navigation

▄█████  ▄▄▄  ▄▄▄▄  ▄▄▄▄▄    ██ ████▄ ██ ▄█▀ 
██     ██▀██ ██▄█▄ ██▄▄     ██  ▄██▀ ████   
▀█████ ▀███▀ ██ ██ ██▄▄▄ ████▀ ███▄▄ ██ ▀█▄ 
A Managed and Portable JPEG2000 Codec for .NET Platforms

NuGet Downloads Build License Socket Badge


🚀 Quick Start

dotnet add package CoreJ2K
dotnet add package CoreJ2K.Skia

Simple API

using CoreJ2K;
using CoreJ2K.Configuration;

// Decode
var image = J2kImage.FromStream(File.OpenRead("image.jp2"));
var bitmap = image.As<SKBitmap>();

// Encode with modern API (recommended)
byte[] data = CompleteConfigurationPresets.Web
    .WithCopyright("© 2025")
    .Encode(imageSource);

// Or use traditional API
byte[] j2kData = J2kImage.ToBytes(bitmap);

📖 Full Documentation💻 More Examples🎯 Modern API Guide📦 All Packages


📑 Table of Contents


About

What is CoreJ2K?

CoreJ2K is a pure C# implementation of the JPEG 2000 image compression standard for .NET. Modern fork of CSJ2K (C# port of jj2000), designed for .NET Standard and modern .NET platforms. Provides both encoding and decoding with 100% ISO/IEC 15444-1 Part 1 compliance.

Key Features

Feature Description
🏆 Standards Compliant 100% JPEG 2000 Part 1 (ISO/IEC 15444-1) • 27 codestream markers • 22 JP2 boxes
⚡ Modern .NET .NET Standard 2.0/2.1 • .NET 8/9 • .NET Framework 4.8.1 • All platforms
🎯 Production Ready Lossless/Lossy • ROI • Files >4GB • Error resilience • 369+ tests
📦 Easy Integration NuGet packages • Simple API • SkiaSharp/ImageSharp/System.Drawing support
🆓 Open Source BSD-3-Clause • No fees • Active development • Community driven

Why Choose CoreJ2K?

✅ For .NET Developers ✅ For Production Use
Native C# (no P/Invoke) Battle-tested & stable
Memory safe (managed code) Complete Part 1 compliance
Thread-safe operations Medical imaging (DICOM) ready
Familiar NuGet install GIS/geospatial compatible
Works with all image libraries Interoperable with all decoders

Comparison: CoreJ2K is the only open-source .NET library with full JPEG 2000 Part 1 compliance and complete pointer marker read/write support.

↑ Back to top


Getting Started

Installation

Core Library

dotnet add package CoreJ2K

With Image Integration

# SkiaSharp (recommended - cross-platform)
dotnet add package CoreJ2K.Skia

# ImageSharp (modern .NET)
dotnet add package CoreJ2K.ImageSharp

# System.Drawing (Windows)
dotnet add package CoreJ2K.Windows

# Pfim (DDS/TGA)
dotnet add package CoreJ2K.Pfim

Quick Examples

Basic Decoding

using CoreJ2K;
using SkiaSharp;

// From file
var image = J2kImage.FromStream(File.OpenRead("image.jp2"));
var bitmap = image.As<SKBitmap>();

// From bytes
byte[] data = File.ReadAllBytes("image.j2k");
var image2 = J2kImage.FromBytes(data);

// Save as PNG
using var output = File.OpenWrite("output.png");
bitmap.Encode(output, SKEncodedImageFormat.Png, 90);

Basic Encoding

// Default (high quality)
byte[] j2k = J2kImage.ToBytes(bitmap);

// Lossless
var lossless = new ParameterList { ["lossless"] = "on", ["file_format"] = "on" };
byte[] data = J2kImage.ToBytes(bitmap, lossless);

// Lossy with target bitrate
var lossy = new ParameterList { ["rate"] = "0.5", ["file_format"] = "on" };
byte[] compressed = J2kImage.ToBytes(bitmap, lossy);

Platform Support

Platform Framework Package
Windows .NET 8/9, Framework 4.8.1, Standard 2.x CoreJ2K, CoreJ2K.Windows
Linux .NET 8/9, Standard 2.x CoreJ2K, CoreJ2K.Skia
macOS .NET 8/9, Standard 2.x CoreJ2K, CoreJ2K.Skia
Mobile .NET 8/9 (MAUI), Xamarin CoreJ2K, CoreJ2K.Skia
Web .NET 8/9, ASP.NET Core CoreJ2K, CoreJ2K.ImageSharp

↑ Back to top


Documentation

Modern Configuration API

CoreJ2K 1.3.0+ includes a comprehensive, fluent configuration API that makes JPEG 2000 encoding easier and more intuitive than ever.

Quick Start with Presets

using CoreJ2K.Configuration;

// One-liner encoding with preset
byte[] webImage = CompleteConfigurationPresets.Web
    .WithCopyright("© 2025")
    .Encode(imageSource);

// Medical imaging (lossless)
byte[] medical = CompleteConfigurationPresets.Medical
    .WithMetadata(m => m
        .WithComment("Patient: Anonymous")
        .WithComment("Study: CT Scan"))
    .Encode(dicomImage);

// High-quality photography
byte[] photo = CompleteConfigurationPresets.Photography
    .WithCopyright("© 2025 Photographer")
    .WithComment("Sunset over mountains")
    .Encode(photograph);

Quality Presets

// Lossless (perfect reconstruction)
var config = new CompleteEncoderConfigurationBuilder()
    .ForLossless()
    .Build();

// High quality (90% quality)
var config = new CompleteEncoderConfigurationBuilder()
    .ForHighQuality()
    .Build();

// Balanced (75% quality)
var config = new CompleteEncoderConfigurationBuilder()
    .ForBalanced()
    .Build();

// High compression
var config = new CompleteEncoderConfigurationBuilder()
    .ForHighCompression()
    .Build();

Use Case Presets

// Medical imaging - lossless with appropriate settings
.ForMedical()

// Archival storage - very high quality + error resilience
.ForArchival()

// Web delivery - progressive + balanced quality
.ForWeb()

// Thumbnail generation - fast + small
.ForThumbnail()

// Geospatial/GIS - spatial browsing + tiled
.ForGeospatial()

// Streaming - quality progressive
.ForStreaming()

Fine-Grained Control

var config = new CompleteEncoderConfigurationBuilder()
    .WithQuality(0.85)
    .WithQuantization(q => q
        .UseExpounded()
        .WithBaseStepSize(0.008f)
        .WithGuardBits(2))
    .WithWavelet(w => w
        .UseIrreversible_9_7()
        .WithDecompositionLevels(6))
    .WithProgression(p => p.UseLRCP())
    .WithTiles(t => t.SetSize(512, 512))
    .WithMetadata(m => m
        .WithComment("Custom configuration")
        .WithCopyright("© 2025")
        .WithXml(customMetadata))
    .Build();

byte[] data = J2kImage.ToBytes(image, config);

📚 Complete Guides:

Traditional API (Encoding Guide)

Lossless

var p = new ParameterList();
p["lossless"] = "on";
p["file_format"] = "on";
byte[] data = J2kImage.ToBytes(bitmap, p);

Lossy with Quality

var p = new ParameterList();
p["rate"] = "0.5";         // 0.5 bits/pixel
p["file_format"] = "on";   // JP2 wrapper
p["tiles"] = "1024 1024";  // Tile size
p["Wlev"] = "5";           // Decomposition levels
byte[] data = J2kImage.ToBytes(bitmap, p);

Progressive Quality Layers

var p = new ParameterList();
p["rate"] = "0.2";
p["Alayers"] = "0.015 +20 2.0 +10";  // Multiple layers
p["Aptype"] = "res";                  // Resolution progression
byte[] data = J2kImage.ToBytes(bitmap, p);

Advanced Parameters

Common encoder parameters (case-sensitive):

Parameter Example Value Description
lossless "on" / "off" Enable lossless compression
rate "0.5" Target bitrate (bits per pixel)
file_format "on" / "off" Use JP2 container format
tiles "1024 1024" Tile dimensions (width height)
Wlev "5" Wavelet decomposition levels
Wcboff "0 0" Code-block partition origin
Ffilters "w5x3" / "w9x7" Wavelet filter (reversible/irreversible)
Qtype "reversible" / "expounded" Quantization type
Aptype "res" / "layer" / "pos-comp" Progression order
Alayers "0.015 +20 2.0" Layer rate specification
Mct "on" / "off" Multi-component transform
Psop "on" / "off" SOP markers (error resilience)
Peph "on" / "off" EPH markers (error resilience)

Note: Parameter names match internal encoder conventions (no leading dashes).

Usage Notes

  • InterleavedImage: Cross-platform image wrapper. Use As<T>() to convert to platform types (e.g., SKBitmap)
  • ParameterList: Optional encoding parameters. Use indexer to set: params["key"] = "value"
  • Image Sources: Accepts SKBitmap, Bitmap, Image, or codec-specific formats (PGM/PPM/PGX streams)
  • Thread Safety: Decoding and encoding operations are thread-safe

↑ Back to top


Standards & Compliance

Part 1: Core Coding System

CoreJ2K achieves 100% JPEG 2000 Part 1 (ISO/IEC 15444-1) compliance:

Component Support Details
Codestream Markers ✅ 27/27 (100%) All main header, tile-part, and packet markers
JP2 File Format ✅ 22/22 boxes (100%) All required and optional boxes
Wavelet Transforms ✅ Complete 5-3 (reversible), 9-7 (irreversible)
Quantization ✅ Complete Reversible, scalar derived, scalar expounded
Entropy Coding ✅ Complete Full MQ coder (arithmetic coding)
ROI Encoding ✅ Complete Max-shift method, arbitrary shapes
Progression Orders ✅ All 5 LRCP, RLCP, RPCL, PCRL, CPRL
Error Resilience ✅ Complete SOP/EPH markers, segmentation symbols
Pointer Markers ✅ Full R/W PPM, PPT, PLM, PLT, TLM (read and write)
Extended Length ✅ Complete XLBox support for files >4GB
ICC Profiles ✅ Complete Full color management support
Metadata ✅ Complete XML, UUID, resolution, channels

Compliance Scores:

  • Baseline Profile: ✅ 100%
  • Profile 0: ✅ 100%
  • Profile 1: ✅ 100%
  • Extended Features: ✅ 100%

Library Comparison

Quick comparison with major JPEG 2000 libraries:

Feature CoreJ2K Kakadu OpenJPEG JJ2000 LEADTOOLS
Part 1 Compliance ✅ 100% ✅ 100% ⚠️ ~95% ⚠️ ~90% ✅ 100%
Language C# C++ C Java C/C++
License BSD (Free) Commercial BSD (Free) JJ2000 Commercial
Cost ✅ Free ❌ $$$$ ✅ Free ✅ Free ❌ $$$$
.NET Native ⚠️ P/Invoke
Memory Safety ✅ Managed ⚠️ Manual ⚠️ Manual ✅ Managed ⚠️ Manual
Pointer Markers ✅ Full R/W ✅ Full R/W ⚠️ Read only ⚠️ Read only ✅ Full R/W
Files >4GB ✅ Yes ✅ Yes ⚠️ Limited ❌ No ✅ Yes
Active Dev ✅ 2025 ✅ 2024 ✅ 2024 ❌ 2010 ✅ 2024

CoreJ2K Unique Advantages:

  • Only open-source .NET library with full Part 1 compliance
  • Only open-source library with complete pointer marker read/write
  • Memory-safe managed code (no buffer overflows)
  • Zero licensing costs

📊 View detailed comparison tables →

JPEG 2000 Specification Compliance

CoreJ2K supports multiple parts of ISO/IEC 15444:

Part Name Read Write Status
Part 1 Core Coding System ✅ Full ✅ Full 100% Complete
Part 2 Extensions ⚠️ Partial ⚠️ Partial ~30% (select features)
Part 4 Conformance Testing N/A N/A 100% Complete

Part 1 covers 99% of real-world JPEG 2000 usage including:

  • ✅ Medical imaging (DICOM)
  • ✅ Digital cinema (DCP)
  • ✅ Geospatial/satellite imagery
  • ✅ Digital archives and libraries
  • ✅ High-quality image storage

📖 View complete specification details →

↑ Back to top


Support

Resources

External Links

Support the Project

If CoreJ2K helps your project:

  • Star the repository on GitHub
  • 📢 Share with others
  • 💰 Donate via cryptocurrency:
    • ZEC
    • BTC

↑ Back to top


Contributing

Contributions welcome! Ways to help:

  • 🐛 Report bugs via GitHub Issues
  • 💡 Suggest features in Discussions
  • 📝 Improve docs with pull requests
  • 🧪 Add tests for better coverage
  • 🔧 Fix issues and submit PRs

↑ Back to top


License

BSD 3-Clause License

Copyright (c) 1999-2000 JJ2000 Partners
Copyright (c) 2007-2012 Jason S. Clary
Copyright (c) 2013-2016 Anders Gustafsson, Cureos AB
Copyright (c) 2024-2025 Sjofn LLC

Free to use in commercial and open-source projects. No licensing fees.

→ Full license text


Made with ❤️ for the .NET community

GitHub stars GitHub issues Commit Activity

↑ Back to top


Appendix: Detailed Comparison Tables

Click to expand full library comparison

Standards Compliance and Features

Feature CoreJ2K Kakadu OpenJPEG JJ2000 JasPer Pillow LEADTOOLS
Part 1 Compliance ✅ 100% ✅ 100% ⚠️ ~95% ⚠️ ~90% ⚠️ ~85% ⚠️ ~70% ✅ 100%
Decode ✅ Full ✅ Full ✅ Full ✅ Full ✅ Full ✅ Basic ✅ Full
Encode ✅ Full ✅ Full ✅ Full ✅ Full ✅ Full ❌ No ✅ Full
JP2 File Format ✅ Full ✅ Full ✅ Full ✅ Full ⚠️ Partial ⚠️ Basic ✅ Full
Lossless ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
Lossy ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
Error Resilience (SOP/EPH) ✅ Full ✅ Full ✅ Full ✅ Full ⚠️ Partial ❌ No ✅ Full
Pointer Markers (PPM/PPT/PLM/PLT/TLM) ✅ Full R/W ✅ Full R/W ⚠️ Read only ⚠️ Read only ❌ No ❌ No ✅ Full R/W
ROI (Region of Interest) ✅ Yes ✅ Yes ✅ Yes ✅ Yes ⚠️ Limited ❌ No ✅ Yes
Extended Length (XLBox) ✅ Full ✅ Full ⚠️ Limited ❌ No ❌ No ❌ No ✅ Full
Multi-component Transform ✅ Yes ✅ Yes ✅ Yes ✅ Yes ⚠️ Limited ⚠️ Limited ✅ Yes
Tile-based Processing ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes ⚠️ Limited ✅ Yes
Progression Orders ✅ All 5 ✅ All 5 ✅ All 5 ✅ All 5 ⚠️ Limited ⚠️ Limited ✅ All 5
Quality Layers ✅ Unlimited ✅ Unlimited ✅ Unlimited ✅ Unlimited ⚠️ Limited ⚠️ Limited ✅ Unlimited
ICC Profile Support ✅ Full ✅ Full ✅ Full ⚠️ Basic ⚠️ Basic ✅ Full ✅ Full
Metadata (XML/UUID) ✅ Full ✅ Full ⚠️ Partial ⚠️ Partial ❌ No ⚠️ Basic ✅ Full
Palette/Component Mapping ✅ Full ✅ Full ✅ Full ⚠️ Partial ⚠️ Partial ❌ No ✅ Full

Technical Characteristics

Aspect CoreJ2K Kakadu OpenJPEG JJ2000 JasPer Pillow LEADTOOLS
Language C# C++ C Java C Python/C C/C++
License BSD (Open) Commercial BSD (Open) JJ2000 (Open) MIT (Open) PIL (Open) Commercial
Cost ✅ Free ❌ $$$$ ✅ Free ✅ Free ✅ Free ✅ Free ❌ $$$$
Active Development ✅ Active ✅ Active ✅ Active ❌ Abandoned ⚠️ Minimal ✅ Active ✅ Active
Last Update 2025 2024 2024 2010 2022 2025 2024
Platform Support .NET all All All JVM All All Windows mainly
Cross-platform ✅ Full ✅ Full ✅ Full ✅ Full ✅ Full ✅ Full ⚠️ Limited
Memory Safety ✅ Managed ⚠️ Manual ⚠️ Manual ✅ Managed ⚠️ Manual ✅ Managed ⚠️ Manual
Multi-threading ✅ Safe ✅ Yes ✅ Yes ⚠️ Limited ⚠️ Limited ✅ Yes ✅ Yes
SIMD Optimization ⚠️ Planned ✅ Full ✅ Full ❌ No ❌ No ⚠️ Limited ✅ Full

Performance and Quality

Metric CoreJ2K Kakadu OpenJPEG JJ2000 JasPer Pillow LEADTOOLS
Encoding Speed ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐
Decoding Speed ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐
Compression Ratio ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐
Image Quality ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐
Memory Efficiency ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐
Large File Support (>4GB) ✅ Yes ✅ Yes ⚠️ Limited ❌ No ❌ No ❌ No ✅ Yes

Developer Experience

Aspect CoreJ2K Kakadu OpenJPEG JJ2000 JasPer Pillow LEADTOOLS
Documentation ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
API Simplicity ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐
Code Examples ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
NuGet/Package Manager ✅ Yes ❌ No ✅ Yes ⚠️ Maven ❌ Manual ✅ PyPI ✅ Yes
Community Support ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐
Issue Tracking ✅ GitHub ⚠️ Private ✅ GitHub ❌ Closed ✅ GitHub ✅ GitHub ⚠️ Private
Integration Ease ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐

Use Case Suitability

Use Case CoreJ2K Kakadu OpenJPEG JJ2000 JasPer Pillow LEADTOOLS
.NET Applications ⭐⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐
Cross-platform Apps ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐
Web Services ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐
Mobile Apps ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐
Medical Imaging ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐
Geospatial/GIS ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐⭐⭐
Archive/Digital Libraries ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐

About

CoreJ2K is a managed JPEG2000 codec for C#

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%