Skip to content

Commit

Permalink
Tidied up TARGE extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Mar 27, 2020
1 parent 5e51ed0 commit 45011de
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/core/lib/FileSignatures.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export const FILE_SIGNATURES = {
mime: "image/x-targa",
description: "",
signature: [
{
{ // This signature is not at the beginning of the file. The extractor works backwards.
0: 0x54,
1: 0x52,
2: 0x55,
Expand All @@ -492,7 +492,6 @@ export const FILE_SIGNATURES = {
14: 0x4c,
15: 0x45,
16: 0x2e

}
],
extractor: extractTARGA
Expand Down Expand Up @@ -3075,14 +3074,14 @@ export function extractICO(bytes, offset) {
return stream.carve();
}


/**
* TARGA extractor.
*
* @param {Uint8Array} bytes
* @param {number} offset
*/
export function extractTARGA(bytes, offset) {

// Need all the bytes since we do not know how far up the image goes.
const stream = new Stream(bytes);
stream.moveTo(offset - 8);
Expand All @@ -3094,7 +3093,7 @@ export function extractTARGA(bytes, offset) {
stream.moveBackwardsBy(8);

/**
* Move's backwards in the stream until it meet bytes that are the same as the amount of bytes moved.
* Moves backwards in the stream until it meet bytes that are the same as the amount of bytes moved.
*
* @param {number} sizeOfSize
* @param {number} maxSize
Expand All @@ -3115,7 +3114,6 @@ export function extractTARGA(bytes, offset) {

/**
* Moves backwards in the stream until we meet bytes(when calculated) that are the same as the amount of bytes moved.
*
*/
function moveBackwardsUntilImageSize() {
stream.moveBackwardsBy(5);
Expand All @@ -3134,14 +3132,12 @@ export function extractTARGA(bytes, offset) {

if (extensionOffset || developerOffset) {
if (extensionOffset) {

// Size is stored in two bytes hence the maximum is 0xffff.
moveBackwardsUntilSize(0xffff, 2);

// Move to where we think the start of the file is.
stream.moveBackwardsBy(extensionOffset);
} else if (developerOffset) {

// Size is stored in 4 bytes hence the maxiumum is 0xffffffff.
moveBackwardsUntilSize(0xffffffff, 4);

Expand All @@ -3152,7 +3148,6 @@ export function extractTARGA(bytes, offset) {
stream.moveBackwardsBy(developerOffset);
}
} else {

// Move backwards until size === number of bytes passed.
moveBackwardsUntilImageSize();

Expand Down

0 comments on commit 45011de

Please sign in to comment.