Skip to content

Commit 523522b

Browse files
committed
Fixed filter weights
1 parent 9a75415 commit 523522b

File tree

5 files changed

+16
-22
lines changed

5 files changed

+16
-22
lines changed

app/src/main.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,12 @@
2828
*/
2929
mod image_wrapper;
3030

31-
use image::{
32-
imageops, EncodableLayout, GenericImageView,
33-
ImageReader,
34-
};
31+
use fast_image_resize::images::Image;
32+
use fast_image_resize::{CpuExtensions, FilterType, PixelType, ResizeAlg, ResizeOptions, Resizer};
33+
use image::{imageops, EncodableLayout, GenericImageView, ImageReader};
3534
use pic_scale_safe::{resize_rgb8, resize_rgba8, ImageSize, ResamplingFunction};
3635
use std::ops::{BitXor, Shr};
3736
use std::time::Instant;
38-
use fast_image_resize::images::Image;
39-
use fast_image_resize::{CpuExtensions, FilterType, PixelType, ResizeAlg, ResizeOptions, Resizer};
4037

4138
fn main() {
4239
let img = ImageReader::open("./assets/test_alpha.JPG")
@@ -50,7 +47,7 @@ fn main() {
5047

5148
let src_size = ImageSize::new(dimensions.0 as usize, dimensions.1 as usize);
5249
// let dst_size = ImageSize::new(dimensions.0 as usize / 4, dimensions.1 as usize / 4);
53-
let dst_size = ImageSize::new(src_size.width / 6, src_size.height /6);
50+
let dst_size = ImageSize::new(3240, 2160);
5451

5552
// let start_mul = Instant::now();
5653
//
@@ -64,7 +61,7 @@ fn main() {
6461
&working_store,
6562
src_size,
6663
dst_size,
67-
ResamplingFunction::Lanczos3,
64+
ResamplingFunction::CatmullRom,
6865
)
6966
.unwrap();
7067

@@ -113,7 +110,7 @@ fn main() {
113110
// .unwrap();
114111
//
115112
// println!("Working time {:?}", start.elapsed());
116-
113+
117114
// let img = u8_to_u16(dst_image.buffer());
118115
//
119116
// let rgba_image = DynamicImage::ImageRgb8(RgbImage::from_raw(dst_image.width() as u32, dst_image.height() as u32, dst_image.buffer().to_vec()).unwrap());

src/compute_weights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ where
6969
true => scale.max(1f32.as_()),
7070
false => 1f32.as_(),
7171
};
72-
let filter_base_size = resampling_filter.min_kernel_size;
72+
let filter_base_size = resampling_filter.min_kernel_size * 2.;
7373
let resampling_function = resampling_filter.kernel;
7474
let window_func = resampling_filter.window;
7575

src/floating_point_horizontal.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929
use crate::color_group::{
30-
load_color_group, load_color_group_with_offset, fast_mixed_store_color_group,
31-
ColorGroup,
30+
fast_mixed_store_color_group, load_color_group, load_color_group_with_offset, ColorGroup,
3231
};
3332
use crate::filter_weights::FilterWeights;
3433
use crate::mixed_storage::MixedStorage;

src/floating_point_vertical.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
*/
2929
use crate::color_group::{
30-
load_color_group, load_color_group_with_offset, fast_mixed_store_color_group,
31-
ColorGroup,
30+
fast_mixed_store_color_group, load_color_group, load_color_group_with_offset, ColorGroup,
3231
};
3332
use crate::filter_weights::FilterBounds;
3433
use crate::mixed_storage::MixedStorage;
@@ -86,11 +85,10 @@ pub(crate) fn convolve_column_handler_floating_point_4<
8685
load_color_group_with_offset!(src_ptr1, CHANNELS, 0, J),
8786
weight1,
8887
);
89-
sums1 = (load_color_group_with_offset!(src_ptr0, CHANNELS, CHANNELS, J) * weight0)
90-
.mul_add(
91-
load_color_group_with_offset!(src_ptr1, CHANNELS, CHANNELS, J),
92-
weight1,
93-
);
88+
sums1 = (load_color_group_with_offset!(src_ptr0, CHANNELS, CHANNELS, J) * weight0).mul_add(
89+
load_color_group_with_offset!(src_ptr1, CHANNELS, CHANNELS, J),
90+
weight1,
91+
);
9492
sums2 = (load_color_group_with_offset!(src_ptr0, CHANNELS, CHANNELS * 2, J) * weight0)
9593
.mul_add(
9694
load_color_group_with_offset!(src_ptr1, CHANNELS, CHANNELS * 2, J),

src/sampler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,8 @@ impl ResamplingFunction {
248248
usize: AsPrimitive<T>,
249249
{
250250
match self {
251-
ResamplingFunction::Bilinear => ResamplingFilter::new(bilinear, 2f32),
252-
ResamplingFunction::Area => ResamplingFilter::new_area(box_weight, 2f32),
251+
ResamplingFunction::Bilinear => ResamplingFilter::new(bilinear, 1f32),
252+
ResamplingFunction::Area => ResamplingFilter::new_area(box_weight, 0.5f32),
253253
ResamplingFunction::Nearest => {
254254
// Just a stab for nearest
255255
ResamplingFilter::new(bilinear, 2f32)
@@ -266,7 +266,7 @@ impl ResamplingFunction {
266266
ResamplingFunction::Bicubic => ResamplingFilter::new(bicubic_spline, 2f32),
267267
ResamplingFunction::Lanczos4 => ResamplingFilter::new(lanczos4, 4f32),
268268
ResamplingFunction::Lanczos2 => ResamplingFilter::new(lanczos2, 2f32),
269-
ResamplingFunction::Hamming => ResamplingFilter::new(hamming, 2f32),
269+
ResamplingFunction::Hamming => ResamplingFilter::new(hamming, 1f32),
270270
ResamplingFunction::Hanning => ResamplingFilter::new(hanning, 2f32),
271271
ResamplingFunction::Welch => ResamplingFilter::new(welch, 2f32),
272272
ResamplingFunction::Quadric => ResamplingFilter::new(quadric, 2f32),

0 commit comments

Comments
 (0)