Пример #1
0
//解码一组二进制到一个方向向量
//0上 1 下 2 左 3 右
vector<int> EnumKare::Decode(const vector<int> &bits)
{
	vector<int> directions;
	int  gene = 0;
	for (; gene < bits.size(); gene+= m_iGeneLength)
	{
		vector<int> ThisGene;
		int bit = 0;
		for (; bit < m_iGeneLength; ++bit)
		{
			ThisGene.push_back(bits[gene + bit]);
		}
		//转换为十进制并加入到方向向量中
		directions.push_back(BinToInt(ThisGene));
	}

	return directions;
}
Пример #2
0
void InvRunLengthEnc(List *input, int32_t output[], int16_t dc_value)
{
   uint8_t j;
   for( j = 0; j < SIZE_OF_BLOCK; j++)
	   output[j] = 0;
   output[0] = dc_value;
   uint16_t i = 1;
   List *cur = input;
   while(cur)
   {
	 i += (cur->content).VLC.NOZ;
	 if((cur->content).VLC.amplitude == 0)
		 i++;
	 else
		 output[i++] = BinToInt((cur->content).VLI, (cur->content).VLC.amplitude);
	 List *cr = cur;
	 cur = cur->next;
	 free(cr);
   }
}
Пример #3
0
//---------------------------Decode-------------------------------------
//
//	decodes a vector of bits into a vector of ints
//
//-----------------------------------------------------------------------
vector<int> SGenome::Decode()
{
	vector<int>	decoded;

	//step through the chromosome a gene at a time
	for (int gene=0; gene < vecBits.size(); gene += iGeneLength)
	{
		//get the gene at this position
		vector<int> ThisGene;
		
		for (int bit = 0; bit < iGeneLength; ++bit)
		{
			ThisGene.push_back(vecBits[gene+bit]);
		}

		//convert to decimal and add to list of decoded
		decoded.push_back(BinToInt(ThisGene));
	}

	return decoded;
}
Пример #4
0
//---------------------------Decode-------------------------------------
//
//	decodes a vector of bits into a vector of directions (ints)
//
//	0=North, 1=South, 2=East, 3=West
//-----------------------------------------------------------------------
vector<int> CgaBob::Decode(const vector<int> &bits)
{
	vector<int>	directions;
    
	//step through the chromosome a gene at a time
	for (int gene=0; gene < bits.size(); gene += m_iGeneLength)
	{
		//get the gene at this position
		vector<int> ThisGene;
		
		for (int bit = 0; bit < m_iGeneLength; ++bit)
		{
			ThisGene.push_back(bits[gene+bit]);
		}
        
		//convert to decimal and add to list of directions
		directions.push_back(BinToInt(ThisGene));
	}
    
	return directions;
}
Пример #5
0
void Decoding(scancodeDC *DCDiff, scancodeAC *ACCoef, Scan_1D_1D *InPackage, FramePop property)
{
	 List* input_h;
	 //uint8_t size = 32;//sizeof(int) * 8
	 uint16_t width = property.width/8, height = property.height/8;
	 uint32_t lim = width * height;
	 int16_t dc_value = 0, pos = 0;
	 uint32_t i;
	 for( i = 0; i < lim; i++)
	 {
		 SYMBOL dcVal = (*DCDiff).Y[pos];
		 if(dcVal.VLC.amplitude != 0)
			 dc_value += BinToInt(dcVal.VLI, dcVal.VLC.amplitude);
		 List* cur = (*ACCoef).Y[pos];
		 input_h = (List *)malloc(sizeof(List));
		 input_h->content.VLC.NOZ = 0;
		 input_h->content.VLC.amplitude = 0;
		 input_h->content.VLI = 0;
		 input_h->next = NULL;
		 input_h->previous = NULL;
		 List *input = input_h;
		 while(cur)
		 {
			 if((cur->content).VLC.NOZ != 0 || (cur->content).VLC.amplitude != 0)
				 input = push(input, cur->content);
			 List *cr = cur;
			 cur = cur->next;
			 free(cr);
		 }
		 InvRunLengthEnc(input_h, (*InPackage).Y[i].data, dc_value);
		 pos++;
	 }
	 dc_value = 0;
	 pos = 0;
	 width = property.thumbwidth/8, height = property.thumbheight/8;
	 lim = width * height;
	 for( i = 0; i < lim; i++)
	 {
		 SYMBOL dcVal = (*DCDiff).Cb[pos];
		 if(dcVal.VLC.amplitude != 0)
			 dc_value += BinToInt(dcVal.VLI,dcVal.VLC.amplitude);
		 List* cur = (*ACCoef).Cb[pos];
		 input_h = (List *)malloc(sizeof(List));
		 input_h->content.VLC.NOZ = 0;
		 input_h->content.VLC.amplitude = 0;
		 input_h->content.VLI = 0;
		 input_h->next = NULL;
		 input_h->previous = NULL;
		 List *input = input_h;
		 while(cur)
		 {
			 if((cur->content).VLC.NOZ != 0 || (cur->content).VLC.amplitude != 0)
				 input = push(input, cur->content);
			 List *cr = cur;
			 cur = cur->next;
			 free(cr);
		 }
		 InvRunLengthEnc(input_h, (*InPackage).Cb[i].data, dc_value);
		 pos++;
	 }
	 dc_value = 0;
	 pos  = 0;
	 for( i = 0; i < lim; i++)
	 {
		 SYMBOL dcVal = (*DCDiff).Cr[pos];
		 if(dcVal.VLC.amplitude != 0)
			 dc_value += BinToInt(dcVal.VLI, dcVal.VLC.amplitude);
		 List* cur = (*ACCoef).Cr[pos];
		 input_h = (List *)malloc(sizeof(List));
		 input_h->content.VLC.NOZ = 0;
		 input_h->content.VLC.amplitude = 0;
		 input_h->content.VLI = 0;
		 input_h->next = NULL;
		 input_h->previous = NULL;
		 List *input = input_h;
		 while(cur)
		 {
			 if((cur->content).VLC.NOZ != 0 || (cur->content).VLC.amplitude != 0)
				 input = push(input, cur->content);
			 List *cr = cur;
			 cur = cur->next;
			 free(cr);
		 }
		 InvRunLengthEnc(input_h, (*InPackage).Cr[i].data, dc_value);
		 pos++;
	 }
}