mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-14 09:39:15 +00:00
Exposed speed slider, but it's weird
This commit is contained in:
@@ -5,17 +5,23 @@
|
|||||||
|
|
||||||
using namespace emscripten;
|
using namespace emscripten;
|
||||||
|
|
||||||
|
struct JXLOptions {
|
||||||
|
// 1 = slowest
|
||||||
|
// 7 = fastest
|
||||||
|
int speed;
|
||||||
|
};
|
||||||
|
|
||||||
uint8_t *result;
|
uint8_t *result;
|
||||||
val encode(std::string image, int width, int height) {
|
val encode(std::string image, int width, int height, JXLOptions options) {
|
||||||
jxl::CompressParams cparams;
|
jxl::CompressParams cparams;
|
||||||
jxl::PassesEncoderState passes_enc_state;
|
jxl::PassesEncoderState passes_enc_state;
|
||||||
// jxl::ThreadPool pool;
|
|
||||||
jxl::CodecInOut io;
|
jxl::CodecInOut io;
|
||||||
jxl::PaddedBytes bytes;
|
jxl::PaddedBytes bytes;
|
||||||
jxl::ImageBundle *main = &io.Main();
|
jxl::ImageBundle *main = &io.Main();
|
||||||
|
|
||||||
cparams.speed_tier = jxl::SpeedTier::kFalcon;
|
cparams.speed_tier = static_cast<jxl::SpeedTier>(options.speed);
|
||||||
cparams.color_transform = jxl::ColorTransform::kNone;
|
cparams.color_transform = jxl::ColorTransform::kNone;
|
||||||
|
|
||||||
uint8_t *inBuffer = (uint8_t *)image.c_str();
|
uint8_t *inBuffer = (uint8_t *)image.c_str();
|
||||||
|
|
||||||
auto result = main->SetFromSRGB(
|
auto result = main->SetFromSRGB(
|
||||||
@@ -36,6 +42,9 @@ val encode(std::string image, int width, int height) {
|
|||||||
void free_result() { delete result; }
|
void free_result() { delete result; }
|
||||||
|
|
||||||
EMSCRIPTEN_BINDINGS(my_module) {
|
EMSCRIPTEN_BINDINGS(my_module) {
|
||||||
|
value_object<JXLOptions>("JXLOptions")
|
||||||
|
.field("speed", &JXLOptions::speed);
|
||||||
|
|
||||||
function("encode", &encode);
|
function("encode", &encode);
|
||||||
function("free_result", &free_result);
|
function("free_result", &free_result);
|
||||||
}
|
}
|
||||||
|
|||||||
4
codecs/jxl_enc/jxl_enc.d.ts
vendored
4
codecs/jxl_enc/jxl_enc.d.ts
vendored
@@ -1,7 +1,7 @@
|
|||||||
// import { EncodeOptions } from '../../src/codecs/avif/encoder-meta';
|
import { EncodeOptions } from '../../src/codecs/jxl/encoder-meta';
|
||||||
|
|
||||||
interface JXLModule extends EmscriptenWasm.Module {
|
interface JXLModule extends EmscriptenWasm.Module {
|
||||||
encode(data: BufferSource, width: number, height: number): Uint8Array;
|
encode(data: BufferSource, width: number, height: number, options: EncodeOptions): Uint8Array;
|
||||||
free_result(): void;
|
free_result(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -1,4 +1,5 @@
|
|||||||
export interface EncodeOptions {
|
export interface EncodeOptions {
|
||||||
|
speed: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
export interface EncoderState { type: typeof type; options: EncodeOptions; }
|
||||||
@@ -9,4 +10,5 @@ export const mimeType = 'image/jpegxl';
|
|||||||
export const extension = 'jxl';
|
export const extension = 'jxl';
|
||||||
// These come from struct WebPConfig in encode.h.
|
// These come from struct WebPConfig in encode.h.
|
||||||
export const defaultOptions: EncodeOptions = {
|
export const defaultOptions: EncodeOptions = {
|
||||||
|
speed: 1,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ export async function encode(data: ImageData, options: EncodeOptions): Promise<A
|
|||||||
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(jxl_enc, wasmUrl);
|
if (!emscriptenModule) emscriptenModule = initEmscriptenModule(jxl_enc, wasmUrl);
|
||||||
|
|
||||||
const module = await emscriptenModule;
|
const module = await emscriptenModule;
|
||||||
const resultView = module.encode(data.data, data.width, data.height);
|
console.log(options);
|
||||||
|
const resultView = module.encode(data.data, data.width, data.height, options);
|
||||||
const result = new Uint8Array(resultView);
|
const result = new Uint8Array(resultView);
|
||||||
module.free_result();
|
module.free_result();
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { h, Component } from 'preact';
|
import { h, Component } from 'preact';
|
||||||
import { bind } from '../../lib/initial-util';
|
import { bind } from '../../lib/initial-util';
|
||||||
import { /*inputFieldCheckedAsNumber, inputFieldValueAsNumber,*/ preventDefault } from '../../lib/util';
|
import { inputFieldValueAsNumber, preventDefault } from '../../lib/util';
|
||||||
import { EncodeOptions } from './encoder-meta';
|
import { EncodeOptions } from './encoder-meta';
|
||||||
import * as style from '../../components/Options/style.scss';
|
import * as style from '../../components/Options/style.scss';
|
||||||
// import Checkbox from '../../components/checkbox';
|
// import Checkbox from '../../components/checkbox';
|
||||||
// import Expander from '../../components/expander';
|
// import Expander from '../../components/expander';
|
||||||
// import Select from '../../components/select';
|
// import Select from '../../components/select';
|
||||||
// import Range from '../../components/range';
|
import Range from '../../components/range';
|
||||||
// import linkState from 'linkstate';
|
// import linkState from 'linkstate';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -14,29 +14,40 @@ interface Props {
|
|||||||
onChange(newOptions: EncodeOptions): void;
|
onChange(newOptions: EncodeOptions): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {}
|
||||||
}
|
|
||||||
|
|
||||||
export default class JXLEncoderOptions extends Component<Props, State> {
|
export default class JXLEncoderOptions extends Component<Props, State> {
|
||||||
state: State = {
|
state: State = {};
|
||||||
};
|
|
||||||
|
|
||||||
@bind
|
@bind
|
||||||
onChange(event: Event) {
|
onChange(event: Event) {
|
||||||
// const form = (event.currentTarget as HTMLInputElement).closest('form') as HTMLFormElement;
|
const form = (event.currentTarget as HTMLInputElement).closest(
|
||||||
// const { options } = this.props;
|
'form',
|
||||||
|
) as HTMLFormElement;
|
||||||
|
const { options } = this.props;
|
||||||
|
|
||||||
// const newOptions: EncodeOptions = {
|
const newOptions: EncodeOptions = {
|
||||||
// // Copy over options the form doesn't care about, eg emulate_jpeg_size
|
// Copy over options the form doesn't care about, eg emulate_jpeg_size
|
||||||
// ...options,
|
...options,
|
||||||
// };
|
speed: inputFieldValueAsNumber(form.speed, options.speed),
|
||||||
// this.props.onChange(newOptions);
|
};
|
||||||
|
this.props.onChange(newOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
render({ options }: Props) {
|
render({ options }: Props) {
|
||||||
return (
|
return (
|
||||||
<form class={style.optionsSection} onSubmit={preventDefault}>
|
<form class={style.optionsSection} onSubmit={preventDefault}>
|
||||||
Lol
|
<div class={style.optionOneCell}>
|
||||||
|
<Range
|
||||||
|
name="speed"
|
||||||
|
min="1"
|
||||||
|
max="7"
|
||||||
|
value={options.speed}
|
||||||
|
onInput={this.onChange}
|
||||||
|
>
|
||||||
|
Speed:
|
||||||
|
</Range>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user