Skip to content

Commit

Permalink
chore: switch to vim.base64.encode()
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd committed Nov 3, 2024
1 parent 4769132 commit 3e0fb47
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 78 deletions.
4 changes: 2 additions & 2 deletions lua/image/backends/kitty/helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local codes = require("image/backends/kitty/codes")
local utils = require("image/utils")

local uv = vim.uv
-- Allow for loop to be used on older versions
-- Allow for loop to be used on older versions
if not uv then uv = vim.loop end

local stdout = vim.loop.new_tty(1, false)
Expand Down Expand Up @@ -98,7 +98,7 @@ local write_graphics = function(config, data)
local file = io.open(data, "rb")
data = file:read("*all")
end
data = utils.base64.encode(data):gsub("%-", "/")
data = vim.base64.encode(data):gsub("%-", "/")
local chunks = get_chunked(data)
local m = #chunks > 1 and 1 or 0
control_payload = control_payload .. ",m=" .. m
Expand Down
10 changes: 5 additions & 5 deletions lua/image/image.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function Image:render(geometry)
local format = self.global_state.processor.get_format(self.original_path)

if format ~= "png" then
local converted_path = self.global_state.tmp_dir .. "/" .. utils.base64.encode(self.id) .. "-source.png"
local converted_path = self.global_state.tmp_dir .. "/" .. vim.base64.encode(self.id) .. "-source.png"
self.path = self.global_state.processor.convert_to_png(self.original_path, converted_path)
end

Expand Down Expand Up @@ -189,7 +189,7 @@ end

---@param brightness number
function Image:brightness(brightness)
local altered_path = self.global_state.tmp_dir .. "/" .. utils.base64.encode(self.id) .. "-source.png"
local altered_path = self.global_state.tmp_dir .. "/" .. vim.base64.encode(self.id) .. "-source.png"
self.path = self.global_state.processor.brightness(self.path, brightness, altered_path)
self.cropped_path = self.path
self.resize_hash = nil
Expand All @@ -203,7 +203,7 @@ end

---@param saturation number
function Image:saturation(saturation)
local altered_path = self.global_state.tmp_dir .. "/" .. utils.base64.encode(self.id) .. "-source.png"
local altered_path = self.global_state.tmp_dir .. "/" .. vim.base64.encode(self.id) .. "-source.png"
self.path = self.global_state.processor.saturation(self.path, saturation, altered_path)
self.cropped_path = self.path
self.resize_hash = nil
Expand All @@ -217,7 +217,7 @@ end

---@param hue number
function Image:hue(hue)
local altered_path = self.global_state.tmp_dir .. "/" .. utils.base64.encode(self.id) .. "-source.png"
local altered_path = self.global_state.tmp_dir .. "/" .. vim.base64.encode(self.id) .. "-source.png"
self.path = self.global_state.processor.hue(self.path, hue, altered_path)
self.cropped_path = self.path
self.resize_hash = nil
Expand Down Expand Up @@ -294,7 +294,7 @@ local from_file = function(path, options, state)

-- convert non-png images to png and read the dimensions
local source_path = absolute_original_path
local converted_path = state.tmp_dir .. "/" .. utils.base64.encode(id) .. "-source.png"
local converted_path = state.tmp_dir .. "/" .. vim.base64.encode(id) .. "-source.png"

-- case 1: non-png, already converted
if
Expand Down
4 changes: 2 additions & 2 deletions lua/image/renderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ local render = function(image)
image.resize_hash = resize_hash
else
-- perform resize
local tmp_path = state.tmp_dir .. "/" .. utils.base64.encode(image.id) .. "-resized-" .. resize_hash .. ".png"
local tmp_path = state.tmp_dir .. "/" .. vim.base64.encode(image.id) .. "-resized-" .. resize_hash .. ".png"
image.resized_path = state.processor.resize(image.path, pixel_width, pixel_height, tmp_path)
image.resize_hash = resize_hash
image_cache.resized[resize_hash] = image.resized_path
Expand All @@ -404,7 +404,7 @@ local render = function(image)
image.crop_hash = crop_hash
else
-- perform crop
local tmp_path = state.tmp_dir .. "/" .. utils.base64.encode(image.id) .. "-cropped-" .. crop_hash .. ".png"
local tmp_path = state.tmp_dir .. "/" .. vim.base64.encode(image.id) .. "-cropped-" .. crop_hash .. ".png"
image.cropped_path = state.processor.crop(
image.resized_path or image.path,
0,
Expand Down
67 changes: 0 additions & 67 deletions lua/image/utils/base64.lua

This file was deleted.

2 changes: 0 additions & 2 deletions lua/image/utils/init.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
local base64 = require("image/utils/base64")
local hash = require("image/utils/hash")
local logger = require("image/utils/logger")
local magic = require("image/utils/magic")
Expand All @@ -14,7 +13,6 @@ return {
log = logger.log,
throw = logger.throw,
debug = logger.debug,
base64 = base64,
random = random,
window = window,
term = term,
Expand Down

0 comments on commit 3e0fb47

Please sign in to comment.