-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
425 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,10 @@ | |
TODO | ||
--> | ||
|
||
## 1.0.3~1.0.6 | ||
|
||
- try fix npm install | ||
|
||
## 1.0.2 | ||
|
||
- switch to TypeScript | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export declare const version: string; | ||
export declare const minQuality: number; | ||
export declare const maxQuality: number; | ||
export declare const defaultQuality: number; | ||
export interface Image { | ||
width: number; | ||
height: number; | ||
channels: number; | ||
depth: number; | ||
stride: number; | ||
pix: Uint8Array; | ||
} | ||
export declare function encodeImage(m: Image, quality?: number): Uint8Array; | ||
export declare function encodeGray(pix: Uint8Array, w: number, h: number, stride: number, quality: number): Uint8Array; | ||
export declare function encodeRGB(pix: Uint8Array, w: number, h: number, stride: number, quality: number): Uint8Array; | ||
export declare function encodeRGBA(pix: Uint8Array, w: number, h: number, stride: number, quality: number): Uint8Array; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
"use strict"; | ||
exports.__esModule = true; | ||
var Module = require("./cxx-emscripten/guetzli.out"); | ||
function cToUint8Array(p, size) { | ||
var q = new Uint8Array(size | 0); | ||
for (var i = 0; i < q.length; i++) { | ||
q[i] = Module.HEAPU8[p + i]; | ||
} | ||
return q; | ||
} | ||
// CAPI_EXPORT(const char*) guetzliGetVersion(); | ||
function guetzliGetVersion() { | ||
return Module.ccall('guetzliGetVersion', 'string', [], []); | ||
} | ||
// CAPI_EXPORT(guetzli_string_t*) guetzli_string_new(int size); | ||
function guetzli_string_new(size) { | ||
return Module.ccall('guetzli_string_new', 'number', ['number'], [size]); | ||
} | ||
// CAPI_EXPORT(void) guetzli_string_delete(guetzli_string_t* p); | ||
function guetzli_string_delete(p) { | ||
Module.ccall('guetzli_string_delete', 'null', ['number'], [p]); | ||
} | ||
// CAPI_EXPORT(void) guetzli_string_resize(guetzli_string_t* p, int size); | ||
function guetzli_string_resize(p, size) { | ||
return Module.ccall('guetzli_string_resize', 'null', ['number', 'number'], [p, size]); | ||
} | ||
// CAPI_EXPORT(int) guetzli_string_size(guetzli_string_t* p); | ||
function guetzli_string_size(p) { | ||
return Module.ccall('guetzli_string_size', 'number', ['number'], [p]); | ||
} | ||
// CAPI_EXPORT(char*) guetzli_string_data(guetzli_string_t* p); | ||
function guetzli_string_data(p) { | ||
return Module.ccall('guetzli_string_data', 'number', ['number'], [p]); | ||
} | ||
// CAPI_EXPORT(guetzli_string_t*) | ||
// guetzli_encode_Gray(const uint8_t* pix, int w, int h, int stride, float quality); | ||
function guetzli_encode_Gray(pix, w, h, stride, quality) { | ||
return Module.ccall('guetzli_encode_Gray', 'number', ['array', 'number', 'number', 'number', 'number'], [pix, w, h, stride, quality]); | ||
} | ||
// CAPI_EXPORT(guetzli_string_t*) | ||
// guetzli_encode_RGB(const uint8_t* pix, int w, int h, int stride, float quality); | ||
function guetzli_encode_RGB(pix, w, h, stride, quality) { | ||
return Module.ccall('guetzli_encode_RGB', 'number', ['array', 'number', 'number', 'number', 'number'], [pix, w, h, stride, quality]); | ||
} | ||
// CAPI_EXPORT(guetzli_string_t*) | ||
// guetzli_encode_RGBA(const uint8_t* pix, int w, int h, int stride, float quality); | ||
function guetzli_encode_RGBA(pix, w, h, stride, quality) { | ||
return Module.ccall('guetzli_encode_RGBA', 'number', ['array', 'number', 'number', 'number', 'number'], [pix, w, h, stride, quality]); | ||
} | ||
exports.version = guetzliGetVersion(); | ||
exports.minQuality = 84; | ||
exports.maxQuality = 110; | ||
exports.defaultQuality = 95; | ||
function encodeImage(m, quality) { | ||
if (quality === void 0) { quality = exports.defaultQuality; } | ||
switch (m.channels) { | ||
case 1: return encodeGray(m.pix, m.width, m.height, m.stride, quality); | ||
case 3: return encodeRGB(m.pix, m.width, m.height, m.stride, quality); | ||
case 4: return encodeRGBA(m.pix, m.width, m.height, m.stride, quality); | ||
} | ||
throw "guetzli.encodeImage: unknown channels:" + m.channels; | ||
} | ||
exports.encodeImage = encodeImage; | ||
function encodeGray(pix, w, h, stride, quality) { | ||
var s = guetzli_encode_Gray(pix, w, h, stride, quality); | ||
var q = cToUint8Array(guetzli_string_data(s), guetzli_string_size(s)); | ||
guetzli_string_delete(s); | ||
return q; | ||
} | ||
exports.encodeGray = encodeGray; | ||
function encodeRGB(pix, w, h, stride, quality) { | ||
var s = guetzli_encode_RGB(pix, w, h, stride, quality); | ||
var q = cToUint8Array(guetzli_string_data(s), guetzli_string_size(s)); | ||
guetzli_string_delete(s); | ||
return q; | ||
} | ||
exports.encodeRGB = encodeRGB; | ||
function encodeRGBA(pix, w, h, stride, quality) { | ||
var s = guetzli_encode_RGBA(pix, w, h, stride, quality); | ||
var q = cToUint8Array(guetzli_string_data(s), guetzli_string_size(s)); | ||
guetzli_string_delete(s); | ||
return q; | ||
} | ||
exports.encodeRGBA = encodeRGBA; | ||
if (require.main === module) { | ||
console.log('guetzli-', guetzliGetVersion()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// Module | ||
|
||
export function print(str: string): void; | ||
export function printErr(str: string): void; | ||
|
||
export let preInit: { (): void }[]; | ||
export let preRun: { (): void }[]; | ||
export let postRun: { (): void }[]; | ||
export let noExitRuntime: boolean; | ||
|
||
export let Runtime: any; | ||
|
||
export function ccall(ident: string, returnType: string, argTypes: string[], args: any[]): any; | ||
export function cwrap(ident: string, returnType: string, argTypes: string[]): any; | ||
|
||
export function setValue(ptr: number, value: any, type: string, noSafe?: boolean): void; | ||
export function getValue(ptr: number, type: string, noSafe?: boolean): number; | ||
|
||
export let ALLOC_NORMAL: number; | ||
export let ALLOC_STACK: number; | ||
export let ALLOC_STATIC: number; | ||
export let ALLOC_DYNAMIC: number; | ||
export let ALLOC_NONE: number; | ||
|
||
export function allocate(slab: any, types: string, allocator: number, ptr: number): number; | ||
export function allocate(slab: any, types: string[], allocator: number, ptr: number): number; | ||
|
||
export function Pointer_stringify(ptr: number, length?: number): string; | ||
export function UTF16ToString(ptr: number): string; | ||
export function stringToUTF16(str: string, outPtr: number): void; | ||
export function UTF32ToString(ptr: number): string; | ||
export function stringToUTF32(str: string, outPtr: number): void; | ||
|
||
// USE_TYPED_ARRAYS == 1 | ||
export let HEAP: Int32Array; | ||
export let IHEAP: Int32Array; | ||
export let FHEAP: Float64Array; | ||
|
||
// USE_TYPED_ARRAYS == 2 | ||
export let HEAP8: Int8Array; | ||
export let HEAP16: Int16Array; | ||
export let HEAP32: Int32Array; | ||
export let HEAPU8: Uint8Array; | ||
export let HEAPU16: Uint16Array; | ||
export let HEAPU32: Uint32Array; | ||
export let HEAPF32: Float32Array; | ||
export let HEAPF64: Float64Array; | ||
|
||
export let TOTAL_STACK: number; | ||
export let TOTAL_MEMORY: number; | ||
export let FAST_MEMORY: number; | ||
|
||
export function addOnPreRun(cb: () => any): void; | ||
export function addOnInit(cb: () => any): void; | ||
export function addOnPreMain(cb: () => any): void; | ||
export function addOnExit(cb: () => any): void; | ||
export function addOnPostRun(cb: () => any): void; | ||
|
||
// Tools | ||
export function intArrayFromString(stringy: string, dontAddNull?: boolean, length?: number): number[]; | ||
export function intArrayToString(array: number[]): string; | ||
export function writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void; | ||
export function writeArrayToMemory(array: number[], buffer: number): void; | ||
export function writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void; | ||
|
||
export function addRunDependency(id: any): void; | ||
export function removeRunDependency(id: any): void; | ||
|
||
|
||
export let preloadedImages: any; | ||
export let preloadedAudios: any; | ||
|
||
export function _malloc(size: number): number; | ||
export function _free(ptr: number): void; | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
declare const fs: any; | ||
declare const guetzli: any; | ||
declare function main(args: string[]): void; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
var fs = require('fs'); | ||
var guetzli = require('./main'); | ||
if (require.main === module) { | ||
main(process.argv.splice(2)); | ||
} | ||
function main(args) { | ||
if (args.length == 1 && args[0] == '-v') { | ||
console.log('guetzli-' + guetzli.version); | ||
process.exit(0); | ||
} | ||
if (args.length == 1 && args[0] == '-h') { | ||
console.log('Usage: guetzli input_filename output_filename'); | ||
process.exit(0); | ||
} | ||
if (args.length != 2) { | ||
process.exit(0); | ||
} | ||
// load png | ||
var data = fs.readFileSync(args[0]); | ||
// decode png image | ||
var m = guetzli.decodePng32(data); | ||
// encode jpg image | ||
var jpegData = guetzli.encodeRGBA(m.pix, m.width, m.height, 0, guetzli.defaultQuality); | ||
// save jpg | ||
fs.writeFileSync(args[1], jpegData); | ||
// OK | ||
console.log('Done'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export declare const version: string; | ||
export declare const minQuality: number; | ||
export declare const maxQuality: number; | ||
export declare const defaultQuality: number; | ||
export interface Image { | ||
width: number; | ||
height: number; | ||
channels: number; | ||
depth: number; | ||
stride: number; | ||
pix: Uint8Array; | ||
} | ||
export declare function encodeImage(m: Image, quality?: number): Uint8Array; | ||
export declare function encodeGray(pix: Uint8Array, width: number, height: number, stride: number, quality: number): Uint8Array; | ||
export declare function encodeRGB(pix: Uint8Array, width: number, height: number, stride: number, quality: number): Uint8Array; | ||
export declare function encodeRGBA(pix: Uint8Array, width: number, height: number, stride: number, quality: number): Uint8Array; | ||
export declare function decodePng24(data: Uint8Array): Image; | ||
export declare function decodePng32(data: Uint8Array): Image; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
"use strict"; | ||
exports.__esModule = true; | ||
var ccapi = function () { | ||
try { | ||
return require('../build/Release/guetzli.node'); | ||
} | ||
catch (err) { | ||
return require('../build/Debug/guetzli.node'); | ||
} | ||
}(); | ||
var assert = require('assert'); | ||
var utils = require('./utils'); | ||
exports.version = ccapi.getVersion(); | ||
exports.minQuality = 84; | ||
exports.maxQuality = 110; | ||
exports.defaultQuality = 95; | ||
function encodeImage(m, quality) { | ||
if (quality === void 0) { quality = exports.defaultQuality; } | ||
switch (m.channels) { | ||
case 1: return encodeGray(m.pix, m.width, m.height, m.stride, quality); | ||
case 3: return encodeRGB(m.pix, m.width, m.height, m.stride, quality); | ||
case 4: return encodeRGBA(m.pix, m.width, m.height, m.stride, quality); | ||
} | ||
throw "guetzli.encodeImage: unknown channels:" + m.channels; | ||
} | ||
exports.encodeImage = encodeImage; | ||
function encodeGray(pix, width, height, stride, quality) { | ||
assert(utils.isBuffer(pix)); | ||
assert((width | 0) > 0 && (height | 0) > 0); | ||
assert((stride | 0) == 0 || (stride | 0) >= (width | 0) * 1); | ||
assert((quality | 0) >= this.minQuality && (quality | 0) <= this.maxQuality); | ||
return ccapi.encodeGray(pix, width, height, stride, quality); | ||
} | ||
exports.encodeGray = encodeGray; | ||
function encodeRGB(pix, width, height, stride, quality) { | ||
assert(utils.isBuffer(pix)); | ||
assert((width | 0) > 0 && (height | 0) > 0); | ||
assert((stride | 0) == 0 || (stride | 0) >= (width | 0) * 3); | ||
assert((quality | 0) >= this.minQuality && (quality | 0) <= this.maxQuality); | ||
return ccapi.encodeRGB(pix, width, height, stride, quality); | ||
} | ||
exports.encodeRGB = encodeRGB; | ||
function encodeRGBA(pix, width, height, stride, quality) { | ||
assert(utils.isBuffer(pix)); | ||
assert((width | 0) > 0 && (height | 0) > 0); | ||
assert((stride | 0) == 0 || (stride | 0) >= (width | 0) * 4); | ||
assert((quality | 0) >= this.minQuality && (quality | 0) <= this.maxQuality); | ||
return ccapi.encodeRGBA(pix, width, height, stride, quality); | ||
} | ||
exports.encodeRGBA = encodeRGBA; | ||
function decodePng24(data) { | ||
assert(utils.isBuffer(data)); | ||
assert(data.length > 0); | ||
var m = ccapi.decodePng24(data); | ||
assert(utils.isBuffer(m.pix)); | ||
assert(m.width > 0 && m.height > 0); | ||
assert(m.channels > 0 && m.depth > 0); | ||
return { | ||
width: m.width, | ||
height: m.height, | ||
channels: m.channels, | ||
depth: m.depth, | ||
stride: m.width * 3, | ||
pix: m.pix | ||
}; | ||
} | ||
exports.decodePng24 = decodePng24; | ||
function decodePng32(data) { | ||
assert(utils.isBuffer(data)); | ||
assert(data.length > 0); | ||
var m = ccapi.decodePng32(data); | ||
assert(utils.isBuffer(m.pix)); | ||
assert(m.width > 0 && m.height > 0); | ||
assert(m.channels > 0 && m.depth > 0); | ||
return { | ||
width: m.width, | ||
height: m.height, | ||
channels: m.channels, | ||
depth: m.depth, | ||
stride: m.width * 4, | ||
pix: m.pix | ||
}; | ||
} | ||
exports.decodePng32 = decodePng32; | ||
if (require.main === module) { | ||
main(process.argv.splice(2)); | ||
} | ||
function main(args) { | ||
if (args.length == 1 && args[0] == '-v') { | ||
console.log('guetzli-' + ccapi.getVersion()); | ||
process.exit(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare let pkg: any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright 2017 <chaishushan{AT}gmail.com>. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
var pkg = require('./main'); | ||
exports.testVersion = function (t) { | ||
t.ok(pkg.version == '1.0.1'); | ||
t.ok(/^\d+\.\d+\.\d+$/.test(pkg.version)); | ||
t.done(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export declare function isNode(): boolean; | ||
export declare const is_node: boolean; | ||
export declare function isUint8Array(obj: any): boolean; | ||
export declare function isArrayBuffer(obj: any): boolean; | ||
export declare function isBuffer(obj: any): boolean; |
Oops, something went wrong.