How to use getBlocksDimensions method in wpt

Best JavaScript code snippet using wpt

jpx.js

Source:jpx.js Github

copy

Full Screen

...441 tile.components[i] = tileComponent;442 }443 }444 }445 function getBlocksDimensions(context, component, r) {446 var codOrCoc = component.codingStyleParameters;447 var result = {};448 if (!codOrCoc.entropyCoderWithCustomPrecincts) {449 result.PPx = 15;450 result.PPy = 15;451 } else {452 result.PPx = codOrCoc.precinctsSizes[r].PPx;453 result.PPy = codOrCoc.precinctsSizes[r].PPy;454 }455 // calculate codeblock size as described in section B.7456 result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :457 Math.min(codOrCoc.xcb, result.PPx));458 result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :459 Math.min(codOrCoc.ycb, result.PPy));460 return result;461 }462 function buildPrecincts(context, resolution, dimensions) {463 // Section B.6 Division resolution to precincts464 var precinctWidth = 1 << dimensions.PPx;465 var precinctHeight = 1 << dimensions.PPy;466 // Jasper introduces codeblock groups for mapping each subband codeblocks467 // to precincts. Precinct partition divides a resolution according to width468 // and height parameters. The subband that belongs to the resolution level469 // has a different size than the level, unless it is the zero resolution.470 // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:471 // The precinct partitioning for a particular subband is derived from a472 // partitioning of its parent LL band (i.e., the LL band at the next higher473 // resolution level)... The LL band associated with each resolution level is474 // divided into precincts... Each of the resulting precinct regions is then475 // mapped into its child subbands (if any) at the next lower resolution476 // level. This is accomplished by using the coordinate transformation477 // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the478 // coordinates of a point in the LL band and child subband, respectively.479 var isZeroRes = resolution.resLevel === 0;480 var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));481 var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));482 var numprecinctswide = (resolution.trx1 > resolution.trx0 ?483 Math.ceil(resolution.trx1 / precinctWidth) -484 Math.floor(resolution.trx0 / precinctWidth) : 0);485 var numprecinctshigh = (resolution.try1 > resolution.try0 ?486 Math.ceil(resolution.try1 / precinctHeight) -487 Math.floor(resolution.try0 / precinctHeight) : 0);488 var numprecincts = numprecinctswide * numprecinctshigh;489 resolution.precinctParameters = {490 precinctWidth: precinctWidth,491 precinctHeight: precinctHeight,492 numprecinctswide: numprecinctswide,493 numprecinctshigh: numprecinctshigh,494 numprecincts: numprecincts,495 precinctWidthInSubband: precinctWidthInSubband,496 precinctHeightInSubband: precinctHeightInSubband497 };498 }499 function buildCodeblocks(context, subband, dimensions) {500 // Section B.7 Division sub-band into code-blocks501 var xcb_ = dimensions.xcb_;502 var ycb_ = dimensions.ycb_;503 var codeblockWidth = 1 << xcb_;504 var codeblockHeight = 1 << ycb_;505 var cbx0 = subband.tbx0 >> xcb_;506 var cby0 = subband.tby0 >> ycb_;507 var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;508 var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;509 var precinctParameters = subband.resolution.precinctParameters;510 var codeblocks = [];511 var precincts = [];512 var i, j, codeblock, precinctNumber;513 for (j = cby0; j < cby1; j++) {514 for (i = cbx0; i < cbx1; i++) {515 codeblock = {516 cbx: i,517 cby: j,518 tbx0: codeblockWidth * i,519 tby0: codeblockHeight * j,520 tbx1: codeblockWidth * (i + 1),521 tby1: codeblockHeight * (j + 1)522 };523 codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);524 codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);525 codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);526 codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);527 // Calculate precinct number for this codeblock, codeblock position528 // should be relative to its subband, use actual dimension and position529 // See comment about codeblock group width and height530 var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /531 precinctParameters.precinctWidthInSubband);532 var pj = Math.floor((codeblock.tby0_ - subband.tby0) /533 precinctParameters.precinctHeightInSubband);534 precinctNumber = pi + (pj * precinctParameters.numprecinctswide);535 codeblock.precinctNumber = precinctNumber;536 codeblock.subbandType = subband.type;537 codeblock.Lblock = 3;538 if (codeblock.tbx1_ <= codeblock.tbx0_ ||539 codeblock.tby1_ <= codeblock.tby0_) {540 continue;541 }542 codeblocks.push(codeblock);543 // building precinct for the sub-band544 var precinct = precincts[precinctNumber];545 if (precinct !== undefined) {546 if (i < precinct.cbxMin) {547 precinct.cbxMin = i;548 } else if (i > precinct.cbxMax) {549 precinct.cbxMax = i;550 }551 if (j < precinct.cbyMin) {552 precinct.cbxMin = j;553 } else if (j > precinct.cbyMax) {554 precinct.cbyMax = j;555 }556 } else {557 precincts[precinctNumber] = precinct = {558 cbxMin: i,559 cbyMin: j,560 cbxMax: i,561 cbyMax: j562 };563 }564 codeblock.precinct = precinct;565 }566 }567 subband.codeblockParameters = {568 codeblockWidth: xcb_,569 codeblockHeight: ycb_,570 numcodeblockwide: cbx1 - cbx0 + 1,571 numcodeblockhigh: cby1 - cby0 + 1572 };573 subband.codeblocks = codeblocks;574 subband.precincts = precincts;575 }576 function createPacket(resolution, precinctNumber, layerNumber) {577 var precinctCodeblocks = [];578 // Section B.10.8 Order of info in packet579 var subbands = resolution.subbands;580 // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence581 for (var i = 0, ii = subbands.length; i < ii; i++) {582 var subband = subbands[i];583 var codeblocks = subband.codeblocks;584 for (var j = 0, jj = codeblocks.length; j < jj; j++) {585 var codeblock = codeblocks[j];586 if (codeblock.precinctNumber !== precinctNumber) {587 continue;588 }589 precinctCodeblocks.push(codeblock);590 }591 }592 return {593 layerNumber: layerNumber,594 codeblocks: precinctCodeblocks595 };596 }597 function LayerResolutionComponentPositionIterator(context) {598 var siz = context.SIZ;599 var tileIndex = context.currentTile.index;600 var tile = context.tiles[tileIndex];601 var layersCount = tile.codingStyleDefaultParameters.layersCount;602 var componentsCount = siz.Csiz;603 var maxDecompositionLevelsCount = 0;604 for (var q = 0; q < componentsCount; q++) {605 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,606 tile.components[q].codingStyleParameters.decompositionLevelsCount);607 }608 var l = 0, r = 0, i = 0, k = 0;609 this.nextPacket = function JpxImage_nextPacket() {610 // Section B.12.1.1 Layer-resolution-component-position611 for (; l < layersCount; l++) {612 for (; r <= maxDecompositionLevelsCount; r++) {613 for (; i < componentsCount; i++) {614 var component = tile.components[i];615 if (r > component.codingStyleParameters.decompositionLevelsCount) {616 continue;617 }618 var resolution = component.resolutions[r];619 var numprecincts = resolution.precinctParameters.numprecincts;620 for (; k < numprecincts;) {621 var packet = createPacket(resolution, k, l);622 k++;623 return packet;624 }625 k = 0;626 }627 i = 0;628 }629 r = 0;630 }631 throw new Error('JPX Error: Out of packets');632 };633 }634 function ResolutionLayerComponentPositionIterator(context) {635 var siz = context.SIZ;636 var tileIndex = context.currentTile.index;637 var tile = context.tiles[tileIndex];638 var layersCount = tile.codingStyleDefaultParameters.layersCount;639 var componentsCount = siz.Csiz;640 var maxDecompositionLevelsCount = 0;641 for (var q = 0; q < componentsCount; q++) {642 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,643 tile.components[q].codingStyleParameters.decompositionLevelsCount);644 }645 var r = 0, l = 0, i = 0, k = 0;646 this.nextPacket = function JpxImage_nextPacket() {647 // Section B.12.1.2 Resolution-layer-component-position648 for (; r <= maxDecompositionLevelsCount; r++) {649 for (; l < layersCount; l++) {650 for (; i < componentsCount; i++) {651 var component = tile.components[i];652 if (r > component.codingStyleParameters.decompositionLevelsCount) {653 continue;654 }655 var resolution = component.resolutions[r];656 var numprecincts = resolution.precinctParameters.numprecincts;657 for (; k < numprecincts;) {658 var packet = createPacket(resolution, k, l);659 k++;660 return packet;661 }662 k = 0;663 }664 i = 0;665 }666 l = 0;667 }668 throw new Error('JPX Error: Out of packets');669 };670 }671 function ResolutionPositionComponentLayerIterator(context) {672 var siz = context.SIZ;673 var tileIndex = context.currentTile.index;674 var tile = context.tiles[tileIndex];675 var layersCount = tile.codingStyleDefaultParameters.layersCount;676 var componentsCount = siz.Csiz;677 var l, r, c, p;678 var maxDecompositionLevelsCount = 0;679 for (c = 0; c < componentsCount; c++) {680 var component = tile.components[c];681 maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,682 component.codingStyleParameters.decompositionLevelsCount);683 }684 var maxNumPrecinctsInLevel = new Int32Array(685 maxDecompositionLevelsCount + 1);686 for (r = 0; r <= maxDecompositionLevelsCount; ++r) {687 var maxNumPrecincts = 0;688 for (c = 0; c < componentsCount; ++c) {689 var resolutions = tile.components[c].resolutions;690 if (r < resolutions.length) {691 maxNumPrecincts = Math.max(maxNumPrecincts,692 resolutions[r].precinctParameters.numprecincts);693 }694 }695 maxNumPrecinctsInLevel[r] = maxNumPrecincts;696 }697 l = 0;698 r = 0;699 c = 0;700 p = 0;701 this.nextPacket = function JpxImage_nextPacket() {702 // Section B.12.1.3 Resolution-position-component-layer703 for (; r <= maxDecompositionLevelsCount; r++) {704 for (; p < maxNumPrecinctsInLevel[r]; p++) {705 for (; c < componentsCount; c++) {706 var component = tile.components[c];707 if (r > component.codingStyleParameters.decompositionLevelsCount) {708 continue;709 }710 var resolution = component.resolutions[r];711 var numprecincts = resolution.precinctParameters.numprecincts;712 if (p >= numprecincts) {713 continue;714 }715 for (; l < layersCount;) {716 var packet = createPacket(resolution, p, l);717 l++;718 return packet;719 }720 l = 0;721 }722 c = 0;723 }724 p = 0;725 }726 throw new Error('JPX Error: Out of packets');727 };728 }729 function PositionComponentResolutionLayerIterator(context) {730 var siz = context.SIZ;731 var tileIndex = context.currentTile.index;732 var tile = context.tiles[tileIndex];733 var layersCount = tile.codingStyleDefaultParameters.layersCount;734 var componentsCount = siz.Csiz;735 var precinctsSizes = getPrecinctSizesInImageScale(tile);736 var precinctsIterationSizes = precinctsSizes;737 var l = 0, r = 0, c = 0, px = 0, py = 0;738 this.nextPacket = function JpxImage_nextPacket() {739 // Section B.12.1.4 Position-component-resolution-layer740 for (; py < precinctsIterationSizes.maxNumHigh; py++) {741 for (; px < precinctsIterationSizes.maxNumWide; px++) {742 for (; c < componentsCount; c++) {743 var component = tile.components[c];744 var decompositionLevelsCount =745 component.codingStyleParameters.decompositionLevelsCount;746 for (; r <= decompositionLevelsCount; r++) {747 var resolution = component.resolutions[r];748 var sizeInImageScale =749 precinctsSizes.components[c].resolutions[r];750 var k = getPrecinctIndexIfExist(751 px,752 py,753 sizeInImageScale,754 precinctsIterationSizes,755 resolution);756 if (k === null) {757 continue;758 }759 for (; l < layersCount;) {760 var packet = createPacket(resolution, k, l);761 l++;762 return packet;763 }764 l = 0;765 }766 r = 0;767 }768 c = 0;769 }770 px = 0;771 }772 throw new Error('JPX Error: Out of packets');773 };774 }775 function ComponentPositionResolutionLayerIterator(context) {776 var siz = context.SIZ;777 var tileIndex = context.currentTile.index;778 var tile = context.tiles[tileIndex];779 var layersCount = tile.codingStyleDefaultParameters.layersCount;780 var componentsCount = siz.Csiz;781 var precinctsSizes = getPrecinctSizesInImageScale(tile);782 var l = 0, r = 0, c = 0, px = 0, py = 0;783 this.nextPacket = function JpxImage_nextPacket() {784 // Section B.12.1.5 Component-position-resolution-layer785 for (; c < componentsCount; ++c) {786 var component = tile.components[c];787 var precinctsIterationSizes = precinctsSizes.components[c];788 var decompositionLevelsCount =789 component.codingStyleParameters.decompositionLevelsCount;790 for (; py < precinctsIterationSizes.maxNumHigh; py++) {791 for (; px < precinctsIterationSizes.maxNumWide; px++) {792 for (; r <= decompositionLevelsCount; r++) {793 var resolution = component.resolutions[r];794 var sizeInImageScale = precinctsIterationSizes.resolutions[r];795 var k = getPrecinctIndexIfExist(796 px,797 py,798 sizeInImageScale,799 precinctsIterationSizes,800 resolution);801 if (k === null) {802 continue;803 }804 for (; l < layersCount;) {805 var packet = createPacket(resolution, k, l);806 l++;807 return packet;808 }809 l = 0;810 }811 r = 0;812 }813 px = 0;814 }815 py = 0;816 }817 throw new Error('JPX Error: Out of packets');818 };819 }820 function getPrecinctIndexIfExist(821 pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {822 var posX = pxIndex * precinctIterationSizes.minWidth;823 var posY = pyIndex * precinctIterationSizes.minHeight;824 if (posX % sizeInImageScale.width !== 0 ||825 posY % sizeInImageScale.height !== 0) {826 return null;827 }828 var startPrecinctRowIndex =829 (posY / sizeInImageScale.width) *830 resolution.precinctParameters.numprecinctswide;831 return (posX / sizeInImageScale.height) + startPrecinctRowIndex;832 }833 function getPrecinctSizesInImageScale(tile) {834 var componentsCount = tile.components.length;835 var minWidth = Number.MAX_VALUE;836 var minHeight = Number.MAX_VALUE;837 var maxNumWide = 0;838 var maxNumHigh = 0;839 var sizePerComponent = new Array(componentsCount);840 for (var c = 0; c < componentsCount; c++) {841 var component = tile.components[c];842 var decompositionLevelsCount =843 component.codingStyleParameters.decompositionLevelsCount;844 var sizePerResolution = new Array(decompositionLevelsCount + 1);845 var minWidthCurrentComponent = Number.MAX_VALUE;846 var minHeightCurrentComponent = Number.MAX_VALUE;847 var maxNumWideCurrentComponent = 0;848 var maxNumHighCurrentComponent = 0;849 var scale = 1;850 for (var r = decompositionLevelsCount; r >= 0; --r) {851 var resolution = component.resolutions[r];852 var widthCurrentResolution =853 scale * resolution.precinctParameters.precinctWidth;854 var heightCurrentResolution =855 scale * resolution.precinctParameters.precinctHeight;856 minWidthCurrentComponent = Math.min(857 minWidthCurrentComponent,858 widthCurrentResolution);859 minHeightCurrentComponent = Math.min(860 minHeightCurrentComponent,861 heightCurrentResolution);862 maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,863 resolution.precinctParameters.numprecinctswide);864 maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,865 resolution.precinctParameters.numprecinctshigh);866 sizePerResolution[r] = {867 width: widthCurrentResolution,868 height: heightCurrentResolution869 };870 scale <<= 1;871 }872 minWidth = Math.min(minWidth, minWidthCurrentComponent);873 minHeight = Math.min(minHeight, minHeightCurrentComponent);874 maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);875 maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);876 sizePerComponent[c] = {877 resolutions: sizePerResolution,878 minWidth: minWidthCurrentComponent,879 minHeight: minHeightCurrentComponent,880 maxNumWide: maxNumWideCurrentComponent,881 maxNumHigh: maxNumHighCurrentComponent882 };883 }884 return {885 components: sizePerComponent,886 minWidth: minWidth,887 minHeight: minHeight,888 maxNumWide: maxNumWide,889 maxNumHigh: maxNumHigh890 };891 }892 function buildPackets(context) {893 var siz = context.SIZ;894 var tileIndex = context.currentTile.index;895 var tile = context.tiles[tileIndex];896 var componentsCount = siz.Csiz;897 // Creating resolutions and sub-bands for each component898 for (var c = 0; c < componentsCount; c++) {899 var component = tile.components[c];900 var decompositionLevelsCount =901 component.codingStyleParameters.decompositionLevelsCount;902 // Section B.5 Resolution levels and sub-bands903 var resolutions = [];904 var subbands = [];905 for (var r = 0; r <= decompositionLevelsCount; r++) {906 var blocksDimensions = getBlocksDimensions(context, component, r);907 var resolution = {};908 var scale = 1 << (decompositionLevelsCount - r);909 resolution.trx0 = Math.ceil(component.tcx0 / scale);910 resolution.try0 = Math.ceil(component.tcy0 / scale);911 resolution.trx1 = Math.ceil(component.tcx1 / scale);912 resolution.try1 = Math.ceil(component.tcy1 / scale);913 resolution.resLevel = r;914 buildPrecincts(context, resolution, blocksDimensions);915 resolutions.push(resolution);916 var subband;917 if (r === 0) {918 // one sub-band (LL) with last decomposition919 subband = {};920 subband.type = 'LL';...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptoolkit = require('wptoolkit');2wptoolkit.getBlocksDimensions('test.php',function(err,blocks){3 if(err){4 console.log(err);5 }else{6 console.log(blocks);7 }8});9[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('./wptools');2var fs = require('fs');3wptools.getBlocksDimensions(url).then(function (data) {4 console.log(data);5 fs.writeFileSync('data.json', JSON.stringify(data));6});7{8 "block1": {9 },10 "block2": {11 },12}13* [cheerio](

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var input = "input.txt";3var output = "output.txt";4wptoolkit.getBlocksDimensions(input, output);5 {6 "dimensions": {7 }8 },9 {10 "dimensions": {11 }12 },13 {14 "dimensions": {15 }16 },17 {18 "dimensions": {19 }20 }21[MIT](LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wpt = require('wpt-api')('API_KEY');2 if (err) {3 console.log(err);4 }5 else {6 console.log(data.data);7 }8});9 console.log(data);10}).catch((err) => {11 console.log(err);12});13const wpt = require('wpt-api')('API_KEY');14 if (err) {15 console.log(err);16 }17 else {18 console.log(data.data);19 }20});21 console.log(data);22}).catch((err) => {23 console.log(err);24});25const wpt = require('wpt-api')('API_KEY');26 if (err) {27 console.log(err);28 }29 else {30 console.log(data.data);31 }32});33 console.log(data);34}).catch((err) => {35 console.log(err);36});37const wpt = require('wpt-api')('API_KEY');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpage-test');2var wpt = new WebPageTest('www.webpagetest.org', 'A.5cdd3b6c0f7a4a9a9a0f7f4e4a4d4f60');3 if (err) {4 console.log(err);5 } else {6 console.log(data);7 }8});9### new WebPageTest(host, apiKey)10### wpt.runTest(url, options, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt-api');2var options = {3};4wpt.getBlocksDimensions(options, function(err, data) {5 if (err) {6 console.log('Error: ' + err);7 } else {8 console.log(data);9 }10});11### getBreakdown(options, callback)12var wpt = require('wpt-api');13var options = {14};15wpt.getBreakdown(options, function(err, data) {16 if (err) {17 console.log('Error: ' + err);18 } else {19 console.log(data);20 }21});22### getConsoleLog(options, callback)23var wpt = require('wpt-api');24var options = {25};26wpt.getConsoleLog(options, function(err, data) {27 if (err) {28 console.log('Error: ' + err);29 } else {30 console.log(data);31 }32});33### getCustomMetric(options, callback)

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful