Java Code Examples for com.google.android.exoplayer2.util.ParsableBitArray#bitsLeft()
The following examples show how to use
com.google.android.exoplayer2.util.ParsableBitArray#bitsLeft() .
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: DtsUtil.java From Telegram with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 2
Source File: DtsUtil.java From MediaSDK with Apache License 2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 3
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { int bitsLeft = data.bitsLeft(); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true); sampleRateHz = config.first; channelCount = config.second; return bitsLeft - data.bitsLeft(); }
Example 4
Source File: LatmReader.java From Telegram with GNU General Public License v2.0 | 5 votes |
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { int bitsLeft = data.bitsLeft(); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true); sampleRateHz = config.first; channelCount = config.second; return bitsLeft - data.bitsLeft(); }
Example 5
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 6
Source File: LatmReader.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { int bitsLeft = data.bitsLeft(); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true); sampleRateHz = config.first; channelCount = config.second; return bitsLeft - data.bitsLeft(); }
Example 7
Source File: LatmReader.java From MediaSDK with Apache License 2.0 | 5 votes |
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { int bitsLeft = data.bitsLeft(); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true); sampleRateHz = config.first; channelCount = config.second; return bitsLeft - data.bitsLeft(); }
Example 8
Source File: DtsUtil.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 9
Source File: DtsUtil.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private static ParsableBitArray getNormalizedFrameHeader(byte[] frameHeader) { if (frameHeader[0] == FIRST_BYTE_BE) { // The frame is already 16-bit mode, big endian. return new ParsableBitArray(frameHeader); } // Data is not normalized, but we don't want to modify frameHeader. frameHeader = Arrays.copyOf(frameHeader, frameHeader.length); if (isLittleEndianFrameHeader(frameHeader)) { // Change endianness. for (int i = 0; i < frameHeader.length - 1; i += 2) { byte temp = frameHeader[i]; frameHeader[i] = frameHeader[i + 1]; frameHeader[i + 1] = temp; } } ParsableBitArray frameBits = new ParsableBitArray(frameHeader); if (frameHeader[0] == (byte) (SYNC_VALUE_14B_BE >> 24)) { // Discard the 2 most significant bits of each 16 bit word. ParsableBitArray scratchBits = new ParsableBitArray(frameHeader); while (scratchBits.bitsLeft() >= 16) { scratchBits.skipBits(2); frameBits.putInt(scratchBits.readBits(14), 14); } } frameBits.reset(frameHeader); return frameBits; }
Example 10
Source File: LatmReader.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private int parseAudioSpecificConfig(ParsableBitArray data) throws ParserException { int bitsLeft = data.bitsLeft(); Pair<Integer, Integer> config = CodecSpecificDataUtil.parseAacAudioSpecificConfig(data, true); sampleRateHz = config.first; channelCount = config.second; return bitsLeft - data.bitsLeft(); }
Example 11
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Decodes a subtitling packet, returning a list of parsed {@link Cue}s. * * @param data The subtitling packet data to decode. * @param limit The limit in {@code data} at which to stop decoding. * @return The parsed {@link Cue}s. */ public List<Cue> decode(byte[] data, int limit) { // Parse the input data. ParsableBitArray dataBitArray = new ParsableBitArray(data, limit); while (dataBitArray.bitsLeft() >= 48 // sync_byte (8) + segment header (40) && dataBitArray.readBits(8) == 0x0F) { parseSubtitlingSegment(dataBitArray, subtitleService); } if (subtitleService.pageComposition == null) { return Collections.emptyList(); } // Update the canvas bitmap if necessary. DisplayDefinition displayDefinition = subtitleService.displayDefinition != null ? subtitleService.displayDefinition : defaultDisplayDefinition; if (bitmap == null || displayDefinition.width + 1 != bitmap.getWidth() || displayDefinition.height + 1 != bitmap.getHeight()) { bitmap = Bitmap.createBitmap(displayDefinition.width + 1, displayDefinition.height + 1, Bitmap.Config.ARGB_8888); canvas.setBitmap(bitmap); } // Build the cues. List<Cue> cues = new ArrayList<>(); SparseArray<PageRegion> pageRegions = subtitleService.pageComposition.regions; for (int i = 0; i < pageRegions.size(); i++) { PageRegion pageRegion = pageRegions.valueAt(i); int regionId = pageRegions.keyAt(i); RegionComposition regionComposition = subtitleService.regions.get(regionId); // Clip drawing to the current region and display definition window. int baseHorizontalAddress = pageRegion.horizontalAddress + displayDefinition.horizontalPositionMinimum; int baseVerticalAddress = pageRegion.verticalAddress + displayDefinition.verticalPositionMinimum; int clipRight = Math.min(baseHorizontalAddress + regionComposition.width, displayDefinition.horizontalPositionMaximum); int clipBottom = Math.min(baseVerticalAddress + regionComposition.height, displayDefinition.verticalPositionMaximum); canvas.clipRect(baseHorizontalAddress, baseVerticalAddress, clipRight, clipBottom, Region.Op.REPLACE); ClutDefinition clutDefinition = subtitleService.cluts.get(regionComposition.clutId); if (clutDefinition == null) { clutDefinition = subtitleService.ancillaryCluts.get(regionComposition.clutId); if (clutDefinition == null) { clutDefinition = defaultClutDefinition; } } SparseArray<RegionObject> regionObjects = regionComposition.regionObjects; for (int j = 0; j < regionObjects.size(); j++) { int objectId = regionObjects.keyAt(j); RegionObject regionObject = regionObjects.valueAt(j); ObjectData objectData = subtitleService.objects.get(objectId); if (objectData == null) { objectData = subtitleService.ancillaryObjects.get(objectId); } if (objectData != null) { Paint paint = objectData.nonModifyingColorFlag ? null : defaultPaint; paintPixelDataSubBlocks(objectData, clutDefinition, regionComposition.depth, baseHorizontalAddress + regionObject.horizontalPosition, baseVerticalAddress + regionObject.verticalPosition, paint, canvas); } } if (regionComposition.fillFlag) { int color; if (regionComposition.depth == REGION_DEPTH_8_BIT) { color = clutDefinition.clutEntries8Bit[regionComposition.pixelCode8Bit]; } else if (regionComposition.depth == REGION_DEPTH_4_BIT) { color = clutDefinition.clutEntries4Bit[regionComposition.pixelCode4Bit]; } else { color = clutDefinition.clutEntries2Bit[regionComposition.pixelCode2Bit]; } fillRegionPaint.setColor(color); canvas.drawRect(baseHorizontalAddress, baseVerticalAddress, baseHorizontalAddress + regionComposition.width, baseVerticalAddress + regionComposition.height, fillRegionPaint); } Bitmap cueBitmap = Bitmap.createBitmap(bitmap, baseHorizontalAddress, baseVerticalAddress, regionComposition.width, regionComposition.height); cues.add(new Cue(cueBitmap, (float) baseHorizontalAddress / displayDefinition.width, Cue.ANCHOR_TYPE_START, (float) baseVerticalAddress / displayDefinition.height, Cue.ANCHOR_TYPE_START, (float) regionComposition.width / displayDefinition.width, (float) regionComposition.height / displayDefinition.height)); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); } return cues; }
Example 12
Source File: DvbParser.java From Telegram with GNU General Public License v2.0 | 4 votes |
/** * Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock(byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; byte[] clutMapTable2To4 = null; byte[] clutMapTable2To8 = null; byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString(data, clutEntries, null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }
Example 13
Source File: DvbParser.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
/** * Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock(byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; byte[] clutMapTable2To4 = null; byte[] clutMapTable2To8 = null; byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString(data, clutEntries, null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }
Example 14
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock(byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; byte[] clutMapTable2To4 = null; byte[] clutMapTable2To8 = null; byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString(data, clutEntries, null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }
Example 15
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock(byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; byte[] clutMapTable2To4 = null; byte[] clutMapTable2To8 = null; byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString(data, clutEntries, null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }
Example 16
Source File: DvbParser.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
/** * Decodes a subtitling packet, returning a list of parsed {@link Cue}s. * * @param data The subtitling packet data to decode. * @param limit The limit in {@code data} at which to stop decoding. * @return The parsed {@link Cue}s. */ public List<Cue> decode(byte[] data, int limit) { // Parse the input data. ParsableBitArray dataBitArray = new ParsableBitArray(data, limit); while (dataBitArray.bitsLeft() >= 48 // sync_byte (8) + segment header (40) && dataBitArray.readBits(8) == 0x0F) { parseSubtitlingSegment(dataBitArray, subtitleService); } if (subtitleService.pageComposition == null) { return Collections.emptyList(); } // Update the canvas bitmap if necessary. DisplayDefinition displayDefinition = subtitleService.displayDefinition != null ? subtitleService.displayDefinition : defaultDisplayDefinition; if (bitmap == null || displayDefinition.width + 1 != bitmap.getWidth() || displayDefinition.height + 1 != bitmap.getHeight()) { bitmap = Bitmap.createBitmap(displayDefinition.width + 1, displayDefinition.height + 1, Bitmap.Config.ARGB_8888); canvas.setBitmap(bitmap); } // Build the cues. List<Cue> cues = new ArrayList<>(); SparseArray<PageRegion> pageRegions = subtitleService.pageComposition.regions; for (int i = 0; i < pageRegions.size(); i++) { PageRegion pageRegion = pageRegions.valueAt(i); int regionId = pageRegions.keyAt(i); RegionComposition regionComposition = subtitleService.regions.get(regionId); // Clip drawing to the current region and display definition window. int baseHorizontalAddress = pageRegion.horizontalAddress + displayDefinition.horizontalPositionMinimum; int baseVerticalAddress = pageRegion.verticalAddress + displayDefinition.verticalPositionMinimum; int clipRight = Math.min(baseHorizontalAddress + regionComposition.width, displayDefinition.horizontalPositionMaximum); int clipBottom = Math.min(baseVerticalAddress + regionComposition.height, displayDefinition.verticalPositionMaximum); canvas.clipRect(baseHorizontalAddress, baseVerticalAddress, clipRight, clipBottom, Region.Op.REPLACE); ClutDefinition clutDefinition = subtitleService.cluts.get(regionComposition.clutId); if (clutDefinition == null) { clutDefinition = subtitleService.ancillaryCluts.get(regionComposition.clutId); if (clutDefinition == null) { clutDefinition = defaultClutDefinition; } } SparseArray<RegionObject> regionObjects = regionComposition.regionObjects; for (int j = 0; j < regionObjects.size(); j++) { int objectId = regionObjects.keyAt(j); RegionObject regionObject = regionObjects.valueAt(j); ObjectData objectData = subtitleService.objects.get(objectId); if (objectData == null) { objectData = subtitleService.ancillaryObjects.get(objectId); } if (objectData != null) { Paint paint = objectData.nonModifyingColorFlag ? null : defaultPaint; paintPixelDataSubBlocks(objectData, clutDefinition, regionComposition.depth, baseHorizontalAddress + regionObject.horizontalPosition, baseVerticalAddress + regionObject.verticalPosition, paint, canvas); } } if (regionComposition.fillFlag) { int color; if (regionComposition.depth == REGION_DEPTH_8_BIT) { color = clutDefinition.clutEntries8Bit[regionComposition.pixelCode8Bit]; } else if (regionComposition.depth == REGION_DEPTH_4_BIT) { color = clutDefinition.clutEntries4Bit[regionComposition.pixelCode4Bit]; } else { color = clutDefinition.clutEntries2Bit[regionComposition.pixelCode2Bit]; } fillRegionPaint.setColor(color); canvas.drawRect(baseHorizontalAddress, baseVerticalAddress, baseHorizontalAddress + regionComposition.width, baseVerticalAddress + regionComposition.height, fillRegionPaint); } Bitmap cueBitmap = Bitmap.createBitmap(bitmap, baseHorizontalAddress, baseVerticalAddress, regionComposition.width, regionComposition.height); cues.add(new Cue(cueBitmap, (float) baseHorizontalAddress / displayDefinition.width, Cue.ANCHOR_TYPE_START, (float) baseVerticalAddress / displayDefinition.height, Cue.ANCHOR_TYPE_START, (float) regionComposition.width / displayDefinition.width, (float) regionComposition.height / displayDefinition.height)); canvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); } return cues; }
Example 17
Source File: DvbParser.java From MediaSDK with Apache License 2.0 | 4 votes |
/** Draws a pixel data sub-block, as defined by ETSI EN 300 743 7.2.5.1, into a canvas. */ private static void paintPixelDataSubBlock( byte[] pixelData, int[] clutEntries, int regionDepth, int horizontalAddress, int verticalAddress, @Nullable Paint paint, Canvas canvas) { ParsableBitArray data = new ParsableBitArray(pixelData); int column = horizontalAddress; int line = verticalAddress; @Nullable byte[] clutMapTable2To4 = null; @Nullable byte[] clutMapTable2To8 = null; @Nullable byte[] clutMapTable4To8 = null; while (data.bitsLeft() != 0) { int dataType = data.readBits(8); switch (dataType) { case DATA_TYPE_2BP_CODE_STRING: @Nullable byte[] clutMapTable2ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable2ToX = clutMapTable2To8 == null ? defaultMap2To8 : clutMapTable2To8; } else if (regionDepth == REGION_DEPTH_4_BIT) { clutMapTable2ToX = clutMapTable2To4 == null ? defaultMap2To4 : clutMapTable2To4; } else { clutMapTable2ToX = null; } column = paint2BitPixelCodeString(data, clutEntries, clutMapTable2ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_4BP_CODE_STRING: @Nullable byte[] clutMapTable4ToX; if (regionDepth == REGION_DEPTH_8_BIT) { clutMapTable4ToX = clutMapTable4To8 == null ? defaultMap4To8 : clutMapTable4To8; } else { clutMapTable4ToX = null; } column = paint4BitPixelCodeString(data, clutEntries, clutMapTable4ToX, column, line, paint, canvas); data.byteAlign(); break; case DATA_TYPE_8BP_CODE_STRING: column = paint8BitPixelCodeString( data, clutEntries, /* clutMapTable= */ null, column, line, paint, canvas); break; case DATA_TYPE_24_TABLE_DATA: clutMapTable2To4 = buildClutMapTable(4, 4, data); break; case DATA_TYPE_28_TABLE_DATA: clutMapTable2To8 = buildClutMapTable(4, 8, data); break; case DATA_TYPE_48_TABLE_DATA: clutMapTable4To8 = buildClutMapTable(16, 8, data); break; case DATA_TYPE_END_LINE: column = horizontalAddress; line += 2; break; default: // Do nothing. break; } } }