Changed inputType to ArrayBuffer for 'Frequency distribution', 'Chi Square' and 'Extract EXIF' operations.

feature-extract-files
n1474335 2017-12-28 00:24:16 +00:00
parent 50e4daeaf2
commit e18ec5f2b2
3 changed files with 16 additions and 15 deletions

View File

@ -3287,7 +3287,7 @@ const OperationConfig = {
"Frequency distribution": {
module: "Default",
description: "Displays the distribution of bytes in the data as a graph.",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "html",
args: [
{
@ -3300,7 +3300,7 @@ const OperationConfig = {
"Chi Square": {
module: "Default",
description: "Calculates the Chi Square distribution of values.",
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "number",
args: []
},
@ -3740,7 +3740,7 @@ const OperationConfig = {
"<br><br>",
"EXIF data from photos usually contains information about the image file itself as well as the device used to create it.",
].join("\n"),
inputType: "byteArray",
inputType: "ArrayBuffer",
outputType: "string",
args: [],
},

View File

@ -81,22 +81,23 @@ const Entropy = {
/**
* Frequency distribution operation.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {html}
*/
runFreqDistrib: function (input, args) {
if (!input.length) return "No data";
const data = new Uint8Array(input);
if (!data.length) return "No data";
let distrib = new Array(256).fill(0),
percentages = new Array(256),
len = input.length,
len = data.length,
showZeroes = args[0],
i;
// Count bytes
for (i = 0; i < len; i++) {
distrib[input[i]]++;
distrib[data[i]]++;
}
// Calculate percentages
@ -138,21 +139,22 @@ const Entropy = {
/**
* Chi Square operation.
*
* @param {byteArray} data
* @param {ArrayBuffer} data
* @param {Object[]} args
* @returns {number}
*/
runChiSq: function(input, args) {
const data = new Uint8Array(input);
let distArray = new Array(256).fill(0),
total = 0;
for (let i = 0; i < input.length; i++) {
distArray[input[i]]++;
for (let i = 0; i < data.length; i++) {
distArray[data[i]]++;
}
for (let i = 0; i < distArray.length; i++) {
if (distArray[i] > 0) {
total += Math.pow(distArray[i] - input.length / 256, 2) / (input.length / 256);
total += Math.pow(distArray[i] - data.length / 256, 2) / (data.length / 256);
}
}

View File

@ -20,14 +20,13 @@ const Image = {
*
* Extracts EXIF data from a byteArray, representing a JPG or a TIFF image.
*
* @param {byteArray} input
* @param {ArrayBuffer} input
* @param {Object[]} args
* @returns {string}
*/
runExtractEXIF(input, args) {
try {
const bytes = Uint8Array.from(input);
const parser = ExifParser.create(bytes.buffer);
const parser = ExifParser.create(input);
const result = parser.parse();
let lines = [];
@ -53,7 +52,7 @@ const Image = {
* @author David Moodie [davidmoodie12@gmail.com]
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
* @returns {byteArray}
*/
runRemoveEXIF(input, args) {
// Do nothing if input is empty