-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
370 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,5 @@ | ||
defmodule Imageflow do | ||
alias Imageflow.{Native, Job} | ||
|
||
def get_long_version_string(), do: Native.get_long_version_string() | ||
|
||
@input "input.jpg" | ||
@output "output.png" | ||
|
||
@steps %{ | ||
framewise: %{ | ||
steps: [ | ||
%{ | ||
decode: %{ | ||
io_id: 0 | ||
} | ||
}, | ||
%{ | ||
constrain: %{ | ||
mode: "within", | ||
w: 50 | ||
} | ||
}, | ||
%{ | ||
encode: %{ | ||
io_id: 1, | ||
preset: %{ | ||
pngquant: %{quality: 80} | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
|
||
def test do | ||
{:ok, job} = Job.create() | ||
|
||
job | ||
|> Job.add_input_file(0, @input) | ||
|> Job.add_output_buffer(1) | ||
|> Job.message("v0.1/execute", @steps) | ||
|> Job.save_output_to_file(1, @output) | ||
|
||
{:ok, out} = | ||
Job.get_output_buffer(job, 1) | ||
|> IO.inspect() | ||
|
||
File.write!("out2.png", out, [:binary]) | ||
|
||
Job.destroy(job) | ||
end | ||
def get_long_version_string, do: Native.get_long_version_string() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,56 @@ | ||
defmodule Imageflow.Job do | ||
alias Imageflow.Native | ||
|
||
defstruct [:id] | ||
@type t :: %__MODULE__{} | ||
@type native_ret_t :: :ok | {:error, binary} | ||
|
||
defstruct id: nil | ||
|
||
@spec create :: {:ok, t} | ||
def create do | ||
{:ok, id} = Native.job_create() | ||
|
||
{:ok, %__MODULE__{id: id}} | ||
end | ||
|
||
@spec create! :: t | ||
def create! do | ||
{:ok, job} = __MODULE__.create() | ||
|
||
job | ||
end | ||
|
||
def destroy(%__MODULE__{id: id}), do: Native.job_destroy(id) | ||
|
||
def add_input_buffer(%__MODULE__{id: id} = job, io_id, bytes) do | ||
@spec add_input_buffer(t, number, binary) :: native_ret_t | ||
def add_input_buffer(%__MODULE__{id: id}, io_id, bytes) do | ||
Native.job_add_input_buffer(id, io_id, bytes) | ||
|
||
job | ||
end | ||
|
||
def add_input_file(%__MODULE__{id: id} = job, io_id, path) do | ||
@spec add_input_file(t, number, binary) :: native_ret_t | ||
def add_input_file(%__MODULE__{id: id}, io_id, path) do | ||
Native.job_add_input_file(id, io_id, path) | ||
|
||
job | ||
end | ||
|
||
def add_output_buffer(%__MODULE__{id: id} = job, io_id) do | ||
@spec add_output_buffer(t, number) :: native_ret_t | ||
def add_output_buffer(%__MODULE__{id: id}, io_id) do | ||
Native.job_add_output_buffer(id, io_id) | ||
|
||
job | ||
end | ||
|
||
def save_output_to_file(%__MODULE__{id: id} = job, io_id, path) do | ||
@spec save_output_to_file(t, number, binary) :: native_ret_t | ||
def save_output_to_file(%__MODULE__{id: id}, io_id, path) do | ||
Native.job_save_output_to_file(id, io_id, path) | ||
|
||
job | ||
end | ||
|
||
@spec get_output_buffer(t, number) :: {:ok, binary} | {:error, binary} | ||
def get_output_buffer(%__MODULE__{id: id} = _job, io_id) do | ||
Native.job_get_output_buffer(id, io_id) | ||
end | ||
|
||
def message(%__MODULE__{id: id} = job, method, message) do | ||
@spec message(t, binary, binary) :: {:ok, any} | {:error, binary} | ||
def message(%__MODULE__{id: id}, method, message) do | ||
with {:ok, resp} <- Native.job_message(id, method, Jason.encode!(message)) do | ||
Jason.decode(resp) | ||
{:ok, Jason.decode!(resp)} | ||
end | ||
|
||
job | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
%{ | ||
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"}, | ||
"rustler": {:hex, :rustler, "0.21.1", "5299980be32da997c54382e945bacaa015ed97a60745e1e639beaf6a7b278c65", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6ee1651e10645b2b2f3bb70502bf180341aa058709177e9bc28c105934094bc6"}, | ||
"rustler": {:git, "https://github.com/hansihe/rustler.git", "fa221b9292332955ece4d5733e61cf9054efbc23", [sparse: "rustler_mix"]}, | ||
"toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.