Best JavaScript code snippet using wpt
jpx.js
Source:jpx.js
...365 buildPackets(context);366 }367 // moving to the end of the data368 length = tile.dataEnd - position;369 parseTilePackets(context, data, position, length);370 break;371 case 0xFF55: // Tile-part lengths, main header (TLM)372 case 0xFF57: // Packet length, main header (PLM)373 case 0xFF58: // Packet length, tile-part header (PLT)374 case 0xFF64: // Comment (COM)375 length = readUint16(data, position);376 // skipping content377 break;378 case 0xFF53: // Coding style component (COC)379 throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +380 'not implemented');381 default:382 throw new Error('JPX Error: Unknown codestream code: ' +383 code.toString(16));384 }385 position += length;386 }387 } catch (e) {388 if (doNotRecover || this.failOnCorruptedImage) {389 throw e;390 } else {391 warn('Trying to recover from ' + e.message);392 }393 }394 this.tiles = transformComponents(context);395 this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;396 this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;397 this.componentsCount = context.SIZ.Csiz;398 }399 };400 function calculateComponentDimensions(component, siz) {401 // Section B.2 Component mapping402 component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);403 component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);404 component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);405 component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);406 component.width = component.x1 - component.x0;407 component.height = component.y1 - component.y0;408 }409 function calculateTileGrids(context, components) {410 var siz = context.SIZ;411 // Section B.3 Division into tile and tile-components412 var tile, tiles = [];413 var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);414 var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);415 for (var q = 0; q < numYtiles; q++) {416 for (var p = 0; p < numXtiles; p++) {417 tile = {};418 tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);419 tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);420 tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);421 tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);422 tile.width = tile.tx1 - tile.tx0;423 tile.height = tile.ty1 - tile.ty0;424 tile.components = [];425 tiles.push(tile);426 }427 }428 context.tiles = tiles;429 var componentsCount = siz.Csiz;430 for (var i = 0, ii = componentsCount; i < ii; i++) {431 var component = components[i];432 for (var j = 0, jj = tiles.length; j < jj; j++) {433 var tileComponent = {};434 tile = tiles[j];435 tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);436 tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);437 tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);438 tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);439 tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;440 tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;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';921 subband.tbx0 = Math.ceil(component.tcx0 / scale);922 subband.tby0 = Math.ceil(component.tcy0 / scale);923 subband.tbx1 = Math.ceil(component.tcx1 / scale);924 subband.tby1 = Math.ceil(component.tcy1 / scale);925 subband.resolution = resolution;926 buildCodeblocks(context, subband, blocksDimensions);927 subbands.push(subband);928 resolution.subbands = [subband];929 } else {930 var bscale = 1 << (decompositionLevelsCount - r + 1);931 var resolutionSubbands = [];932 // three sub-bands (HL, LH and HH) with rest of decompositions933 subband = {};934 subband.type = 'HL';935 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);936 subband.tby0 = Math.ceil(component.tcy0 / bscale);937 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);938 subband.tby1 = Math.ceil(component.tcy1 / bscale);939 subband.resolution = resolution;940 buildCodeblocks(context, subband, blocksDimensions);941 subbands.push(subband);942 resolutionSubbands.push(subband);943 subband = {};944 subband.type = 'LH';945 subband.tbx0 = Math.ceil(component.tcx0 / bscale);946 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);947 subband.tbx1 = Math.ceil(component.tcx1 / bscale);948 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);949 subband.resolution = resolution;950 buildCodeblocks(context, subband, blocksDimensions);951 subbands.push(subband);952 resolutionSubbands.push(subband);953 subband = {};954 subband.type = 'HH';955 subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);956 subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);957 subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);958 subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);959 subband.resolution = resolution;960 buildCodeblocks(context, subband, blocksDimensions);961 subbands.push(subband);962 resolutionSubbands.push(subband);963 resolution.subbands = resolutionSubbands;964 }965 }966 component.resolutions = resolutions;967 component.subbands = subbands;968 }969 // Generate the packets sequence970 var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;971 switch (progressionOrder) {972 case 0:973 tile.packetsIterator =974 new LayerResolutionComponentPositionIterator(context);975 break;976 case 1:977 tile.packetsIterator =978 new ResolutionLayerComponentPositionIterator(context);979 break;980 case 2:981 tile.packetsIterator =982 new ResolutionPositionComponentLayerIterator(context);983 break;984 case 3:985 tile.packetsIterator =986 new PositionComponentResolutionLayerIterator(context);987 break;988 case 4:989 tile.packetsIterator =990 new ComponentPositionResolutionLayerIterator(context);991 break;992 default:993 throw new Error('JPX Error: Unsupported progression order ' +994 progressionOrder);995 }996 }997 function parseTilePackets(context, data, offset, dataLength) {998 var position = 0;999 var buffer, bufferSize = 0, skipNextBit = false;1000 function readBits(count) {1001 while (bufferSize < count) {1002 var b = data[offset + position];1003 position++;1004 if (skipNextBit) {1005 buffer = (buffer << 7) | b;1006 bufferSize += 7;1007 skipNextBit = false;1008 } else {1009 buffer = (buffer << 8) | b;1010 bufferSize += 8;1011 }...
Using AI Code Generation
1var wptiles = require('wptiles');2var tilePackets = wptiles.parseTilePackets(tilePackets);3console.log(tilePackets);4 var tilePackets = wptiles.parseTilePackets(tilePackets);5 console.log(tilePackets);6var wptiles = require('wptiles');7var tilePackets = wptiles.parseTilePackets(tilePackets);8console.log(tilePackets);9 var tilePackets = wptiles.parseTilePackets(tilePackets);10 console.log(tilePackets);11var wptiles = require('wptiles');12 {13 "data": {14 {15 "geometry": {16 },17 "properties": {18 }19 }20 }21 },22 {23 "data": {24 {25 "geometry": {26 },27 "properties": {28 }29 }30 }31 }32];33var tilePackets = wptiles.parseTilePackets(tilePackets);34console.log(tilePackets);
Using AI Code Generation
1var fs = require('fs');2var wptile = require('./wptile.js');3var tile = fs.readFileSync('tile');4wptile.parseTilePackets(tile, function(err, result) {5 if (err) {6 console.log(err);7 } else {8 console.log(result);9 }10});11var wptile = module.exports = {12 parseTilePackets: function(tile, callback) {13 var result = {};14 var index = 0;15 var tileLength = tile.length;16 while (index < tileLength) {17 var packetLength = tile.readUInt32LE(index);18 index += 4;19 var packet = tile.slice(index, index + packetLength);20 index += packetLength;21 var packetType = packet.readUInt8(0);22 var packetData = packet.slice(1);23 if (packetType == 0) {24 result['version'] = packetData.readUInt8(0);25 } else if (packetType == 1) {26 result['header'] = packetData.toString('utf8');27 } else if (packetType == 2) {28 result['body'] = packetData.toString('utf8');29 } else if (packetType == 3) {30 result['footer'] = packetData.toString('utf8');31 } else {32 callback('Unknown packet type: ' + packetType);33 }34 }35 callback(null, result);36 }37};
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!