Skip to content
Merged
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
12 changes: 0 additions & 12 deletions .dialyzer_ignore_warnings

This file was deleted.

46 changes: 13 additions & 33 deletions lib/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7080,7 +7080,6 @@ defmodule Image do
{20, 10, 3}

"""
@dialyzer {:nowarn_function, {:ripple, 1}}
@doc subject: "Operation"

@spec ripple(Vimage.t(), Options.Mapim.background_options()) ::
Expand Down Expand Up @@ -7143,7 +7142,6 @@ defmodule Image do
{20, 10, 3}

"""
@dialyzer {:nowarn_function, {:ripple!, 1}}
@doc subject: "Operation"

@spec ripple!(Vimage.t(), Options.Mapim.background_options()) :: Vimage.t() | no_return()
Expand Down Expand Up @@ -9570,7 +9568,6 @@ defmodule Image do
{10, 10, 3}

"""
@dialyzer {:nowarn_function, {:to_polar_coordinates, 1}}
@doc subject: "Operation"

@spec to_polar_coordinates(Vimage.t(), Options.Mapim.background_options()) ::
Expand Down Expand Up @@ -9621,7 +9618,6 @@ defmodule Image do
{10, 10, 3}

"""
@dialyzer {:nowarn_function, {:to_polar_coordinates!, 1}}
@doc subject: "Operation"

@spec to_polar_coordinates!(Vimage.t(), Options.Mapim.background_options()) ::
Expand Down Expand Up @@ -9670,7 +9666,6 @@ defmodule Image do
{10, 10, 3}

"""
@dialyzer {:nowarn_function, {:to_rectangular_coordinates, 1}}
@doc subject: "Operation"

@spec to_rectangular_coordinates(Vimage.t(), Options.Mapim.interpolate_options()) ::
Expand Down Expand Up @@ -9723,7 +9718,6 @@ defmodule Image do
{10, 10, 3}

"""
@dialyzer {:nowarn_function, {:to_rectangular_coordinates!, 1}}
@doc subject: "Operation"

@spec to_rectangular_coordinates!(Vimage.t(), Options.Mapim.interpolate_options()) ::
Expand Down Expand Up @@ -11419,12 +11413,10 @@ defmodule Image do
{:ok, Vimage.t()} | {:error, error()}
def drop_shadow(%Vimage{} = image, options \\ []) do
color = Keyword.get(options, :color, :black)
opacity = Keyword.get(options, :opacity, 0.5)
sigma = Keyword.get(options, :sigma, 5.0)
dx = Keyword.get(options, :dx, 0)
dy = Keyword.get(options, :dy, round(sigma * 2))

with :ok <- validate_drop_shadow_args(opacity, sigma) do
with {:ok, {opacity, sigma}} <- validate_drop_shadow_args(options) do
dy = Keyword.get(options, :dy, round(sigma * 2))
image = if has_alpha?(image), do: image, else: add_alpha!(image, :opaque)
width = width(image)
height = height(image)
Expand Down Expand Up @@ -11472,24 +11464,29 @@ defmodule Image do
end
end

defp validate_drop_shadow_args(opacity, sigma) do
defp validate_drop_shadow_args(options) do
opacity = Keyword.get(options, :opacity, 0.5)
sigma = Keyword.get(options, :sigma, 5.0)

cond do
not (is_number(opacity) and opacity >= 0.0 and opacity <= 1.0) ->
{:error,
%Image.Error{
message: ":opacity must be a number in [0.0, 1.0]",
reason: ":opacity must be a number in [0.0, 1.0]"
reason: :invalid_option,
value: {:opacity, opacity},
message: ":opacity must be a number in [0.0, 1.0]. Found #{inspect(opacity)}"
}}

not (is_number(sigma) and sigma > 0.0) ->
{:error,
%Image.Error{
message: ":sigma must be a positive number",
reason: ":sigma must be a positive number"
reason: :invalid_option,
value: {:sigma, sigma},
message: ":sigma must be a positive number. Found #{inspect(sigma)}"
}}

true ->
:ok
{:ok, {opacity, sigma}}
end
end

Expand Down Expand Up @@ -12551,11 +12548,6 @@ defmodule Image do

"""

# For some reason dialyzer thinks Vix.Vips.Image.write_to_tensor/1
# can only return `{:error, _}`.
@dialyzer {:nowarn_function, {:to_nx, 1}}
@dialyzer {:nowarn_function, {:to_nx, 2}}

@default_shape :hwb

@doc subject: "Matrix", since: "0.5.0"
Expand Down Expand Up @@ -12642,11 +12634,6 @@ defmodule Image do
"""
@doc subject: "Matrix", since: "0.27.0"

# Because of the dialyzer issue for to_nx/2, dialyzer then
# thinks this function has no local return.
@dialyzer {:nowarn_function, {:to_nx!, 1}}
@dialyzer {:nowarn_function, {:to_nx!, 2}}

@spec to_nx!(image :: Vimage.t(), options :: Keyword.t()) ::
Nx.Tensor.t() | no_return()

Expand Down Expand Up @@ -13354,7 +13341,6 @@ defmodule Image do
true

"""
@dialyzer {:nowarn_function, {:to_evision, 2}}

@doc subject: "Matrix", since: "0.9.0"

Expand Down Expand Up @@ -13401,7 +13387,6 @@ defmodule Image do
{300, 328, 3}

"""
@dialyzer {:nowarn_function, {:from_evision, 1}}

@doc subject: "Matrix", since: "0.9.0"

Expand Down Expand Up @@ -13643,8 +13628,6 @@ defmodule Image do
end
end

@dialyzer {:nowarn_function, {:compare_by_metric, 4}}

# Mean square error
# mse = ((a - b) ** 2).avg()

Expand Down Expand Up @@ -13712,8 +13695,6 @@ defmodule Image do
end
end

@dialyzer {:nowarn_function, {:format_size, 1}}

defp format_size(image) do
case Image.BandFormat.nx_format(image) do
{:ok, {:u, size}} -> {:ok, round(:math.pow(2, size))}
Expand Down Expand Up @@ -13969,7 +13950,6 @@ defmodule Image do
upright.

"""
@dialyzer {:nowarn_function, {:skew_angle, 1}}
@doc subject: "Operation"

@spec skew_angle(Vimage.t()) :: float()
Expand Down
14 changes: 0 additions & 14 deletions lib/image/complex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,28 @@ defmodule Image.Complex do
defguard float_format(format) when format in [:VIPS_FORMAT_FLOAT, :VIPS_FORMAT_DOUBLE]
defguard even(bands) when rem(bands, 2) === 0

@dialyzer {:nowarn_function, {:polar, 1}}

def polar(%Vimage{} = image) do
complex(image, &Operation.complex(&1, :VIPS_OPERATION_COMPLEX_POLAR))
end

@dialyzer {:nowarn_function, {:polar!, 1}}

def polar!(%Vimage{} = image) do
case polar(image) do
{:ok, polar} -> polar
{:error, reason} -> raise Image.Error, reason
end
end

@dialyzer {:nowarn_function, {:rectangular, 1}}

def rectangular(%Vimage{} = image) do
complex(image, &Operation.complex(&1, :VIPS_OPERATION_COMPLEX_RECT))
end

@dialyzer {:nowarn_function, {:rectangular!, 1}}

def rectangular!(%Vimage{} = image) do
case rectangular(image) do
{:ok, image} -> image
{:error, reason} -> raise Image.Error, reason
end
end

@dialyzer {:nowarn_function, {:complex, 2}}

defp complex(%Vimage{} = image, fun) do
bands = Vimage.bands(image)
original_format = Vimage.format(image)
Expand All @@ -54,8 +44,6 @@ defmodule Image.Complex do

# Convert to complex

@dialyzer {:nowarn_function, {:to_complex, 3}}

defp to_complex(%Vimage{} = _image, format, bands)
when not complex(format) and not even(bands) do
{:error,
Expand Down Expand Up @@ -85,8 +73,6 @@ defmodule Image.Complex do

# Convert from complex

@dialyzer {:nowarn_function, {:from_complex, 4}}

defp from_complex(image, original_format, :VIPS_FORMAT_DPCOMPLEX, bands)
when not complex(original_format) do
Operation.copy(image, format: :VIPS_FORMAT_DOUBLE, bands: bands)
Expand Down
2 changes: 0 additions & 2 deletions lib/image/enum/band_format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ defmodule Image.BandFormat do
end
end

@dialyzer {:nowarn_function, {:nx_format, 1}}

@doc """
Returns the `Image` format type for an
`Nx` format type.
Expand Down
26 changes: 10 additions & 16 deletions lib/image/math.ex
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ defmodule Image.Math do
{:ok, Kernel.**(a, b)}
end

@spec cos(Vimage.t()) :: {:ok, Vimage.t()}
@spec cos(Vimage.t()) :: {:ok, Vimage.t()} | {:error, Image.error()}
def cos(%Vimage{} = image) do
Operation.math(image, :VIPS_OPERATION_MATH_COS)
end
Expand All @@ -433,7 +433,7 @@ defmodule Image.Math do
{:ok, :math.cos(other)}
end

@spec sin(Vimage.t()) :: {:ok, Vimage.t()}
@spec sin(Vimage.t()) :: {:ok, Vimage.t()} | {:error, Image.error()}
def sin(%Vimage{} = image) do
Operation.math(image, :VIPS_OPERATION_MATH_SIN)
end
Expand Down Expand Up @@ -671,7 +671,7 @@ defmodule Image.Math do
Kernel.>(a, b)
end

@spec greater_than_or_equal!(Vimage.t(), Image.pixel()) :: Vimage.t() | no_return()
@spec greater_than_or_equal!(Vimage.t(), Vimage.t() | Image.pixel()) :: Vimage.t() | no_return()
def greater_than_or_equal!(%Vimage{} = image, value) do
case greater_than_or_equal(image, value) do
{:ok, image} -> image
Expand All @@ -684,7 +684,7 @@ defmodule Image.Math do
Kernel.>=(a, b)
end

@spec equal!(Vimage.t(), Image.pixel()) :: Vimage.t() | no_return()
@spec equal!(Vimage.t(), Vimage.t() | Image.pixel()) :: Vimage.t() | no_return()
def equal!(%Vimage{} = image, value) do
case equal(image, value) do
{:ok, image} -> image
Expand All @@ -697,7 +697,7 @@ defmodule Image.Math do
Kernel.==(a, b)
end

@spec not_equal!(Vimage.t(), Image.pixel()) :: Vimage.t() | no_return()
@spec not_equal!(Vimage.t(), Vimage.t() | Image.pixel()) :: Vimage.t() | no_return()
def not_equal!(%Vimage{} = image, value) do
case not_equal(image, value) do
{:ok, image} -> image
Expand All @@ -710,7 +710,7 @@ defmodule Image.Math do
Kernel.!=(a, b)
end

@spec add!(Vimage.t(), Image.pixel() | number()) :: Vimage.t() | no_return()
@spec add!(Vimage.t(), Vimage.t() | Image.pixel() | number()) :: Vimage.t() | no_return()
def add!(%Vimage{} = image, value) do
case add(image, value) do
{:ok, image} -> image
Expand All @@ -731,7 +731,7 @@ defmodule Image.Math do
Kernel.+(a, b)
end

@spec subtract!(Vimage.t(), Image.pixel()) :: Vimage.t() | no_return()
@spec subtract!(Vimage.t(), Vimage.t() | Image.pixel()) :: Vimage.t() | no_return()
def subtract!(%Vimage{} = image, value) do
case subtract(image, value) do
{:ok, image} -> image
Expand All @@ -752,7 +752,7 @@ defmodule Image.Math do
Kernel.-(a, b)
end

@spec multiply!(Vimage.t(), Image.pixel() | number()) :: Vimage.t() | no_return()
@spec multiply!(Vimage.t(), Vimage.t() | Image.pixel() | number()) :: Vimage.t() | no_return()
def multiply!(%Vimage{} = image, value) do
case multiply(image, value) do
{:ok, image} -> image
Expand All @@ -773,7 +773,7 @@ defmodule Image.Math do
Kernel.*(a, b)
end

@spec divide!(Vimage.t(), Image.pixel()) :: Vimage.t() | no_return()
@spec divide!(Vimage.t(), Vimage.t() | Image.pixel()) :: Vimage.t() | no_return()
def divide!(%Vimage{} = image, value) do
case divide(image, value) do
{:ok, image} -> image
Expand Down Expand Up @@ -826,7 +826,7 @@ defmodule Image.Math do
end
end

@spec pow!(Vimage.t(), number()) :: Vimage.t() | no_return()
@spec pow!(Vimage.t(), Vimage.t() | number()) :: Vimage.t() | no_return()
def pow!(%Vimage{} = image, value) do
case pow(image, value) do
{:ok, image} -> image
Expand All @@ -839,8 +839,6 @@ defmodule Image.Math do
Kernel.**(a, b)
end

@dialyzer {:nowarn_function, {:cos!, 1}}

@spec cos!(Vimage.t()) :: Vimage.t() | no_return()
def cos!(%Vimage{} = image) do
case cos(image) do
Expand All @@ -849,8 +847,6 @@ defmodule Image.Math do
end
end

@dialyzer {:nowarn_function, {:sin!, 1}}

@spec sin!(Vimage.t()) :: Vimage.t() | no_return()
def sin!(%Vimage{} = image) do
case sin(image) do
Expand Down Expand Up @@ -1068,7 +1064,6 @@ defmodule Image.Math do
max_coordinates :: [Image.point(), ...],
maybe_overflow :: :maybe_overflow | nil
}
@dialyzer {:nowarn_function, maxpos: 2}
def maxpos(%Vimage{} = image, n \\ 10) when is_integer(n) do
band_format = Image.band_format(image)
{:ok, {max, opts}} = Operation.max(image, size: n)
Expand Down Expand Up @@ -1119,7 +1114,6 @@ defmodule Image.Math do
{1.0, [{0, 0}], nil}

"""
@dialyzer {:nowarn_function, minpos: 2}
@spec minpos(image :: Vimage.t(), n :: non_neg_integer()) ::
{
maximum :: number(),
Expand Down
2 changes: 0 additions & 2 deletions lib/image/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@ defmodule Image.Text do
# For transparent text we need to render the text in
# white which is then converted later to a transparency
# mask
@dialyzer {:nowarn_function, {:render_text, 2}}

defp render_text(text, %{text_fill_color: :transparent} = options) do
render_text(text, Map.put(options, :text_fill_color, :white))
end
Expand Down
1 change: 0 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ defmodule Image.MixProject do
]
],
dialyzer: [
ignore_warnings: ".dialyzer_ignore_warnings",
plt_add_apps: ~w(mix nx plug evision ex_unit)a
],
compilers: Mix.compilers()
Expand Down
Loading
Loading