MCPcopy Create free account
hub / github.com/denimgroup/threadfix / getJpegSize

Function getJpegSize

threadfix-main/src/main/webapp/scripts/jspdf.debug.js:2526–2565  ·  view source on GitHub ↗
(imgData)

Source from the content-addressed store, hash-verified

2524 //a jpeg image and returns [width, height]
2525 //Algorithm from: http://www.64lines.com/jpeg-width-height
2526 var getJpegSize = function(imgData) {
2527 'use strict'
2528 var width, height, numcomponents;
2529 // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
2530 if (!imgData.charCodeAt(0) === 0xff ||
2531 !imgData.charCodeAt(1) === 0xd8 ||
2532 !imgData.charCodeAt(2) === 0xff ||
2533 !imgData.charCodeAt(3) === 0xe0 ||
2534 !imgData.charCodeAt(6) === 'J'.charCodeAt(0) ||
2535 !imgData.charCodeAt(7) === 'F'.charCodeAt(0) ||
2536 !imgData.charCodeAt(8) === 'I'.charCodeAt(0) ||
2537 !imgData.charCodeAt(9) === 'F'.charCodeAt(0) ||
2538 !imgData.charCodeAt(10) === 0x00) {
2539 throw new Error('getJpegSize requires a binary string jpeg file')
2540 }
2541 var blockLength = imgData.charCodeAt(4)*256 + imgData.charCodeAt(5);
2542 var i = 4, len = imgData.length;
2543 while ( i < len ) {
2544 i += blockLength;
2545 if (imgData.charCodeAt(i) !== 0xff) {
2546 throw new Error('getJpegSize could not find the size of the image');
2547 }
2548 if (imgData.charCodeAt(i+1) === 0xc0 || //(SOF) Huffman - Baseline DCT
2549 imgData.charCodeAt(i+1) === 0xc1 || //(SOF) Huffman - Extended sequential DCT
2550 imgData.charCodeAt(i+1) === 0xc2 || // Progressive DCT (SOF2)
2551 imgData.charCodeAt(i+1) === 0xc3 || // Spatial (sequential) lossless (SOF3)
2552 imgData.charCodeAt(i+1) === 0xc4 || // Differential sequential DCT (SOF5)
2553 imgData.charCodeAt(i+1) === 0xc5 || // Differential progressive DCT (SOF6)
2554 imgData.charCodeAt(i+1) === 0xc6 || // Differential spatial (SOF7)
2555 imgData.charCodeAt(i+1) === 0xc7) {
2556 height = imgData.charCodeAt(i+5)*256 + imgData.charCodeAt(i+6);
2557 width = imgData.charCodeAt(i+7)*256 + imgData.charCodeAt(i+8);
2558 numcomponents = imgData.charCodeAt(i+9);
2559 return [width, height, numcomponents];
2560 } else {
2561 i += 2;
2562 blockLength = imgData.charCodeAt(i)*256 + imgData.charCodeAt(i+1)
2563 }
2564 }
2565 }
2566 , getJpegSizeFromBytes = function(data) {
2567
2568 var hdr = (data[0] << 8) | data[1];

Callers 1

jspdf.debug.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected