⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 armicjp_bitstream.c

📁 The OpenMAX DL (Development Layer) APIs contain a comprehensive set of audio, video, signal processi
💻 C
字号:
#include "armCOMM.h"#include "armCOMM_Bitstream.h"#include "armICJP_Bitstream.h"/*** Function :armICJP_GetByte()** Description :*   Returns the first byte pointed to by the double pointer ppBitStream.** Parametrs:* [in] ppBitStream   double pointer to the first byte in the bitstream.* [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit ** Return:* [out]             Byte from bi stream is returned.* *    **/OMX_U8 armICJP_GetByte(const OMX_U8 **ppBitStream, OMX_INT *pOffset){	return *(*ppBitStream)++;}/*** Function :armICJP_SkipBytes()** Description :*   The double pointer ppBitStream is incremented by the number of bytes to be skipped.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bytes         Number of bytes to skip**    **/OMXVoid armICJP_SkipBytes(							  const OMX_U8 **ppBitStream, 							  OMX_INT *pOffset, 							  OMX_INT bytes){	*ppBitStream += bytes;}/*** Function :armICJP_GetHWord()** Description :*   Returns first two bytes pointed to by the double pointer ppBitStream and ppBitStream will not be updated.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit ** Return:* [out]             Two bytes are returned.* *    **/OMX_U16 armICJP_GetHWord(const OMX_U8 **ppBitStream, OMX_INT *pOffset){	return (((*ppBitStream)++)[0] << 8) + ((*ppBitStream)++)[1];}/*** Function :armICJP_PeekEntropyBits()** Description :*   Requested number of bits is read from the entropy coded bistream pointed to by the double pointer*   ppBitStream by taking care of markers in between. The number of valid entropy bits read is saved *   at pBitsRead, and bit stream descriptors will not be modified.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bits          Number of bits to be peeked. * [in] pBitsRead     pointer to the number of bits actually read. ** Return:* [out]              Requested number of bits is returned.* *    **/OMX_U16 armICJP_PeekEntropyBits(									const OMX_U8 **ppBitStream, 									OMX_INT *pOffset,  									OMX_INT bits,									OMX_INT *pBitsRead){	const OMX_U8 *pBitStream1 = *ppBitStream; 	OMX_INT offset1 = *pOffset;	OMX_U16 value;	value = armICJP_ReadValidBits(ppBitStream, pOffset, bits,pBitsRead);	*ppBitStream = pBitStream1;	*pOffset = offset1;	return value;}/*** Function :armICJP_ReadEntropyBits()** Description :*   Requested number of bits is read from the entropy coded bistream pointed to by the double pointer*   ppBitStream by taking care of markers in between. If the valid number of bits read are less than the*   numbers of bytes requesd then -1 is returned.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bits          Number of bits to be read. ** Return:* [out]              If bits read are less than the requested number of bits then retun -1 *                    otherwise return the bits read.  *    **/OMX_U32 armICJP_ReadEntropyBits(									const OMX_U8 **ppBitStream, 									OMX_INT *pOffset, 									OMX_INT bits									){	OMX_U16 value;	OMX_INT BitsRead = 0;	value = armICJP_ReadValidBits(ppBitStream, pOffset, bits,&BitsRead);	if(BitsRead < bits)	{		return 0xFFFFFFFF; /*Returning -1; indiacating there is an error */	}	return value;}/*** Function :armICJP_ReadBits()** Description :*   Requested number of bits is read bit stream descriptors are modified.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bits          Number of bits to be peeked. ** Return:* [out]              Requested number of bits is retuned.* *    **/OMX_U16 armICJP_ReadBits(const OMX_U8 **ppBitStream, 							 OMX_INT *pOffset, 							 OMX_INT bits){	const OMX_U8 *pBitStream = *ppBitStream;	OMX_INT Offset = *pOffset;	OMX_U32 Value;	/* Read next 32 bits from stream */	Value = (pBitStream[0] << 24 ) | ( pBitStream[1] << 16)  | (pBitStream[2] << 8 ) | (pBitStream[3]) ;	Value = (Value << Offset ) | (pBitStream[4] >> (8-Offset));	/* Advance bitstream pointer by N bits */	Offset += bits;	*ppBitStream = pBitStream + (Offset>>3);	*pOffset = Offset & 7;	/* Return N bits */	if((32-bits) >= 32) {		Value = 0;	} else {		Value = Value >> (32-bits); 	}	return Value;}/*** Function :armICJP_UnPackVLC16()** Description :*   The function decodes VLD code from the bit stream and returns the index in the code book. If*   no valid symbol is found in the code book an error ARM_NO_CODEBOOK_INDEX is returned. ** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] pCodeBook     pointer to the OMXICJPHuffmanDecodeSpec structure . ** Return:* [out]              Index to the decoded VLD code in the code book is returned.* *    **/OMX_U16 armICJP_UnPackVLC16(								const OMX_U8 **ppBitStream, 								OMX_INT *pOffset, 								const ARM_VLC32 *pCodeBook){	OMX_INT Offset = *pOffset;	OMX_U32 Value;	OMX_INT Index;	OMX_INT BitsRead = 0;	armAssert(Offset>=0 && Offset<=7);	/* Read next 16 bits from stream */	Value = armICJP_PeekEntropyBits(ppBitStream, pOffset, 16, &BitsRead);	/* Search through the codebook */    	for (Index = 0; pCodeBook->codeLen != 0 || pCodeBook->codeWord != 0; Index++)	{		if(BitsRead >= pCodeBook->codeLen)		{			if (pCodeBook->codeWord == (Value >> (BitsRead- pCodeBook->codeLen)))			{				armAssert(pCodeBook->codeLen <= 16);				armICJP_ReadEntropyBits(ppBitStream, pOffset, pCodeBook->codeLen);				return Index;			}   		}		pCodeBook++;	}		/* If code book not found check for the marker error*/	if( BitsRead < 16 )	{		return ARM_JPEGMarkerErr; 	}	/* No code match found */	return ARM_NO_CODEBOOK_INDEX;}/*** Function :armICJP_SkipEntropyBits()** Description :*   This function skips the requested number of valid entropy coded bits from the bit stream.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bits          Number of bits to be peeked. **    **/void armICJP_SkipEntropyBits(const OMX_U8 **ppBitStream, 								 OMX_INT *pOffset, 								 OMX_INT bits){	armICJP_ReadEntropyBits(ppBitStream, pOffset, bits);}/*** Function :armICJP_ReadValidBits()** Description :*   This function reads the valid entropy coded bits from the bit stream. The number of valid *   entropy bits actually read are stored at pBitsRead and valid entropy bits read are returned.** Parametrs:* [in] ppBitStream   double pointer to the first bit stream byte. * [in] pOffset       pointer to the starting bit position in the bit stream byte *                    pointed by *ppBitStream; valid within the range of 0 to 7, where *					  0 corresponds to the most significant bit, and 7 corresponds to *                    the least significant bit * [in] bits          Number of bits to be peeked. * [in] pBitsRead     pointer to the number of bits actually read. ** Return:* [out]              Requested number of bits is returned.* *    **/OMX_U16 armICJP_ReadValidBits(								  const OMX_U8 **ppBitStream, 								  OMX_INT *pOffset, 								  OMX_INT bits,								  OMX_INT *pBitsRead								  ){	const OMX_U8 * pBitStream;	OMX_INT Offset;	OMX_U32 Buffer, NextByte;	OMX_INT BitsRequested;	pBitStream = *ppBitStream;	Offset = *pOffset;	BitsRequested = bits;	Buffer = 0;	while (bits>0)	{		NextByte = pBitStream[0];		if (NextByte==0xFF)		{			while (pBitStream[1]==0xFF)			{				/* skip 0xFF padding */				pBitStream++;			}			if (pBitStream[1]!=0)			{				/* hit a marker and so run out of data */				break;			}		}		/* Read up to next 8 bits */		NextByte = NextByte & (255>>Offset);		if (Offset + bits < 8)		{			/* this byte not fully used */			Offset += bits;			NextByte = NextByte >> (8-Offset);			Buffer = (Buffer << bits) | NextByte;			bits = 0;		}		else		{			/* use up the whole of this byte */			Buffer = (Buffer << (8-Offset)) | NextByte;			bits = bits - (8-Offset);			Offset = 0;			if (pBitStream[0]==0xFF)			{				/* Skip the 00 in FF00 */				pBitStream++;			}			pBitStream++;		}	}	*pBitsRead = BitsRequested - bits;	*pOffset = Offset;	*ppBitStream = pBitStream;	return Buffer;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -