/** Request decoded image data for given item id's.
* @param {number} contextId Id of the context.
* @param {Array.<number>} itemIds Array of item id's to be decoded.
* @param {function} callback Callback function that receives the payload as a parameter. */
this.requestImageData = function (contextId, itemIds, callback) {
console.log(_name + ": REQUEST IMAGE DATA: " + itemIds);
if (itemIds.constructor !== Array) {
itemIds = [itemIds];
}
if (itemIds.length < 1) {
return;
}
var stream = new Uint8Array();
var decodeIds = [];
var dependencies = {};
var displayDependencies = {};
for (var i = 0; i < itemIds.length; i++) {
var refs = self._heifReader.getItemDecodeDependencies(contextId, itemIds[i]);
for (var j = 0; j < refs.length; j++) {
if (refs[j] !== itemIds[i]) {
// Add dependency data to the stream if the id is not already listed in dependencies
if(!(refs[j] in dependencies) && !(refs[j] in displayDependencies)) {
dependencies[refs[j]] = true;
stream = _appendBuffer(stream, new Uint8Array(self._heifReader.getItemDataWithDecoderParameters(contextId, refs[j])));
decodeIds.push(refs[j]);
}
} else {
// Item has itself as dependency => we want to display that item despite being a dependency
displayDependencies[refs[j]] = true;
}
}
}
// Add data of the actual items to the stream (that already contains dependency data)
for (i = 0; i < itemIds.length; i++) {
stream = _appendBuffer(stream, new Uint8Array(self._heifReader.getItemDataWithDecoderParameters(contextId, itemIds[i])));
decodeIds.push(itemIds[i]);
}
var payload = new Payload(true, [], 0, 0);
self._hevcDecoder.pushRequestContext(new RequestContext(callback, decodeIds, stream, dependencies, payload));
self._hevcDecoder.decode();
};