Skip to content

Commit

Permalink
Merge pull request #247 from b0o/detection-perf-improvements
Browse files Browse the repository at this point in the history
Format/size detection performance improvements
  • Loading branch information
3rd authored Dec 5, 2024
2 parents 8b6b2e8 + 43dca75 commit a45e2cd
Show file tree
Hide file tree
Showing 27 changed files with 1,130 additions and 48 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: CI
on:
workflow_dispatch: {}
push:
branches:
- master
pull_request:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: nightly
- name: Run Tests
run: make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.tests/
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: test

test:
nvim -l ./tests/busted.lua tests/
8 changes: 6 additions & 2 deletions lua/image/processors/magick_cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ end
local MagickCliProcessor = {}

function MagickCliProcessor.get_format(path)
local result = utils.magic.detect_format(path)
if result then return result end
-- fallback to slower method:
guard()
local result = nil
local stdout = vim.loop.new_pipe()
Expand Down Expand Up @@ -76,8 +79,10 @@ function MagickCliProcessor.convert_to_png(path, output_path)
end

function MagickCliProcessor.get_dimensions(path)
local result = utils.dimensions.get_dimensions(path)
if result then return result end
-- fallback to slower method:
guard()
local result = nil
local stdout = vim.loop.new_pipe()
local stderr = vim.loop.new_pipe()
local output = ""
Expand Down Expand Up @@ -281,4 +286,3 @@ function MagickCliProcessor.hue(path, hue, output_path)
end

return MagickCliProcessor

9 changes: 8 additions & 1 deletion lua/image/processors/magick_rock.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local utils = require("image/utils")
local has_magick, magick = pcall(require, "magick")

local function guard()
Expand All @@ -10,6 +11,9 @@ end
local MagickRockProcessor = {}

function MagickRockProcessor.get_format(path)
local result = utils.magic.detect_format(path)
if result then return result end
-- fallback to slower method:
guard()
local image = magick.load_image(path)
local format = image:get_format()
Expand All @@ -28,6 +32,9 @@ function MagickRockProcessor.convert_to_png(path, output_path)
end

function MagickRockProcessor.get_dimensions(path)
local result = utils.dimensions.get_dimensions(path)
if result then return result end
-- fallback to slower method:
guard()
local image = magick.load_image(path)
local width = image:get_width()
Expand Down Expand Up @@ -86,4 +93,4 @@ function MagickRockProcessor.hue(path, hue, output_path)
return out_path
end

return MagickRockProcessor
return MagickRockProcessor
Loading

0 comments on commit a45e2cd

Please sign in to comment.