MCPcopy
hub / github.com/ollm/OpenComic / rawToBuffer

Function rawToBuffer

scripts/image.js:200–227  ·  view source on GitHub ↗
(fromBuffer, raw = {}, config = {})

Source from the content-addressed store, hash-verified

198}
199
200async 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
229var isAnimatedCache = {};
230

Callers

nothing calls this directly

Calls 2

loadSharpFunction · 0.85
resolveFunction · 0.85

Tested by

no test coverage detected