Color differences / compression artefact using Sharp / NPM / Nodejs

31 views Asked by At

I've been working on a bigger app that pack 3D models together in nodeJS, and notice something I bumped into something I cannot resolve after hours of researches.

I did manage to get my basic problem into a few line of code.

import Sharp from 'sharp'


async function process(){

var sharpOriginal = Sharp('./samples/checker.jpg')

const sharpNew      = Sharp({
    create: {
        
        width: 100,
        height: 100,
        channels: 3,
        background: { r: 255, g: 255, b: 255 }
    }
}) 

var  op = {
    input: await sharpOriginal.toBuffer(),
    left: 0,
    top: 0,
    width: 100,
    height: 100
}

var extractedImage = sharpOriginal.extract( op )

extractedImage.jpeg({quality:100})

var composite = [
    
        {
            input: await extractedImage.toBuffer(),
            left: 0,
            top: 0
        }
    ]
    sharpNew.composite(composite).jpeg({quality:100}).toFile('./samples/extract.jpg')
}

process()

Basically, using sharp, https://www.npmjs.com/package/sharp, v0.33.2

1 ) Importing an image

2 ) extracting a portion into another one

3 ) Compositing it into a new one, and save it, leads to color changes. I'm using a basic UV-checker jpg :

enter image description here

There is the result :

enter image description here

Using gimp to compare colors :

enter image description here

Original color : bcd300

enter image description here

Extracted color : c6c724

enter image description here

We can also notice a neat color difference between left : extracted / right : original

enter image description here

Is there a way to get all those operation without altering any of the color informations ?

0

There are 0 answers