Skip to content

promote fillvalue type if it is Colorant#25

Closed
johnnychen94 wants to merge 1 commit intomasterfrom
jc/colors
Closed

promote fillvalue type if it is Colorant#25
johnnychen94 wants to merge 1 commit intomasterfrom
jc/colors

Conversation

@johnnychen94
Copy link
Copy Markdown
Member

@johnnychen94 johnnychen94 commented Mar 16, 2020

It's weird that regions are not filled by fillvalue in following cases

# in master: filled by Gray(RGB(1.,0.,0.))
# in this PR: filled by RGB(1.,0.,0.)
PaddedView(RGB(1.,0.,0.), fill(Gray(0.), 2, 2), (-1:4, -1:4))

Cases such as transparent colors as fillvalue are also handled.

The only issue I see is the loading time:

  • this branch without ColorTypes loaded: 0.26s
  • this branch with ColorTypes loaded: 0.48s
  • master: 0.07s

If the loading time is unacceptable, the only place I can think of is ImageShow/ImageCore -- but that would be type piracy IIUC.

This PR serves JuliaImages/ImageShow.jl#19 to make mosaicview a really useful imshow alternative

It's weird that regions are not filled by `fillvalue` in following cases

    PaddedView(colorant"red", fill(Gray(0.), 2, 2), (-1:4, -1:4))

This commit introduce a new non-exported trait `filltype` to promote
fillvalue type so that these kinds of behaviors are corrected.

Missing and Nothing are also handled by `filltype`
@johnnychen94 johnnychen94 requested a review from timholy March 16, 2020 19:19
@johnnychen94 johnnychen94 changed the title promote filltype if it is Colorant promote fillvalue type if it is Colorant Mar 16, 2020
@johnnychen94 johnnychen94 removed the request for review from timholy March 19, 2020 14:59
@johnnychen94
Copy link
Copy Markdown
Member Author

I now think this patch should go to ImageCore instead of this package.

johnnychen94 added a commit that referenced this pull request Mar 20, 2020
This continues #24 by make filltype conversion extensible to other
packages, e.g., it makes lifting filltype for `Colorants` possible
in other packages.

This is a rework/breaking PR of #25
johnnychen94 added a commit to JuliaImages/ImageCore.jl that referenced this pull request Mar 20, 2020
This ensure that `fillvalue` is of dominant role of eltype of PaddedView.

One consequence of this is transparent color is correctly filled even if
`img` isn't of eltype `ARGB`:

`PaddedView(ARGB(0, 0, 0, 0), img, indices)`

This is a rework of JuliaArrays/PaddedViews.jl#25
and co-operates JuliaArrays/PaddedViews.jl#26
@johnnychen94
Copy link
Copy Markdown
Member Author

closed in favor of #26

@johnnychen94 johnnychen94 deleted the jc/colors branch March 20, 2020 17:46
johnnychen94 added a commit that referenced this pull request Mar 20, 2020
This continues #24 by make filltype conversion extensible to other
packages, e.g., it makes lifting filltype for `Colorants` possible
in other packages.

This is a rework/breaking PR of #25
johnnychen94 added a commit that referenced this pull request Apr 2, 2020
This continues #24 by make filltype conversion extensible to other
packages, e.g., it makes lifting filltype for `Colorants` possible
in other packages.

This is a rework/breaking PR of #25
@timholy
Copy link
Copy Markdown
Member

timholy commented Apr 3, 2020

Sorry to be slow to look at this, "real work" has been quite insane lately. Next week should settle out considerably.

What about adding a constructor PaddedView{T}(fillvalue, data, ...) letting the user pick the eltype directly?

@johnnychen94
Copy link
Copy Markdown
Member Author

johnnychen94 commented Apr 6, 2020

Sorry to be slow to look at this, "real work" has been quite insane lately. Next week should settle out considerably.

Keep safe! ❤️

What about adding a constructor PaddedView{T}(fillvalue, data, ...) letting the user pick the eltype directly?

Exporting the type control to users looks good to me, but I'm a little worried when this usage being abused, e.g.,

julia> A = rand(Float64, 512, 512);

julia> @btime collect(PaddedView(0, $A, (-2:515, -2:515)));
  167.392 μs (3 allocations: 2.05 MiB)

julia> @btime collect(PaddedView{Float32}(0, $A, (-2:515, -2:515)));
  195.014 μs (3 allocations: 1.02 MiB)

would this be an issue?

@timholy
Copy link
Copy Markdown
Member

timholy commented Apr 6, 2020

In the first case values are being returned directly from A, in the second they are converted to Float32 before use. It's slightly puzzling in light of

julia> using BenchmarkTools, MappedArrays

julia> A = rand(Float64, 512, 512);

julia> B64 = of_eltype(Float64, A);

julia> B32 = of_eltype(Float32, A);

julia> @btime collect($B64);
  106.468 μs (2 allocations: 2.00 MiB)

julia> @btime collect($B32);
  71.884 μs (2 allocations: 1.00 MiB)

but the presence of a branch here is not to be discounted.

@johnnychen94
Copy link
Copy Markdown
Member Author

johnnychen94 commented Apr 7, 2020

I think I benchmarked incorrectly, the memory reallocation differs for Float32 and Float64. The new benchmark is left in #27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants