add something like `mutable`
まだ誰も着手していません。
評価
調査の方向性
Start by reading the existing image class and the set, remove, and draw_circle implementations; the issue does not name their files or tests. Then study how Lua anonymous functions could support a mutate block and how libvips handles copied image data. Done means a mutable image class safely gates destructive operations and returns a new image after the block.
索引モデルが issue の本文から書いたものです。
説明
The ruby-vips binding has a nice feature for encapsulating destructive operations, like metadata change or the draw operations:
https://www.libvips.org/2021/03/08/ruby-vips-mutate.html
tldr: you can write eg.:
z = x.mutate do |y|
1000.times do
y.draw_circle! Array.new(3) {rand(255)},
rand(y.width), rand(y.height), rand(100), fill: true
end
end
mutatetakes an image (xin this case) and makes an instance of a class calledMutableImage- This constructor runs
copy()to make a private copy of the underlying vips image, and subclassesImage, adding a few new methods such asdraw_circle!(ruby uses the!suffix on method names to indicate destructive operations) mutateexecutes the block after, passing in the mutable image (yin this case)draw_circle!modifies the image you give it by erm drawing a circle ... the first time this happens, libvips will force the iamge into memory, ie. allocate a huge ram buffer and render the image into that- Now the 1000 circles are drawn directly into memory with no copying and no chance of side effects
- Finally, the mutable block ends, and
mutateuses the modified vips image to build a new instance of theImageclass - And this new Image instance is returned (and assigned to
zin this code)
So this scheme automates the copying that lua-vips requires right now before you can use destructive operations like metadata changes, or line or circle draw. It has locks to prevent things like set or remove being used on a non-mutable image, so it's always safe.
You see a nice speedup too: that code is more than 10x faster and needs less than 1/10th the memory compared to ruby-vips without mutate.
This would be a nice thing to add to lua-vips. You could perhaps use anonymous functions, so the code above might be:
z = x:mutate(function (y)
for i = 1, 1000 do
y:draw_circle(... stuff)
end
end)
You'd need to add a new mutable image class and some locks to gate access to set, remove, draw_circle, etc.
- 主要言語
- Lua
- スター
- 151
- フォーク
- 10
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
libvips/lua-vips のほかの issue
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
-
question
難易度 3/5 1〜2日 初心者へのやさしさ 32/100
-
question
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
libvips/lua-vips の issue をすべて見る
似ている issue
-
follow-up needs-review
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ksysoev/duet.nvim#310 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
Jaliborc/PetTracker#509 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
bug discord triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
fitzforge/polestar#5203 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信