How to use the image-q.image function in image-q

To help you get started, we’ve selected a few image-q examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jhuckaby / canvas-plus / lib / filter / quantize.js View on Github external
// create chosen palette quantizer (see classes implementing `iq.palette.IPaletteQuantizer`) 
		var paletteQuantizer = new iq.palette[opts.quantizer](distanceCalculator, targetColors);
		
		// feed out pointContainer filled with image to paletteQuantizer
		paletteQuantizer.sample(pointContainer);

		// generate palette
		var palette = paletteQuantizer.quantize();

		// get color array
		var iq_colors = palette.getPointContainer().getPointArray();
		
		// create image quantizer (see classes implementing `iq.image.IImageDitherer`)
		var imageDitherer = opts.dither ? 
			(new iq.image.ErrorDiffusionArray(distanceCalculator, iq.image.ErrorDiffusionArrayKernel[opts.ditherType])) : 
			(new iq.image.NearestColor(distanceCalculator));
		
		// apply palette to image
		var resultPointContainer = imageDitherer.quantize(pointContainer, palette);

		// get pixel array
		var iq_pixels = resultPointContainer.getPointArray();
		
		// convert pixels to array of palette indexes
		var palette_offset = 0;
		var palette_data = new Uint8Array( iq_colors.length * 3 );
		var color_hash = {};
		var iq_color = null;
		
		// build palette structure and color hash table
		for (var idx = 0, len = iq_colors.length; idx < len; idx++) {
			iq_color = iq_colors[idx];
github jhuckaby / canvas-plus / lib / filter / quantize.js View on Github external
// create chosen palette quantizer (see classes implementing `iq.palette.IPaletteQuantizer`) 
		var paletteQuantizer = new iq.palette[opts.quantizer](distanceCalculator, targetColors);
		
		// feed out pointContainer filled with image to paletteQuantizer
		paletteQuantizer.sample(pointContainer);

		// generate palette
		var palette = paletteQuantizer.quantize();

		// get color array
		var iq_colors = palette.getPointContainer().getPointArray();
		
		// create image quantizer (see classes implementing `iq.image.IImageDitherer`)
		var imageDitherer = opts.dither ? 
			(new iq.image.ErrorDiffusionArray(distanceCalculator, iq.image.ErrorDiffusionArrayKernel[opts.ditherType])) : 
			(new iq.image.NearestColor(distanceCalculator));
		
		// apply palette to image
		var resultPointContainer = imageDitherer.quantize(pointContainer, palette);

		// get pixel array
		var iq_pixels = resultPointContainer.getPointArray();
		
		// convert pixels to array of palette indexes
		var palette_offset = 0;
		var palette_data = new Uint8Array( iq_colors.length * 3 );
		var color_hash = {};
		var iq_color = null;
		
		// build palette structure and color hash table
		for (var idx = 0, len = iq_colors.length; idx < len; idx++) {
github jtlapp / gifwrap / src / gifutil.js View on Github external
}
        if (dither.minimumColorDistanceToDither === undefined) {
            dither.minimumColorDistanceToDither = 0;
        }
        if (dither.calculateErrorLikeGIMP === undefined) {
            dither.calculateErrorLikeGIMP = false;
        }
    }

    const distCalculator = new ImageQ.distance.Euclidean();
    const quantizer = new ImageQ.palette[method](distCalculator, maxColorIndexes, modifier);
    let imageMaker;
    if (dither) {
        imageMaker = new ImageQ.image.ErrorDiffusionArray(
            distCalculator,
            ImageQ.image.ErrorDiffusionArrayKernel[dither.ditherAlgorithm],
            dither.serpentine,
            dither.minimumColorDistanceToDither,
            dither.calculateErrorLikeGIMP
        );
    }
    else {
        imageMaker = new ImageQ.image.NearestColor(distCalculator);
    }

    const inputContainers = [];
    images.forEach(image => {

        const imageBuf = image.bitmap.data;
        const inputBuf = new ArrayBuffer(imageBuf.length);
        const inputArray = new Uint32Array(inputBuf);
        for (let bi = 0, ai = 0; bi < imageBuf.length; bi += 4, ++ai) {
github jtlapp / gifwrap / src / gifutil.js View on Github external
if (dither.serpentine === undefined) {
            dither.serpentine = true;
        }
        if (dither.minimumColorDistanceToDither === undefined) {
            dither.minimumColorDistanceToDither = 0;
        }
        if (dither.calculateErrorLikeGIMP === undefined) {
            dither.calculateErrorLikeGIMP = false;
        }
    }

    const distCalculator = new ImageQ.distance.Euclidean();
    const quantizer = new ImageQ.palette[method](distCalculator, maxColorIndexes, modifier);
    let imageMaker;
    if (dither) {
        imageMaker = new ImageQ.image.ErrorDiffusionArray(
            distCalculator,
            ImageQ.image.ErrorDiffusionArrayKernel[dither.ditherAlgorithm],
            dither.serpentine,
            dither.minimumColorDistanceToDither,
            dither.calculateErrorLikeGIMP
        );
    }
    else {
        imageMaker = new ImageQ.image.NearestColor(distCalculator);
    }

    const inputContainers = [];
    images.forEach(image => {

        const imageBuf = image.bitmap.data;
        const inputBuf = new ArrayBuffer(imageBuf.length);

image-q

Image Quantization Library in **TypeScript** *(MIT Licensed)*

MIT
Latest version published 3 years ago

Package Health Score

65 / 100
Full package analysis