-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LfGlobal decoding: LF quantization factors, scaffolding
- Loading branch information
Showing
11 changed files
with
178 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright (c) the JPEG XL Project Authors. All rights reserved. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
use crate::{ | ||
bit_reader::BitReader, | ||
error::{Error, Result}, | ||
headers::encodings::{Empty, UnconditionalCoder}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
#[allow(dead_code)] | ||
pub struct LfQuantFactors { | ||
pub quant_factors: [f32; 3], | ||
pub inv_quant_factors: [f32; 3], | ||
} | ||
|
||
impl LfQuantFactors { | ||
pub fn new(br: &mut BitReader) -> Result<LfQuantFactors> { | ||
let mut quant_factors = [0.0f32; 3]; | ||
if br.read(1)? == 1 { | ||
quant_factors[0] = 1.0 / 4096.0; | ||
quant_factors[1] = 1.0 / 512.0; | ||
quant_factors[2] = 1.0 / 256.0; | ||
} else { | ||
for i in 0..3 { | ||
quant_factors[i] = f32::read_unconditional(&(), br, &Empty {})? / 128.0; | ||
if quant_factors[i] < 1e-8 { | ||
return Err(Error::LfQuantFactorTooSmall(quant_factors[i])); | ||
} | ||
} | ||
} | ||
|
||
let inv_quant_factors = quant_factors.map(f32::recip); | ||
|
||
Ok(LfQuantFactors { | ||
quant_factors, | ||
inv_quant_factors, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.