uint8_t decoderFF::clonePic (AVFrame * src, ADMImage * out)
{
  uint32_t    u,v;
  ADM_assert(out->_isRef);
  out->_planes[0] = (uint8_t *) src->data[0];
  out->_planeStride[0] = src->linesize[0];
  if (_swapUV)
    {
      u = 1;
      v = 2;
    }
  else
    {
      u = 2;
      v = 1;
    }
  out->_planes[1] = (uint8_t *) src->data[u];
  out->_planeStride[1] = src->linesize[u];

  out->_planes[2] = (uint8_t *) src->data[v];
  out->_planeStride[2] = src->linesize[v];

  _lastQ = 0;			//_context->quality;
  out->_Qp = (src->quality * 32) / FF_LAMBDA_MAX;
  out->flags = frameType ();

  // Quant ?
  if (src->qstride && src->qscale_table && codecId != CODEC_ID_H264)
    {
      out->quant = (uint8_t *) src->qscale_table;
      out->_qStride = src->qstride;
      out->_qSize = (_w + 15) >> 4;
      out->_qSize *= (_h + 15) >> 4;	// FixME?
    }
void ffmpegEncoder::postAmble (ADMBitstream * out, uint32_t sz)
{
  out->ptsFrame = _context->coded_frame->display_picture_number; //real_pict_num;;
 //printf("Out : %u\n",out->ptsFrame);
  out->len = (uint32_t) sz;
  out->flags = frameType ();;
  if(!_context->coded_frame->quality)
      out->out_quantizer=(int) floor (_frame.quality / (float) FF_QP2LAMBDA);
  else
      out->out_quantizer =(int) floor (_context->coded_frame->quality / (float) FF_QP2LAMBDA);

}
uint8_t     decoderFF::uncompress(uint8_t *in,uint8_t *out,uint32_t len,uint32_t *flagz)

{
 int got_picture=0;
 uint8_t *oBuff[3];
 int strideTab[3];
 int strideTab2[3];
 int ret=0;


		if(len==0 && !_allowNull) // Null frame, silently skipped
				{
            				if(flagz) *flagz=AVI_KEY_FRAME;
              				printf("\n ff4: null frame\n");
					return 1;
				}

		ret= avcodec_decode_video(_context,&_frame,&got_picture, in, len);
		
		if(0>ret && !_context->hurry_up)
		{
					printf("\n error in FFMP43/mpeg4!\n");
					return 0;
		}
		if(!got_picture && !_context->hurry_up)
		{
				// Some encoder code a vop header with the 
				// vop flag set to 0
				// it is meant to mean frame skipped but very dubious
				if(len<8)
					{
						printf("Probably pseudo black frame...\n");
						return 1;
					}
				// allow null means we allow null frame in and so potentially
				// have no frame out for a time
				// in that case silently fill with black and returns it as KF
				if(_allowNull)
				{
					if(flagz) *flagz=AVI_KEY_FRAME;
					memset(out,0,_w*_h);
					memset(out+_w*_h,128,(_w*_h)>>1);
					printf("\n ignoring got pict ==0\n");
					return 1;

				}
					printf("\n error in FFMP43/mpeg4!: got picture \n");
					//GUI_Alert("Please retry with misc->Turbo off");
					//return 1;
					return 0;			 			
		}		  
		if(_context->hurry_up)
		{
			if(flagz)
			{
			*flagz=frameType();
			}
 			return 1;
		}
		// convert ffmpeg to our format : yv12
		uint8_t **src;
		uint32_t stridex[3];
		uint8_t  *inx[3];


		switch(_context->pix_fmt)
		{
		case PIX_FMT_YUV411P:
			stridex[0]=	_frame.linesize[0 ];
			stridex[1]=	_frame.linesize[1 ];
			stridex[2]=	_frame.linesize[2 ];

			inx[0]=_frame.data[0];
			inx[1]=_frame.data[1];
			inx[2]=_frame.data[2];


			COL_411_YV12(inx,stridex,_internalBuffer,_w,_h);

			oBuff[0]=_internalBuffer;
		 	oBuff[1]=_internalBuffer+_w*_h;
 		 	oBuff[2]=oBuff[1]+((_w*_h)>>2);
			src= (uint8_t **)oBuff;
			_frame.linesize[0 ]=_w;
			_frame.linesize[1 ]=_w>>1;
			_frame.linesize[2 ]=_w>>1;

			break;

		case PIX_FMT_YUV422P:
			stridex[0]=	_frame.linesize[0 ];
			stridex[1]=	_frame.linesize[1 ];
			stridex[2]=	_frame.linesize[2 ];

			inx[0]=_frame.data[0];
			inx[1]=_frame.data[1];
			inx[2]=_frame.data[2];

			
			COL_422_YV12(inx,stridex,_internalBuffer,_w,_h);

			oBuff[0]=_internalBuffer;
		 	oBuff[1]=_internalBuffer+_w*_h;
 		 	oBuff[2]=oBuff[1]+((_w*_h)>>2);
			src= (uint8_t **)oBuff;
			_frame.linesize[0 ]=_w;
			_frame.linesize[1 ]=_w>>1;
			_frame.linesize[2 ]=_w>>1;
			break;
		default:

		// Default is YV12 or I420
		// In that case depending on swap u/v
		// we do it or not

				src= (uint8_t **) _frame.data;
#ifndef ADM_BIG_ENDIAN_ZZ
			if(_postproc.postProcType && _postproc.postProcStrength)
			{ 	// we do postproc !
				// keep

		 				oBuff[0]=_internalBuffer;
		 				oBuff[1]=_internalBuffer+_frame.linesize[0]*_h;
 		 				oBuff[2]=oBuff[1]+((_frame.linesize[1]*_h)>>1);
        			for(uint32_t s=0;s<3;s++)
	          		{
			            strideTab[s]=strideTab2[s]=_frame.linesize[s];
            			}
		 		   pp_postprocess(
		      			_frame.data,
		        		strideTab,
		          		oBuff,
		         		strideTab2,
		      			_w,
		        		_h,
		          		_frame.qscale_table,
		          		_frame.qstride,
		         		_postproc.ppMode,
		          		_postproc.ppContext,
		          		_frame.pict_type);
			  	src= (uint8_t **)oBuff;
			}
#endif
			break;
		}
void MyPlugin2SelectionObserver::HandleSelectionChanged(const ISelectionMessage* selectionMessage)
{
	// get selection manager for active selection.
	ISelectionManager* iSelectionManager = Utils<ISelectionUtils>()->GetActiveSelection();
	return;
	//get pointer to textSelectionSuite using selection manager OR fCurrentSelection.
	InterfacePtr<ITextSelectionSuite> iTextSelectionSuite(iSelectionManager, UseDefaultIID());
	CAlert::InformationAlert("Selection** changed..");
	if (iTextSelectionSuite) {
		//get pointer to integrator target text using textSelectionSuite.
		//Use to  Return a list of interfaces from the "concrete selection"
		InterfacePtr<const IIntegratorTarget> iIntegratorTarget_text(iTextSelectionSuite, UseDefaultIID());
		if (iIntegratorTarget_text == nil)
			return;
		RangeData rangeData(0, RangeData::kLeanForward);
		UIDRef textRef;
		PMString tagName;
		PMString childCountString = "xml child count-";
		PMString tagUIDString = "UID of TAG -";
		UID tagUID;
		TextIndex startPosXML = 0, endPosXML = 0;
		int startIndexSelection;
		int endIndexSelection;
		// Return a list of interfaces from the "concrete selection"
		//auto_ptr automatically makes clean up of objects.
		std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_text(iIntegratorTarget_text->GetTarget(ITextTarget::kDefaultIID));
		for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_text->size(); i++)
		{
			//Get target text.
			ITextTarget* target = (ITextTarget*)selectionSuites_text->at(i).get();
			if (!target)
				continue;
			// extract range from target text.
			rangeData = target->GetRange();
			
			// get start and end index of range selected.
			 startIndexSelection = rangeData.Start(nil);
			 endIndexSelection = rangeData.End();
		

			// get text model for target text.
			InterfacePtr<ITextModel>textModel(target->QueryTextModel());
			
			// get UIDRef of text model.
			textRef	= target->GetTextModel();

			// query xml reference data for text model.
			IXMLReferenceData *xmlReferenceData = Utils<IXMLUtils>()->QueryXMLReferenceData(textRef);
			if (xmlReferenceData)
			{
				// get xml reference from xml reference data.
				XMLReference xmlRef = xmlReferenceData->GetReference();
			
				// obtain xml element from xml reference
				InterfacePtr<IIDXMLElement> xmlElement(xmlRef.Instantiate());
				if (xmlElement != nil) {
					childCountString.AppendNumber(xmlElement->GetChildCount());
					XMLReference childRef = xmlElement->GetNthChild(0);
					InterfacePtr<IIDXMLElement> childXMLElement(childRef.Instantiate());
					if (childXMLElement != nil){
						tagUID = childXMLElement->GetTagUID();
						tagName = childXMLElement->GetTagString();
						Utils<IXMLUtils>()->GetElementMarkerPositions(childXMLElement, &startPosXML, &endPosXML);
					}
		    	}

			}
							
		} // for end
		int length = rangeData.Length();
		if (length >= 1) {
			PMString textFrameContentLength = "selected content length-";
			textFrameContentLength.AppendNumber(length);
			PMString srtPosString = "Start Position XML tag-";
			PMString endPosString = "End postion XML tag-";
			PMString srtPosSelString = "Start Position of Selection-";
			PMString endPosSelString = "End postion Selection-";
			srtPosString.AppendNumber(startPosXML);
			endPosString.AppendNumber(endPosXML);
			srtPosSelString.AppendNumber(startIndexSelection);
			endPosSelString.AppendNumber(endIndexSelection);
			CAlert::InformationAlert(textFrameContentLength);
			CAlert::InformationAlert(childCountString);
			CAlert::InformationAlert(tagName);
			CAlert::InformationAlert(srtPosString);
			CAlert::InformationAlert(endPosString);
			CAlert::InformationAlert(srtPosSelString);
			CAlert::InformationAlert(endPosSelString);

			if (startPosXML <= startIndexSelection && endPosXML >= endIndexSelection) {
				CAlert::InformationAlert("Selection inside tag- "+tagName);
			}
			else
			{
				CAlert::WarningAlert("Selection not inside tag- " + tagName);
			}
		}
	}
	// --------:: Table selection ::---------
	InterfacePtr<ITableSelectionSuite> iTableSelectionSuite(fCurrentSelection, UseDefaultIID());
	if (iTableSelectionSuite == nil)
		return;

	InterfacePtr<const IIntegratorTarget> iIntegratorTarget_table(iTableSelectionSuite, UseDefaultIID());
	if (iIntegratorTarget_table == nil)
		return;

	UIDRef 	tableUIDRef;
	GridArea tableGridArea;
	PMString PMRowCount = "Total no of rows-";
	PMString PMColCount = "Total no of cols-";
	std::auto_ptr<IIntegratorTarget::TargetSuiteCollection> selectionSuites_table(iIntegratorTarget_table->GetTarget(ITableTarget::kDefaultIID));
	for (IIntegratorTarget::TargetSuiteCollection::size_type i = 0; i < selectionSuites_table->size(); i++)
	{
		ITableTarget* target = (ITableTarget*)selectionSuites_table->at(i).get();
		if (!target)
			continue;
		tableUIDRef = target->GetModel();
		if (tableUIDRef != UIDRef(nil, kInvalidUID))
		{
			CAlert::WarningAlert("Table selection occured");
			tableGridArea = target->GetRange();
		}
		InterfacePtr<ITableModel>tableModel(target->QueryModel());
		if (tableModel != nil) {
			RowRange totalRows = tableModel->GetTotalRows();
			ColRange totalCols = tableModel->GetTotalCols();
			int rowCount = totalRows.count;
			int colCount = totalCols.count;
			PMRowCount.AppendNumber(rowCount);
			PMColCount.AppendNumber(colCount);
			CAlert::InformationAlert(PMRowCount);
			CAlert::InformationAlert(PMColCount);

			InterfacePtr<ITableLayout> tableLayout(tableModel, UseDefaultIID());
			if (tableLayout == nil) {
				break;
			}
			CAlert::InformationAlert("table layout present");
			ITableLayout::frame_iterator frameIter = tableLayout->begin_frame_iterator();
			CAlert::InformationAlert("Frame Iterator ppresent");
			
			CAlert::InformationAlert("Frame Iterator present");
			
			InterfacePtr<ITableFrame> tableFrame(frameIter->QueryFrame());
			CAlert::InformationAlert("table frame ppresent");
			if (tableFrame == nil){
				break;
			}
			CAlert::InformationAlert("table frame present");
			UIDRef tableContainerUIDRef = tableFrame->GetFrameRef();
			if (tableContainerUIDRef == nil){
				break;
			}
			CAlert::InformationAlert("table container UIDRef present");
			InterfacePtr<IFrameType> frameType(tableContainerUIDRef, UseDefaultIID());
			//if (frameType == nil) {
				//break;
			//}
			CAlert::InformationAlert("container frame present");
			PMString textFrameType = "Is container , text frame-";   // TYPE OF TEXT FRAME
			
		//	bool isTextFrame = frameType->IsTextFrame();
			CAlert::InformationAlert("Is text frame success");

			if (true) {
				textFrameType.Append("YES");
				CAlert::InformationAlert(textFrameType);
			}
			else {
				textFrameType.Append("NO");
				CAlert::InformationAlert(textFrameType);
			}
		}
	}
	
};