openjpeg_ffi 0.3.1 copy "openjpeg_ffi: ^0.3.1" to clipboard
openjpeg_ffi: ^0.3.1 copied to clipboard

Dart bindings to OpenJPEG for encoding and decoding raw JPEG2000 codestreams — native-assets FFI on native platforms, WebAssembly on web. No manual setup required either way.

example/lib/main.dart

import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:openjpeg_ffi/openjpeg_ffi.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String resultText = 'loading…';

  @override
  void initState() {
    super.initState();
    _run();
  }

  Future<void> _run() async {
    // No-op on native platforms; on web this awaits the WebAssembly module
    // instantiating — required before the first decodeJ2k/encodeJ2k call.
    await initOpenJpegWasm();

    // No bundled .j2k fixture in this minimal example — this just proves
    // the call reaches OpenJPEG (native or WebAssembly, depending on
    // platform) and a real decode error comes back, which is enough to
    // confirm the wiring itself works end to end. See
    // ../test/openjpeg_ffi_test.dart / ../test/openjpeg_ffi_web_test.dart
    // for real decodes against real JPEG2000 data.
    String text;
    try {
      final image = decodeJ2k(Uint8List(0));
      text = 'decoded ${image.width}x${image.height}';
    } on Jp2kDecodeException catch (e) {
      text =
          'call reached OpenJPEG, got the expected decode error:\n${e.message}';
    }
    setState(() => resultText = text);
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: const Text('openjpeg_ffi')),
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(24),
            child: Text(
              resultText,
              style: const TextStyle(fontSize: 18),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ),
    );
  }
}
0
likes
160
points
449
downloads

Documentation

API reference

Publisher

verified publishermonlycute.id.vn

Weekly Downloads

Dart bindings to OpenJPEG for encoding and decoding raw JPEG2000 codestreams — native-assets FFI on native platforms, WebAssembly on web. No manual setup required either way.

Repository (GitHub)
View/report issues

Topics

#ffi #jpeg2000 #image #codec

License

Apache-2.0 (license)

Dependencies

code_assets, ffi, hooks, logging, native_toolchain_c

More

Packages that depend on openjpeg_ffi