Exemplo n.º 1
0
static void SetSegmentProbas(VP8Encoder* const enc) {
  int p[NUM_MB_SEGMENTS] = { 0 };
  int n;

  for (n = 0; n < enc->mb_w_ * enc->mb_h_; ++n) {
    const VP8MBInfo* const mb = &enc->mb_info_[n];
    ++p[mb->segment_];
  }
#if !defined(WEBP_DISABLE_STATS)
  if (enc->pic_->stats != NULL) {
    for (n = 0; n < NUM_MB_SEGMENTS; ++n) {
      enc->pic_->stats->segment_size[n] = p[n];
    }
  }
#endif
  if (enc->segment_hdr_.num_segments_ > 1) {
    uint8_t* const probas = enc->proba_.segments_;
    probas[0] = GetProba(p[0] + p[1], p[2] + p[3]);
    probas[1] = GetProba(p[0], p[1]);
    probas[2] = GetProba(p[2], p[3]);

    enc->segment_hdr_.update_map_ =
        (probas[0] != 255) || (probas[1] != 255) || (probas[2] != 255);
    if (!enc->segment_hdr_.update_map_) ResetSegments(enc);
    enc->segment_hdr_.size_ =
        p[0] * (VP8BitCost(0, probas[0]) + VP8BitCost(0, probas[1])) +
        p[1] * (VP8BitCost(0, probas[0]) + VP8BitCost(1, probas[1])) +
        p[2] * (VP8BitCost(1, probas[0]) + VP8BitCost(0, probas[2])) +
        p[3] * (VP8BitCost(1, probas[0]) + VP8BitCost(1, probas[2]));
  } else {
    enc->segment_hdr_.update_map_ = 0;
    enc->segment_hdr_.size_ = 0;
  }
}
Exemplo n.º 2
0
void CTextMessageDecoder::ClearText()
{
	/* Reset segments */
	ResetSegments();

	/* Clear text */	
	*pstrText = "";
}
Exemplo n.º 3
0
void CTextMessageDecoder::Init(string* pstrNewPText)
{
	int i;

	pstrText = pstrNewPText;
	biOldToggleBit = 0;
	iBitCount = 0;

	/* Init segments */
	ResetSegments();

	/* Init and reset stream buffer */
	biStreamBuffer.Init(TOT_NUM_BITS_PER_PIECE, 0);
}
Exemplo n.º 4
0
/******************************************************************************\
* Text message decoder (for receiver)                                          *
\******************************************************************************/
void CTextMessageDecoder::Decode(CVector<_BINARY>& pData)
{
	int			i, j;
	_BOOLEAN	bBeginningFound;

	/* Reset binary vector function. Always four bytes of data */
	pData.ResetBitAccess();

	/* Identify the beginning of a segment, all four bytes are 0xFF, otherwise
	   store total new buffer in internal intermediate buffer. This buffer is
	   read, when a beginning was found */
	bBeginningFound = TRUE;
	for (i = 0; i < NUM_BYTES_TEXT_MESS_IN_AUD_STR; i++)
	{
		if (pData.Separate(SIZEOF__BYTE) != 0xFF)
			bBeginningFound = FALSE;
	}

	if (bBeginningFound)
	{
		/* Analyse old stream buffer, which should be completed now --------- */
		/* Get header information. This function separates 16 bits from
		   stream */
		biStreamBuffer.ResetBitAccess();
		ReadHeader();

		/* Check CRC */
		biStreamBuffer.ResetBitAccess();
		CRCObject.Reset(16);

		/* "byLengthBody" was defined in the header */
		for (i = 0; i < byLengthBody + 2 /* Header */; i++)
			CRCObject.AddByte(biStreamBuffer.Separate(SIZEOF__BYTE));

		if (CRCObject.CheckCRC(biStreamBuffer.Separate(16)) == TRUE)
		{
			if (biCommandFlag == 1)
			{
				switch (byCommand)
				{
				case 1: /* 0001 */
					/* The message shall be removed from the display */
					ClearText();
					break;
				}
			}
			else
			{
				/* Body ----------------------------------------------------- */
				/* Evaluate toggle bit */
				if (biToggleBit != biOldToggleBit)
				{
					/* A new message is sent, clear all old segments */
					ResetSegments();

					biOldToggleBit = biToggleBit;
				}


				/* Read all bytes in stream buffer -------------------------- */
				/* First, check if segment was already OK and if new data has
				   the same content or not. If the content is different, a new
				   message is being send, clear all other segments */
				if (Segment[bySegmentID].bIsOK == TRUE)
				{
					/* Reset bit access and skip header bits to go directly to
					   the body bytes */
					biStreamBuffer.ResetBitAccess();
					biStreamBuffer.Separate(16);

					_BOOLEAN bIsSame = TRUE;
					for (i = 0; i < byLengthBody; i++)
					{
						if (Segment[bySegmentID].byData[i] !=
							biStreamBuffer.Separate(SIZEOF__BYTE))
						{
							bIsSame = FALSE;
						}
					}

					/* If a new message is sent, clear all old segments */
					if (bIsSame == FALSE)
						ResetSegments();
				}

				/* Reset bit access and skip header bits to go directly to the
				   body bytes */
				biStreamBuffer.ResetBitAccess();
				biStreamBuffer.Separate(16);

				/* Get all body bytes */
				for (i = 0; i < byLengthBody; i++)
				{
					Segment[bySegmentID].byData[i] =
						biStreamBuffer.Separate(SIZEOF__BYTE);
				}

				/* Set length of this segment and OK flag */
				Segment[bySegmentID].iNumBytes = byLengthBody;
				Segment[bySegmentID].bIsOK = TRUE;

				/* Check length of text message */
				if (biLastFlag == 1)
					iNumSegments = bySegmentID + 1;

				/* Set text to display */
				SetText();
			}
		}

		/* Reset bit count */
		iBitCount = 0;
	}
	else
	{
		for (i = 0; i < NUM_BYTES_TEXT_MESS_IN_AUD_STR; i++)
		{
			/* Check, if number of bytes is not too big */
			if (iBitCount < TOT_NUM_BITS_PER_PIECE)
			{
				for (j = 0; j < SIZEOF__BYTE; j++)
					biStreamBuffer[iBitCount + j] = pData[i * SIZEOF__BYTE + j];

				iBitCount += SIZEOF__BYTE;
			}
		}
	}
}