Giter Site home page Giter Site logo

Comparison to hologram.nvim about image.nvim HOT 7 CLOSED

3rd avatar 3rd commented on June 9, 2024
Comparison to hologram.nvim

from image.nvim.

Comments (7)

donovanglover avatar donovanglover commented on June 9, 2024 2

Thanks, I got it to work! Took a second for me to figure out that you need to add treesitter since there were no errors with the vimwiki syntax, but having jpg and other image formats in the editor is great.

I made a PR NixOS/nixpkgs#244038 to add image.nvim to nixpkgs and updated the magick PR with the patch.

from image.nvim.

3rd avatar 3rd commented on June 9, 2024

The aim is not to have any display issues.
Making it compatible with zen-mode is out of scope, as it's not an issue but a missing feature at best, but my guess is that it should work even there.
Try it out.

from image.nvim.

donovanglover avatar donovanglover commented on June 9, 2024

I would love to try image.nvim! Unfortunately, I haven't been able to get magick working yet. The instructions in the README have been a great help, however changing try_to_load to /nix/store/vhc3pka4gjs6hghbsk7alc2nsry9k81i-imagemagick-7.1.1-12/lib/libMagickWand-7.Q16HDRI.so doesn't change the error message for me.

I was trying to add magick to nixpkgs earlier. I think patching it like this could get it to work and I might be using the wrong .so. See: NixOS/nixpkgs#243687

from image.nvim.

3rd avatar 3rd commented on June 9, 2024

Yes, it's a bit of a pain, would be great to get it in nixpkgs. I'm looking to replace it as the rock can't be used to do masking.

To get it to work I patched ~/.luarocks/share/lua/5.1/magick/wand/lib.lua like this:

Screenshot_2023-07-16-21-03-32-902_com.server.auditor.ssh.client.jpg

from image.nvim.

donovanglover avatar donovanglover commented on June 9, 2024

Not sure if I missed anything but I couldn't get that to work either. Can you share the file later? Planning to add the patch to the PR if I can get it to work.

from image.nvim.

3rd avatar 3rd commented on June 9, 2024

I did a luarocks --local install magick and then went to find the wand .so from the nix store:

cd (dirname (which magick))/../lib
# found libMagickWand-7.Q16HDRI.so

And then I just hardcoded the path to that .so in ~/.luarocks/share/lua/5.1/magick/wand/lib.lua

~/.luarocks/share/lua/5.1/magick/wand/lib.lua
local ffi = require("ffi")
local lib
ffi.cdef([[  typedef void MagickWand;
  typedef void PixelWand;

  typedef int MagickBooleanType;
  typedef int ExceptionType;
  typedef int ssize_t;
  typedef int CompositeOperator;
  typedef int GravityType;
  typedef int OrientationType;
  typedef int InterlaceType;

  void MagickWandGenesis();
  MagickWand* NewMagickWand();
  MagickWand* CloneMagickWand(const MagickWand *wand);
  MagickWand* DestroyMagickWand(MagickWand*);
  MagickBooleanType MagickReadImage(MagickWand*, const char*);
  MagickBooleanType MagickReadImageBlob(MagickWand*, const void*, const size_t);

  char* MagickGetException(const MagickWand*, ExceptionType*);

  int MagickGetImageWidth(MagickWand*);
  int MagickGetImageHeight(MagickWand*);

  MagickBooleanType MagickAddImage(MagickWand*, const MagickWand*);

  MagickBooleanType MagickAdaptiveResizeImage(MagickWand*, const size_t, const size_t);

  MagickBooleanType MagickWriteImage(MagickWand*, const char*);

  unsigned char* MagickGetImageBlob(MagickWand*, size_t*);

  void* MagickRelinquishMemory(void*);

  MagickBooleanType MagickCropImage(MagickWand*,
    const size_t, const size_t, const ssize_t, const ssize_t);

  MagickBooleanType MagickBlurImage(MagickWand*, const double, const double);
  MagickBooleanType MagickModulateImage(MagickWand*, const double, const double, const double);
  MagickBooleanType MagickBrightnessContrastImage(MagickWand*, const double, const double);

  MagickBooleanType MagickSetImageFormat(MagickWand* wand, const char* format);
  char* MagickGetImageFormat(MagickWand* wand);

  size_t MagickGetImageCompressionQuality(MagickWand * wand);
  MagickBooleanType MagickSetImageCompressionQuality(MagickWand *wand,
  const size_t quality);

  MagickBooleanType MagickSharpenImage(MagickWand *wand,
    const double radius,const double sigma);

  MagickBooleanType MagickScaleImage(MagickWand *wand,
    const size_t columns,const size_t rows);

  MagickBooleanType MagickRotateImage(MagickWand *wand,
  const PixelWand *background,const double degrees);

  MagickBooleanType MagickSetOption(MagickWand *,const char *,const char *);
  char* MagickGetOption(MagickWand *,const char *);

  MagickBooleanType MagickCompositeImage(MagickWand *wand,
    const MagickWand *source_wand,const CompositeOperator compose,
    const ssize_t x,const ssize_t y);

  GravityType MagickGetImageGravity(MagickWand *wand);
  MagickBooleanType MagickSetImageGravity(MagickWand *wand,
    const GravityType gravity);

  MagickBooleanType MagickStripImage(MagickWand *wand);

  MagickBooleanType MagickGetImagePixelColor(MagickWand *wand,
    const ssize_t x,const ssize_t y,PixelWand *color);

  MagickWand* MagickCoalesceImages(MagickWand*);

  PixelWand *NewPixelWand(void);
  PixelWand *DestroyPixelWand(PixelWand *);

  double PixelGetAlpha(const PixelWand *);
  double PixelGetRed(const PixelWand *);
  double PixelGetGreen(const PixelWand *);
  double PixelGetBlue(const PixelWand *);

  void PixelSetAlpha(PixelWand *wand, const double alpha);
  void PixelSetRed(PixelWand *wand, const double red);
  void PixelSetGreen(PixelWand *wand, const double green);
  void PixelSetBlue(PixelWand *wand, const double blue);

  MagickBooleanType MagickTransposeImage(MagickWand *wand);

  MagickBooleanType MagickTransverseImage(MagickWand *wand);

  MagickBooleanType MagickFlipImage(MagickWand *wand);

  MagickBooleanType MagickFlopImage(MagickWand *wand);

  char* MagickGetImageProperty(MagickWand *wand, const char *property);
  MagickBooleanType MagickSetImageProperty(MagickWand *wand,
    const char *property,const char *value);

  OrientationType MagickGetImageOrientation(MagickWand *wand);
  MagickBooleanType MagickSetImageOrientation(MagickWand *wand,
    const OrientationType orientation);

  InterlaceType MagickGetImageInterlaceScheme(MagickWand *wand);
  MagickBooleanType MagickSetImageInterlaceScheme(MagickWand *wand,
    const InterlaceType interlace_scheme);

  MagickBooleanType MagickAutoOrientImage(MagickWand *wand);

  MagickBooleanType MagickResetImagePage(MagickWand *wand, const char *page);

  MagickBooleanType MagickSetImageDepth(MagickWand *,const unsigned long);
  unsigned long MagickGetImageDepth(MagickWand *);

]])
local get_flags
get_flags = function()
  local proc = io.popen("pkg-config --cflags --libs MagickWand", "r")
  local flags = proc:read("*a")
  get_flags = function()
    return flags
  end
  proc:close()
  return flags
end
local get_filters
get_filters = function()
  local suffixes = {
    "magick/resample.h",
    "MagickCore/resample.h",
  }
  local prefixes = {
    "/usr/include/ImageMagick",
    "/usr/local/include/ImageMagick",
    -- unpack((function()
    --   local _accum_0 = {}
    --   local _len_0 = 1
    --   for p in get_flags():gmatch("-I([^%s]+)") do
    --     _accum_0[_len_0] = p
    --     _len_0 = _len_0 + 1
    --   end
    --   return _accum_0
    -- end)()),
  }
  for _index_0 = 1, #prefixes do
    local p = prefixes[_index_0]
    for _index_1 = 1, #suffixes do
      local suffix = suffixes[_index_1]
      local full = tostring(p) .. "/" .. tostring(suffix)
      do
        local f = io.open(full)
        if f then
          local content
          do
            local _with_0 = f:read("*a")
            f:close()
            content = _with_0
          end
          local filter_types = content:match("(typedef enum.-FilterTypes?;)")
          if filter_types then
            ffi.cdef(filter_types)
            if filter_types:match("FilterTypes;") then return "FilterTypes" end
            return "FilterType"
          end
        end
      end
    end
  end
  return false
end
local get_filter
get_filter = function(name)
  return lib[name .. "Filter"]
end
local can_resize
do
  local enum_name = get_filters()
  if enum_name then
    ffi.cdef([[    MagickBooleanType MagickResizeImage(MagickWand*,
      const size_t, const size_t,
      const ]] .. enum_name .. [[, const double);
  ]])
    can_resize = true
  end
end
local try_to_load
try_to_load = function(...)
  local out
  local _list_0 = {
    ...,
  }
  for _index_0 = 1, #_list_0 do
    local _continue_0 = false
    repeat
      local name = _list_0[_index_0]
      if "function" == type(name) then
        name = name()
        if not name then
          _continue_0 = true
          break
        end
      end
      return ffi.load(name)
    -- if pcall(function()
    -- out = ffi.load(name)
    -- end) then
    --   return out
    -- end
    -- _continue_0 = true
    until true
    if not _continue_0 then break end
  end
  return error("Failed to load ImageMagick (" .. tostring(...) .. ")")
end
lib = try_to_load(
  "/nix/store/48zg59xi37kxsw4m0bx28jgiszxpxpr1-imagemagick-7.1.1-11/lib/libMagickWand-7.Q16HDRI.so",
  function()
    -- return "/nix/store/48zg59xi37kxsw4m0bx28jgiszxpxpr1-imagemagick-7.1.1-11/lib/libMagickWand-7.Q16HDRI.so"
    -- local lname = get_flags():match("-l(MagickWand[^%s]*)")
    -- local suffix
    -- if ffi.os == "OSX" then
    --   suffix = ".dylib"
    -- elseif ffi.os == "Windows" then
    --   suffix = ".dll"
    -- else
    --   suffix = ".so"
    -- end
    -- return lname and "lib" .. lname .. suffix
  end
)
return {
  lib = lib,
  can_resize = can_resize,
  get_filter = get_filter,
}

from image.nvim.

3rd avatar 3rd commented on June 9, 2024

Thanks, I got it to work! Took a second for me to figure out that you need to add treesitter since there were no errors with the vimwiki syntax, but having jpg and other image formats in the editor is great.

I made a PR NixOS/nixpkgs#244038 to add image.nvim to nixpkgs and updated the magick PR with the patch.

Amazing, glad it works, and thanks for the PR!

from image.nvim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.