Tweaking wp2 options

This commit is contained in:
Jake Archibald
2020-12-15 10:32:20 +00:00
parent c3d05e0e2d
commit d6c178f9dc
10 changed files with 62 additions and 25 deletions

BIN
codecs/wp2/dec/wp2_dec.wasm Normal file → Executable file

Binary file not shown.

Binary file not shown.

View File

@@ -18,6 +18,7 @@ struct WP2Options {
int csp_type; int csp_type;
int error_diffusion; int error_diffusion;
bool use_random_matrix; bool use_random_matrix;
int tile_shape;
}; };
val encode(std::string image_in, int image_width, int image_height, WP2Options options) { val encode(std::string image_in, int image_width, int image_height, WP2Options options) {
@@ -32,6 +33,7 @@ val encode(std::string image_in, int image_width, int image_height, WP2Options o
config.sns = options.sns; config.sns = options.sns;
config.error_diffusion = options.error_diffusion; config.error_diffusion = options.error_diffusion;
config.use_random_matrix = options.use_random_matrix; config.use_random_matrix = options.use_random_matrix;
config.tile_shape = static_cast<WP2::TileShape>(options.tile_shape);
uint8_t* image_buffer = (uint8_t*)image_in.c_str(); uint8_t* image_buffer = (uint8_t*)image_in.c_str();
WP2::ArgbBuffer src = WP2::ArgbBuffer(); WP2::ArgbBuffer src = WP2::ArgbBuffer();

View File

@@ -8,6 +8,7 @@ export interface EncodeOptions {
csp_type: Csp; csp_type: Csp;
error_diffusion: number; error_diffusion: number;
use_random_matrix: boolean; use_random_matrix: boolean;
tile_shape: TileShape;
} }
export const enum UVMode { export const enum UVMode {
@@ -24,6 +25,14 @@ export const enum Csp {
kYIQ, kYIQ,
} }
export const enum TileShape {
Square128,
Square256,
Square512,
Wide,
Auto,
}
export interface WP2Module extends EmscriptenWasm.Module { export interface WP2Module extends EmscriptenWasm.Module {
encode( encode(
data: BufferSource, data: BufferSource,

BIN
codecs/wp2/enc/wp2_enc.wasm Normal file → Executable file

Binary file not shown.

BIN
codecs/wp2/enc/wp2_enc_mt.wasm Normal file → Executable file

Binary file not shown.

BIN
codecs/wp2/enc/wp2_enc_mt_simd.wasm Normal file → Executable file

Binary file not shown.

Binary file not shown.

View File

@@ -10,6 +10,7 @@ import Checkbox from 'client/lazy-app/Compress/Options/Checkbox';
import Expander from 'client/lazy-app/Compress/Options/Expander'; import Expander from 'client/lazy-app/Compress/Options/Expander';
import linkState from 'linkstate'; import linkState from 'linkstate';
import Revealer from 'client/lazy-app/Compress/Options/Revealer'; import Revealer from 'client/lazy-app/Compress/Options/Revealer';
import { TileShape } from 'codecs/wp2/enc/wp2_enc';
export const encode = ( export const encode = (
signal: AbortSignal, signal: AbortSignal,
@@ -38,6 +39,7 @@ interface State {
useRandomMatrix: boolean; useRandomMatrix: boolean;
showAdvanced: boolean; showAdvanced: boolean;
separateAlpha: boolean; separateAlpha: boolean;
tileShape: number;
} }
export class Options extends Component<Props, State> { export class Options extends Component<Props, State> {
@@ -62,6 +64,7 @@ export class Options extends Component<Props, State> {
errorDiffusion: options.error_diffusion, errorDiffusion: options.error_diffusion,
useRandomMatrix: options.use_random_matrix, useRandomMatrix: options.use_random_matrix,
separateAlpha: options.quality !== options.alpha_quality, separateAlpha: options.quality !== options.alpha_quality,
tileShape: options.tile_shape,
}; };
// If quality is > 95, it's lossless with slight loss // If quality is > 95, it's lossless with slight loss
@@ -121,6 +124,7 @@ export class Options extends Component<Props, State> {
csp_type: optionState.colorSpace, csp_type: optionState.colorSpace,
error_diffusion: optionState.errorDiffusion, error_diffusion: optionState.errorDiffusion,
use_random_matrix: optionState.useRandomMatrix, use_random_matrix: optionState.useRandomMatrix,
tile_shape: optionState.tileShape,
}; };
// Updating options, so we don't recalculate in getDerivedStateFromProps. // Updating options, so we don't recalculate in getDerivedStateFromProps.
@@ -151,6 +155,7 @@ export class Options extends Component<Props, State> {
useRandomMatrix, useRandomMatrix,
separateAlpha, separateAlpha,
showAdvanced, showAdvanced,
tileShape,
}: State, }: State,
) { ) {
return ( return (
@@ -213,17 +218,23 @@ export class Options extends Component<Props, State> {
</div> </div>
)} )}
</Expander> </Expander>
<label class={style.optionReveal}> </div>
<Revealer )}
checked={showAdvanced} </Expander>
onChange={linkState(this, 'showAdvanced')} <label class={style.optionReveal}>
/> <Revealer
Advanced settings checked={showAdvanced}
</label> onChange={linkState(this, 'showAdvanced')}
/>
Advanced settings
</label>
<Expander>
{showAdvanced && (
<div>
<Expander> <Expander>
{showAdvanced && ( {!lossless && (
<div> <div>
<div class={style.optionOneCell}> {/*<div class={style.optionOneCell}>
<Range <Range
min="1" min="1"
max="10" max="10"
@@ -233,7 +244,7 @@ export class Options extends Component<Props, State> {
> >
Passes: Passes:
</Range> </Range>
</div> </div>*/}
<div class={style.optionOneCell}> <div class={style.optionOneCell}>
<Range <Range
min="0" min="0"
@@ -245,17 +256,6 @@ export class Options extends Component<Props, State> {
Spatial noise shaping: Spatial noise shaping:
</Range> </Range>
</div> </div>
<div class={style.optionOneCell}>
<Range
min="0"
max="100"
step="1"
value={errorDiffusion}
onInput={this._inputChange('errorDiffusion', 'number')}
>
Error diffusion:
</Range>
</div>
<label class={style.optionTextFirst}> <label class={style.optionTextFirst}>
Subsample chroma: Subsample chroma:
<Select <Select
@@ -263,7 +263,7 @@ export class Options extends Component<Props, State> {
onInput={this._inputChange('uvMode', 'number')} onInput={this._inputChange('uvMode', 'number')}
> >
<option value={UVMode.UVModeAuto}>Auto</option> <option value={UVMode.UVModeAuto}>Auto</option>
<option value={UVMode.UVModeAdapt}>Vary</option> <option value={UVMode.UVModeAdapt}>Mixed</option>
<option value={UVMode.UVMode420}>Half</option> <option value={UVMode.UVMode420}>Half</option>
<option value={UVMode.UVMode444}>Off</option> <option value={UVMode.UVMode444}>Off</option>
</Select> </Select>
@@ -276,10 +276,11 @@ export class Options extends Component<Props, State> {
> >
<option value={Csp.kYCoCg}>YCoCg</option> <option value={Csp.kYCoCg}>YCoCg</option>
<option value={Csp.kYCbCr}>YCbCr</option> <option value={Csp.kYCbCr}>YCbCr</option>
<option value={Csp.kCustom}>Adaptive</option>
<option value={Csp.kYIQ}>YIQ</option> <option value={Csp.kYIQ}>YIQ</option>
</Select> </Select>
</label> </label>
<label class={style.optionToggle}> {/*<label class={style.optionToggle}>
Random matrix Random matrix
<Checkbox <Checkbox
checked={useRandomMatrix} checked={useRandomMatrix}
@@ -288,10 +289,34 @@ export class Options extends Component<Props, State> {
'boolean', 'boolean',
)} )}
/> />
</label> </label>*/}
<div class={style.optionOneCell}>
<Range
min="0"
max="100"
step="1"
value={errorDiffusion}
onInput={this._inputChange('errorDiffusion', 'number')}
>
Error diffusion:
</Range>
</div>
</div> </div>
)} )}
</Expander> </Expander>
<label class={style.optionTextFirst}>
Tile shape:
<Select
value={tileShape}
onInput={this._inputChange('tileShape', 'number')}
>
<option value={TileShape.Auto}>Auto</option>
<option value={TileShape.Square128}>128x128</option>
<option value={TileShape.Square256}>256x256</option>
<option value={TileShape.Square512}>512x512</option>
<option value={TileShape.Wide}>Maximum</option>
</Select>
</label>
</div> </div>
)} )}
</Expander> </Expander>

View File

@@ -11,7 +11,7 @@
* limitations under the License. * limitations under the License.
*/ */
import type { EncodeOptions } from 'codecs/wp2/enc/wp2_enc'; import type { EncodeOptions } from 'codecs/wp2/enc/wp2_enc';
import { UVMode, Csp } from 'codecs/wp2/enc/wp2_enc'; import { UVMode, Csp, TileShape } from 'codecs/wp2/enc/wp2_enc';
export { EncodeOptions, UVMode, Csp }; export { EncodeOptions, UVMode, Csp };
@@ -28,4 +28,5 @@ export const defaultOptions: EncodeOptions = {
csp_type: Csp.kYCoCg, csp_type: Csp.kYCoCg,
error_diffusion: 0, error_diffusion: 0,
use_random_matrix: false, use_random_matrix: false,
tile_shape: TileShape.Auto,
}; };