package blurhash

  1. Overview
  2. Docs
A BlurHash encoder in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

0.1.0.tar.gz
md5=5f9831d3f9a22528f1e28f01ee9aec0b
sha512=d73828e4556c94a2460f05629e69ffee4f481763731cec5cbb87a1dafcedcd337613c39ab67661a08dcc5e15dc3b4ff18b34db3685fe5e245030588aafb75014

Description

A BlurHash encoder in OCaml

Tags

blurhash

Published: 12 Sep 2023

README

ocaml-blurhash

A Blurhash encoder implementation written in OCaml.

Documentation.

Usage

The only function provided by ocaml-blurhash is Blurhash.blur_hash_for_pixels, which takes the same arguments as blurHashForPixels in the C reference implementation.

Although ocaml-blurhash does not depend on any image library, you can use camlimages to load an image from a file.

let load_image_as_rgb24 ~path =
  match OImages.(load path [] |> tag) with
  | Rgb24 img -> img
  | Rgba32 img -> img#to_rgb24
  | Index8 img -> img#to_rgb24
  | Index16 img -> img#to_rgb24
  | Cmyk32 _ -> failwith "Not supported image type: Cmyk32"

let blurhash ~x_components ~y_components src =
  Blurhash.blur_hash_for_pixels ~x_components ~y_components ~width:src#width
    ~height:src#height ~bytes_per_row:(src#width * 3) src#dump

let test_encode_case1 () =
  let src = load_image_as_rgb24 ~path:"../../../test/test.ppm" in
  let hash = blurhash ~x_components:4 ~y_components:3 src in
  Alcotest.(check string) "test1" "LFE.@D9F01_2%L%MIVD*9Goe-;WB" hash;
  ()

License

MIT

Dependencies (2)

  1. ocaml >= "4.08.0"
  2. dune >= "3.3"

Dev Dependencies (3)

  1. odoc with-doc
  2. camlimages with-test
  3. alcotest with-test

Used by

None

Conflicts

None

OCaml

Innovation. Community. Security.