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:
$(CXX) \
-I ${MOZJPEG}/include \
-L ${MOZJPEG}/lib \
${CXXFLAGS} \
${LDFLAGS} \
--bind \
-O3 \
-flto \
-s FILESYSTEM=0 \
-s PTHREAD_POOL_SIZE=navigator.hardwareConcurrency \
-s ALLOW_MEMORY_GROWTH=1 \
-s TEXTDECODER=2 \
-s NODEJS_CATCH_EXIT=0 -s NODEJS_CATCH_REJECTION=0 \
-s ENVIRONMENT=$(ENVIRONMENT) \
-s EXPORT_ES6=1 \
-lembind \
${CXXFLAGS} \
${LDFLAGS} \
-o $@ \
-I ${MOZJPEG}/include \
-L ${MOZJPEG}/lib \
-ljpeg \
${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};
in
with pkgs;
{
rec {
packages = rec {
default = mozjpeg-squoosh;
mozjpeg-squoosh = stdenv.mkDerivation {
name = "mozjpeg-squoosh";
src = ./.;
src = lib.cleanSource ./.;
nativeBuildInputs = [
emscripten
mozjpeg
@@ -38,7 +38,7 @@
'';
installPhase = ''
mkdir -p $out
cp enc/*.{wasm,js} $out
cp -r enc $out
'';
};
mozjpeg = stdenv.mkDerivation {
@@ -77,14 +77,15 @@
dontFixup = true;
};
installScript = writeShellScriptBin "install.sh" ''
${pkgs.coreutils}/bin/mkdir build
${pkgs.coreutils}/bin/cp ${mozjpeg-squoosh}/* build/
${pkgs.coreutils}/bin/rm -rf build
${pkgs.coreutils}/bin/mkdir -p build
${pkgs.rsync}/bin/rsync --chmod=u+w -r ${mozjpeg-squoosh}/* build/
'';
};
apps = {
install = {
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 {
EncodeOptions,
MozJpegColorSpace,
} from 'codecs/mozjpeg/enc/mozjpeg_enc';
} from 'codecs/mozjpeg/build/enc/mozjpeg_enc';
export { EncodeOptions, MozJpegColorSpace };
export const label = 'MozJPEG';

View File

@@ -10,7 +10,9 @@
* See the License for the specific language governing permissions and
* 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 { initEmscriptenModule } from 'features/worker-utils';