Esempio n. 1
0
// Initialize the console.
void CConsole::Initialize(const CTFileName &fnmLog, INDEX ctCharsPerLine, INDEX ctLines)
{
  con_csConsole.cs_iIndex = -1;
  // synchronize access to console
  CTSingleLock slConsole(&con_csConsole, TRUE);

  // allocate the buffer
  con_ctCharsPerLine = ctCharsPerLine;
  con_ctLines        = ctLines;
  con_ctLinesPrinted = 0;
  // note: we add +1 for '\n' perline and +1 '\0' at the end of buffer
  con_strBuffer = (char *)AllocMemory((ctCharsPerLine+2)*ctLines+1);
  con_strLineBuffer = (char *)AllocMemory(ctCharsPerLine+2); // includes '\n' and '\0'
  con_atmLines = (TIME*)AllocMemory((ctLines+1)*sizeof(TIME));
  // make it empty
  for(INDEX iLine=0; iLine<ctLines; iLine++) {
    ClearLine(iLine);
  }
  // add string terminator at the end
  con_strBuffer[(ctCharsPerLine+1)*ctLines] = 0;

  // start printing in last line
  con_strLastLine = con_strBuffer+(ctCharsPerLine+1)*(ctLines-1);
  con_strCurrent = con_strLastLine;

//안태훈 수정 시작	//(Block Log)(0.1)
  //CreateLogFile(fnmLog);	//로그파일 생성을 막는다.
//안태훈 수정 끝	//(Block Log)(0.1)

  // print one dummy line on start
  CPrintF("\n");
}
Esempio n. 2
0
void AACQuantizeInit(CoderInfo *coderInfo, unsigned int numChannels,
		     AACQuantCfg *aacquantCfg)
{
    unsigned int channel, i;

    aacquantCfg->pow43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));
    aacquantCfg->adj43 = (double*)AllocMemory(PRECALC_SIZE*sizeof(double));

    aacquantCfg->pow43[0] = 0.0;
    for(i=1;i<PRECALC_SIZE;i++)
        aacquantCfg->pow43[i] = pow((double)i, 4.0/3.0);

#if TAKEHIRO_IEEE754_HACK
    aacquantCfg->adj43[0] = 0.0;
    for (i = 1; i < PRECALC_SIZE; i++)
      aacquantCfg->adj43[i] = i - 0.5 - pow(0.5 * (aacquantCfg->pow43[i - 1] + aacquantCfg->pow43[i]),0.75);
#else // !TAKEHIRO_IEEE754_HACK
    for (i = 0; i < PRECALC_SIZE-1; i++)
        aacquantCfg->adj43[i] = (i + 1) - pow(0.5 * (aacquantCfg->pow43[i] + aacquantCfg->pow43[i + 1]), 0.75);
    aacquantCfg->adj43[i] = 0.5;
#endif

    for (channel = 0; channel < numChannels; channel++) {
        coderInfo[channel].requantFreq = (double*)AllocMemory(BLOCK_LEN_LONG*sizeof(double));
    }
}
Esempio n. 3
0
char *GetCurrentWorkingDirectory (void)
{
	long buffer_length = 128;
	char *buffer_s = (char *) AllocMemory (buffer_length);
	char *path_s = NULL;

	while (!path_s && buffer_s)
		{
			path_s = getcwd (buffer_s, buffer_length);

			if (!path_s)
				{
					FreeMemory (buffer_s);

					if (errno == ERANGE)
						{
							buffer_length <<= 1;
							buffer_s = (char *) AllocMemory (buffer_length);
						}
					else
						{
							buffer_s = NULL;
						}
				}
		}

	return path_s;
}
Esempio n. 4
0
void
ComputeDTWHammingDistance(VG_RAM_WNN *vg_ram_wnn, DATA_SET *testing_set, double *accumulated_cost, int *step_list, int step_list_size)
{
	int data_size = vg_ram_wnn->memory_size;
	int query_size = testing_set->num_samples;
	int number_of_neurons = vg_ram_wnn->number_of_neurons;
	int memory_bit_group_size = vg_ram_wnn->memory_bit_group_size;

	int *query = (int *) AllocMemory((size_t) number_of_neurons * query_size * (memory_bit_group_size + 1) * sizeof(int));
	int *neuron_cost = (int *) AllocMemory((size_t) number_of_neurons * data_size * query_size * sizeof(int));
	double *mean_cost = (double *) AllocMemory((size_t) data_size * query_size * sizeof(double));

	BuildBitPatternForQuery(vg_ram_wnn, testing_set, query);

	ComputeLocalCostForNeurons(vg_ram_wnn, query, query_size, neuron_cost);
//	SaveLocalCostMatrix(neuron_cost, number_of_neurons, query_size, data_size);

	ComputeMeanCostForNeurons(neuron_cost, query_size, data_size, number_of_neurons, mean_cost);
//	SaveMeanCostMatrix(mean_cost, query_size, data_size);

	ComputeAccumulatedCost(mean_cost, query_size, data_size, step_list, step_list_size, accumulated_cost);
//	SaveAccumCostMatrix(accumulated_cost, query_size, data_size);

	free(query);
	free(mean_cost);
	free(neuron_cost);
}
Esempio n. 5
0
File: ltp.c Progetto: Arcen/faac
void LtpInit(faacEncStruct* hEncoder)
{
    int i;
    unsigned int channel;

    for (channel = 0; channel < hEncoder->numChannels; channel++) {
        LtpInfo *ltpInfo = &(hEncoder->coderInfo[channel].ltpInfo);

        ltpInfo->buffer = AllocMemory(NOK_LT_BLEN * sizeof(double));
        ltpInfo->mdct_predicted = AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));
        ltpInfo->time_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));
        ltpInfo->ltp_overlap_buffer = AllocMemory(BLOCK_LEN_LONG*sizeof(double));

        for (i = 0; i < NOK_LT_BLEN; i++)
            ltpInfo->buffer[i] = 0;

        ltpInfo->weight_idx = 0;
        for(i = 0; i < MAX_SHORT_WINDOWS; i++)
            ltpInfo->sbk_prediction_used[i] = ltpInfo->delay[i] = 0;

        for(i = 0; i < MAX_SCFAC_BANDS; i++)
            ltpInfo->sfb_prediction_used[i] = 0;

        ltpInfo->side_info = LEN_LTP_DATA_PRESENT;

        for(i = 0; i < 2 * BLOCK_LEN_LONG; i++)
            ltpInfo->mdct_predicted[i] = 0.0;

	}
}
Esempio n. 6
0
// make a difference file from two saved games
void DIFF_Diff_t(CTStream *pstrmOld, CTStream *pstrmNew, CTStream *pstrmDiff)
{
  try {
    CTimerValue tv0 = _pTimer->GetHighPrecisionTimer();

    _slSizeOld = pstrmOld->GetStreamSize()-pstrmOld->GetPos_t();
    _pubOld = (UBYTE*)AllocMemory(_slSizeOld);
    pstrmOld->Read_t(_pubOld, _slSizeOld);

    _slSizeNew = pstrmNew->GetStreamSize()-pstrmNew->GetPos_t();
    _pubNew = (UBYTE*)AllocMemory(_slSizeNew);
    pstrmNew->Read_t(_pubNew, _slSizeNew);

    CRC_Start(_ulCRC);
    CRC_AddBlock(_ulCRC, _pubNew, _slSizeNew);
    CRC_Finish(_ulCRC);

    _pstrmOut = pstrmDiff;

    MakeDiff_t();

    CTimerValue tv1 = _pTimer->GetHighPrecisionTimer();
    //CPrintF("diff encoded in %.2gs\n", (tv1-tv0).GetSeconds());

    Cleanup();

  } catch (char *) {
    Cleanup();
    throw;
  }
}
Esempio n. 7
0
// make a new saved game from difference file and old saved game
void DIFF_Undiff_t(CTStream *pstrmOld, CTStream *pstrmDiff, CTStream *pstrmNew)
{
  try {
    CTimerValue tv0 = _pTimer->GetHighPrecisionTimer();

    _slSizeOld = pstrmOld->GetStreamSize()-pstrmOld->GetPos_t();
    _pubOld = (UBYTE*)AllocMemory(_slSizeOld);
    pstrmOld->Read_t(_pubOld, _slSizeOld);

    _slSizeNew = pstrmDiff->GetStreamSize()-pstrmDiff->GetPos_t();
    _pubNew = (UBYTE*)AllocMemory(_slSizeNew);
    pstrmDiff->Read_t(_pubNew, _slSizeNew);

    _pstrmOut = pstrmNew;

    UnDiff_t();

    CTimerValue tv1 = _pTimer->GetHighPrecisionTimer();
    //CPrintF("diff decoded in %.2gs\n", (tv1-tv0).GetSeconds());

    Cleanup();

  } catch (char *) {
    Cleanup();
    throw;
  }
}
Esempio n. 8
0
bool	IndexBitConnector::Load(char *fileName)
{
	IndexBitConnectorHeader	h;
	while (true)
	{
		if (CacheFileName.Set(fileName)==false)
			break;
		if (OpeanCacheFile(fileName,CACHE_SIG_NAME,&h,sizeof(h))==false)
			break;
		if (Data!=NULL)
			delete Data;
		if (Indexes!=NULL)
			delete Indexes;
		Data = NULL;
		Indexes = NULL;
		MemToAlloc = h.MemToAlloc;
		Method = h.Flags; 
	
		if (CacheMemory!=0)
		{
			notifier->Info("[%s] -> Using %d bytes for cache",ObjectName,CacheMemory);
			if (AllocMemory(CacheMemory)==false)
			{
				notifier->Error("[%s] -> Unable to allocate space for cache memory (%d)",ObjectName,CacheMemory);
				break;
			}
			if (file.SetFilePos((UInt64)sizeof(h)+(UInt64)MemToAlloc)==false)
				break;			
		} else {
			if (AllocMemory(h.MemToAlloc)==false)
			{
				notifier->Error("[%s] -> Unable to allocate space for cache initialization",ObjectName);
				break;
			}
			if (file.Read(Data,MemToAlloc)==false)
				break;
		}
		if (file.Read(Indexes,sizeof(UInt64)*((UInt64)nrRecords))==false)
			break;
		if (file.Read(Labels.GetData(),Labels.GetAllocated())==false)
			break;
		if (LoadRecordHashesAndFeatureNames(&h)==false)
			break;
		CloseCacheFile();
		if (CacheMemory!=0)
		{
			dataMemorySize = (UInt64)nrRecords * sizeof(UInt64) + CacheMemory+Labels.GetAllocated();
		} else {
			dataMemorySize = (UInt64)nrRecords * sizeof(UInt64) + MemToAlloc+Labels.GetAllocated();
		}		
		return true;		
	}
	ClearColumnIndexes();
	CloseCacheFile();
	CacheFileName.Set("");
	notifier->Error("[%s] -> Error read data from %s",ObjectName,fileName);
	return false;
}
Esempio n. 9
0
static void GenerateFont(void)
{
  if(!_bInitialized) return;
  try {
    _iiFont.Clear();
    _iiGrid.Clear();

    _iiFont.ii_Width = GetIntFromControl(ICB_TEX_WIDTH);
    _iiFont.ii_Height = GetIntFromControl(ICB_TEX_HEIGHT);
    _iiFont.ii_BitsPerPixel = 32;

    _iiGrid.ii_Width = _iiFont.ii_Width;
    _iiGrid.ii_Height = _iiFont.ii_Height;
    _iiGrid.ii_BitsPerPixel = _iiFont.ii_BitsPerPixel;

    SLONG slSize = _iiFont.ii_Width*_iiFont.ii_Height * _iiFont.ii_BitsPerPixel/8;
    _iiFont.ii_Picture = (UBYTE*)AllocMemory(slSize);
    _iiGrid.ii_Picture = (UBYTE*)AllocMemory(slSize);

    memset(_iiFont.ii_Picture,0,slSize);
    memset(_iiGrid.ii_Picture,0,slSize);

    CTString strFontName = GetFontName();
    if(strFontName.Length() == 0) {
      throw("No font selected");
    }


    ULONG ulFlags = GetFontFlags();
    INDEX iFontSize = GetIntFromControl(IEC_FONT_SIZE);
    INDEX iFirstChar = GetIntFromControl(IEC_FIRST_CHAR);
    INDEX iLastChar = GetIntFromControl(IEC_LAST_CHAR);
    INDEX iAlignH  = GetComboIndex(IDC_ALIGN_H);
    INDEX iAlignV  = GetComboIndex(IDC_ALIGN_V);
    INDEX iPaddingX = GetIntFromControl(IEC_PADDINGX);
    INDEX iPaddingY = GetIntFromControl(IEC_PADDINGY);
    INDEX iWidthAdd = GetIntFromControl(IEC_WIDTH_ADD);
    INDEX iHeightAdd = GetIntFromControl(IEC_HEIGHT_ADD);
    INDEX ctShadows = GetIntFromControl(IEC_SHADOW_PASSES);
    
    if(ulFlags&FNT_HAS_SHADOW) {
      iPaddingX+=ctShadows;
      iPaddingY+=ctShadows;
      iWidthAdd+=ctShadows;
      iHeightAdd+=ctShadows;
    }

    _pfdCurrentFont = NULL;
    GenerateFont_t(_fdFont,_iiFont,_iiGrid,strFontName,iFontSize,iLastChar,iFirstChar,iAlignH,iAlignV,iPaddingX,iPaddingY,iWidthAdd,iHeightAdd,ulFlags,ctShadows);
    _pfdCurrentFont = &_fdFont;

    RefreshCanvas();
  } catch (char *strErr) {
    MessageBox(_hWnd,strErr,0,0);
  }
}
Esempio n. 10
0
void fft_initialize( FFT_Tables *fft_tables )
{
	int i;
	fft_tables->costbl		= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->costbl[0] ) );
	fft_tables->negsintbl	= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->negsintbl[0] ) );
	fft_tables->reordertbl	= AllocMemory( (MAXLOGM+1) * sizeof( fft_tables->reordertbl[0] ) );
	
	for( i = 0; i< MAXLOGM+1; i++ )
	{
		fft_tables->costbl[i]		= NULL;
		fft_tables->negsintbl[i]	= NULL;
		fft_tables->reordertbl[i]	= NULL;
	}
}
Esempio n. 11
0
// ---------------------------------------------------------------------
void DIBitmap::Create(
	SInt32 sizeX,		//!< horizontal size
	SInt32 sizeY		//!< vertical size
)
{
	if (NULL != bitmapInfo)
	{
		FreeMemory(bitmapInfo);
		bitmapInfo = NULL;
	}
	if (NULL != bits)
	{
		FreeMemory(bits);
		bits = NULL;
	}

	// allocates buffers for the header
	bitmapInfo = reinterpret_cast<BITMAPINFO*>(AllocMemory(sizeof(BITMAPINFO)));
	if (NULL == bitmapInfo)
	{
		MemoryException::Throw();
	}

	// sets header information
	BITMAPINFOHEADER* biP = &(bitmapInfo->bmiHeader);

	biP->biSize = sizeof(BITMAPINFOHEADER);
	biP->biWidth = sizeX;
	biP->biHeight = sizeY;
	biP->biPlanes = 1;
	biP->biBitCount = 24;
	biP->biCompression = BI_RGB;
	biP->biSizeImage = 0;
	biP->biXPelsPerMeter = 0;
	biP->biYPelsPerMeter = 0;
	biP->biClrUsed = 0;
	biP->biClrImportant = 0;

	// allocates buffers for each pixel bits
	SInt32 bitsSize = sizeY * getStorageWidth();
	bits = reinterpret_cast<Byte*>(AllocMemory(bitsSize));
	if (NULL == bits)
	{
		MemoryException::Throw();
	}

	// initializes all pixels with black color
	memset( bits, 0, bitsSize );
}
Esempio n. 12
0
char *ConvertLongToString (const int64 value)
{
	char *value_s = NULL;
	size_t num_digits = 1;

	if (value < 0)
		{
			size_t temp = (size_t) log10 ((double) -value);
			++ num_digits;

			num_digits += temp;
		}
	else if (value > 0)
		{
			num_digits += (size_t) log10 ((double) value);
		}

	value_s = (char *) AllocMemory (num_digits + 1);

	if (value_s)
		{
			sprintf (value_s, "%" PRId64 , value);
			* (value_s + num_digits) = '\0';
		}

	return value_s;
}
Esempio n. 13
0
char *ConvertIntegerToString (const int32 value)
{
	char *value_s = NULL;
	size_t num_digits = 1;
	size_t temp;

	if (value != 0)
		{
			double d = (double) value;

			if (value < 0)
				{
					d = -d;
					++ num_digits;
				}

			d = log10 (d);
			temp = (size_t) (floor (d));
			num_digits += temp;
		}

	value_s = (char *) AllocMemory (num_digits + 1);

	if (value_s)
		{
			sprintf (value_s, INT32_FMT, value);
			* (value_s + num_digits) = '\0';
		}

	return value_s;
}
Esempio n. 14
0
	std::pair<u8*, u32> Map(u32 size) override
	{
		AllocMemory(size);
		u8* pointer = (u8*)glMapBufferRange(m_buffertype, m_iterator, size,
			GL_MAP_WRITE_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | GL_MAP_UNSYNCHRONIZED_BIT);
		return std::make_pair(pointer, m_iterator);
	}
Esempio n. 15
0
static void reorder( FFT_Tables *fft_tables, double *x, int logm)
{
	int i;
	int size = 1 << logm;
	unsigned short *r;	//size


	if ( fft_tables->reordertbl[logm] == NULL ) // create bit reversing table
	{
		fft_tables->reordertbl[logm] = AllocMemory(size * sizeof(*(fft_tables->reordertbl[0])));

		for (i = 0; i < size; i++)
		{
			int reversed = 0;
			int b0;
			int tmp = i;

			for (b0 = 0; b0 < logm; b0++)
			{
				reversed = (reversed << 1) | (tmp & 1);
				tmp >>= 1;
			}
			fft_tables->reordertbl[logm][i] = reversed;
		}
	}
Esempio n. 16
0
File: hyp.c Progetto: abinition/hs
sHyp* gHyp_hyp_new ( char *method )
{
  /* Description:
   *
   *	Create a new program space. 
   *
   * Arguments:
   *
   *	method	[R]
   *	- name of method
   *
   * Return value:
   *
   *	Pointer to program's sHyp structure
   *
   */
  sHyp *pHyp = (sHyp*) AllocMemory ( sizeof ( sHyp ) ) ;
  assert ( pHyp ) ;
  strcpy ( pHyp->method, method ) ;
  pHyp->pCode = NULL ;
  pHyp->size = 0 ;
  pHyp->count = 0 ;
  pHyp->highWaterCount = pHyp->count ;

  gzTraceBufPrev[0] = '\0' ;
  gzTraceBufPrevPrev[0] = '\0' ;
  gzTraceBuf[0]     = '\0' ;

  /*  gHyp_util_logInfo("Creating Hyp %s",method ) ; */
  return pHyp ;
}
Esempio n. 17
0
static Service *GetWebSearchService (json_t *operation_json_p, size_t UNUSED_PARAM (i))
{									
	Service *web_service_p = (Service *) AllocMemory (sizeof (Service));
	
	if (web_service_p)
		{
			ServiceData *data_p = (ServiceData *) AllocateWebSearchServiceData (operation_json_p);
			
			if (data_p)
				{
					InitialiseService (web_service_p,
						GetWebSearchServiceName,
						GetWebSearchServiceDesciption,
						GetWebSearchServiceInformationUri,
						RunWebSearchService,
						IsResourceForWebSearchService,
						GetWebSearchServiceParameters,
						ReleaseWebSearchServiceParameters,
						CloseWebSearchService,
						NULL,
						false,
						true,
						data_p);

					return web_service_p;
				}
			
			FreeMemory (web_service_p);
		}		/* if (web_service_p) */
			
	return NULL;
}
Esempio n. 18
0
static WebSearchServiceData *AllocateWebSearchServiceData (json_t *op_json_p)
{
	WebSearchServiceData *service_data_p = (WebSearchServiceData *) AllocMemory (sizeof (WebSearchServiceData));
	
	if (service_data_p)
		{
			WebServiceData *data_p = & (service_data_p -> wssd_base_data);

			if (InitWebServiceData (data_p, op_json_p))
				{
					service_data_p -> wssd_link_selector_s = GetJSONString (op_json_p, "link_selector");

					if (service_data_p -> wssd_link_selector_s)
						{
							service_data_p -> wssd_title_selector_s = GetJSONString (op_json_p, "title_selector");

							return service_data_p;
						}

					ClearWebServiceData (data_p);
				}

			FreeMemory (service_data_p);
		}
		
	return NULL;
}
Esempio n. 19
0
bool DataServer::ConnectMdServer(const char *file, const char *servername)
{
    //获取空间,绑定队列,注册回调
    if (!AllocMemory())
        return false;
    //读取信息
    ReadInifile(file, servername);
    dblog->RegisterPath(logpath);
    if (!ConnectMongodb())
        return false;
    //处理连接
    MD_Connect(md, path.c_str(), mdServer.c_str(), brokerid.c_str(), investor.c_str(), password.c_str());
    TD_Connect(td, path.c_str(), tdServer.c_str(), brokerid.c_str(), investor.c_str(), password.c_str(), THOST_TERT_RESTART, "", "");
    
    if (TD_WaitForConnected(td))
    {
        dblog->PrintLog("交易端已经登录(行情端账户)");
    }
    else return false;
    if (MD_WaitForConnected(md))
    {
        dblog->PrintLog("行情端已经登录(行情端账户)");
    }
    else return false;

    return true;
}
Esempio n. 20
0
DrmaaServiceJob *AllocateDrmaaServiceJob (const char *drmaa_program_name_s, Service *service_p, const char *job_name_s)
{
	DrmaaServiceJob *job_p = NULL;
	DrmaaTool *drmaa_tool_p = AllocateDrmaaTool (drmaa_program_name_s);

	if (drmaa_tool_p)
		{
			job_p = (DrmaaServiceJob *) AllocMemory (sizeof (DrmaaServiceJob));

			if (job_p)
				{
					InitDrmaaServiceJob (job_p, service_p, job_name_s, NULL);
					job_p -> dsj_drmaa_p = drmaa_tool_p;
				}
			else
				{
					FreeDrmaaTool (drmaa_tool_p);
					PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate drmaa service job");
				}
		}
	else
		{
			PrintErrors (STM_LEVEL_SEVERE, __FILE__, __LINE__, "Failed to allocate drmaa tool");
		}

	return job_p;
}
Esempio n. 21
0
 u32 Stream(u32 size, const void* src) override
 {
   AllocMemory(size);
   std::memcpy(m_pointer + m_iterator, src, size);
   u32 iter = m_iterator;
   m_iterator += size;
   return iter;
 }
Esempio n. 22
0
CUtlString &CUtlString::operator+=( char c )
{
	const int lhsLength( Length() );

	AllocMemory( lhsLength + 1 );
	m_pString[ lhsLength ] = c;

	return *this;
}
void CMessageBuffer::Allocate(void)
{
  if (mb_ulMessageBufferSize==0) {
    ASSERT(mb_pvMessageBuffer == NULL);
    // allocate message buffer
    mb_ulMessageBufferSize = 16000;
    mb_pvMessageBuffer = AllocMemory(mb_ulMessageBufferSize);
  }
}
Esempio n. 24
0
/* need a buffer where the final 6 chars are XXXXXX, see mkstemp */
char *GetTempFilenameBuffer (const char * const working_directory_s, const char * const prefix_s, const char * const temp_suffix_s)
{
	char *buffer_s = 0;
	const char * const suffix_s = temp_suffix_s ? temp_suffix_s : "XXXXXX";
	const size_t working_dir_length = working_directory_s ? strlen (working_directory_s) : 0;
	const size_t suffix_length = suffix_s ? strlen (suffix_s) : 0;
	const size_t prefix_length = strlen (prefix_s);

	size_t size = 1 + working_dir_length + prefix_length + suffix_length;
	bool needs_slash_flag = false;

	if (working_directory_s)
		{
			needs_slash_flag = (* (working_directory_s + (size - 1)) != GetFileSeparatorChar ());
		}

	if (needs_slash_flag)
		{
			++ size;
		}

	buffer_s = (char *) AllocMemory (size * sizeof (char));

	if (buffer_s)
		{
			char *buffer_p = buffer_s;

			if (working_directory_s)
				{
					memcpy (buffer_p, working_directory_s, working_dir_length * sizeof (char));
					buffer_p +=  working_dir_length * sizeof (char);

					if (needs_slash_flag)
						{
							*buffer_p = GetFileSeparatorChar ();
							++ buffer_p;
						}
				}

			if (prefix_s)
				{
					memcpy (buffer_p, prefix_s, prefix_length * sizeof (char));
					buffer_p +=  prefix_length * sizeof (char);
				}

			if (suffix_s)
				{
					memcpy (buffer_p, suffix_s, suffix_length * sizeof (char));
					buffer_p += suffix_length * sizeof (char);
				}

			*buffer_p = '\0';
		}

	return buffer_s;
}
IMG_BOOL BM_Alloc(void *hDevMemHeap, struct IMG_DEV_VIRTADDR *psDevVAddr,
		  size_t uSize, u32 *pui32Flags, u32 uDevVAddrAlignment,
		  void **phBuf)
{
	struct BM_BUF *pBuf;
	struct BM_CONTEXT *pBMContext;
	struct BM_HEAP *psBMHeap;
	struct SYS_DATA *psSysData;
	u32 uFlags;

	if (pui32Flags == NULL) {
		PVR_DPF(PVR_DBG_ERROR, "BM_Alloc: invalid parameter");
		PVR_DBG_BREAK;
		return IMG_FALSE;
	}

	uFlags = *pui32Flags;

	PVR_DPF(PVR_DBG_MESSAGE,
		 "BM_Alloc (uSize=0x%x, uFlags=0x%x, uDevVAddrAlignment=0x%x)",
		 uSize, uFlags, uDevVAddrAlignment);

	if (SysAcquireData(&psSysData) != PVRSRV_OK)
		return IMG_FALSE;

	psBMHeap = (struct BM_HEAP *)hDevMemHeap;
	pBMContext = psBMHeap->pBMContext;

	if (uDevVAddrAlignment == 0)
		uDevVAddrAlignment = 1;

	if (OSAllocMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(struct BM_BUF),
		       (void **)&pBuf, NULL) != PVRSRV_OK) {
		PVR_DPF(PVR_DBG_ERROR, "BM_Alloc: BM_Buf alloc FAILED");
		return IMG_FALSE;
	}
	OSMemSet(pBuf, 0, sizeof(struct BM_BUF));

	if (AllocMemory(pBMContext, psBMHeap, psDevVAddr, uSize, uFlags,
			uDevVAddrAlignment, pBuf) != IMG_TRUE) {
		OSFreeMem(PVRSRV_OS_PAGEABLE_HEAP, sizeof(struct BM_BUF), pBuf,
			  NULL);
		PVR_DPF(PVR_DBG_ERROR, "BM_Alloc: AllocMemory FAILED");
		return IMG_FALSE;
	}

	PVR_DPF(PVR_DBG_MESSAGE, "BM_Alloc (uSize=0x%x, uFlags=0x%x)=%08X",
		 uSize, uFlags, pBuf);

	pBuf->ui32RefCount = 1;
	pvr_get_ctx(pBMContext);
	*phBuf = (void *) pBuf;
	*pui32Flags = uFlags | psBMHeap->ui32Attribs;

	return IMG_TRUE;
}
Esempio n. 26
0
static  name    *RTMemRef( rt_class rt_index )
/*********************************************
    create a memory_name to reference the given runtime label.
*/
{
    label_handle        hdl;

    hdl = RTLabel( rt_index );
    return( AllocMemory( hdl, 0, CG_LBL, WD ) );
}
Esempio n. 27
0
 u32 Stream(u32 size, const void* src) override
 {
   AllocMemory(size);
   u32 iter = m_iterator;
   m_iterator += size;
   std::memcpy(m_pointer + iter, src, size);
   if (!coherent)
     glFlushMappedBufferRange(m_buffertype, iter, size);
   return iter;
 }
Esempio n. 28
0
File: ltp.c Progetto: Arcen/faac
int LtpEncode(faacEncHandle hEncoder,
                CoderInfo *coderInfo,
                LtpInfo *ltpInfo,
                TnsInfo *tnsInfo,
                double *p_spectrum,
                double *p_time_signal)
{
    int i, last_band;
    double num_bit[MAX_SHORT_WINDOWS];
    double *predicted_samples;

    ltpInfo->global_pred_flag = 0;
    ltpInfo->side_info = 0;

    predicted_samples = (double*)AllocMemory(2*BLOCK_LEN_LONG*sizeof(double));

    switch(coderInfo->block_type)
    {
    case ONLY_LONG_WINDOW:
    case LONG_SHORT_WINDOW:
    case SHORT_LONG_WINDOW:
        last_band = (coderInfo->nr_of_sfb < MAX_LT_PRED_LONG_SFB) ? coderInfo->nr_of_sfb : MAX_LT_PRED_LONG_SFB;

        ltpInfo->delay[0] =
            pitch(p_time_signal, ltpInfo->buffer, 2 * BLOCK_LEN_LONG,
                0, 2 * BLOCK_LEN_LONG, predicted_samples, &ltpInfo->weight,
                &ltpInfo->weight_idx);

		
        num_bit[0] =
            ltp_enc_tf(hEncoder, coderInfo, p_spectrum, predicted_samples,
                ltpInfo->mdct_predicted,
                coderInfo->sfb_offset, coderInfo->nr_of_sfb,
                last_band, ltpInfo->side_info, ltpInfo->sfb_prediction_used,
                tnsInfo);


		ltpInfo->global_pred_flag = (num_bit[0] == 0.0) ? 0 : 1;

        if(ltpInfo->global_pred_flag)
            for (i = 0; i < coderInfo->sfb_offset[last_band]; i++)
                p_spectrum[i] -= ltpInfo->mdct_predicted[i];
            else
                ltpInfo->side_info = 1;

            break;

    default:
        break;
    }

    if (predicted_samples) FreeMemory(predicted_samples);

    return (ltpInfo->global_pred_flag);
}
Esempio n. 29
0
// expand image edges
void CImageInfo::ExpandEdges( INDEX ctPasses/*=8192*/)
{
  // do nothing if image is too small or doesn't have an alpha channel
  if( ii_Width<3 || ii_Height<3 || ii_BitsPerPixel!=32) return;

  // allocate some memory for spare picture and wipe it clean
  SLONG slSize = ii_Width*ii_Height*ii_BitsPerPixel/8;
  ULONG *pulSrc = (ULONG*)ii_Picture;
  ULONG *pulDst = (ULONG*)AllocMemory(slSize);
  memcpy( pulDst, pulSrc, slSize);

  // loop while there are some more pixels to be processed or for specified number of passes
  for( INDEX iPass=0; iPass<ctPasses; iPass++)
  { 
    BOOL bAllPixelsVisible = TRUE;
    // loop thru rows
    for( PIX pixV=1; pixV<ii_Height-1; pixV++)
    { // loop thru pixels in row
      for( PIX pixU=1; pixU<ii_Width-1; pixU++)
      { // determine pixel location
        const PIX pixOffset = pixV*ii_Width + pixU;
        // do nothing if it is already visible
        COLOR col = ByteSwap(pulSrc[pixOffset]);
        if( ((col&CT_AMASK)>>CT_ASHIFT)>3) continue;
        bAllPixelsVisible = FALSE;
        // average all surrounding pixels that are visible
        ULONG ulRa=0, ulGa=0, ulBa=0;
        INDEX ctVisible=0;
        for( INDEX j=-1; j<=1; j++) {
          for( INDEX i=-1; i<=1; i++) {
            const PIX pixSurrOffset = pixOffset + j*ii_Width + i;
            col = ByteSwap(pulSrc[pixSurrOffset]);
            if( ((col&CT_AMASK)>>CT_ASHIFT)<4) continue; // skip non-visible pixels
            UBYTE ubR, ubG, ubB;
            ColorToRGB( col, ubR,ubG,ubB);
            ulRa+=ubR;  ulGa+=ubG;  ulBa += ubB;
            ctVisible++;
          }
        } // if there were some visible pixels around
        if( ctVisible>0) {
          // calc average
          ulRa/=ctVisible;  ulGa/=ctVisible;  ulBa/=ctVisible;
          col = RGBAToColor( ulRa,ulGa,ulBa,255);
          // put it to center pixel
          pulDst[pixOffset] = ByteSwap(col);
        }
      }
    } // copy resulting picture over source
    memcpy( pulSrc, pulDst, slSize);
    // done if all pixels are visible
    if( bAllPixelsVisible) break;
  }
  // free temp memory
  FreeMemory(pulDst);
}
Esempio n. 30
0
/*-----------------------------------------------------------------------------
 Data Members
------------------------------------------------------------------------------*/
PROTECTED extern PacketMgrInputBufferInfo packetMgrInputBuffer;


//*****************************************************************************
//
// Exported Functions
//
//*****************************************************************************


//****************************************************************************/
PROTECTED Result PacketMgrParsePacket(pLIB_XML_Tag *Tag, uint32 *PacketId)
{
    Result result = PACKET_MGR_RESULT(SUCCESS);
    uint32 packetSizeBytes;
    uint32 pi;
    pLIB_XML_Tag tag;

    tag = *Tag;
    pi = packetMgrInputBuffer.FirstPacketIndex;

    if( packetMgrInputBuffer.PacketInfo[pi].StartIndex < packetMgrInputBuffer.PacketInfo[pi].EndIndex )
    {
        packetSizeBytes = packetMgrInputBuffer.PacketInfo[pi].EndIndex - packetMgrInputBuffer.PacketInfo[pi].StartIndex;
    }
    else
    {
        packetSizeBytes = PACKET_MGR_INPUT_BUFFER_SIZE - packetMgrInputBuffer.PacketInfo[pi].StartIndex + packetMgrInputBuffer.PacketInfo[pi].EndIndex;
    }


    if( (tag = (pLIB_XML_Tag) AllocMemory(sizeof(LIB_XML_Tag) + packetSizeBytes)) == NULL )
    {
        result = PACKET_MGR_RESULT(MEM_ALLOC_FAIL);
    }
    else
    {
        tag->Data = (uint8*)tag + sizeof(LIB_XML_Tag);
        tag->ChildCount = 1;
        *PacketId = packetMgrInputBuffer.PacketInfo[pi].Id;

        if( packetMgrInputBuffer.PacketInfo[pi].StartIndex < packetMgrInputBuffer.PacketInfo[pi].EndIndex )
        {
            CopyMemory(tag->Data, &packetMgrInputBuffer.Buffer[packetMgrInputBuffer.PacketInfo[pi].StartIndex], packetSizeBytes);
        }
        else
        {
            packetSizeBytes = PACKET_MGR_INPUT_BUFFER_SIZE - packetMgrInputBuffer.PacketInfo[pi].StartIndex;

            CopyMemory(tag->Data, &packetMgrInputBuffer.Buffer[packetMgrInputBuffer.PacketInfo[pi].StartIndex], packetSizeBytes);
            CopyMemory(&((uint8*)tag->Data)[packetSizeBytes], packetMgrInputBuffer.Buffer, packetMgrInputBuffer.PacketInfo[pi].EndIndex);
        }

        if( sscanf(tag->Data, "<%s>", tag->Tag) != 1 )
        {
            result = PACKET_MGR_RESULT(BAD_PACKET);
        }
    }

    SetMemory(&packetMgrInputBuffer.PacketInfo[pi], PACKET_NULL_INDEX, sizeof(PacketMgrPacketInfo));
    packetMgrInputBuffer.FirstPacketIndex = (packetMgrInputBuffer.FirstPacketIndex+1)/PACKET_MGR_INPUT_MAX_PACKETS;
    packetMgrInputBuffer.PacketsAvailable--;
    packetMgrInputBuffer.BytesUsed -= packetSizeBytes;

    return result;
}