Comments (6)
You can reuse the memory buffer that is used for dst_image
.
let mut dst_buffer: Vec<u8> = Vec:new();
for variation in variations {
...
let dst_buf_size = ...;
dst_buffer.resize(dst_buf_size, 0);
let mut dst_image = fr::Image::from_slice_u8(
dst_width,
dst_height,
&mut dst_buffer,
src_image.pixel_type(),
).unwrap();
...
}
I think that creating an instance of JpegEncoder
is a fairly easy operation. But you may look at the image
crate documentation. May be you can find something about how to reuse exists JpegEncoder
instance to encode different images.
But, in any case, to store 100+ result images you must create 100+ vectors.
from fast_image_resize.
Move these lines inside of for-loop:
let mut result_buffer: Vec<u8> = Vec::new();
let mut buf_writer = BufWriter::new( &mut result_buffer );
let mut encoder = JpegEncoder::new_with_quality( &mut buf_writer, 100 );
from fast_image_resize.
Is there a way to avoid creating new instances in the loop?
from fast_image_resize.
Your question is irrelevant to the fast_image_resize
crate. It is more related to the Rust language and how computer's memory works. Value of the result_buffer
variable can't be used after it is moved into image_variations
vector.
How do you want to use the same buffer to store different images at the same time? It is impossible. You must create a new buffer to store each image.
from fast_image_resize.
Thank you, let me modify my question, if the encoder and the resizer holds the logic of how to process images: Is there a way to create only one instance of these two, to use in +100 resize & encode ops. in loop?
from fast_image_resize.
Thank you!
from fast_image_resize.
Related Issues (20)
- how does the speed compare with opencv? HOT 21
- resize_with_pad HOT 5
- Bad unsafe is caught by latest rust nightly (rustc 1.70.0-nightly (2eaeb1eee 2023-04-05)) HOT 5
- Crop source slice length does not match destination slice length HOT 3
- Allow passing an immutable slice to Image::from_slice_u8 HOT 2
- num-traits error HOT 2
- f32 example HOT 2
- no gaussian kernel HOT 7
- Equivalent to OpenCV cv2.INTER_AREA? HOT 2
- wrong image color HOT 10
- Floating point exception during convolutional downscale (Lanczos) HOT 4
- Are the examples updated to the last version? HOT 5
- Invalid buffer length issue HOT 1
- Support for `F32x2` `F32x3` & `F32x4`? HOT 9
- how do you apply a crop on the target buffer? HOT 4
- Equivalent to OpenCV `cv2.INTER_LINEAR` HOT 12
- Inaccurate colors appear in the corners of the image after scaling HOT 10
- resize-rgba8-image example uses a no longer supported function. HOT 1
- the lasted resized example cannot be compiled correctly HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fast_image_resize.