Java Code Examples for com.google.android.exoplayer2.util.ParsableBitArray#readBit()
The following examples show how to use
com.google.android.exoplayer2.util.ParsableBitArray#readBit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LatmReader.java From MediaSDK with Apache License 2.0 | 6 votes |
/** * Parses an AudioMuxElement as defined in 14496-3:2009, Section 1.7.3.1, Table 1.41. * * @param data A {@link ParsableBitArray} containing the AudioMuxElement's bytes. */ private void parseAudioMuxElement(ParsableBitArray data) throws ParserException { boolean useSameStreamMux = data.readBit(); if (!useSameStreamMux) { streamMuxRead = true; parseStreamMuxConfig(data); } else if (!streamMuxRead) { return; // Parsing cannot continue without StreamMuxConfig information. } if (audioMuxVersionA == 0) { if (numSubframes != 0) { throw new ParserException(); } int muxSlotLengthBytes = parsePayloadLengthInfo(data); parsePayloadMux(data, muxSlotLengthBytes); if (otherDataPresent) { data.skipBits((int) otherDataLenBits); } } else { throw new ParserException(); // Not defined by ISO/IEC 14496-3:2009. } }
Example 2
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
/** * Parses an AudioMuxElement as defined in 14496-3:2009, Section 1.7.3.1, Table 1.41. * * @param data A {@link ParsableBitArray} containing the AudioMuxElement's bytes. */ private void parseAudioMuxElement(ParsableBitArray data) throws ParserException { boolean useSameStreamMux = data.readBit(); if (!useSameStreamMux) { streamMuxRead = true; parseStreamMuxConfig(data); } else if (!streamMuxRead) { return; // Parsing cannot continue without StreamMuxConfig information. } if (audioMuxVersionA == 0) { if (numSubframes != 0) { throw new ParserException(); } int muxSlotLengthBytes = parsePayloadLengthInfo(data); parsePayloadMux(data, muxSlotLengthBytes); if (otherDataPresent) { data.skipBits((int) otherDataLenBits); } } else { throw new ParserException(); // Not defined by ISO/IEC 14496-3:2009. } }
Example 3
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Parses a display definition segment, as defined by ETSI EN 300 743 7.2.1. */ private static DisplayDefinition parseDisplayDefinition(ParsableBitArray data) { data.skipBits(4); // dds_version_number (4). boolean displayWindowFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int horizontalPositionMinimum; int horizontalPositionMaximum; int verticalPositionMinimum; int verticalPositionMaximum; if (displayWindowFlag) { horizontalPositionMinimum = data.readBits(16); horizontalPositionMaximum = data.readBits(16); verticalPositionMinimum = data.readBits(16); verticalPositionMaximum = data.readBits(16); } else { horizontalPositionMinimum = 0; horizontalPositionMaximum = width; verticalPositionMinimum = 0; verticalPositionMaximum = height; } return new DisplayDefinition(width, height, horizontalPositionMinimum, horizontalPositionMaximum, verticalPositionMinimum, verticalPositionMaximum); }
Example 4
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Parses an object data segment, as defined by ETSI EN 300 743 7.2.5. * * @return The parsed object data. */ private static ObjectData parseObjectData(ParsableBitArray data) { int objectId = data.readBits(16); data.skipBits(4); // Skip object_version_number int objectCodingMethod = data.readBits(2); boolean nonModifyingColorFlag = data.readBit(); data.skipBits(1); // Skip reserved. byte[] topFieldData = null; byte[] bottomFieldData = null; if (objectCodingMethod == OBJECT_CODING_STRING) { int numberOfCodes = data.readBits(8); // TODO: Parse and use character_codes. data.skipBits(numberOfCodes * 16); // Skip character_codes. } else if (objectCodingMethod == OBJECT_CODING_PIXELS) { int topFieldDataLength = data.readBits(16); int bottomFieldDataLength = data.readBits(16); if (topFieldDataLength > 0) { topFieldData = new byte[topFieldDataLength]; data.readBytes(topFieldData, 0, topFieldDataLength); } if (bottomFieldDataLength > 0) { bottomFieldData = new byte[bottomFieldDataLength]; data.readBytes(bottomFieldData, 0, bottomFieldDataLength); } else { bottomFieldData = topFieldData; } } return new ObjectData(objectId, nonModifyingColorFlag, topFieldData, bottomFieldData); }
Example 5
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Parses an object data segment, as defined by ETSI EN 300 743 7.2.5. * * @return The parsed object data. */ private static ObjectData parseObjectData(ParsableBitArray data) { int objectId = data.readBits(16); data.skipBits(4); // Skip object_version_number int objectCodingMethod = data.readBits(2); boolean nonModifyingColorFlag = data.readBit(); data.skipBits(1); // Skip reserved. byte[] topFieldData = null; byte[] bottomFieldData = null; if (objectCodingMethod == OBJECT_CODING_STRING) { int numberOfCodes = data.readBits(8); // TODO: Parse and use character_codes. data.skipBits(numberOfCodes * 16); // Skip character_codes. } else if (objectCodingMethod == OBJECT_CODING_PIXELS) { int topFieldDataLength = data.readBits(16); int bottomFieldDataLength = data.readBits(16); if (topFieldDataLength > 0) { topFieldData = new byte[topFieldDataLength]; data.readBytes(topFieldData, 0, topFieldDataLength); } if (bottomFieldDataLength > 0) { bottomFieldData = new byte[bottomFieldDataLength]; data.readBytes(bottomFieldData, 0, bottomFieldDataLength); } else { bottomFieldData = topFieldData; } } return new ObjectData(objectId, nonModifyingColorFlag, topFieldData, bottomFieldData); }
Example 6
Source File: Ac4Util.java From MediaSDK with Apache License 2.0 | 5 votes |
private static int readVariableBits(ParsableBitArray data, int bitsPerRead) { int value = 0; while (true) { value += data.readBits(bitsPerRead); if (!data.readBit()) { break; } value++; value <<= bitsPerRead; } return value; }
Example 7
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 5 votes |
/** * Parses an object data segment, as defined by ETSI EN 300 743 7.2.5. * * @return The parsed object data. */ private static ObjectData parseObjectData(ParsableBitArray data) { int objectId = data.readBits(16); data.skipBits(4); // Skip object_version_number int objectCodingMethod = data.readBits(2); boolean nonModifyingColorFlag = data.readBit(); data.skipBits(1); // Skip reserved. @Nullable byte[] topFieldData = null; @Nullable byte[] bottomFieldData = null; if (objectCodingMethod == OBJECT_CODING_STRING) { int numberOfCodes = data.readBits(8); // TODO: Parse and use character_codes. data.skipBits(numberOfCodes * 16); // Skip character_codes. } else if (objectCodingMethod == OBJECT_CODING_PIXELS) { int topFieldDataLength = data.readBits(16); int bottomFieldDataLength = data.readBits(16); if (topFieldDataLength > 0) { topFieldData = new byte[topFieldDataLength]; data.readBytes(topFieldData, 0, topFieldDataLength); } if (bottomFieldDataLength > 0) { bottomFieldData = new byte[bottomFieldDataLength]; data.readBytes(bottomFieldData, 0, bottomFieldDataLength); } else { bottomFieldData = topFieldData; } } return new ObjectData(objectId, nonModifyingColorFlag, topFieldData, bottomFieldData); }
Example 8
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Paint an 8-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint8BitPixelCodeString( ParsableBitArray data, int[] clutEntries, @Nullable byte[] clutMapTable, int column, int line, @Nullable Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(8); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else { if (!data.readBit()) { peek = data.readBits(7); if (peek != 0x00) { runLength = peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else { runLength = data.readBits(7); clutIndex = data.readBits(8); } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 9
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 10
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Paint a 4-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint4BitPixelCodeString( ParsableBitArray data, int[] clutEntries, @Nullable byte[] clutMapTable, int column, int line, @Nullable Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(4); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (!data.readBit()) { peek = data.readBits(3); if (peek != 0x00) { runLength = 2 + peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else if (!data.readBit()) { runLength = 4 + data.readBits(2); clutIndex = data.readBits(4); } else { switch (data.readBits(2)) { case 0x00: runLength = 1; break; case 0x01: runLength = 2; break; case 0x02: runLength = 9 + data.readBits(4); clutIndex = data.readBits(4); break; case 0x03: runLength = 25 + data.readBits(8); clutIndex = data.readBits(4); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 11
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString( ParsableBitArray data, int[] clutEntries, @Nullable byte[] clutMapTable, int column, int line, @Nullable Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 12
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 13
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 14
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Paint a 4-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint4BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(4); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (!data.readBit()) { peek = data.readBits(3); if (peek != 0x00) { runLength = 2 + peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else if (!data.readBit()) { runLength = 4 + data.readBits(2); clutIndex = data.readBits(4); } else { switch (data.readBits(2)) { case 0x00: runLength = 1; break; case 0x01: runLength = 2; break; case 0x02: runLength = 9 + data.readBits(4); clutIndex = data.readBits(4); break; case 0x03: runLength = 25 + data.readBits(8); clutIndex = data.readBits(4); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 15
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Paint a 4-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint4BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(4); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (!data.readBit()) { peek = data.readBits(3); if (peek != 0x00) { runLength = 2 + peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else if (!data.readBit()) { runLength = 4 + data.readBits(2); clutIndex = data.readBits(4); } else { switch (data.readBits(2)) { case 0x00: runLength = 1; break; case 0x01: runLength = 2; break; case 0x02: runLength = 9 + data.readBits(4); clutIndex = data.readBits(4); break; case 0x03: runLength = 25 + data.readBits(8); clutIndex = data.readBits(4); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 16
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 17
Source File: Ac4Util.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Returns AC-4 format information given {@code data} containing a syncframe. The reading position * of {@code data} will be modified. * * @param data The data to parse, positioned at the start of the syncframe. * @return The AC-4 format data parsed from the header. */ public static SyncFrameInfo parseAc4SyncframeInfo(ParsableBitArray data) { int headerSize = 0; int syncWord = data.readBits(16); headerSize += 2; int frameSize = data.readBits(16); headerSize += 2; if (frameSize == 0xFFFF) { frameSize = data.readBits(24); headerSize += 3; // Extended frame_size } frameSize += headerSize; if (syncWord == AC41_SYNCWORD) { frameSize += 2; // crc_word } int bitstreamVersion = data.readBits(2); if (bitstreamVersion == 3) { bitstreamVersion += readVariableBits(data, /* bitsPerRead= */ 2); } int sequenceCounter = data.readBits(10); if (data.readBit()) { // b_wait_frames if (data.readBits(3) > 0) { // wait_frames data.skipBits(2); // reserved } } int sampleRate = data.readBit() ? 48000 : 44100; int frameRateIndex = data.readBits(4); int sampleCount = 0; if (sampleRate == 44100 && frameRateIndex == 13) { sampleCount = SAMPLE_COUNT[frameRateIndex]; } else if (sampleRate == 48000 && frameRateIndex < SAMPLE_COUNT.length) { sampleCount = SAMPLE_COUNT[frameRateIndex]; switch (sequenceCounter % 5) { case 1: // fall through case 3: if (frameRateIndex == 3 || frameRateIndex == 8) { sampleCount++; } break; case 2: if (frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; case 4: if (frameRateIndex == 3 || frameRateIndex == 8 || frameRateIndex == 11) { sampleCount++; } break; default: break; } } return new SyncFrameInfo(bitstreamVersion, CHANNEL_COUNT_2, sampleRate, frameSize, sampleCount); }
Example 18
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Parses a region composition segment, as defined by ETSI EN 300 743 7.2.3. */ private static RegionComposition parseRegionComposition(ParsableBitArray data, int length) { int id = data.readBits(8); data.skipBits(4); // Skip region_version_number boolean fillFlag = data.readBit(); data.skipBits(3); // Skip reserved. int width = data.readBits(16); int height = data.readBits(16); int levelOfCompatibility = data.readBits(3); int depth = data.readBits(3); data.skipBits(2); // Skip reserved. int clutId = data.readBits(8); int pixelCode8Bit = data.readBits(8); int pixelCode4Bit = data.readBits(4); int pixelCode2Bit = data.readBits(2); data.skipBits(2); // Skip reserved int remainingLength = length - 10; SparseArray<RegionObject> regionObjects = new SparseArray<>(); while (remainingLength > 0) { int objectId = data.readBits(16); int objectType = data.readBits(2); int objectProvider = data.readBits(2); int objectHorizontalPosition = data.readBits(12); data.skipBits(4); // Skip reserved. int objectVerticalPosition = data.readBits(12); remainingLength -= 6; int foregroundPixelCode = 0; int backgroundPixelCode = 0; if (objectType == 0x01 || objectType == 0x02) { // Only seems to affect to char subtitles. foregroundPixelCode = data.readBits(8); backgroundPixelCode = data.readBits(8); remainingLength -= 2; } regionObjects.put(objectId, new RegionObject(objectType, objectProvider, objectHorizontalPosition, objectVerticalPosition, foregroundPixelCode, backgroundPixelCode)); } return new RegionComposition(id, fillFlag, width, height, levelOfCompatibility, depth, clutId, pixelCode8Bit, pixelCode4Bit, pixelCode2Bit, regionObjects); }
Example 19
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Paint a 2-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint2BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(2); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (data.readBit()) { runLength = 3 + data.readBits(3); clutIndex = data.readBits(2); } else if (data.readBit()) { runLength = 1; } else { switch (data.readBits(2)) { case 0x00: endOfPixelCodeString = true; break; case 0x01: runLength = 2; break; case 0x02: runLength = 12 + data.readBits(4); clutIndex = data.readBits(2); break; case 0x03: runLength = 29 + data.readBits(8); clutIndex = data.readBits(2); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }
Example 20
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Paint a 4-bit/pixel code string, as defined by ETSI EN 300 743 7.2.5.2, to a canvas. */ private static int paint4BitPixelCodeString(ParsableBitArray data, int[] clutEntries, byte[] clutMapTable, int column, int line, Paint paint, Canvas canvas) { boolean endOfPixelCodeString = false; do { int runLength = 0; int clutIndex = 0; int peek = data.readBits(4); if (peek != 0x00) { runLength = 1; clutIndex = peek; } else if (!data.readBit()) { peek = data.readBits(3); if (peek != 0x00) { runLength = 2 + peek; clutIndex = 0x00; } else { endOfPixelCodeString = true; } } else if (!data.readBit()) { runLength = 4 + data.readBits(2); clutIndex = data.readBits(4); } else { switch (data.readBits(2)) { case 0x00: runLength = 1; break; case 0x01: runLength = 2; break; case 0x02: runLength = 9 + data.readBits(4); clutIndex = data.readBits(4); break; case 0x03: runLength = 25 + data.readBits(8); clutIndex = data.readBits(4); break; } } if (runLength != 0 && paint != null) { paint.setColor(clutEntries[clutMapTable != null ? clutMapTable[clutIndex] : clutIndex]); canvas.drawRect(column, line, column + runLength, line + 1, paint); } column += runLength; } while (!endOfPixelCodeString); return column; }