A suite to track Project Diva score statistics and ratings / D4DJ event data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
projectdivar/server/node_modules/image-pixels/lib/raw.js

47 lines
1.1 KiB

// decode any data in node
'use strict'
var clipPixels = require('clip-pixels')
var cache = require('./cache')
var decode = require('image-decode')
module.exports = loadRaw
function loadRaw (data, o) {
var width = o.shape[0], height = o.shape[1]
var clip = o.clip
var type = o.type
var decodedData = decode(data, type)
if (!decodedData) {
// cannot detect encoded data, consider it raw pixels
if (!width || !height) throw new Error('Raw data requires options.width and options.height')
}
else {
data = decodedData.data
width = decodedData.width
height = decodedData.height
}
var pixels = {
// in order to avoid copying
data: data.slice(),
width: width,
height: height
}
if (clip.x || clip.y ||
(clip.width && clip.width !== pixels.width) ||
(clip.height && clip.height !== pixels.height)
) {
pixels.data = new Uint8Array(clipPixels(data, [width, height], [clip.x, clip.y, clip.width, clip.height]))
pixels.width = clip.width || width
pixels.height = clip.height || height
}
if (o.cache) cache.set(o.cache, pixels)
return Promise.resolve(pixels)
}