コード例 #1
0
    double findMedianSortedArrays(int A[], int m, int B[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function

      if((n+m)%2 ==0)
      {
        return (GetMedian(A,m,B,n, (m+n)/2) + GetMedian(A,m,B,n, (m+n)/2+1))/2.0;
      }
      else
        return GetMedian(A,m,B,n, (m+n)/2+1);
    }
コード例 #2
0
ファイル: TrOccDB.C プロジェクト: krafczyk/AMS
void TrLadOcc::Info(int verbosity) {
  printf("TrLadOcc::Info-V HwId: %03d\n",GetHwId());
  printf("  MedianX: %10.6e   DeviationX: %10.6e\n",GetMedian(0),GetDeviation(0));
  printf("  MedianY: %10.6e   DeviationY: %10.6e\n",GetMedian(1),GetDeviation(1));
  if (verbosity>0) {
    TrLadCal* ladcal = TrCalDB::Head->FindCal_HwId(GetHwId()); // additional infos
    for (int address=0; address<1024; address++) {
      printf("  Address:%4d  Occ.:%8.3f  OccStatus:%4d  Ped.:%8.3f  SigmaRaw:%8.3f  Sigma:%8.3f  Status:%4d\n",
        address,GetOccupancy(address),GetStatus(address),
        ladcal->GetPedestal(address),ladcal->GetSigmaRaw(address),ladcal->GetSigma(address),ladcal->GetStatus(address)
      );
    }
  }
}
コード例 #3
0
	//std::distance, std::next, and GetMedian require the passed iterator to be an InputIterator
	//std::iter_swap requires the passed iterator to be a ForwardIterator
	//std::prev requires the passed iterator to be an BidirectionalIterator
	BidirIt Partition(BidirIt begin, BidirIt end, Compare Comp) {
		size_t length = std::distance(begin,end);
		auto middle = std::next(begin, length/2);

		auto left = std::prev(begin);
		auto right = end;

		//For the pivot, use the median of the begin, right, and middle element
		auto pivotValue = *GetMedian(begin, middle, std::prev(end), Comp);
		while (1) {
			do {
				++left;
			} while (left != right && Comp(*left, pivotValue));

			if (left == right) {
				//The left and right iterators have crossed eachother
				//	everything is now on the correct side of the pivot
				return left;
			}

			do {
				--right;
			} while (left != right && Comp(pivotValue, *right));

			if (left == right) {
				//The left and right iterators have crossed eachother
				//	everything is now on the correct side of the pivot
				return left;
			}
			//Both left and right are on opposite sides
			//	of the pivot that they should be
			std::iter_swap(left,right);
		}
	}
コード例 #4
0
ファイル: TrOccDB.C プロジェクト: krafczyk/AMS
bool TrLadOcc::OccDBToLinear(float* offset) {
  if (!offset) return false;
  int index = 0;
  offset[index++] = (float) GetHwId();
  for (int iside=0; iside<2; iside++) offset[index++] = (float) GetMedian(iside);
  for (int iside=0; iside<2; iside++) offset[index++] = (float) GetDeviation(iside);
  for (int address=0; address<1024; address++) offset[index++] = (float) GetOccupancy(address);
  return true;
}
コード例 #5
0
 double GetMedian(int a[], int n, int b[], int m, int k)
 {
         assert(a && b);
         if (n <= 0) return b[k-1];
         if (m <= 0) return a[k-1];
         if (k <= 1) return min(a[0], b[0]);
         if (b[m/2] >= a[n/2])
         {
              if ((n/2 + 1 + m/2) >= k)
                   return GetMedian(a, n, b, m/2, k);
              else
                  return GetMedian(a + n/2 + 1, n - (n/2 + 1), b, m, k - (n/2 + 1));
         }
         else
         {
              if ((m/2 + 1 + n/2) >= k)
                   return GetMedian( a, n/2,b, m, k);
             else
                   return GetMedian( a, n, b + m/2 + 1, m - (m/2 + 1),k - (m/2 + 1));
         }
   }
コード例 #6
0
static int PointsGrouping(char* box,int buf_width, int buf_height,int* median_X,int* median_Y)
{
	int RedNum = 0;
    int Xmean,Ymean,x,y;
    int* NumsX = (int*)malloc((int)(ROI_width*Scaling*ROI_height*Scaling));
    int* NumsY = (int*)malloc((int)(ROI_width*Scaling*ROI_height*Scaling));
    //掃ROI pixels
    for( y = Start_Y; y< Start_Y+ROI_height*Scaling ;y++)
    {
        for( x = Start_X; x< Start_X+ROI_width*Scaling ;x++)
        {
            if(x>=0 && x<buf_width && y>=0 && y<buf_height && box[x+y*buf_width]==TRUE)
            {
                NumsX[RedNum] = x;
                NumsY[RedNum] = y;
                RedNum++;
            }
        }
    }
     Xmean = GetMedian(RedNum,NumsX);
     Ymean = GetMedian(RedNum,NumsY);
    if(RedNum >= NumOfCandiate_LowerBound)
    {
       *median_X = Xmean;
       *median_Y = Ymean;
	   free(NumsX);
	   free(NumsY);
        return TRUE;
	}
	else
	{
		free(NumsX);
		free(NumsY);
	    return FALSE;
	}
    free(NumsX); 
    free(NumsY);
}
コード例 #7
0
unsigned long long int GDistanceMatrix(value* x, void* ddmVoid) {
	int i;
	unsigned long long int res = 0;
	unsigned long long int initial = 1;
	confDistanceMatrix* ddm = ddmVoid;
	value* x1, *x2;
	x1 = malloc(sizeof(value));
	x2 = malloc(sizeof(value));
	GetIthData(ddm->index, x2);
	for (i = 0; i < dm->k; ++i) {
		GetIthData(i, x1);
		if (ddm->T[i] != ddm->T[i])
			ddm->T[i] = GetMedian(x1, x2);
		initial = HiDistanceMatrix(x, x1, x2, ddm->T[i]);
		res |= initial << i;
	}
	free(x1);
	free(x2);
	return res;
}
コード例 #8
0
ファイル: Temperature.cpp プロジェクト: jlino/brew
void Temperature::measure(boolean ln) {
  if(millis() - _lastTemperatureRead >= _TimeBetweenReadings) {                           //time to measure temperature
    
    /** measure Vout analog sample */
    digitalWrite(_OutputPin_SensorPower, HIGH);      // initialize sensor on
    delay(10);
    _VoutAnalogSample = analogRead(_InputPin_TemperatureReading);     // Get a reading
    digitalWrite(_OutputPin_SensorPower, LOW);      // initialize sensor on

    _lastTemperatureRead            = millis();                                             // Mark time of temperature reading

    _rTemperatureMeasurementsMarker++;                                                                                                                                                   // Position reading buffer marker at the last updated position
    if(_rTemperatureMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rTemperatureMeasurementsMarker = 0;           // Check that it has not gone out of the buffer range
    _rTemperatureMeasurements[_rTemperatureMeasurementsMarker] = _VoutAnalogSample;
    
    //workingSample = GetMedianAverage(_rTemperatureMeasurements, 6);
    float workingSample = GetMedian(_rTemperatureMeasurements);
    /** Calculate temperature value */
    if(_pump) {
        _measuredTemperature = ( workingSample - _b1 ) / _m1;
    } else {
        _measuredTemperature = ( workingSample - _b2 ) / _m2;
    }    

    #ifdef DEBUG
    Serial.print(_name);
    Serial.print(",");
    //Serial.print(_VoutAnalogSample);
    //Serial.print(workingSample);
    Serial.print(_measuredTemperature);
    //Serial.print(GetMedianAverage(_rTemperatureMeasurements, 6));
    Serial.print(",");

    if(ln) Serial.println("");
    #endif
  }
}
コード例 #9
0
ファイル: PT100.cpp プロジェクト: jlino/PT100
void PT100::measure1(boolean ln, boolean rline) {
  if(millis() - _lastTemperatureRead >= _TimeBetweenReadings) {                           //time to measure temperature
    
    /** measure Vout analog sample */
    digitalWrite(_OutputPin_SensorPower, HIGH);      // initialize sensor on
    digitalWrite(_OutputPin_ThirdLinePower, HIGH);      // initialize sensor on
    delay(10);
    _VoutAnalogSample = analogRead(_InputPin_TemperatureReading) + _sampleDeviation;     // Get a reading
    _VoutRAnalogSample = analogRead(_InputPin_ThirdLineReading) + _sampleDeviation;     // Get a reading
    digitalWrite(_OutputPin_SensorPower, LOW);      // initialize sensor on
    digitalWrite(_OutputPin_ThirdLinePower, LOW);      // initialize sensor on

    _lastTemperatureRead            = millis();                                             // Mark time of temperature reading

    _rPT100MeasurementsMarker++;                                                                                                                                                   // Position reading buffer marker at the last updated position
    if(_rPT100MeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rPT100MeasurementsMarker = 0;           // Check that it has not gone out of the buffer range
    _rPT100Measurements[_rPT100MeasurementsMarker] = _VoutAnalogSample;
    float Vout = GetMedian(_rPT100Measurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
    float Rx = _R1 / ( _Vs / Vout - 1.0);

    if(rline) {
        _rLineMeasurementsMarker++;                                                                                                                                                   // Position reading buffer marker at the last updated position
        if(_rLineMeasurementsMarker >= TEMPERATURE_AVERAGE_VALUE_I) _rLineMeasurementsMarker = 0;           // Check that it has not gone out of the buffer range
        _rLineMeasurements[_rLineMeasurementsMarker] = _VoutRAnalogSample;

        /** Calculate temperature value */
        float VoutR = GetMedian(_rLineMeasurements) * _ADCVmax / CONSTANT_ADC_STEP_COUNT;
        float Rline = _R2 / ( _Vs / VoutR - 1.0);
        _measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * (Rx - Rline)));
    }
    else {
        /** Calculate temperature value */
        _measuredTemperature = 1.08271 * pow(10.0, -13.0) * (3.12508 * pow(10.0, 16.0) - 5.65566 * pow(10.0, 6.0) * sqrt(3.51501 * pow(10.0, 19.0) - 4.61805 * pow(10.0, 16.0) * Rx));
    }
    

    //xFilterNoise(_temperatureMeasurementsMarker);
/*
    Serial.print("PT100 : [");
    Serial.print(_name);
    Serial.print("]\tVoutSample: [");
    Serial.print(_VoutAnalogSample);


//    Serial.print("]\tVout[");
//    Serial.print(Vout,6);
//    Serial.print("]\tRx[");
//    Serial.print(Rx,6);

    
    Serial.print("]\tTNow[");
    Serial.print(measuredTemperatureNow,6);
    Serial.print("]\tTCalc[");
    Serial.print(_measuredTemperature,6);
    Serial.println("] ");
*/


    //Serial.print("PT100 : [");
    #ifdef DEBUG
    Serial.print(_name);
    Serial.print(",");
    Serial.print(_VoutAnalogSample);
    Serial.print(",");
    //Serial.print(_VoutRAnalogSample);
    //Serial.print(",");

    /*Serial.print(test);
    Serial.print(",");
    Serial.print(Rtest);
    Serial.print(",");*/
    /*Serial.print(Vout,6);
    Serial.print(",");
    Serial.print(Rx,6);

    
    Serial.print(",");
    Serial.print(measuredTemperatureNow,6);
    Serial.print(",");
    Serial.print(_measuredTemperature,6);
    Serial.print(",");*/
    if(ln) Serial.println("");
    #endif
  }
}
コード例 #10
0
ファイル: UCalcParameter.cpp プロジェクト: gcucho/solanum
//---------------------------------------------------------------------------
void __fastcall TfrmCalcParameter::butGetThermalTimeClick(TObject *Sender)
{
// --------------------------------------------------------------------------
//
//                             THERMAL TIME
//
// --------------------------------------------------------------------------

    int EmergencyDays=edEmDay->Text.ToInt();
    double parameters1,parameters2,parameters3,parameters4;
    parameters1=0.0;
    parameters2=12.0;
    parameters3=24.0;
    parameters4=35.0;
    double b1 = 1.0/(parameters2 - parameters1);
    double a1 = -1.0 * b1 * parameters1;
    double b2 = 1.0/(parameters3 - parameters4);
    double a2 = -1.0 * b2 * parameters4;
    int ndays=159;
    double* tempMin=new double[ndays];
    condTemp->GetColumnDataFromCSVFile("tempSelected.csv","tmin",tempMin);
    double* tempMax=new double[ndays];
    condTemp->GetColumnDataFromCSVFile("tempSelected.csv","tmax",tempMax);
    condTemp->setTmin(tempMin,ndays);
    condTemp->setTmax(tempMax,ndays);
    double minimo=GetMedian(condTemp->MinTemp,condTemp->RecNum);
    double base = 0.0;
    if (minimo > 10.0) base = 2.0;
//    TT <- NULL
//    peso <- NULL
//    day <- NULL
    double Y0 = (condTemp->tminSelected[0] + condTemp->tmaxSelected[0])/2.0;
    double k = 1.0;
    if (Y0 < parameters2) {
        k = a1 + b1 * Y0 ;
    }
    if (Y0 > parameters3) {
        k = a2 + b2 * Y0;
    }
    if (Y0 < parameters1 || Y0 > parameters4) {
        k = 0;
    }
    double* peso=new double[ndays];
    double* TT=new double[ndays];
    int* day=new int[ndays];
    peso[0]= k;
    TT[0]  = peso[0] * (Y0 - base);
    day[0] = EmergencyDays;
    for(int i=1;i<ndays;i++)
    {
        Y0 = (condTemp->tminSelected[i] + condTemp->tmaxSelected[i])/2.0;
        k = 1.0;
        if (Y0 < parameters2) {
            k = a1 + b1 * Y0;
        }
        if (Y0 > parameters3) {
            k = a2 + b2 * Y0;
        }
        if (Y0 < parameters1 || Y0 > parameters4) {
            k = 0.0;
        }
        peso[i] = k;
        TT[i] = TT[i - 1] + peso[i] * (Y0 - base);
        day[i] = day[i - 1] + 1.0;
    }
    delete []peso;
    delete []tempMin;
    delete []tempMax;
// --------------------------------------------------------------------------
//
//                             THERMAL TIME
//
// --------------------------------------------------------------------------
    parameters1=0.0;
    parameters2=12.0;
    parameters3=24.0;
    parameters4=35.0;
    double Wmax = 0.8;
    double cover1p = 32.0;
    int GrowthZero = 160;
// Canopy
    double tm;
    double te=BetaFunction(TT,day,ndays,cover1p,GrowthZero,Wmax,&tm);
    double TIOnset=thermalDAP2(TT,day,tm,ndays);
    double A=0.75;
    double Tu=0.0;
    double b=GompertzFunction(TT,TIOnset,A,GrowthZero,&Tu,day,ndays); // generic
    delete []TT;
    delete []day;
}
コード例 #11
0
void GroupOfPlanes::ExtraDivide(int *out, int flags)
{
    out += 2; // skip full size and validity
	for (int i = nLevelCount - 1; i >= 1; i-- ) // skip all levels up to finest estimated
		out += planes[i]->GetArraySize(0);

    int * inp = out + 1; // finest estimated plane
    out += out[0] + 1; // position for divided sublocks data

    int nBlkY = planes[0]->GetnBlkY();
    int nBlkXN = N_PER_BLOCK*planes[0]->GetnBlkX();
   // 6 stored variables

    int by = 0; // top blocks
        for (int bx = 0; bx<nBlkXN; bx+=N_PER_BLOCK)
        {
            for (int i=0; i<2; i++) // vx, vy
            {
                out[bx*2+i] = inp[bx+i]; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]; // bottom right subblock
            }
            for (int i=2; i<N_PER_BLOCK; i++) // sad, var, luma, ref
            {
                out[bx*2+i] = inp[bx+i]>>2; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]>>2; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]>>2; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]>>2; // bottom right subblock
            }
        }
        out += nBlkXN*4;
        inp += nBlkXN;
    for (by = 1; by<nBlkY-1; by++) // middle blocks
    {
        int bx = 0;
             for (int i=0; i<2; i++)
            {
                out[bx*2+i] = inp[bx+i]; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]; // bottom right subblock
            }
             for (int i=2; i<N_PER_BLOCK; i++)
            {
                out[bx*2+i] = inp[bx+i]>>2; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]>>2; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]>>2; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]>>2; // bottom right subblock
            }
        for (bx = N_PER_BLOCK; bx<nBlkXN-N_PER_BLOCK; bx+=N_PER_BLOCK)
        {
            if (divideExtra==1)
            {
                out[bx*2] = inp[bx]; // top left subblock
                out[bx*2+N_PER_BLOCK] = inp[bx]; // top right subblock
                out[bx*2 + nBlkXN*2] = inp[bx]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2] = inp[bx]; // bottom right subblock
                out[bx*2+1] = inp[bx+1]; // top left subblock
                out[bx*2+N_PER_BLOCK+1] = inp[bx+1]; // top right subblock
                out[bx*2 + nBlkXN*2+1] = inp[bx+1]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+1] = inp[bx+1]; // bottom right subblock
            }
            else // divideExtra=2
            {
                int vx;
                int vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx-N_PER_BLOCK], inp[bx+1-N_PER_BLOCK], inp[bx-nBlkXN], inp[bx+1-nBlkXN]);// top left subblock
                out[bx*2] = vx;
                out[bx*2+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx+N_PER_BLOCK], inp[bx+1+N_PER_BLOCK], inp[bx-nBlkXN], inp[bx+1-nBlkXN]);// top right subblock
                out[bx*2+N_PER_BLOCK] = vx;
                out[bx*2+N_PER_BLOCK+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx-N_PER_BLOCK], inp[bx+1-N_PER_BLOCK], inp[bx+nBlkXN], inp[bx+1+nBlkXN]);// bottom left subblock
                out[bx*2 + nBlkXN*2] = vx;
                out[bx*2 + nBlkXN*2+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx+N_PER_BLOCK], inp[bx+1+N_PER_BLOCK], inp[bx+nBlkXN], inp[bx+1+nBlkXN]);// bottom right subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2] = vx;
                out[bx*2+N_PER_BLOCK + nBlkXN*2+1] = vy;
            }
             for (int i=2; i<N_PER_BLOCK; i++)
            {
                out[bx*2+i] = inp[bx+i]>>2; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]>>2; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]>>2; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]>>2; // bottom right subblock
            }
        }
        bx = nBlkXN - N_PER_BLOCK;
             for (int i=0; i<2; i++)
            {
                out[bx*2+i] = inp[bx+i]; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]; // bottom right subblock
            }
             for (int i=2; i<N_PER_BLOCK; i++)
            {
                out[bx*2+i] = inp[bx+i]>>2; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]>>2; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]>>2; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]>>2; // bottom right subblock
            }
        out += nBlkXN*4;
        inp += nBlkXN;
    }
     by = nBlkY - 1; // bottom blocks
        for (int bx = 0; bx<nBlkXN; bx+=N_PER_BLOCK)
        {
             for (int i=0; i<2; i++)
            {
                out[bx*2+i] = inp[bx+i]; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]; // bottom right subblock
            }
             for (int i=2; i<N_PER_BLOCK; i++)
            {
                out[bx*2+i] = inp[bx+i]>>2; // top left subblock
                out[bx*2+N_PER_BLOCK+i] = inp[bx+i]>>2; // top right subblock
                out[bx*2 + nBlkXN*2+i] = inp[bx+i]>>2; // bottom left subblock
                out[bx*2+N_PER_BLOCK + nBlkXN*2+i] = inp[bx+i]>>2; // bottom right subblock
            }
        }
}
コード例 #12
0
void GroupOfPlanes::ExtraDivide(int *out, int flags)
{
    out += 2; // skip full size and validity
    for (int i = nLevelCount - 1; i >= 1; --i ) // skip all levels up to finest estimated
        out += planes[i]->GetArraySize(0);

    int * inp = out + 1; // finest estimated plane
    out += out[0] + 1; // position for divided sublocks data

    int nBlkY = planes[0]->GetnBlkY();
    int const ArrayElem=PlaneOfBlocks::ARRAY_ELEMENTS;
    int nBlkXAE = PlaneOfBlocks::ARRAY_ELEMENTS*planes[0]->GetnBlkX();
   // ARRAY_ELEMENTS stored variables

    int by = 0; // top blocks
    for (int bx = 0; bx<nBlkXAE; bx+=ArrayElem) {
        for (int i=0; i<2; ++i) // vx, vy
        {
            out[bx*2+i] = inp[bx+i]; // top left subblock
            out[bx*2+ArrayElem+i] = inp[bx+i]; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = inp[bx+i]; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = inp[bx+i]; // bottom right subblock
        }
        for (int i=2; i<ArrayElem; ++i) // sads, var, luma, ref
        {
            out[bx*2+i] = (inp[bx+i]+2)>>2; // top left subblock
            out[bx*2+ArrayElem+i] = (inp[bx+i]+2)>>2; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom right subblock
        }
    }
    out += nBlkXAE*4;
    inp += nBlkXAE;
    for (by = 1; by<nBlkY-1; ++by) // middle blocks
    {
        int bx = 0;
        for (int i=0; i<2; ++i) {
            out[bx*2+i] = inp[bx+i]; // top left subblock
            out[bx*2+ArrayElem+i] = inp[bx+i]; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = inp[bx+i]; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = inp[bx+i]; // bottom right subblock
        }
        for (int i=2; i<ArrayElem; ++i) { // sads, var, luma, ref
            out[bx*2+i] = (inp[bx+i]+2)>>2; // top left subblock
            out[bx*2+ArrayElem+i] = (inp[bx+i]+2)>>2; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom right subblock
        }
        for (bx = ArrayElem; bx<nBlkXAE-ArrayElem; bx+=ArrayElem) {
            if (divideExtra==1) {
                out[bx*2] = inp[bx]; // top left subblock
                out[bx*2+ArrayElem] = inp[bx]; // top right subblock
                out[bx*2 + nBlkXAE*2] = inp[bx]; // bottom left subblock
                out[bx*2+ArrayElem + nBlkXAE*2] = inp[bx]; // bottom right subblock
                out[bx*2+1] = inp[bx+1]; // top left subblock
                out[bx*2+ArrayElem+1] = inp[bx+1]; // top right subblock
                out[bx*2 + nBlkXAE*2+1] = inp[bx+1]; // bottom left subblock
                out[bx*2+ArrayElem + nBlkXAE*2+1] = inp[bx+1]; // bottom right subblock
            }
            else // divideExtra=2
            {
                int vx;
                int vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx-ArrayElem], inp[bx+1-ArrayElem], inp[bx-nBlkXAE], inp[bx+1-nBlkXAE]);// top left subblock
                out[bx*2] = vx;
                out[bx*2+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx+ArrayElem], inp[bx+1+ArrayElem], inp[bx-nBlkXAE], inp[bx+1-nBlkXAE]);// top right subblock
                out[bx*2+ArrayElem] = vx;
                out[bx*2+ArrayElem+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx-ArrayElem], inp[bx+1-ArrayElem], inp[bx+nBlkXAE], inp[bx+1+nBlkXAE]);// bottom left subblock
                out[bx*2 + nBlkXAE*2] = vx;
                out[bx*2 + nBlkXAE*2+1] = vy;
                GetMedian(&vx, &vy, inp[bx], inp[bx+1], inp[bx+ArrayElem], inp[bx+1+ArrayElem], inp[bx+nBlkXAE], inp[bx+1+nBlkXAE]);// bottom right subblock
                out[bx*2+ArrayElem + nBlkXAE*2] = vx;
                out[bx*2+ArrayElem + nBlkXAE*2+1] = vy;
            }
            for (int i=2; i<ArrayElem; ++i) { // sads, var, luma, ref
                out[bx*2+i] = (inp[bx+i]+2)>>2; // top left subblock
                out[bx*2+ArrayElem+i] = (inp[bx+i]+2)>>2; // top right subblock
                out[bx*2 + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom left subblock
                out[bx*2+ArrayElem + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom right subblock
            }
        }
        bx = nBlkXAE - ArrayElem;
        for (int i=0; i<2; ++i) {
            out[bx*2+i] = inp[bx+i]; // top left subblock
            out[bx*2+ArrayElem+i] = inp[bx+i]; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = inp[bx+i]; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = inp[bx+i]; // bottom right subblock
        }
        for (int i=2; i<ArrayElem; ++i) { // sads, var, luma, ref
            out[bx*2+i] = (inp[bx+i]+2)>>2; // top left subblock
            out[bx*2+ArrayElem+i] = (inp[bx+i]+2)>>2; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom right subblock
        }
        out += nBlkXAE*4;
        inp += nBlkXAE;
    }
    by = nBlkY - 1; // bottom blocks
    for (int bx = 0; bx<nBlkXAE; bx+=ArrayElem) {
        for (int i=0; i<2; ++i) {
            out[bx*2+i] = inp[bx+i]; // top left subblock
            out[bx*2+ArrayElem+i] = inp[bx+i]; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = inp[bx+i]; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = inp[bx+i]; // bottom right subblock
        }
        for (int i=2; i<ArrayElem; ++i) { // sads, var, luma, ref
            out[bx*2+i] = (inp[bx+i]+2)>>2; // top left subblock
            out[bx*2+ArrayElem+i] = (inp[bx+i]+2)>>2; // top right subblock
            out[bx*2 + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom left subblock
            out[bx*2+ArrayElem + nBlkXAE*2+i] = (inp[bx+i]+2)>>2; // bottom right subblock
        }
    }
}
コード例 #13
0
ファイル: Algo.cpp プロジェクト: manishs747/Projects
//merge sort method for differnt sizraray
int GetMedianSD(int *A1,int * A2, int m,int n )
{ return GetMedian(A1, A2,(n+m)/2);}