How to use getStandardTable method in wpt

Best JavaScript code snippet using wpt

jbig2.js

Source:jbig2.js Github

copy

Full Screen

...500 var contextCache = decodingContext.contextCache;501 var tableB1 = void 0,502 symbolWidths = void 0;503 if (huffman) {504 tableB1 = getStandardTable(1);505 symbolWidths = [];506 symbolCodeLength = Math.max(symbolCodeLength, 1);507 }508 while (newSymbols.length < numberOfNewSymbols) {509 var deltaHeight = huffman ? huffmanTables.tableDeltaHeight.decode(huffmanInput) : decodeInteger(contextCache, 'IADH', decoder);510 currentHeight += deltaHeight;511 var currentWidth = 0,512 totalWidth = 0;513 var firstSymbol = huffman ? symbolWidths.length : 0;514 while (true) {515 var deltaWidth = huffman ? huffmanTables.tableDeltaWidth.decode(huffmanInput) : decodeInteger(contextCache, 'IADW', decoder);516 if (deltaWidth === null) {517 break;518 }519 currentWidth += deltaWidth;520 totalWidth += currentWidth;521 var bitmap;522 if (refinement) {523 var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);524 if (numberOfInstances > 1) {525 bitmap = decodeTextRegion(huffman, refinement, currentWidth, currentHeight, 0, numberOfInstances, 1, symbols.concat(newSymbols), symbolCodeLength, 0, 0, 1, 0, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, 0, huffmanInput);526 } else {527 var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);528 var rdx = decodeInteger(contextCache, 'IARDX', decoder);529 var rdy = decodeInteger(contextCache, 'IARDY', decoder);530 var symbol = symbolId < symbols.length ? symbols[symbolId] : newSymbols[symbolId - symbols.length];531 bitmap = decodeRefinement(currentWidth, currentHeight, refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt, decodingContext);532 }533 newSymbols.push(bitmap);534 } else if (huffman) {535 symbolWidths.push(currentWidth);536 } else {537 bitmap = decodeBitmap(false, currentWidth, currentHeight, templateIndex, false, null, at, decodingContext);538 newSymbols.push(bitmap);539 }540 }541 if (huffman && !refinement) {542 var bitmapSize = huffmanTables.tableBitmapSize.decode(huffmanInput);543 huffmanInput.byteAlign();544 var collectiveBitmap = void 0;545 if (bitmapSize === 0) {546 collectiveBitmap = readUncompressedBitmap(huffmanInput, totalWidth, currentHeight);547 } else {548 var originalEnd = huffmanInput.end;549 var bitmapEnd = huffmanInput.position + bitmapSize;550 huffmanInput.end = bitmapEnd;551 collectiveBitmap = decodeMMRBitmap(huffmanInput, totalWidth, currentHeight, false);552 huffmanInput.end = originalEnd;553 huffmanInput.position = bitmapEnd;554 }555 var numberOfSymbolsDecoded = symbolWidths.length;556 if (firstSymbol === numberOfSymbolsDecoded - 1) {557 newSymbols.push(collectiveBitmap);558 } else {559 var _i = void 0,560 y = void 0,561 xMin = 0,562 xMax = void 0,563 bitmapWidth = void 0,564 symbolBitmap = void 0;565 for (_i = firstSymbol; _i < numberOfSymbolsDecoded; _i++) {566 bitmapWidth = symbolWidths[_i];567 xMax = xMin + bitmapWidth;568 symbolBitmap = [];569 for (y = 0; y < currentHeight; y++) {570 symbolBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));571 }572 newSymbols.push(symbolBitmap);573 xMin = xMax;574 }575 }576 }577 }578 var exportedSymbols = [];579 var flags = [],580 currentFlag = false;581 var totalSymbolsLength = symbols.length + numberOfNewSymbols;582 while (flags.length < totalSymbolsLength) {583 var runLength = huffman ? tableB1.decode(huffmanInput) : decodeInteger(contextCache, 'IAEX', decoder);584 while (runLength--) {585 flags.push(currentFlag);586 }587 currentFlag = !currentFlag;588 }589 for (var i = 0, ii = symbols.length; i < ii; i++) {590 if (flags[i]) {591 exportedSymbols.push(symbols[i]);592 }593 }594 for (var j = 0; j < numberOfNewSymbols; i++, j++) {595 if (flags[i]) {596 exportedSymbols.push(newSymbols[j]);597 }598 }599 return exportedSymbols;600 }601 function decodeTextRegion(huffman, refinement, width, height, defaultPixelValue, numberOfSymbolInstances, stripSize, inputSymbols, symbolCodeLength, transposed, dsOffset, referenceCorner, combinationOperator, huffmanTables, refinementTemplateIndex, refinementAt, decodingContext, logStripSize, huffmanInput) {602 if (huffman && refinement) {603 throw new Jbig2Error('refinement with Huffman is not supported');604 }605 var bitmap = [];606 var i, row;607 for (i = 0; i < height; i++) {608 row = new Uint8Array(width);609 if (defaultPixelValue) {610 for (var j = 0; j < width; j++) {611 row[j] = defaultPixelValue;612 }613 }614 bitmap.push(row);615 }616 var decoder = decodingContext.decoder;617 var contextCache = decodingContext.contextCache;618 var stripT = huffman ? -huffmanTables.tableDeltaT.decode(huffmanInput) : -decodeInteger(contextCache, 'IADT', decoder);619 var firstS = 0;620 i = 0;621 while (i < numberOfSymbolInstances) {622 var deltaT = huffman ? huffmanTables.tableDeltaT.decode(huffmanInput) : decodeInteger(contextCache, 'IADT', decoder);623 stripT += deltaT;624 var deltaFirstS = huffman ? huffmanTables.tableFirstS.decode(huffmanInput) : decodeInteger(contextCache, 'IAFS', decoder);625 firstS += deltaFirstS;626 var currentS = firstS;627 do {628 var currentT = 0;629 if (stripSize > 1) {630 currentT = huffman ? huffmanInput.readBits(logStripSize) : decodeInteger(contextCache, 'IAIT', decoder);631 }632 var t = stripSize * stripT + currentT;633 var symbolId = huffman ? huffmanTables.symbolIDTable.decode(huffmanInput) : decodeIAID(contextCache, decoder, symbolCodeLength);634 var applyRefinement = refinement && (huffman ? huffmanInput.readBit() : decodeInteger(contextCache, 'IARI', decoder));635 var symbolBitmap = inputSymbols[symbolId];636 var symbolWidth = symbolBitmap[0].length;637 var symbolHeight = symbolBitmap.length;638 if (applyRefinement) {639 var rdw = decodeInteger(contextCache, 'IARDW', decoder);640 var rdh = decodeInteger(contextCache, 'IARDH', decoder);641 var rdx = decodeInteger(contextCache, 'IARDX', decoder);642 var rdy = decodeInteger(contextCache, 'IARDY', decoder);643 symbolWidth += rdw;644 symbolHeight += rdh;645 symbolBitmap = decodeRefinement(symbolWidth, symbolHeight, refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx, (rdh >> 1) + rdy, false, refinementAt, decodingContext);646 }647 var offsetT = t - (referenceCorner & 1 ? 0 : symbolHeight - 1);648 var offsetS = currentS - (referenceCorner & 2 ? symbolWidth - 1 : 0);649 var s2, t2, symbolRow;650 if (transposed) {651 for (s2 = 0; s2 < symbolHeight; s2++) {652 row = bitmap[offsetS + s2];653 if (!row) {654 continue;655 }656 symbolRow = symbolBitmap[s2];657 var maxWidth = Math.min(width - offsetT, symbolWidth);658 switch (combinationOperator) {659 case 0:660 for (t2 = 0; t2 < maxWidth; t2++) {661 row[offsetT + t2] |= symbolRow[t2];662 }663 break;664 case 2:665 for (t2 = 0; t2 < maxWidth; t2++) {666 row[offsetT + t2] ^= symbolRow[t2];667 }668 break;669 default:670 throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');671 }672 }673 currentS += symbolHeight - 1;674 } else {675 for (t2 = 0; t2 < symbolHeight; t2++) {676 row = bitmap[offsetT + t2];677 if (!row) {678 continue;679 }680 symbolRow = symbolBitmap[t2];681 switch (combinationOperator) {682 case 0:683 for (s2 = 0; s2 < symbolWidth; s2++) {684 row[offsetS + s2] |= symbolRow[s2];685 }686 break;687 case 2:688 for (s2 = 0; s2 < symbolWidth; s2++) {689 row[offsetS + s2] ^= symbolRow[s2];690 }691 break;692 default:693 throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');694 }695 }696 currentS += symbolWidth - 1;697 }698 i++;699 var deltaS = huffman ? huffmanTables.tableDeltaS.decode(huffmanInput) : decodeInteger(contextCache, 'IADS', decoder);700 if (deltaS === null) {701 break;702 }703 currentS += deltaS + dsOffset;704 } while (true);705 }706 return bitmap;707 }708 function decodePatternDictionary(mmr, patternWidth, patternHeight, maxPatternIndex, template, decodingContext) {709 var at = [];710 if (!mmr) {711 at.push({712 x: -patternWidth,713 y: 0714 });715 if (template === 0) {716 at.push({717 x: -3,718 y: -1719 });720 at.push({721 x: 2,722 y: -2723 });724 at.push({725 x: -2,726 y: -2727 });728 }729 }730 var collectiveWidth = (maxPatternIndex + 1) * patternWidth;731 var collectiveBitmap = decodeBitmap(mmr, collectiveWidth, patternHeight, template, false, null, at, decodingContext);732 var patterns = [],733 i = 0,734 patternBitmap = void 0,735 xMin = void 0,736 xMax = void 0,737 y = void 0;738 while (i <= maxPatternIndex) {739 patternBitmap = [];740 xMin = patternWidth * i;741 xMax = xMin + patternWidth;742 for (y = 0; y < patternHeight; y++) {743 patternBitmap.push(collectiveBitmap[y].subarray(xMin, xMax));744 }745 patterns.push(patternBitmap);746 i++;747 }748 return patterns;749 }750 function decodeHalftoneRegion(mmr, patterns, template, regionWidth, regionHeight, defaultPixelValue, enableSkip, combinationOperator, gridWidth, gridHeight, gridOffsetX, gridOffsetY, gridVectorX, gridVectorY, decodingContext) {751 var skip = null;752 if (enableSkip) {753 throw new Jbig2Error('skip is not supported');754 }755 if (combinationOperator !== 0) {756 throw new Jbig2Error('operator ' + combinationOperator + ' is not supported in halftone region');757 }758 var regionBitmap = [];759 var i = void 0,760 j = void 0,761 row = void 0;762 for (i = 0; i < regionHeight; i++) {763 row = new Uint8Array(regionWidth);764 if (defaultPixelValue) {765 for (j = 0; j < regionWidth; j++) {766 row[j] = defaultPixelValue;767 }768 }769 regionBitmap.push(row);770 }771 var numberOfPatterns = patterns.length;772 var pattern0 = patterns[0];773 var patternWidth = pattern0[0].length,774 patternHeight = pattern0.length;775 var bitsPerValue = (0, _util.log2)(numberOfPatterns);776 var at = [];777 if (!mmr) {778 at.push({779 x: template <= 1 ? 3 : 2,780 y: -1781 });782 if (template === 0) {783 at.push({784 x: -3,785 y: -1786 });787 at.push({788 x: 2,789 y: -2790 });791 at.push({792 x: -2,793 y: -2794 });795 }796 }797 var grayScaleBitPlanes = [],798 mmrInput = void 0,799 bitmap = void 0;800 if (mmr) {801 mmrInput = new Reader(decodingContext.data, decodingContext.start, decodingContext.end);802 }803 for (i = bitsPerValue - 1; i >= 0; i--) {804 if (mmr) {805 bitmap = decodeMMRBitmap(mmrInput, gridWidth, gridHeight, true);806 } else {807 bitmap = decodeBitmap(false, gridWidth, gridHeight, template, false, skip, at, decodingContext);808 }809 grayScaleBitPlanes[i] = bitmap;810 }811 var mg = void 0,812 ng = void 0,813 bit = void 0,814 patternIndex = void 0,815 patternBitmap = void 0,816 x = void 0,817 y = void 0,818 patternRow = void 0,819 regionRow = void 0;820 for (mg = 0; mg < gridHeight; mg++) {821 for (ng = 0; ng < gridWidth; ng++) {822 bit = 0;823 patternIndex = 0;824 for (j = bitsPerValue - 1; j >= 0; j--) {825 bit = grayScaleBitPlanes[j][mg][ng] ^ bit;826 patternIndex |= bit << j;827 }828 patternBitmap = patterns[patternIndex];829 x = gridOffsetX + mg * gridVectorY + ng * gridVectorX >> 8;830 y = gridOffsetY + mg * gridVectorX - ng * gridVectorY >> 8;831 if (x >= 0 && x + patternWidth <= regionWidth && y >= 0 && y + patternHeight <= regionHeight) {832 for (i = 0; i < patternHeight; i++) {833 regionRow = regionBitmap[y + i];834 patternRow = patternBitmap[i];835 for (j = 0; j < patternWidth; j++) {836 regionRow[x + j] |= patternRow[j];837 }838 }839 } else {840 var regionX = void 0,841 regionY = void 0;842 for (i = 0; i < patternHeight; i++) {843 regionY = y + i;844 if (regionY < 0 || regionY >= regionHeight) {845 continue;846 }847 regionRow = regionBitmap[regionY];848 patternRow = patternBitmap[i];849 for (j = 0; j < patternWidth; j++) {850 regionX = x + j;851 if (regionX >= 0 && regionX < regionWidth) {852 regionRow[regionX] |= patternRow[j];853 }854 }855 }856 }857 }858 }859 return regionBitmap;860 }861 function readSegmentHeader(data, start) {862 var segmentHeader = {};863 segmentHeader.number = (0, _util.readUint32)(data, start);864 var flags = data[start + 4];865 var segmentType = flags & 0x3F;866 if (!SegmentTypes[segmentType]) {867 throw new Jbig2Error('invalid segment type: ' + segmentType);868 }869 segmentHeader.type = segmentType;870 segmentHeader.typeName = SegmentTypes[segmentType];871 segmentHeader.deferredNonRetain = !!(flags & 0x80);872 var pageAssociationFieldSize = !!(flags & 0x40);873 var referredFlags = data[start + 5];874 var referredToCount = referredFlags >> 5 & 7;875 var retainBits = [referredFlags & 31];876 var position = start + 6;877 if (referredFlags === 7) {878 referredToCount = (0, _util.readUint32)(data, position - 1) & 0x1FFFFFFF;879 position += 3;880 var bytes = referredToCount + 7 >> 3;881 retainBits[0] = data[position++];882 while (--bytes > 0) {883 retainBits.push(data[position++]);884 }885 } else if (referredFlags === 5 || referredFlags === 6) {886 throw new Jbig2Error('invalid referred-to flags');887 }888 segmentHeader.retainBits = retainBits;889 var referredToSegmentNumberSize = segmentHeader.number <= 256 ? 1 : segmentHeader.number <= 65536 ? 2 : 4;890 var referredTo = [];891 var i, ii;892 for (i = 0; i < referredToCount; i++) {893 var number = referredToSegmentNumberSize === 1 ? data[position] : referredToSegmentNumberSize === 2 ? (0, _util.readUint16)(data, position) : (0, _util.readUint32)(data, position);894 referredTo.push(number);895 position += referredToSegmentNumberSize;896 }897 segmentHeader.referredTo = referredTo;898 if (!pageAssociationFieldSize) {899 segmentHeader.pageAssociation = data[position++];900 } else {901 segmentHeader.pageAssociation = (0, _util.readUint32)(data, position);902 position += 4;903 }904 segmentHeader.length = (0, _util.readUint32)(data, position);905 position += 4;906 if (segmentHeader.length === 0xFFFFFFFF) {907 if (segmentType === 38) {908 var genericRegionInfo = readRegionSegmentInformation(data, position);909 var genericRegionSegmentFlags = data[position + RegionSegmentInformationFieldLength];910 var genericRegionMmr = !!(genericRegionSegmentFlags & 1);911 var searchPatternLength = 6;912 var searchPattern = new Uint8Array(searchPatternLength);913 if (!genericRegionMmr) {914 searchPattern[0] = 0xFF;915 searchPattern[1] = 0xAC;916 }917 searchPattern[2] = genericRegionInfo.height >>> 24 & 0xFF;918 searchPattern[3] = genericRegionInfo.height >> 16 & 0xFF;919 searchPattern[4] = genericRegionInfo.height >> 8 & 0xFF;920 searchPattern[5] = genericRegionInfo.height & 0xFF;921 for (i = position, ii = data.length; i < ii; i++) {922 var j = 0;923 while (j < searchPatternLength && searchPattern[j] === data[i + j]) {924 j++;925 }926 if (j === searchPatternLength) {927 segmentHeader.length = i + searchPatternLength;928 break;929 }930 }931 if (segmentHeader.length === 0xFFFFFFFF) {932 throw new Jbig2Error('segment end was not found');933 }934 } else {935 throw new Jbig2Error('invalid unknown segment length');936 }937 }938 segmentHeader.headerEnd = position;939 return segmentHeader;940 }941 function readSegments(header, data, start, end) {942 var segments = [];943 var position = start;944 while (position < end) {945 var segmentHeader = readSegmentHeader(data, position);946 position = segmentHeader.headerEnd;947 var segment = {948 header: segmentHeader,949 data: data950 };951 if (!header.randomAccess) {952 segment.start = position;953 position += segmentHeader.length;954 segment.end = position;955 }956 segments.push(segment);957 if (segmentHeader.type === 51) {958 break;959 }960 }961 if (header.randomAccess) {962 for (var i = 0, ii = segments.length; i < ii; i++) {963 segments[i].start = position;964 position += segments[i].header.length;965 segments[i].end = position;966 }967 }968 return segments;969 }970 function readRegionSegmentInformation(data, start) {971 return {972 width: (0, _util.readUint32)(data, start),973 height: (0, _util.readUint32)(data, start + 4),974 x: (0, _util.readUint32)(data, start + 8),975 y: (0, _util.readUint32)(data, start + 12),976 combinationOperator: data[start + 16] & 7977 };978 }979 var RegionSegmentInformationFieldLength = 17;980 function processSegment(segment, visitor) {981 var header = segment.header;982 var data = segment.data,983 position = segment.start,984 end = segment.end;985 var args, at, i, atLength;986 switch (header.type) {987 case 0:988 var dictionary = {};989 var dictionaryFlags = (0, _util.readUint16)(data, position);990 dictionary.huffman = !!(dictionaryFlags & 1);991 dictionary.refinement = !!(dictionaryFlags & 2);992 dictionary.huffmanDHSelector = dictionaryFlags >> 2 & 3;993 dictionary.huffmanDWSelector = dictionaryFlags >> 4 & 3;994 dictionary.bitmapSizeSelector = dictionaryFlags >> 6 & 1;995 dictionary.aggregationInstancesSelector = dictionaryFlags >> 7 & 1;996 dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);997 dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);998 dictionary.template = dictionaryFlags >> 10 & 3;999 dictionary.refinementTemplate = dictionaryFlags >> 12 & 1;1000 position += 2;1001 if (!dictionary.huffman) {1002 atLength = dictionary.template === 0 ? 4 : 1;1003 at = [];1004 for (i = 0; i < atLength; i++) {1005 at.push({1006 x: (0, _util.readInt8)(data, position),1007 y: (0, _util.readInt8)(data, position + 1)1008 });1009 position += 2;1010 }1011 dictionary.at = at;1012 }1013 if (dictionary.refinement && !dictionary.refinementTemplate) {1014 at = [];1015 for (i = 0; i < 2; i++) {1016 at.push({1017 x: (0, _util.readInt8)(data, position),1018 y: (0, _util.readInt8)(data, position + 1)1019 });1020 position += 2;1021 }1022 dictionary.refinementAt = at;1023 }1024 dictionary.numberOfExportedSymbols = (0, _util.readUint32)(data, position);1025 position += 4;1026 dictionary.numberOfNewSymbols = (0, _util.readUint32)(data, position);1027 position += 4;1028 args = [dictionary, header.number, header.referredTo, data, position, end];1029 break;1030 case 6:1031 case 7:1032 var textRegion = {};1033 textRegion.info = readRegionSegmentInformation(data, position);1034 position += RegionSegmentInformationFieldLength;1035 var textRegionSegmentFlags = (0, _util.readUint16)(data, position);1036 position += 2;1037 textRegion.huffman = !!(textRegionSegmentFlags & 1);1038 textRegion.refinement = !!(textRegionSegmentFlags & 2);1039 textRegion.logStripSize = textRegionSegmentFlags >> 2 & 3;1040 textRegion.stripSize = 1 << textRegion.logStripSize;1041 textRegion.referenceCorner = textRegionSegmentFlags >> 4 & 3;1042 textRegion.transposed = !!(textRegionSegmentFlags & 64);1043 textRegion.combinationOperator = textRegionSegmentFlags >> 7 & 3;1044 textRegion.defaultPixelValue = textRegionSegmentFlags >> 9 & 1;1045 textRegion.dsOffset = textRegionSegmentFlags << 17 >> 27;1046 textRegion.refinementTemplate = textRegionSegmentFlags >> 15 & 1;1047 if (textRegion.huffman) {1048 var textRegionHuffmanFlags = (0, _util.readUint16)(data, position);1049 position += 2;1050 textRegion.huffmanFS = textRegionHuffmanFlags & 3;1051 textRegion.huffmanDS = textRegionHuffmanFlags >> 2 & 3;1052 textRegion.huffmanDT = textRegionHuffmanFlags >> 4 & 3;1053 textRegion.huffmanRefinementDW = textRegionHuffmanFlags >> 6 & 3;1054 textRegion.huffmanRefinementDH = textRegionHuffmanFlags >> 8 & 3;1055 textRegion.huffmanRefinementDX = textRegionHuffmanFlags >> 10 & 3;1056 textRegion.huffmanRefinementDY = textRegionHuffmanFlags >> 12 & 3;1057 textRegion.huffmanRefinementSizeSelector = !!(textRegionHuffmanFlags & 0x4000);1058 }1059 if (textRegion.refinement && !textRegion.refinementTemplate) {1060 at = [];1061 for (i = 0; i < 2; i++) {1062 at.push({1063 x: (0, _util.readInt8)(data, position),1064 y: (0, _util.readInt8)(data, position + 1)1065 });1066 position += 2;1067 }1068 textRegion.refinementAt = at;1069 }1070 textRegion.numberOfSymbolInstances = (0, _util.readUint32)(data, position);1071 position += 4;1072 args = [textRegion, header.referredTo, data, position, end];1073 break;1074 case 16:1075 var patternDictionary = {};1076 var patternDictionaryFlags = data[position++];1077 patternDictionary.mmr = !!(patternDictionaryFlags & 1);1078 patternDictionary.template = patternDictionaryFlags >> 1 & 3;1079 patternDictionary.patternWidth = data[position++];1080 patternDictionary.patternHeight = data[position++];1081 patternDictionary.maxPatternIndex = (0, _util.readUint32)(data, position);1082 position += 4;1083 args = [patternDictionary, header.number, data, position, end];1084 break;1085 case 22:1086 case 23:1087 var halftoneRegion = {};1088 halftoneRegion.info = readRegionSegmentInformation(data, position);1089 position += RegionSegmentInformationFieldLength;1090 var halftoneRegionFlags = data[position++];1091 halftoneRegion.mmr = !!(halftoneRegionFlags & 1);1092 halftoneRegion.template = halftoneRegionFlags >> 1 & 3;1093 halftoneRegion.enableSkip = !!(halftoneRegionFlags & 8);1094 halftoneRegion.combinationOperator = halftoneRegionFlags >> 4 & 7;1095 halftoneRegion.defaultPixelValue = halftoneRegionFlags >> 7 & 1;1096 halftoneRegion.gridWidth = (0, _util.readUint32)(data, position);1097 position += 4;1098 halftoneRegion.gridHeight = (0, _util.readUint32)(data, position);1099 position += 4;1100 halftoneRegion.gridOffsetX = (0, _util.readUint32)(data, position) & 0xFFFFFFFF;1101 position += 4;1102 halftoneRegion.gridOffsetY = (0, _util.readUint32)(data, position) & 0xFFFFFFFF;1103 position += 4;1104 halftoneRegion.gridVectorX = (0, _util.readUint16)(data, position);1105 position += 2;1106 halftoneRegion.gridVectorY = (0, _util.readUint16)(data, position);1107 position += 2;1108 args = [halftoneRegion, header.referredTo, data, position, end];1109 break;1110 case 38:1111 case 39:1112 var genericRegion = {};1113 genericRegion.info = readRegionSegmentInformation(data, position);1114 position += RegionSegmentInformationFieldLength;1115 var genericRegionSegmentFlags = data[position++];1116 genericRegion.mmr = !!(genericRegionSegmentFlags & 1);1117 genericRegion.template = genericRegionSegmentFlags >> 1 & 3;1118 genericRegion.prediction = !!(genericRegionSegmentFlags & 8);1119 if (!genericRegion.mmr) {1120 atLength = genericRegion.template === 0 ? 4 : 1;1121 at = [];1122 for (i = 0; i < atLength; i++) {1123 at.push({1124 x: (0, _util.readInt8)(data, position),1125 y: (0, _util.readInt8)(data, position + 1)1126 });1127 position += 2;1128 }1129 genericRegion.at = at;1130 }1131 args = [genericRegion, data, position, end];1132 break;1133 case 48:1134 var pageInfo = {1135 width: (0, _util.readUint32)(data, position),1136 height: (0, _util.readUint32)(data, position + 4),1137 resolutionX: (0, _util.readUint32)(data, position + 8),1138 resolutionY: (0, _util.readUint32)(data, position + 12)1139 };1140 if (pageInfo.height === 0xFFFFFFFF) {1141 delete pageInfo.height;1142 }1143 var pageSegmentFlags = data[position + 16];1144 (0, _util.readUint16)(data, position + 17);1145 pageInfo.lossless = !!(pageSegmentFlags & 1);1146 pageInfo.refinement = !!(pageSegmentFlags & 2);1147 pageInfo.defaultPixelValue = pageSegmentFlags >> 2 & 1;1148 pageInfo.combinationOperator = pageSegmentFlags >> 3 & 3;1149 pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);1150 pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);1151 args = [pageInfo];1152 break;1153 case 49:1154 break;1155 case 50:1156 break;1157 case 51:1158 break;1159 case 53:1160 args = [header.number, data, position, end];1161 break;1162 case 62:1163 break;1164 default:1165 throw new Jbig2Error('segment type ' + header.typeName + '(' + header.type + ')' + ' is not implemented');1166 }1167 var callbackName = 'on' + header.typeName;1168 if (callbackName in visitor) {1169 visitor[callbackName].apply(visitor, args);1170 }1171 }1172 function processSegments(segments, visitor) {1173 for (var i = 0, ii = segments.length; i < ii; i++) {1174 processSegment(segments[i], visitor);1175 }1176 }1177 function parseJbig2Chunks(chunks) {1178 var visitor = new SimpleSegmentVisitor();1179 for (var i = 0, ii = chunks.length; i < ii; i++) {1180 var chunk = chunks[i];1181 var segments = readSegments({}, chunk.data, chunk.start, chunk.end);1182 processSegments(segments, visitor);1183 }1184 return visitor.buffer;1185 }1186 function SimpleSegmentVisitor() {}1187 SimpleSegmentVisitor.prototype = {1188 onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {1189 this.currentPageInfo = info;1190 var rowSize = info.width + 7 >> 3;1191 var buffer = new Uint8ClampedArray(rowSize * info.height);1192 if (info.defaultPixelValue) {1193 for (var i = 0, ii = buffer.length; i < ii; i++) {1194 buffer[i] = 0xFF;1195 }1196 }1197 this.buffer = buffer;1198 },1199 drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {1200 var pageInfo = this.currentPageInfo;1201 var width = regionInfo.width,1202 height = regionInfo.height;1203 var rowSize = pageInfo.width + 7 >> 3;1204 var combinationOperator = pageInfo.combinationOperatorOverride ? regionInfo.combinationOperator : pageInfo.combinationOperator;1205 var buffer = this.buffer;1206 var mask0 = 128 >> (regionInfo.x & 7);1207 var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);1208 var i, j, mask, offset;1209 switch (combinationOperator) {1210 case 0:1211 for (i = 0; i < height; i++) {1212 mask = mask0;1213 offset = offset0;1214 for (j = 0; j < width; j++) {1215 if (bitmap[i][j]) {1216 buffer[offset] |= mask;1217 }1218 mask >>= 1;1219 if (!mask) {1220 mask = 128;1221 offset++;1222 }1223 }1224 offset0 += rowSize;1225 }1226 break;1227 case 2:1228 for (i = 0; i < height; i++) {1229 mask = mask0;1230 offset = offset0;1231 for (j = 0; j < width; j++) {1232 if (bitmap[i][j]) {1233 buffer[offset] ^= mask;1234 }1235 mask >>= 1;1236 if (!mask) {1237 mask = 128;1238 offset++;1239 }1240 }1241 offset0 += rowSize;1242 }1243 break;1244 default:1245 throw new Jbig2Error('operator ' + combinationOperator + ' is not supported');1246 }1247 },1248 onImmediateGenericRegion: function SimpleSegmentVisitor_onImmediateGenericRegion(region, data, start, end) {1249 var regionInfo = region.info;1250 var decodingContext = new DecodingContext(data, start, end);1251 var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height, region.template, region.prediction, null, region.at, decodingContext);1252 this.drawBitmap(regionInfo, bitmap);1253 },1254 onImmediateLosslessGenericRegion: function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {1255 this.onImmediateGenericRegion.apply(this, arguments);1256 },1257 onSymbolDictionary: function SimpleSegmentVisitor_onSymbolDictionary(dictionary, currentSegment, referredSegments, data, start, end) {1258 var huffmanTables = void 0,1259 huffmanInput = void 0;1260 if (dictionary.huffman) {1261 huffmanTables = getSymbolDictionaryHuffmanTables(dictionary, referredSegments, this.customTables);1262 huffmanInput = new Reader(data, start, end);1263 }1264 var symbols = this.symbols;1265 if (!symbols) {1266 this.symbols = symbols = {};1267 }1268 var inputSymbols = [];1269 for (var i = 0, ii = referredSegments.length; i < ii; i++) {1270 var referredSymbols = symbols[referredSegments[i]];1271 if (referredSymbols) {1272 inputSymbols = inputSymbols.concat(referredSymbols);1273 }1274 }1275 var decodingContext = new DecodingContext(data, start, end);1276 symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman, dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols, dictionary.numberOfExportedSymbols, huffmanTables, dictionary.template, dictionary.at, dictionary.refinementTemplate, dictionary.refinementAt, decodingContext, huffmanInput);1277 },1278 onImmediateTextRegion: function SimpleSegmentVisitor_onImmediateTextRegion(region, referredSegments, data, start, end) {1279 var regionInfo = region.info;1280 var huffmanTables = void 0,1281 huffmanInput = void 0;1282 var symbols = this.symbols;1283 var inputSymbols = [];1284 for (var i = 0, ii = referredSegments.length; i < ii; i++) {1285 var referredSymbols = symbols[referredSegments[i]];1286 if (referredSymbols) {1287 inputSymbols = inputSymbols.concat(referredSymbols);1288 }1289 }1290 var symbolCodeLength = (0, _util.log2)(inputSymbols.length);1291 if (region.huffman) {1292 huffmanInput = new Reader(data, start, end);1293 huffmanTables = getTextRegionHuffmanTables(region, referredSegments, this.customTables, inputSymbols.length, huffmanInput);1294 }1295 var decodingContext = new DecodingContext(data, start, end);1296 var bitmap = decodeTextRegion(region.huffman, region.refinement, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.numberOfSymbolInstances, region.stripSize, inputSymbols, symbolCodeLength, region.transposed, region.dsOffset, region.referenceCorner, region.combinationOperator, huffmanTables, region.refinementTemplate, region.refinementAt, decodingContext, region.logStripSize, huffmanInput);1297 this.drawBitmap(regionInfo, bitmap);1298 },1299 onImmediateLosslessTextRegion: function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {1300 this.onImmediateTextRegion.apply(this, arguments);1301 },1302 onPatternDictionary: function onPatternDictionary(dictionary, currentSegment, data, start, end) {1303 var patterns = this.patterns;1304 if (!patterns) {1305 this.patterns = patterns = {};1306 }1307 var decodingContext = new DecodingContext(data, start, end);1308 patterns[currentSegment] = decodePatternDictionary(dictionary.mmr, dictionary.patternWidth, dictionary.patternHeight, dictionary.maxPatternIndex, dictionary.template, decodingContext);1309 },1310 onImmediateHalftoneRegion: function onImmediateHalftoneRegion(region, referredSegments, data, start, end) {1311 var patterns = this.patterns[referredSegments[0]];1312 var regionInfo = region.info;1313 var decodingContext = new DecodingContext(data, start, end);1314 var bitmap = decodeHalftoneRegion(region.mmr, patterns, region.template, regionInfo.width, regionInfo.height, region.defaultPixelValue, region.enableSkip, region.combinationOperator, region.gridWidth, region.gridHeight, region.gridOffsetX, region.gridOffsetY, region.gridVectorX, region.gridVectorY, decodingContext);1315 this.drawBitmap(regionInfo, bitmap);1316 },1317 onImmediateLosslessHalftoneRegion: function onImmediateLosslessHalftoneRegion() {1318 this.onImmediateHalftoneRegion.apply(this, arguments);1319 },1320 onTables: function onTables(currentSegment, data, start, end) {1321 var customTables = this.customTables;1322 if (!customTables) {1323 this.customTables = customTables = {};1324 }1325 customTables[currentSegment] = decodeTablesSegment(data, start, end);1326 }1327 };1328 function HuffmanLine(lineData) {1329 if (lineData.length === 2) {1330 this.isOOB = true;1331 this.rangeLow = 0;1332 this.prefixLength = lineData[0];1333 this.rangeLength = 0;1334 this.prefixCode = lineData[1];1335 this.isLowerRange = false;1336 } else {1337 this.isOOB = false;1338 this.rangeLow = lineData[0];1339 this.prefixLength = lineData[1];1340 this.rangeLength = lineData[2];1341 this.prefixCode = lineData[3];1342 this.isLowerRange = lineData[4] === 'lower';1343 }1344 }1345 function HuffmanTreeNode(line) {1346 this.children = [];1347 if (line) {1348 this.isLeaf = true;1349 this.rangeLength = line.rangeLength;1350 this.rangeLow = line.rangeLow;1351 this.isLowerRange = line.isLowerRange;1352 this.isOOB = line.isOOB;1353 } else {1354 this.isLeaf = false;1355 }1356 }1357 HuffmanTreeNode.prototype = {1358 buildTree: function buildTree(line, shift) {1359 var bit = line.prefixCode >> shift & 1;1360 if (shift <= 0) {1361 this.children[bit] = new HuffmanTreeNode(line);1362 } else {1363 var node = this.children[bit];1364 if (!node) {1365 this.children[bit] = node = new HuffmanTreeNode(null);1366 }1367 node.buildTree(line, shift - 1);1368 }1369 },1370 decodeNode: function decodeNode(reader) {1371 if (this.isLeaf) {1372 if (this.isOOB) {1373 return null;1374 }1375 var htOffset = reader.readBits(this.rangeLength);1376 return this.rangeLow + (this.isLowerRange ? -htOffset : htOffset);1377 }1378 var node = this.children[reader.readBit()];1379 if (!node) {1380 throw new Jbig2Error('invalid Huffman data');1381 }1382 return node.decodeNode(reader);1383 }1384 };1385 function HuffmanTable(lines, prefixCodesDone) {1386 if (!prefixCodesDone) {1387 this.assignPrefixCodes(lines);1388 }1389 this.rootNode = new HuffmanTreeNode(null);1390 var i = void 0,1391 ii = lines.length,1392 line = void 0;1393 for (i = 0; i < ii; i++) {1394 line = lines[i];1395 if (line.prefixLength > 0) {1396 this.rootNode.buildTree(line, line.prefixLength - 1);1397 }1398 }1399 }1400 HuffmanTable.prototype = {1401 decode: function decode(reader) {1402 return this.rootNode.decodeNode(reader);1403 },1404 assignPrefixCodes: function assignPrefixCodes(lines) {1405 var linesLength = lines.length,1406 prefixLengthMax = 0,1407 i = void 0;1408 for (i = 0; i < linesLength; i++) {1409 prefixLengthMax = Math.max(prefixLengthMax, lines[i].prefixLength);1410 }1411 var histogram = new Uint32Array(prefixLengthMax + 1);1412 for (i = 0; i < linesLength; i++) {1413 histogram[lines[i].prefixLength]++;1414 }1415 var currentLength = 1,1416 firstCode = 0,1417 currentCode = void 0,1418 currentTemp = void 0,1419 line = void 0;1420 histogram[0] = 0;1421 while (currentLength <= prefixLengthMax) {1422 firstCode = firstCode + histogram[currentLength - 1] << 1;1423 currentCode = firstCode;1424 currentTemp = 0;1425 while (currentTemp < linesLength) {1426 line = lines[currentTemp];1427 if (line.prefixLength === currentLength) {1428 line.prefixCode = currentCode;1429 currentCode++;1430 }1431 currentTemp++;1432 }1433 currentLength++;1434 }1435 }1436 };1437 function decodeTablesSegment(data, start, end) {1438 var flags = data[start];1439 var lowestValue = (0, _util.readUint32)(data, start + 1) & 0xFFFFFFFF;1440 var highestValue = (0, _util.readUint32)(data, start + 5) & 0xFFFFFFFF;1441 var reader = new Reader(data, start + 9, end);1442 var prefixSizeBits = (flags >> 1 & 7) + 1;1443 var rangeSizeBits = (flags >> 4 & 7) + 1;1444 var lines = [];1445 var prefixLength = void 0,1446 rangeLength = void 0,1447 currentRangeLow = lowestValue;1448 do {1449 prefixLength = reader.readBits(prefixSizeBits);1450 rangeLength = reader.readBits(rangeSizeBits);1451 lines.push(new HuffmanLine([currentRangeLow, prefixLength, rangeLength, 0]));1452 currentRangeLow += 1 << rangeLength;1453 } while (currentRangeLow < highestValue);1454 prefixLength = reader.readBits(prefixSizeBits);1455 lines.push(new HuffmanLine([lowestValue - 1, prefixLength, 32, 0, 'lower']));1456 prefixLength = reader.readBits(prefixSizeBits);1457 lines.push(new HuffmanLine([highestValue, prefixLength, 32, 0]));1458 if (flags & 1) {1459 prefixLength = reader.readBits(prefixSizeBits);1460 lines.push(new HuffmanLine([prefixLength, 0]));1461 }1462 return new HuffmanTable(lines, false);1463 }1464 var standardTablesCache = {};1465 function getStandardTable(number) {1466 var table = standardTablesCache[number];1467 if (table) {1468 return table;1469 }1470 var lines = void 0;1471 switch (number) {1472 case 1:1473 lines = [[0, 1, 4, 0x0], [16, 2, 8, 0x2], [272, 3, 16, 0x6], [65808, 3, 32, 0x7]];1474 break;1475 case 2:1476 lines = [[0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xE], [11, 5, 6, 0x1E], [75, 6, 32, 0x3E], [6, 0x3F]];1477 break;1478 case 3:1479 lines = [[-256, 8, 8, 0xFE], [0, 1, 0, 0x0], [1, 2, 0, 0x2], [2, 3, 0, 0x6], [3, 4, 3, 0xE], [11, 5, 6, 0x1E], [-257, 8, 32, 0xFF, 'lower'], [75, 7, 32, 0x7E], [6, 0x3E]];1480 break;1481 case 4:1482 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xE], [12, 5, 6, 0x1E], [76, 5, 32, 0x1F]];1483 break;1484 case 5:1485 lines = [[-255, 7, 8, 0x7E], [1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 0, 0x6], [4, 4, 3, 0xE], [12, 5, 6, 0x1E], [-256, 7, 32, 0x7F, 'lower'], [76, 6, 32, 0x3E]];1486 break;1487 case 6:1488 lines = [[-2048, 5, 10, 0x1C], [-1024, 4, 9, 0x8], [-512, 4, 8, 0x9], [-256, 4, 7, 0xA], [-128, 5, 6, 0x1D], [-64, 5, 5, 0x1E], [-32, 4, 5, 0xB], [0, 2, 7, 0x0], [128, 3, 7, 0x2], [256, 3, 8, 0x3], [512, 4, 9, 0xC], [1024, 4, 10, 0xD], [-2049, 6, 32, 0x3E, 'lower'], [2048, 6, 32, 0x3F]];1489 break;1490 case 7:1491 lines = [[-1024, 4, 9, 0x8], [-512, 3, 8, 0x0], [-256, 4, 7, 0x9], [-128, 5, 6, 0x1A], [-64, 5, 5, 0x1B], [-32, 4, 5, 0xA], [0, 4, 5, 0xB], [32, 5, 5, 0x1C], [64, 5, 6, 0x1D], [128, 4, 7, 0xC], [256, 3, 8, 0x1], [512, 3, 9, 0x2], [1024, 3, 10, 0x3], [-1025, 5, 32, 0x1E, 'lower'], [2048, 5, 32, 0x1F]];1492 break;1493 case 8:1494 lines = [[-15, 8, 3, 0xFC], [-7, 9, 1, 0x1FC], [-5, 8, 1, 0xFD], [-3, 9, 0, 0x1FD], [-2, 7, 0, 0x7C], [-1, 4, 0, 0xA], [0, 2, 1, 0x0], [2, 5, 0, 0x1A], [3, 6, 0, 0x3A], [4, 3, 4, 0x4], [20, 6, 1, 0x3B], [22, 4, 4, 0xB], [38, 4, 5, 0xC], [70, 5, 6, 0x1B], [134, 5, 7, 0x1C], [262, 6, 7, 0x3C], [390, 7, 8, 0x7D], [646, 6, 10, 0x3D], [-16, 9, 32, 0x1FE, 'lower'], [1670, 9, 32, 0x1FF], [2, 0x1]];1495 break;1496 case 9:1497 lines = [[-31, 8, 4, 0xFC], [-15, 9, 2, 0x1FC], [-11, 8, 2, 0xFD], [-7, 9, 1, 0x1FD], [-5, 7, 1, 0x7C], [-3, 4, 1, 0xA], [-1, 3, 1, 0x2], [1, 3, 1, 0x3], [3, 5, 1, 0x1A], [5, 6, 1, 0x3A], [7, 3, 5, 0x4], [39, 6, 2, 0x3B], [43, 4, 5, 0xB], [75, 4, 6, 0xC], [139, 5, 7, 0x1B], [267, 5, 8, 0x1C], [523, 6, 8, 0x3C], [779, 7, 9, 0x7D], [1291, 6, 11, 0x3D], [-32, 9, 32, 0x1FE, 'lower'], [3339, 9, 32, 0x1FF], [2, 0x0]];1498 break;1499 case 10:1500 lines = [[-21, 7, 4, 0x7A], [-5, 8, 0, 0xFC], [-4, 7, 0, 0x7B], [-3, 5, 0, 0x18], [-2, 2, 2, 0x0], [2, 5, 0, 0x19], [3, 6, 0, 0x36], [4, 7, 0, 0x7C], [5, 8, 0, 0xFD], [6, 2, 6, 0x1], [70, 5, 5, 0x1A], [102, 6, 5, 0x37], [134, 6, 6, 0x38], [198, 6, 7, 0x39], [326, 6, 8, 0x3A], [582, 6, 9, 0x3B], [1094, 6, 10, 0x3C], [2118, 7, 11, 0x7D], [-22, 8, 32, 0xFE, 'lower'], [4166, 8, 32, 0xFF], [2, 0x2]];1501 break;1502 case 11:1503 lines = [[1, 1, 0, 0x0], [2, 2, 1, 0x2], [4, 4, 0, 0xC], [5, 4, 1, 0xD], [7, 5, 1, 0x1C], [9, 5, 2, 0x1D], [13, 6, 2, 0x3C], [17, 7, 2, 0x7A], [21, 7, 3, 0x7B], [29, 7, 4, 0x7C], [45, 7, 5, 0x7D], [77, 7, 6, 0x7E], [141, 7, 32, 0x7F]];1504 break;1505 case 12:1506 lines = [[1, 1, 0, 0x0], [2, 2, 0, 0x2], [3, 3, 1, 0x6], [5, 5, 0, 0x1C], [6, 5, 1, 0x1D], [8, 6, 1, 0x3C], [10, 7, 0, 0x7A], [11, 7, 1, 0x7B], [13, 7, 2, 0x7C], [17, 7, 3, 0x7D], [25, 7, 4, 0x7E], [41, 8, 5, 0xFE], [73, 8, 32, 0xFF]];1507 break;1508 case 13:1509 lines = [[1, 1, 0, 0x0], [2, 3, 0, 0x4], [3, 4, 0, 0xC], [4, 5, 0, 0x1C], [5, 4, 1, 0xD], [7, 3, 3, 0x5], [15, 6, 1, 0x3A], [17, 6, 2, 0x3B], [21, 6, 3, 0x3C], [29, 6, 4, 0x3D], [45, 6, 5, 0x3E], [77, 7, 6, 0x7E], [141, 7, 32, 0x7F]];1510 break;1511 case 14:1512 lines = [[-2, 3, 0, 0x4], [-1, 3, 0, 0x5], [0, 1, 0, 0x0], [1, 3, 0, 0x6], [2, 3, 0, 0x7]];1513 break;1514 case 15:1515 lines = [[-24, 7, 4, 0x7C], [-8, 6, 2, 0x3C], [-4, 5, 1, 0x1C], [-2, 4, 0, 0xC], [-1, 3, 0, 0x4], [0, 1, 0, 0x0], [1, 3, 0, 0x5], [2, 4, 0, 0xD], [3, 5, 1, 0x1D], [5, 6, 2, 0x3D], [9, 7, 4, 0x7D], [-25, 7, 32, 0x7E, 'lower'], [25, 7, 32, 0x7F]];1516 break;1517 default:1518 throw new Jbig2Error('standard table B.' + number + ' does not exist');1519 }1520 var length = lines.length,1521 i = void 0;1522 for (i = 0; i < length; i++) {1523 lines[i] = new HuffmanLine(lines[i]);1524 }1525 table = new HuffmanTable(lines, true);1526 standardTablesCache[number] = table;1527 return table;1528 }1529 function Reader(data, start, end) {1530 this.data = data;1531 this.start = start;1532 this.end = end;1533 this.position = start;1534 this.shift = -1;1535 this.currentByte = 0;1536 }1537 Reader.prototype = {1538 readBit: function readBit() {1539 if (this.shift < 0) {1540 if (this.position >= this.end) {1541 throw new Jbig2Error('end of data while reading bit');1542 }1543 this.currentByte = this.data[this.position++];1544 this.shift = 7;1545 }1546 var bit = this.currentByte >> this.shift & 1;1547 this.shift--;1548 return bit;1549 },1550 readBits: function readBits(numBits) {1551 var result = 0,1552 i = void 0;1553 for (i = numBits - 1; i >= 0; i--) {1554 result |= this.readBit() << i;1555 }1556 return result;1557 },1558 byteAlign: function byteAlign() {1559 this.shift = -1;1560 },1561 next: function next() {1562 if (this.position >= this.end) {1563 return -1;1564 }1565 return this.data[this.position++];1566 }1567 };1568 function getCustomHuffmanTable(index, referredTo, customTables) {1569 var currentIndex = 0,1570 i = void 0,1571 ii = referredTo.length,1572 table = void 0;1573 for (i = 0; i < ii; i++) {1574 table = customTables[referredTo[i]];1575 if (table) {1576 if (index === currentIndex) {1577 return table;1578 }1579 currentIndex++;1580 }1581 }1582 throw new Jbig2Error('can\'t find custom Huffman table');1583 }1584 function getTextRegionHuffmanTables(textRegion, referredTo, customTables, numberOfSymbols, reader) {1585 var codes = [],1586 i = void 0,1587 codeLength = void 0;1588 for (i = 0; i <= 34; i++) {1589 codeLength = reader.readBits(4);1590 codes.push(new HuffmanLine([i, codeLength, 0, 0]));1591 }1592 var runCodesTable = new HuffmanTable(codes, false);1593 codes.length = 0;1594 for (i = 0; i < numberOfSymbols;) {1595 codeLength = runCodesTable.decode(reader);1596 if (codeLength >= 32) {1597 var repeatedLength = void 0,1598 numberOfRepeats = void 0,1599 j = void 0;1600 switch (codeLength) {1601 case 32:1602 if (i === 0) {1603 throw new Jbig2Error('no previous value in symbol ID table');1604 }1605 numberOfRepeats = reader.readBits(2) + 3;1606 repeatedLength = codes[i - 1].prefixLength;1607 break;1608 case 33:1609 numberOfRepeats = reader.readBits(3) + 3;1610 repeatedLength = 0;1611 break;1612 case 34:1613 numberOfRepeats = reader.readBits(7) + 11;1614 repeatedLength = 0;1615 break;1616 default:1617 throw new Jbig2Error('invalid code length in symbol ID table');1618 }1619 for (j = 0; j < numberOfRepeats; j++) {1620 codes.push(new HuffmanLine([i, repeatedLength, 0, 0]));1621 i++;1622 }1623 } else {1624 codes.push(new HuffmanLine([i, codeLength, 0, 0]));1625 i++;1626 }1627 }1628 reader.byteAlign();1629 var symbolIDTable = new HuffmanTable(codes, false);1630 var customIndex = 0,1631 tableFirstS = void 0,1632 tableDeltaS = void 0,1633 tableDeltaT = void 0;1634 switch (textRegion.huffmanFS) {1635 case 0:1636 case 1:1637 tableFirstS = getStandardTable(textRegion.huffmanFS + 6);1638 break;1639 case 3:1640 tableFirstS = getCustomHuffmanTable(customIndex, referredTo, customTables);1641 customIndex++;1642 break;1643 default:1644 throw new Jbig2Error('invalid Huffman FS selector');1645 }1646 switch (textRegion.huffmanDS) {1647 case 0:1648 case 1:1649 case 2:1650 tableDeltaS = getStandardTable(textRegion.huffmanDS + 8);1651 break;1652 case 3:1653 tableDeltaS = getCustomHuffmanTable(customIndex, referredTo, customTables);1654 customIndex++;1655 break;1656 default:1657 throw new Jbig2Error('invalid Huffman DS selector');1658 }1659 switch (textRegion.huffmanDT) {1660 case 0:1661 case 1:1662 case 2:1663 tableDeltaT = getStandardTable(textRegion.huffmanDT + 11);1664 break;1665 case 3:1666 tableDeltaT = getCustomHuffmanTable(customIndex, referredTo, customTables);1667 customIndex++;1668 break;1669 default:1670 throw new Jbig2Error('invalid Huffman DT selector');1671 }1672 if (textRegion.refinement) {1673 throw new Jbig2Error('refinement with Huffman is not supported');1674 }1675 return {1676 symbolIDTable: symbolIDTable,1677 tableFirstS: tableFirstS,1678 tableDeltaS: tableDeltaS,1679 tableDeltaT: tableDeltaT1680 };1681 }1682 function getSymbolDictionaryHuffmanTables(dictionary, referredTo, customTables) {1683 var customIndex = 0,1684 tableDeltaHeight = void 0,1685 tableDeltaWidth = void 0;1686 switch (dictionary.huffmanDHSelector) {1687 case 0:1688 case 1:1689 tableDeltaHeight = getStandardTable(dictionary.huffmanDHSelector + 4);1690 break;1691 case 3:1692 tableDeltaHeight = getCustomHuffmanTable(customIndex, referredTo, customTables);1693 customIndex++;1694 break;1695 default:1696 throw new Jbig2Error('invalid Huffman DH selector');1697 }1698 switch (dictionary.huffmanDWSelector) {1699 case 0:1700 case 1:1701 tableDeltaWidth = getStandardTable(dictionary.huffmanDWSelector + 2);1702 break;1703 case 3:1704 tableDeltaWidth = getCustomHuffmanTable(customIndex, referredTo, customTables);1705 customIndex++;1706 break;1707 default:1708 throw new Jbig2Error('invalid Huffman DW selector');1709 }1710 var tableBitmapSize = void 0,1711 tableAggregateInstances = void 0;1712 if (dictionary.bitmapSizeSelector) {1713 tableBitmapSize = getCustomHuffmanTable(customIndex, referredTo, customTables);1714 customIndex++;1715 } else {1716 tableBitmapSize = getStandardTable(1);1717 }1718 if (dictionary.aggregationInstancesSelector) {1719 tableAggregateInstances = getCustomHuffmanTable(customIndex, referredTo, customTables);1720 } else {1721 tableAggregateInstances = getStandardTable(1);1722 }1723 return {1724 tableDeltaHeight: tableDeltaHeight,1725 tableDeltaWidth: tableDeltaWidth,1726 tableBitmapSize: tableBitmapSize,1727 tableAggregateInstances: tableAggregateInstances1728 };1729 }1730 function readUncompressedBitmap(reader, width, height) {1731 var bitmap = [],1732 x = void 0,1733 y = void 0,1734 row = void 0;1735 for (y = 0; y < height; y++) {...

Full Screen

Full Screen

dataStandard.js

Source:dataStandard.js Github

copy

Full Screen

1/*2 * Tencent is pleased to support the open source community by making BK-BASE 蓝鲸基础平台 available.3 * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.4 * BK-BASE 蓝鲸基础平台 is licensed under the MIT License.5 *6 * License for BK-BASE 蓝鲸基础平台:7 * --------------------------------------------------------------------8 *9 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated10 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,12 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:13 * The above copyright notice and this permission notice shall be included in all copies or substantial14 * portions of the Software.15 *16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT17 * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN18 * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE20 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE21 */22/** 获取标准化表格数据*/23const getStandardTable = {24 url: '/v3/datamanage/dstan/standard_publicity/standards/',25 method: 'POST',26};27/** 获取标准化数据详情28 * @params dm_standard_config_id29 */30const getStandardDetail = {31 url: '/v3/datamanage/dstan/standard_publicity/get_standard_info?online=true',32};33/** 获取存储类型34 */35const getStorageType = {36 url: '/datamart/datadict/dataset_list/storage_type/',37};38/*39 * 数据字典高级搜索数据标准级联选框接口40 */41const getStandardCascadeInfo = {42 url: 'v3/datamanage/dstan/standard_publicity/standards/simple/',43};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2wpt.getStandardTable('test', function (data) {3 console.log(data);4});5var wpt = require('wpt');6wpt.getStandardTable('test', function (data) {7 console.log(data);8});9var wpt = require('wpt');10wpt.getStandardTable('test', function (data) {11 console.log(data);12});13var wpt = require('wpt');14wpt.getStandardTable('test', function (data) {15 console.log(data);16});17var wpt = require('wpt');18wpt.getStandardTable('test', function (data) {19 console.log(data);20});21var wpt = require('wpt');22wpt.getStandardTable('test', function (data) {23 console.log(data);24});25var wpt = require('wpt');26wpt.getStandardTable('test', function (data) {27 console.log(data);28});29var wpt = require('wpt');30wpt.getStandardTable('test', function (data) {31 console.log(data);32});33var wpt = require('wpt');34wpt.getStandardTable('test', function (data) {35 console.log(data);36});37var wpt = require('wpt');38wpt.getStandardTable('test', function (data) {39 console.log(data);40});41var wpt = require('wpt');42wpt.getStandardTable('test', function (data) {43 console.log(data);

Full Screen

Using AI Code Generation

copy

Full Screen

1const wptools = require('wptools');2 console.log(table);3});4 {5 },6 {7 },8 {9 }10### `wptools.getStandardTable(url, title)`11MIT © [Sam Verschueren](

Full Screen

Using AI Code Generation

copy

Full Screen

1var table = getStandardTable();2table.addHeading("Heading 1", "Heading 2");3table.addRow("Value 1", "Value 2");4table.addRow("Value 3", "Value 4");5table.addRow("Value 5", "Value 6");6table.addRow("Value 7", "Value 8");7table.addRow("Value 9", "Value 10");8table.addRow("Value 11", "Value 12");9table.addRow("Value 13", "Value 14");10table.addRow("Value 15", "Value 16");11table.addRow("Value 17", "Value 18");12table.addRow("Value 19", "Value 20");13table.addRow("Value 21", "Value 22");14table.addRow("Value 23", "Value 24");15table.addRow("Value 25", "Value 26");16table.addRow("Value 27", "Value 28");17table.addRow("Value 29", "Value 30");18table.addRow("Value 31", "Value 32");19table.addRow("Value 33", "Value 34");20table.addRow("Value 35", "Value 36");21table.addRow("Value 37", "Value 38");22table.addRow("Value 39", "Value 40");23table.addRow("Value 41", "Value 42");24table.addRow("Value 43", "Value 44");25table.addRow("Value 45", "Value 46");26table.addRow("Value 47", "Value 48");27table.addRow("Value 49", "Value 50");28table.addRow("Value 51", "Value 52");29table.addRow("Value 53", "Value 54");30table.addRow("Value 55", "Value 56");31table.addRow("Value 57", "Value 58");32table.addRow("Value 59", "Value 60");33table.addRow("Value 61", "Value 62");34table.addRow("Value 63", "Value 64");35table.addRow("Value 65", "Value 66");36table.addRow("Value 67", "Value 68");37table.addRow("Value 69", "Value 70");38table.addRow("Value 71", "Value 72");39table.addRow("Value 73", "Value 74");40table.addRow("Value 75", "Value 76");41table.addRow("Value 77", "Value 78");42table.addRow("Value 79", "

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt.js');2 console.log('data: ', data);3});4 console.log('data: ', data);5});6 console.log('data: ', data);7});8 console.log('data: ', data);9});10 console.log('data: ', data);11});12 console.log('data: ', data);13});14 console.log('data: ', data);15});16 console.log('data: ', data);17});18 console.log('data: ', data);19});20 console.log('data: ', data);21});

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