Skip to content

vips_colourspace: no known route from 'matrix' to 'srgb' #431

@noraj

Description

@noraj

Before™️, I had this code working.

  def draw_rubyvips(filename)
    # true -> 1, false -> 0
    @data.map! { |x| x == true ? 1 : x }
    @data.map! { |x| x == false ? 0 : x }
    # make a 2D image from the data array
    im = Vips::Image.new_from_array(@data.each_slice(@width).to_a)
    im = (im == 1).ifthenelse(@colors[1], @colors[0], blend: true)
    if @scale.is_a?(Numeric)
      opts = { kernel: :nearest }
      im = im.resize(@scale, **opts)
    end
    im.write_to_file(filename, compression: 9, palette: true, colours: 2, Q: 0, bitdepth: 1)
  end

Now it throws this error when reaching write_to_file:

/home/noraj/.asdf/installs/ruby/4.0.0/lib/ruby/gems/4.0.0/gems/ruby-vips-2.3.0/lib/vips/operation.rb:228:in 'Vips::Operation#build': vips_colourspace: no known route from 'matrix' to 'srgb' (Vips::Error)

The rest of my code retrieve a (one-line or multiline) CSV, flatten it to one line, converts every value to 0 or 1 and in draw_rubyvips I recreate a 2D array of 0 and 1 and replace every 0 & 1 by it's corresponding RGB color ([0,0,0] and [255,255,255] by default). Options are always set for PNG where I don't need large bitdepth or palette because I always have 2 colors and want an optimized image in terms of space. pp im returns #<Image 35x35 uchar, 3 bands, matrix>, indeed the colourspace is of type matrix. Maybe this approach is no longer the best for my case. I can't figure how to work around this colourspace conversion issue or avoid the colourspace being casted when saving to a file.

I'm using libvips 8.18.0 and ruby-vips 2.3.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions