Skip to content

Commit

Permalink
Merge pull request GoogleChromeLabs#122 from GoogleChromeLabs/quant-u…
Browse files Browse the repository at this point in the history
…i-fix

Quant fixes
  • Loading branch information
surma authored Aug 6, 2018
2 parents 2fc4b90 + 6286ac2 commit 49bc9cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/App/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export default class App extends Component<Props, State> {
// options should always be correct for the type, but TypeScript isn't smart enough.
const encoderState: EncoderState = {
type,
options: options ? options : encoderMap[type].defaultOptions,
options: options || encoderMap[type].defaultOptions,
} as EncoderState;

images[index] = {
Expand Down
51 changes: 29 additions & 22 deletions src/components/Options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,15 @@ export default class Options extends Component<Props, State> {
onPreprocessorEnabledChange(event: Event) {
const el = event.currentTarget as HTMLInputElement;

const preprocessorState = this.props.preprocessorState;
const preprocessor = el.name.split('.')[0] as keyof typeof preprocessorState;
preprocessorState[preprocessor].enabled = el.checked;
this.props.onPreprocessorOptionsChange(preprocessorState);
const preprocessor = el.name.split('.')[0] as keyof PreprocessorState;

this.props.onPreprocessorOptionsChange({
...this.props.preprocessorState,
[preprocessor]: {
...this.props.preprocessorState[preprocessor],
enabled: el.checked,
},
});
}

@bind
Expand All @@ -107,25 +112,27 @@ export default class Options extends Component<Props, State> {

return (
<div class={`${style.options}${className ? (' ' + className) : ''}`}>
<p>Quantization</p>
<label>
<input
name="quantizer.enable"
type="checkbox"
checked={!!preprocessorState.quantizer.enabled}
onChange={this.onPreprocessorEnabledChange}
/>
Enable
</label>
{preprocessorState.quantizer.enabled ? (
<QuantizerOptionsComponent
options={preprocessorState.quantizer}
onChange={this.onQuantizerOptionsChange}
/>
) : (
<div/>
{encoderState.type !== 'identity' && (
<div>
<p>Quantization</p>
<label>
<input
name="quantizer.enable"
type="checkbox"
checked={!!preprocessorState.quantizer.enabled}
onChange={this.onPreprocessorEnabledChange}
/>
Enable
</label>
{preprocessorState.quantizer.enabled &&
<QuantizerOptionsComponent
options={preprocessorState.quantizer}
onChange={this.onQuantizerOptionsChange}
/>
}
<hr/>
</div>
)}
<hr/>
<label>
Mode:
{encoderSupportMap ?
Expand Down

0 comments on commit 49bc9cf

Please sign in to comment.