Esempio n. 1
0
void CPMotion::OnZigZag()
{
    short Velocity = 100;
    short Duration = 1;			//seconds
    short Iterations = 3;
    ZigZag(Velocity, Duration, Iterations);

}
Esempio n. 2
0
// quantized dct values
void DCTBlock::qData(bool hide)
{
	// uniform quantization table is 2^n.
   q = vid->uQ[layer];

	// ZigZag dct data
   ZigZag();

	/*
	if((float)dct[0]/(float)q > 0)
   {
      ac = sInt16((float)dct[0]/(float)q + 0.5);
   } else {
      ac = sInt16((float)dct[0]/(float)q - 0.5);
   }
   */
   
   for(i = 0; i < DCT_BLOCKSIZE; ++i)
   {
   	if((float)dct[i]/(float)q > 0)
      {
         qd[i] = sInt16((float)dct[i]/(float)q + 0.5);
      } else {
         qd[i] = sInt16((float)dct[i]/(float)q - 0.5);
      }
   }
   
   /*
   if(hide)
   {
      printf(" -- raw --\n");
      PrintBlock(raw, DCT_BLOCKWIDTH, DCT_BLOCKWIDTH);
      printf(" -- dct --\n");
      PrintBlock(dct, DCT_BLOCKWIDTH, DCT_BLOCKWIDTH);
      printf(" -- qd --\n");
      PrintBlock(qd, DCT_BLOCKWIDTH, DCT_BLOCKWIDTH);
   }
   */
   
   //BlockCopy(raw, qd, 0, 0, DCT_BLOCKWIDTH, DCT_BLOCKWIDTH, 0, 0, DCT_BLOCKWIDTH, DCT_BLOCKWIDTH);
}
Esempio n. 3
0
function run()
{
	set(PLOTNOW);
	NumYears = 1;
	MaxBars = 210;
	PlotScale = 8;
	PlotWidth = 800;
	PlotHeight1 = 350;
	PlotHeight2 = 80;
	vars Price = series(price());
	
// plot Bollinger bands
	BBands(Price,30,2,2,MAType_SMA);
	plot("Bollinger1",rRealUpperBand,BAND1,0x00CC00);
	plot("Bollinger2",rRealLowerBand,BAND2,0xCC00FF00);
	plot("SAR",SAR(0.02,0.02,0.2),DOT,RED);
	ZigZag(Price,20*PIP,5,BLUE);
	
// plot some other indicators	
	plot("ATR (PIP)",ATR(20)/PIP,NEW,RED);
	plot("Doji",CDLDoji(),NEW+BARS,BLUE);
	plot("FractalDim",FractalDimension(Price,30),NEW,RED);
	plot("ShannonGain",ShannonGain(Price,40),NEW,RED);
}
Esempio n. 4
0
static unsigned int Down(unsigned int k) { return ZigZag(Row(k)+1,Column(k)); }
Esempio n. 5
0
static unsigned int UpAndLeft(unsigned int k) { return ZigZag(Row(k)-1,Column(k)-1); }
Esempio n. 6
0
static unsigned int Right(unsigned int k) { return ZigZag(Row(k),Column(k)+1); }
Esempio n. 7
0
static unsigned int Up(unsigned int k) { return ZigZag(Row(k)-1,Column(k)); }
Esempio n. 8
0
static int DecodeDCComponent(WinZipJPEGDecompressor *self,int comp,
const WinZipJPEGBlock *current,const WinZipJPEGBlock *north,const WinZipJPEGBlock *west,
const WinZipJPEGQuantizationTable *quantization)
{
	// Decode DC component. (5.6.7)

	// DC prediction. (5.6.7.1)
	int predicted;
	if(!north&&!west)
	{
		predicted=0;
	}
	else if(!north)
	{
		// NOTE: Spec says west[1]-current[1].
		int t1=west->c[0]*10000-11038*quantization->c[1]*(west->c[1]+current->c[1])/quantization->c[0];
		int p1=((t1<0)?(t1-5000):(t1+5000))/10000;
		predicted=p1;
	}
	else if(!west)
	{
		// NOTE: Spec says north->c[2]-current->c[2].
		int t0=north->c[0]*10000-11038*quantization->c[2]*(north->c[2]+current->c[2])/quantization->c[0];
		int p0=((t0<0)?(t0-5000):(t0+5000))/10000;
		predicted=p0;
	}
	else
	{
		// NOTE: Spec says north[2]-current[2] and west[1]-current[1].
		int t0=north->c[0]*10000-11038*quantization->c[2]*(north->c[2]+current->c[2])/quantization->c[0];
		int p0=((t0<0)?(t0-5000):(t0+5000))/10000;

		int t1=west->c[0]*10000-11038*quantization->c[1]*(west->c[1]+current->c[1])/quantization->c[0];
		int p1=((t1<0)?(t1-5000):(t1+5000))/10000;

		// Prediction refinement. (5.6.7.2)
		int d0=0,d1=0;
		for(int i=1;i<8;i++)
		{
			// Note: Spec says Abs(Abs(north->c[ZigZag(i,0)])-
			// Abs(current->c[ZigZag(i,0)])) and similarly for west.
			d0+=Abs(north->c[ZigZag(i,0)]-current->c[ZigZag(i,0)]);
			d1+=Abs(west->c[ZigZag(0,i)]-current->c[ZigZag(0,i)]);
		}

		if(d0>d1)
		{
			int64_t weight=1LL<<Min(d0-d1,31);
			predicted=(int)((weight*(int64_t)p1+(int64_t)p0)/(1+weight));
		}
		else
		{
			int64_t weight=1LL<<Min(d1-d0,31);
			predicted=(int)((weight*(int64_t)p0+(int64_t)p1)/(1+weight));
		}
	}

	// Decode DC residual. (5.6.7.3)

	// Decode absolute value. (5.6.7.3.1)
	int absvalue;
	int sum=Sum(0,current);
	int valuecontext=Min(Category(sum),12);

	absvalue=DecodeBinarization(&self->decoder,
	self->dcmagnitudebins[comp][valuecontext],
	self->dcremainderbins[comp][valuecontext],
	15,10);
	if(absvalue==0) return predicted;

	// Decode sign. (5.6.7.3.2)
	// NOTE: Spec says north[0]<0 and west[0]<0.
	if(!north) north=&ZeroBlock;
	if(!west) west=&ZeroBlock;
	int northsign=(north->c[0]<predicted);
	int westsign=(west->c[0]<predicted);
	int predictedsign=(predicted<0);

	int sign=NextBitFromWinZipJPEGArithmeticDecoder(&self->decoder,
	&self->dcsignbins[comp][northsign][westsign][predictedsign]);

	if(sign) return predicted-absvalue;
	else return predicted+absvalue;
}
Esempio n. 9
0
static void CompressDCComponent(JPEGCompressor *self,int comp,
const JPEGBlock *current,const JPEGBlock *north,const JPEGBlock *west,
const JPEGQuantizationTable *quantization)
{
	// DC prediction.
	int predicted;
	if(!north&&!west)
	{
		predicted=0;
	}
	else if(!north)
	{
		// NOTE: Spec says west[1]-current[1].
		int t1=west->c[0]*10000-11038*quantization->c[1]*(west->c[1]+current->c[1])/quantization->c[0];
		int p1=((t1<0)?(t1-5000):(t1+5000))/10000;
		predicted=p1;
	}
	else if(!west)
	{
		// NOTE: Spec says north->c[2]-current->c[2].
		int t0=north->c[0]*10000-11038*quantization->c[2]*(north->c[2]+current->c[2])/quantization->c[0];
		int p0=((t0<0)?(t0-5000):(t0+5000))/10000;
		predicted=p0;
	}
	else
	{
		// NOTE: Spec says north[2]-current[2] and west[1]-current[1].
		int t0=north->c[0]*10000-11038*quantization->c[2]*(north->c[2]+current->c[2])/quantization->c[0];
		int p0=((t0<0)?(t0-5000):(t0+5000))/10000;

		int t1=west->c[0]*10000-11038*quantization->c[1]*(west->c[1]+current->c[1])/quantization->c[0];
		int p1=((t1<0)?(t1-5000):(t1+5000))/10000;

		// Prediction refinement. (5.6.7.2)
		int d0=0,d1=0;
		for(int i=1;i<8;i++)
		{
			// Note: Spec says Abs(Abs(north->c[ZigZag(i,0)])-
			// Abs(current->c[ZigZag(i,0)])) and similarly for west.
			d0+=Abs(north->c[ZigZag(i,0)]-current->c[ZigZag(i,0)]);
			d1+=Abs(west->c[ZigZag(0,i)]-current->c[ZigZag(0,i)]);
		}

		if(d0>d1)
		{
			int64_t weight=1LL<<Min(d0-d1,31);
			predicted=(weight*(int64_t)p1+(int64_t)p0)/(1+weight);
		}
		else
		{
			int64_t weight=1LL<<Min(d1-d0,31);
			predicted=(weight*(int64_t)p0+(int64_t)p1)/(1+weight);
		}
	}

	// Compress DC residual.
	int value=current->c[0]-predicted;

	// Compress absolute value.
	int absvalue=Abs(value);
	int sum=Sum(0,current);
	int valuecontext=Min(Category(sum),12);

	WriteUniversalCode(&self->encoder,absvalue,
	self->dcmagnitudebins[comp][valuecontext],
	self->dcmagnitudeshift,
	self->dcremainderbins[comp][valuecontext],
	self->dcremaindershift);
	if(absvalue==0) return;

	// Decode sign.
	// NOTE: Spec says north[0]<0 and west[0]<0.
	if(!north) north=&ZeroBlock;
	if(!west) west=&ZeroBlock;
	int northsign=(north->c[0]<predicted);
	int westsign=(west->c[0]<predicted);
	int predictedsign=(predicted<0);

	WriteDynamicBit(&self->encoder,value<0,
	&self->dcsignbins[comp][northsign][westsign][predictedsign],
	self->dcsignshift);
}
Esempio n. 10
0
static void make_zig_curve(const CCurve& input_curve, double y0, double y)
{
	CCurve curve(input_curve);

	if(rightward_for_zigs)
	{
		if(curve.IsClockwise())
			curve.Reverse();
	}
	else
	{
		if(!curve.IsClockwise())
			curve.Reverse();
	}

    // find a high point to start looking from
	Point top_left;
	int top_left_index;
	bool top_left_found = false;
	Point top_right;
	int top_right_index;
	bool top_right_found = false;
	Point bottom_left;
	int bottom_left_index;
	bool bottom_left_found = false;

	int i =0;
	for(std::list<CVertex>::const_iterator VIt = curve.m_vertices.begin(); VIt != curve.m_vertices.end(); VIt++, i++)
	{
		const CVertex& vertex = *VIt;

		test_y_point(i, vertex.m_p, top_right, top_right_found, top_right_index, y, !rightward_for_zigs);
		test_y_point(i, vertex.m_p, top_left, top_left_found, top_left_index, y, rightward_for_zigs);
		test_y_point(i, vertex.m_p, bottom_left, bottom_left_found, bottom_left_index, y0, rightward_for_zigs);
	}

	int start_index = 0;
	int end_index = 0;
	int zag_end_index = 0;

	if(bottom_left_found)start_index = bottom_left_index;
	else if(top_left_found)start_index = top_left_index;

	if(top_right_found)
	{
		end_index = top_right_index;
		zag_end_index = top_left_index;
	}
	else
	{
		end_index = bottom_left_index;
		zag_end_index =  bottom_left_index;
	}
	if(end_index <= start_index)end_index += (i-1);
	if(zag_end_index <= start_index)zag_end_index += (i-1);

    CCurve zig, zag;
    
    bool zig_started = false;
    bool zig_finished = false;
    bool zag_finished = false;
    
	int v_index = 0;
	for(int i = 0; i < 2; i++)
	{
		// process the curve twice because we don't know where it will start
		if(zag_finished)
			break;
		for(std::list<CVertex>::const_iterator VIt = curve.m_vertices.begin(); VIt != curve.m_vertices.end(); VIt++)
		{
			if(i == 1 && VIt == curve.m_vertices.begin())
			{
				continue;
			}

			const CVertex& vertex = *VIt;

			if(zig_finished)
			{
				zag.m_vertices.push_back(unrotated_vertex(vertex));
				if(v_index == zag_end_index)
				{
					zag_finished = true;
					break;
				}
			}
			else if(zig_started)
			{
				zig.m_vertices.push_back(unrotated_vertex(vertex));
				if(v_index == end_index)
				{
					zig_finished = true;
					if(v_index == zag_end_index)
					{
						zag_finished = true;
						break;
					}
					zag.m_vertices.push_back(unrotated_vertex(vertex));
				}
			}
			else
			{
				if(v_index == start_index)
				{
					zig.m_vertices.push_back(unrotated_vertex(vertex));
					zig_started = true;
				}
			}
			v_index++;
		}
	}
        
    if(zig_finished)
		zigzag_list_for_zigs.push_back(ZigZag(zig, zag));
}
Esempio n. 11
0
//Inserting a node
long int insert(node **root, long int data){
		node *temp;
		node *p =NULL;
		node *x,*y,*z;
		long int flag = 1;
		temp = *root;
		while(temp!=NULL){
			p = temp;
			if(data < temp->data){
				temp = temp->left;
			}
			else{
				temp = temp->right;
			}
		}

		if(p==NULL){
			*root = newNode(data);
			(*root)->parent = NULL;
			return 0;
		}
		temp = newNode(data);
		temp->parent = p;	

		if(p->data >= data){
			p->left = temp;
		}

		else{
			p->right = temp;
		}

//For checking imbalance
		y = temp;
		while(flag && p!=NULL){
			long int l,r;
			if(p->left == NULL){
				l = -1;
				r = p->right->height;
			}
			else if(p->right == NULL){
				r = -1;
				l = p->left->height;
			}

			else{
				l = p->left->height;
				r = p->right->height;
			}
				p->height = l>r?l+1:r+1;
			if(abs(l-r)<2){
				x = y;
				y = p;
				p = p->parent;
			}

			else{
				z = p;
				if( (z->left!=NULL && y->left!=NULL && z->left->data == y->data && y->left->data == x->data) || (z->right!=NULL && y->right!=NULL && z->right->data == y->data && y->right->data == x->data) ){
					ZigZig(root,z,y,x);
					flag = 0;	
				}
				else{
					ZigZag(root,z,y,x);
					flag = 0;
				}
			}
		}
		return 0;

}