mirror of
https://github.com/GoogleChromeLabs/squoosh.git
synced 2025-11-20 12:38:50 +00:00
Extra Wp2 Options (#853)
* wip * wip * Add extra options * Even more options! * Update src/features/encoders/wp2/client/index.tsx Co-authored-by: Surma <surma@surma.dev> Co-authored-by: Surma <surma@surma.dev>
This commit is contained in:
@@ -7,7 +7,31 @@ using namespace emscripten;
|
||||
|
||||
thread_local const val Uint8Array = val::global("Uint8Array");
|
||||
|
||||
val encode(std::string image_in, int image_width, int image_height, WP2::EncoderConfig config) {
|
||||
struct WP2Options {
|
||||
float quality;
|
||||
float alpha_quality;
|
||||
int speed;
|
||||
int pass;
|
||||
int uv_mode;
|
||||
float sns;
|
||||
int csp_type;
|
||||
int error_diffusion;
|
||||
bool use_random_matrix;
|
||||
};
|
||||
|
||||
val encode(std::string image_in, int image_width, int image_height, WP2Options options) {
|
||||
WP2::EncoderConfig config = {};
|
||||
|
||||
config.quality = options.quality;
|
||||
config.alpha_quality = options.alpha_quality;
|
||||
config.speed = options.speed;
|
||||
config.pass = options.pass;
|
||||
config.uv_mode = static_cast<WP2::EncoderConfig::UVMode>(options.uv_mode);
|
||||
config.csp_type = static_cast<WP2::Csp>(options.csp_type);
|
||||
config.sns = options.sns;
|
||||
config.error_diffusion = options.error_diffusion;
|
||||
config.use_random_matrix = options.use_random_matrix;
|
||||
|
||||
uint8_t* image_buffer = (uint8_t*)image_in.c_str();
|
||||
WP2::ArgbBuffer src = WP2::ArgbBuffer();
|
||||
WP2Status status =
|
||||
@@ -27,12 +51,16 @@ val encode(std::string image_in, int image_width, int image_height, WP2::Encoder
|
||||
}
|
||||
|
||||
EMSCRIPTEN_BINDINGS(my_module) {
|
||||
value_object<WP2::EncoderConfig>("WP2EncoderConfig")
|
||||
.field("quality", &WP2::EncoderConfig::quality)
|
||||
.field("alpha_quality", &WP2::EncoderConfig::alpha_quality)
|
||||
.field("speed", &WP2::EncoderConfig::speed)
|
||||
.field("pass", &WP2::EncoderConfig::pass)
|
||||
.field("sns", &WP2::EncoderConfig::sns);
|
||||
value_object<WP2Options>("WP2Options")
|
||||
.field("quality", &WP2Options::quality)
|
||||
.field("alpha_quality", &WP2Options::alpha_quality)
|
||||
.field("speed", &WP2Options::speed)
|
||||
.field("pass", &WP2Options::pass)
|
||||
.field("uv_mode", &WP2Options::uv_mode)
|
||||
.field("csp_type", &WP2Options::csp_type)
|
||||
.field("error_diffusion", &WP2Options::error_diffusion)
|
||||
.field("use_random_matrix", &WP2Options::use_random_matrix)
|
||||
.field("sns", &WP2Options::sns);
|
||||
|
||||
function("encode", &encode);
|
||||
}
|
||||
|
||||
18
codecs/wp2/enc/wp2_enc.d.ts
vendored
18
codecs/wp2/enc/wp2_enc.d.ts
vendored
@@ -4,6 +4,24 @@ export interface EncodeOptions {
|
||||
speed: number;
|
||||
pass: number;
|
||||
sns: number;
|
||||
uv_mode: UVMode;
|
||||
csp_type: Csp;
|
||||
error_diffusion: number;
|
||||
use_random_matrix: boolean;
|
||||
}
|
||||
|
||||
export const enum UVMode {
|
||||
UVModeAdapt = 0, // Mix of 420 and 444 (per block)
|
||||
UVMode420, // All blocks 420
|
||||
UVMode444, // All blocks 444
|
||||
UVModeAuto, // Choose any of the above automatically
|
||||
}
|
||||
|
||||
export const enum Csp {
|
||||
kYCoCg,
|
||||
kYCbCr,
|
||||
kCustom,
|
||||
kYIQ,
|
||||
}
|
||||
|
||||
export interface WP2Module extends EmscriptenWasm.Module {
|
||||
|
||||
@@ -576,7 +576,7 @@ var wp2_enc = (function () {
|
||||
},
|
||||
});
|
||||
var ob = {
|
||||
p: function (a, b, c, d) {
|
||||
t: function (a, b, c, d) {
|
||||
A(
|
||||
'Assertion failed: ' +
|
||||
C(a) +
|
||||
@@ -807,7 +807,7 @@ var wp2_enc = (function () {
|
||||
return [];
|
||||
});
|
||||
},
|
||||
c: function (a, b, c, d, e) {
|
||||
d: function (a, b, c, d, e) {
|
||||
function g(l) {
|
||||
return l;
|
||||
}
|
||||
@@ -1000,10 +1000,10 @@ var wp2_enc = (function () {
|
||||
},
|
||||
});
|
||||
},
|
||||
q: function (a, b, c, d, e, g) {
|
||||
p: function (a, b, c, d, e, g) {
|
||||
Fa[a] = { name: U(b), da: Y(c, d), ea: Y(e, g), U: [] };
|
||||
},
|
||||
e: function (a, b, c, d, e, g, m, h, k, l) {
|
||||
c: function (a, b, c, d, e, g, m, h, k, l) {
|
||||
Fa[a].U.push({
|
||||
X: U(b),
|
||||
aa: c,
|
||||
@@ -1034,7 +1034,7 @@ var wp2_enc = (function () {
|
||||
m: function (a) {
|
||||
4 < a && (X[a].T += 1);
|
||||
},
|
||||
t: function (a, b, c, d) {
|
||||
q: function (a, b, c, d) {
|
||||
a || W('Cannot use deleted val. handle = ' + a);
|
||||
a = X[a].value;
|
||||
var e = ib[b];
|
||||
@@ -1079,7 +1079,7 @@ var wp2_enc = (function () {
|
||||
u: function (a, b, c) {
|
||||
D.copyWithin(a, b, b + c);
|
||||
},
|
||||
d: function (a) {
|
||||
e: function (a) {
|
||||
a >>>= 0;
|
||||
var b = D.length;
|
||||
if (2147483648 < a) return !1;
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user