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

Display bug for non-concrete eltype #53

Open
LilithHafner opened this issue Dec 15, 2022 · 3 comments
Open

Display bug for non-concrete eltype #53

LilithHafner opened this issue Dec 15, 2022 · 3 comments

Comments

@LilithHafner
Copy link

LilithHafner commented Dec 15, 2022

save("test.png", repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
    0 1 1 0 0 0
    1 0 1 0 0 1
    1 1 1 0 0 0
]], inner=(3,3)))

Produces this:
test

With inner=(50,50) it produces this:
test

Note that the matrix being displayed has a non-homogonous elements

repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
    0 1 1 0 0 0
    1 0 1 0 0 1
    1 1 1 0 0 0
]], inner=(3,3))
9×18 Array{RGB,2} with eltype RGB:
 RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)       RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
 RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)        RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
 RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)        RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)     RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)     RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)    RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
 RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)  RGB{Float64}(0.2,0.2,0.2)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)     RGB{N0f8}(0.0,0.0,0.0)
@asinghvi17
Copy link
Member

I can't replicate this:

using FileIO, ImageIO, Colors
 save("test.png", repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
           0 1 1 0 0 0
           1 0 1 0 0 1
           1 1 1 0 0 0
       ]], inner=(3,3)))

test

repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
           0 1 1 0 0 0
           1 0 1 0 0 1
           1 1 1 0 0 0
       ]], inner=(50,50)) |> save("test.png")

test

@LilithHafner
Copy link
Author

This example now throws for me:

(jl_PKeY4u) pkg> st
Status `/tmp/jl_PKeY4u/Project.toml`
  [5ae59095] Colors v0.12.11
  [5789e2e9] FileIO v1.16.3
  [82e4d734] ImageIO v0.6.8

julia> versioninfo()
Julia Version 1.10.4
Commit 48d4fd48430 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (aarch64-linux-gnu)
  CPU: 8 × unknown
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, generic)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = code

julia> using FileIO, ImageIO, Colors

julia> save("test.png", repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
                  0 1 1 0 0 0
                  1 0 1 0 0 1
                  1 1 1 0 0 0
              ]], inner=(3,3)))
Errors encountered while save File{DataFormat{:PNG}, String}("test.png").
All errors:
===========================================
MethodError: no method matching __get_bit_depth(::Type{Any})

Closest candidates are:
  __get_bit_depth(::Type{Bool})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:9
  __get_bit_depth(::Type{<:AbstractFloat})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:13
  __get_bit_depth(::Type{FixedPointNumbers.Normed{T, 16}}) where T
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:11
  ...

===========================================
ArgumentError: Package ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

===========================================
ArgumentError: Package OpenCV [f878e3a2-a245-4720-8660-60795d644f2a] is required but does not seem to be installed:
 - Run `Pkg.instantiate()` to install all recorded dependencies.

===========================================
ArgumentError: Argument does not support conversion to png.
===========================================

Fatal error:
ERROR: MethodError: no method matching __get_bit_depth(::Type{Any})

Closest candidates are:
  __get_bit_depth(::Type{Bool})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:9
  __get_bit_depth(::Type{<:AbstractFloat})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:13
  __get_bit_depth(::Type{FixedPointNumbers.Normed{T, 16}}) where T
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:11
  ...

Stacktrace:
  [1] _get_bit_depth(img::Matrix{RGB})
    @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:4
  [2] _save(png_ptr::Ptr{…}, info_ptr::Ptr{…}, image::Matrix{…}; compression_level::Int64, compression_strategy::Int64, filters::Int64, file_gamma::Nothing, background::Nothing)
    @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:420
  [3] save(fpath::String, image::Matrix{…}; compression_level::Int64, compression_strategy::Int64, filters::Int64, file_gamma::Nothing, background::Nothing)
    @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:361
  [4] save(fpath::String, image::Matrix{RGB})
    @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:335
  [5] invokelatest(::Any, ::Any, ::Vararg{Any}; kwargs::@Kwargs{})
    @ Base ./essentials.jl:892
  [6] invokelatest(::Any, ::Any, ::Vararg{Any})
    @ Base ./essentials.jl:889
  [7] (::LazyModules.LazyFunction)(::String, ::Vararg{Any}; kwargs::@Kwargs{})
    @ LazyModules ~/.julia/packages/LazyModules/d9Be6/src/LazyModules.jl:29
  [8] (::LazyModules.LazyFunction)(::String, ::Vararg{Any})
    @ LazyModules ~/.julia/packages/LazyModules/d9Be6/src/LazyModules.jl:27
  [9] save(f::File{DataFormat{:PNG}, String}, image::Matrix{RGB}; kwargs::@Kwargs{})
    @ ImageIO ~/.julia/packages/ImageIO/eR22t/src/ImageIO.jl:70
 [10] save(f::File{DataFormat{:PNG}, String}, image::Matrix{RGB})
    @ ImageIO ~/.julia/packages/ImageIO/eR22t/src/ImageIO.jl:69
 [11] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [12] invokelatest
    @ ./essentials.jl:889 [inlined]
 [13] action(call::Symbol, libraries::Vector{Union{…}}, file::Formatted, args::Matrix{RGB}; options::@Kwargs{})
    @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:219
 [14] action
    @ ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:196 [inlined]
 [15] action
    @ ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:185 [inlined]
 [16] save(file::String, args::Matrix{RGB}; options::@Kwargs{})
    @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:129
 [17] save(file::String, args::Matrix{RGB})
    @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:125
 [18] top-level scope
    @ REPL[9]:1
Stacktrace:
 [1] handle_error(e::MethodError, q::Base.PkgId, bt::Vector{Union{Ptr{Nothing}, Base.InterpreterIP}})
   @ FileIO ~/.julia/packages/FileIO/xOKyx/src/error_handling.jl:61
 [2] handle_exceptions(exceptions::Vector{Tuple{Any, Union{Base.PkgId, Module}, Vector}}, action::String)
   @ FileIO ~/.julia/packages/FileIO/xOKyx/src/error_handling.jl:56
 [3] action(call::Symbol, libraries::Vector{Union{…}}, file::Formatted, args::Matrix{RGB}; options::@Kwargs{})
   @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:228
 [4] action
   @ ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:196 [inlined]
 [5] action
   @ ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:185 [inlined]
 [6] save(file::String, args::Matrix{RGB}; options::@Kwargs{})
   @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:129
 [7] save(file::String, args::Matrix{RGB})
   @ FileIO ~/.julia/packages/FileIO/xOKyx/src/loadsave.jl:125
 [8] top-level scope
   @ REPL[9]:1
Some type information was truncated. Use `show(err)` to see complete types.

@asinghvi17
Copy link
Member

asinghvi17 commented Jul 21, 2024

Ah, I think I see where the problem is now. I have ImageMagick.jl installed in my environment stack, so

julia> save("test.png", repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
                  0 1 1 0 0 0
                  1 0 1 0 0 1
                  1 1 1 0 0 0
              ]], inner=(3,3)))
[ Info: Precompiling ImageMagick [6218d12a-5da1-5696-b52f-db25d2ecc6d1]

and this saves properly.

This is then probably applicable specifically to PNGFiles.jl.

Using PNGFiles.save, I get:

PNGFiles.save("test.png", repeat([x ? RGB(.2,.2,.2) : RGB(0,0,0) for x in Bool[
                  0 1 1 0 0 0
                  1 0 1 0 0 1
                  1 1 1 0 0 0
              ]], inner=(3,3)))
ERROR: MethodError: no method matching __get_bit_depth(::Type{Any})

Closest candidates are:
  __get_bit_depth(::Type{Bool})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:9
  __get_bit_depth(::Type{<:AbstractFloat})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:13
  __get_bit_depth(::Type{FixedPointNumbers.Normed{T, 16}}) where T
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:11
  ...

Stacktrace:
 [1] _get_bit_depth(img::Matrix{RGB})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/utils.jl:4
 [2] _save(png_ptr::Ptr{Nothing}, info_ptr::Ptr{Nothing}, image::Matrix{RGB}; compression_level::Int64, compression_strategy::Int64, filters::Int64, file_gamma::Nothing, background::Nothing)
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:420
 [3] save(fpath::String, image::Matrix{RGB}; compression_level::Int64, compression_strategy::Int64, filters::Int64, file_gamma::Nothing, background::Nothing)
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:361
 [4] save(fpath::String, image::Matrix{RGB})
   @ PNGFiles ~/.julia/packages/PNGFiles/CBHvB/src/io.jl:335
 [5] top-level scope
   @ REPL[8]:1

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

No branches or pull requests

2 participants