| 169 | } |
| 170 | |
| 171 | async function rawToPng(fromBuffer, toImage, raw = {}, config = {}) |
| 172 | { |
| 173 | await loadSharp(); |
| 174 | |
| 175 | config = { |
| 176 | kernel: 'nearest', |
| 177 | compressionLevel: 2, |
| 178 | ...config, |
| 179 | }; |
| 180 | |
| 181 | return new Promise(function(resolve, reject) { |
| 182 | |
| 183 | const _sharp = sharp(fromBuffer, {raw: raw}); |
| 184 | |
| 185 | if(config.removeAlpha) |
| 186 | _sharp.removeAlpha(); |
| 187 | |
| 188 | _sharp.keepIccProfile().pipelineColourspace(raw.rgb16 ? 'rgb16' : 'srgb').toColourspace(raw.rgb16 ? 'rgb16' : 'srgb').png({force: true, compressionLevel: config.compressionLevel}).toFile(toImage, function(error) { |
| 189 | |
| 190 | if(error) |
| 191 | reject(); |
| 192 | else |
| 193 | resolve(toImage); |
| 194 | |
| 195 | }); |
| 196 | |
| 197 | }); |
| 198 | } |
| 199 | |
| 200 | async function rawToBuffer(fromBuffer, raw = {}, config = {}) |
| 201 | { |