Skip to content

Commit

Permalink
Improve JPEG encoding loop (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcroomp authored May 6, 2024
1 parent ebf1837 commit f0d9c27
Show file tree
Hide file tree
Showing 7 changed files with 533 additions and 241 deletions.
31 changes: 21 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ wide = "0.7"
log = "0.4"
simple_logger ="4.0"
rayon = "1.10"
unroll="*"

[target.'cfg(windows)'.dependencies]
cpu-time = "1.0"
Expand Down
6 changes: 6 additions & 0 deletions src/enabled_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub struct EnabledFeatures {

/// Sadly C++ version has a bug where it uses 16 bit math in the SIMD path and 32 bit math in the scalar path
pub use_16bit_adv_predict: bool,

/// Accept JPEG files that have invalid DHT tables
pub accept_invalid_dht: bool,
}

impl EnabledFeatures {
Expand All @@ -31,6 +34,7 @@ impl EnabledFeatures {
max_jpeg_width: 16386,
use_16bit_dc_estimate: true,
use_16bit_adv_predict: true,
accept_invalid_dht: false,
}
}

Expand All @@ -45,6 +49,7 @@ impl EnabledFeatures {
max_jpeg_width: i32::MAX,
use_16bit_dc_estimate: false,
use_16bit_adv_predict: false,
accept_invalid_dht: true,
}
}

Expand All @@ -59,6 +64,7 @@ impl EnabledFeatures {
max_jpeg_width: i32::MAX,
use_16bit_dc_estimate: true,
use_16bit_adv_predict: true,
accept_invalid_dht: true,
}
}
}
13 changes: 13 additions & 0 deletions src/structs/block_based_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::consts::ZIGZAG_TO_RASTER;

use super::{block_context::BlockContext, jpeg_header::JPegHeader};

use unroll::unroll_for_loops;

/// holds the 8x8 blocks for a given component. Since we do multithreaded encoding,
/// the image may only hold a subset of the components (specified by dpos_offset),
/// but they can be merged
Expand Down Expand Up @@ -203,6 +205,17 @@ impl AlignedBlock {
}

/// gets underlying array of 64 coefficients (guaranteed to be 32-byte aligned)
#[unroll_for_loops]
pub fn zigzag(&self) -> AlignedBlock {
let mut block = AlignedBlock::default();
for i in 0..64 {
block.raw_data[i] = self.raw_data[usize::from(ZIGZAG_TO_RASTER[i])];
}
return block;
}

// used for debugging
#[allow(dead_code)]
pub fn get_block(&self) -> &[i16; 64] {
return &self.raw_data;
}
Expand Down
Loading

0 comments on commit f0d9c27

Please sign in to comment.