Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raising functions and upgrade deps #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ by adding `turbojpeg` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:turbojpeg, "~> 0.4"}
{:turbojpeg, "~> 0.5"}
]
end
```
Expand Down
4 changes: 2 additions & 2 deletions bundlex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ defmodule Turbojpeg.BundlexProject do

def project() do
[
natives: natives(Bundlex.platform())
natives: natives()
]
end

def natives(_platform) do
def natives() do
[
turbojpeg_native: [
interface: :nif,
Expand Down
22 changes: 22 additions & 0 deletions lib/turbojpeg.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ defmodule Turbojpeg do
Native.yuv_to_jpeg(yuv, width, height, quality, format)
end

@doc """
Same as `yuv_to_jpeg/5`, but raises in case of failure.
"""
@spec yuv_to_jpeg!(binary(), width, height, quality, format) :: binary()
def yuv_to_jpeg!(yuv, width, height, quality, format) do
case Native.yuv_to_jpeg(yuv, width, height, quality, format) do
{:ok, binary} -> binary
{:error, reason} -> raise "cannot compress yuv into a jpeg: #{inspect(reason)}"
end
end

@doc """
Converts jpeg to yuv

Expand All @@ -39,6 +50,17 @@ defmodule Turbojpeg do
Native.jpeg_to_yuv(jpeg)
end

@doc """
Same as `jpeg_to_yuv/1`, but raises in case of failure.
"""
@spec jpeg_to_yuv!(binary()) :: binary()
def jpeg_to_yuv!(jpeg) do
case Native.jpeg_to_yuv(jpeg) do
{:ok, binary} -> binary
{:error, reason} -> raise "cannot decompress jpeg: #{inspect(reason)}"
end
end

@doc """
Gets the header from a jpeg binary

Expand Down
8 changes: 4 additions & 4 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Turbojpeg.MixProject do
use Mix.Project

@version "0.4.0"
@version "0.5.0"
@github_link "https://github.com/binarynoggin/elixir-turbojpeg"

def project do
Expand Down Expand Up @@ -33,10 +33,10 @@ defmodule Turbojpeg.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:bundlex, "~> 1.4.0"},
{:unifex, "~> 1.1.0"},
{:bundlex, "~> 1.5.0"},
{:unifex, "~> 1.2.0"},
{:membrane_core, "~> 1.0"},
{:membrane_raw_video_format, "~> 0.3.0"},
{:membrane_raw_video_format, "~> 0.4.0"},
{:ex_doc, "~> 0.30", only: :dev, runtime: false},
{:propcheck, "~> 1.4.0", only: [:test]},
{:mogrify, "~> 0.9.0", only: [:test, :dev]},
Expand Down
Loading