| 198 | } |
| 199 | |
| 200 | async function rawToBuffer(fromBuffer, raw = {}, config = {}) |
| 201 | { |
| 202 | await loadSharp(); |
| 203 | |
| 204 | config = { |
| 205 | kernel: 'nearest', |
| 206 | compressionLevel: 0, |
| 207 | ...config, |
| 208 | }; |
| 209 | |
| 210 | return new Promise(function(resolve, reject) { |
| 211 | |
| 212 | const _sharp = sharp(fromBuffer, {raw: raw}); |
| 213 | |
| 214 | if(config.removeAlpha) |
| 215 | _sharp.removeAlpha(); |
| 216 | |
| 217 | _sharp.keepIccProfile().pipelineColourspace(raw.rgb16 ? 'rgb16' : 'srgb').toColourspace(raw.rgb16 ? 'rgb16' : 'srgb').png({force: true, compressionLevel: config.compressionLevel}).toBuffer(function(error, buffer, info) { |
| 218 | |
| 219 | if(error || !buffer) |
| 220 | reject(error); |
| 221 | else |
| 222 | resolve(buffer); |
| 223 | |
| 224 | }); |
| 225 | |
| 226 | }); |
| 227 | } |
| 228 | |
| 229 | var isAnimatedCache = {}; |
| 230 | |