Types were handwritten

This commit is contained in:
Surma
2024-08-07 14:42:22 +01:00
parent 8c76d43a68
commit ba01d36c20
7 changed files with 60 additions and 22 deletions

View File

@@ -11,14 +11,21 @@ $(filter enc/%,$(OUT_JS)): enc/mozjpeg_enc.cpp
%.js: %.js:
$(CXX) \ $(CXX) \
-I ${MOZJPEG}/include \ -O3 \
-L ${MOZJPEG}/lib \ -flto \
${CXXFLAGS} \ -s FILESYSTEM=0 \
${LDFLAGS} \ -s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency \
--bind \ -s ALLOW_MEMORY_GROWTH=1 \
-s TEXTDECODER=2 \
-s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 \
-s ENVIRONMENT=$(ENVIRONMENT) \ -s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \ -s EXPORT_ES6=1 \
-lembind \
${CXXFLAGS} \
${LDFLAGS} \
-o $@ \ -o $@ \
-I ${MOZJPEG}/include \
-L ${MOZJPEG}/lib \
-ljpeg \ -ljpeg \
${MOZJPEG}/lib/rdswitch.o \ ${MOZJPEG}/lib/rdswitch.o \
$+ $+

37
codecs/mozjpeg/enc/mozjpeg_enc.d.ts vendored Normal file
View File

@@ -0,0 +1,37 @@
export const enum MozJpegColorSpace {
GRAYSCALE = 1,
RGB,
YCbCr,
}
export interface EncodeOptions {
quality: number;
baseline: boolean;
arithmetic: boolean;
progressive: boolean;
optimize_coding: boolean;
smoothing: number;
color_space: MozJpegColorSpace;
quant_table: number;
trellis_multipass: boolean;
trellis_opt_zero: boolean;
trellis_opt_table: boolean;
trellis_loops: number;
auto_subsample: boolean;
chroma_subsample: number;
separate_chroma_quality: boolean;
chroma_quality: number;
}
export interface MozJPEGModule extends EmscriptenWasm.Module {
encode(
data: BufferSource,
width: number,
height: number,
options: EncodeOptions,
): Uint8Array;
}
declare var moduleFactory: EmscriptenWasm.ModuleFactory<MozJPEGModule>;
export default moduleFactory;

View File

@@ -20,12 +20,12 @@
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
in in
with pkgs; with pkgs;
{ rec {
packages = rec { packages = rec {
default = mozjpeg-squoosh; default = mozjpeg-squoosh;
mozjpeg-squoosh = stdenv.mkDerivation { mozjpeg-squoosh = stdenv.mkDerivation {
name = "mozjpeg-squoosh"; name = "mozjpeg-squoosh";
src = ./.; src = lib.cleanSource ./.;
nativeBuildInputs = [ nativeBuildInputs = [
emscripten emscripten
mozjpeg mozjpeg
@@ -38,7 +38,7 @@
''; '';
installPhase = '' installPhase = ''
mkdir -p $out mkdir -p $out
cp enc/*.{wasm,js} $out cp -r enc $out
''; '';
}; };
mozjpeg = stdenv.mkDerivation { mozjpeg = stdenv.mkDerivation {
@@ -77,14 +77,15 @@
dontFixup = true; dontFixup = true;
}; };
installScript = writeShellScriptBin "install.sh" '' installScript = writeShellScriptBin "install.sh" ''
${pkgs.coreutils}/bin/mkdir build ${pkgs.coreutils}/bin/rm -rf build
${pkgs.coreutils}/bin/cp ${mozjpeg-squoosh}/* build/ ${pkgs.coreutils}/bin/mkdir -p build
${pkgs.rsync}/bin/rsync --chmod=u+w -r ${mozjpeg-squoosh}/* build/
''; '';
}; };
apps = { apps = {
install = { install = {
type = "app"; type = "app";
# program = " program = "${packages.installScript}/bin/install.sh";
}; };
}; };
} }

View File

@@ -1,4 +0,0 @@
{
"name": "mozjpeg_enc",
"lockfileVersion": 1
}

View File

@@ -1,5 +0,0 @@
{
"scripts": {
"build": "../build-cpp.sh"
}
}

View File

@@ -13,7 +13,7 @@
import { import {
EncodeOptions, EncodeOptions,
MozJpegColorSpace, MozJpegColorSpace,
} from 'codecs/mozjpeg/enc/mozjpeg_enc'; } from 'codecs/mozjpeg/build/enc/mozjpeg_enc';
export { EncodeOptions, MozJpegColorSpace }; export { EncodeOptions, MozJpegColorSpace };
export const label = 'MozJPEG'; export const label = 'MozJPEG';

View File

@@ -10,7 +10,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
import mozjpeg_enc, { MozJPEGModule } from 'codecs/mozjpeg/enc/mozjpeg_enc'; import mozjpeg_enc, {
MozJPEGModule,
} from 'codecs/mozjpeg/build/enc/mozjpeg_enc';
import { EncodeOptions } from '../shared/meta'; import { EncodeOptions } from '../shared/meta';
import { initEmscriptenModule } from 'features/worker-utils'; import { initEmscriptenModule } from 'features/worker-utils';