add something like `mutable`
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Lua
- Estrellas
- 151
- Forks
- 10
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de libvips/lua-vips
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
question
Dificultad 3/5 1-2 días Aptitud para principiantes 32/100
-
Usage with OpenResty?Abiertoquestion
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
Todos los issues de libvips/lua-vips
Issues similares
-
follow-up needs-review
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
ksysoev/duet.nvim#310 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
LUA error since patch 12.1.7Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Jaliborc/PetTracker#509 ·
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
-
bug discord triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
fitzforge/polestar#5203 · 1 comentario ·
Los mantenedores suelen responder en 1 día