예제 #1
0
/*------------------------------------------------------------------------*/
int set_user_data_property(void* _pvCtx, int iObjUID, void* _pvData, int valueType, int nbRow, int nbCol)
{
    /*NOT COMPATIBLE WITH SCILAB 6*/
    int iRhs = getRhsFromAddress(pvApiCtx, (int*)_pvData);
    int iUserDataSize = GetDataSize(iRhs) * 2; /* GetDataSize returns the size of the variable in double words */
    int *piUserData = (int*)GetData(iRhs);

    BOOL status = FALSE;

    if (setGraphicObjectProperty(iObjUID, __GO_USER_DATA__, piUserData, jni_int_vector, iUserDataSize) == FALSE)
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "user_data");
        return SET_PROPERTY_ERROR;
    }

    return SET_PROPERTY_SUCCEED;
}
예제 #2
0
파일: elf.cpp 프로젝트: StarHack/osx-dev
void CELF<ELFSTRUCTURES>::ParseFile(){
   // Load and parse file buffer
   uint32 i;
   FileHeader = *(TELF_Header*)Buf();   // Copy file header
   NSections = FileHeader.e_shnum;
   SectionHeaders.SetNum(NSections);    // Allocate space for section headers
   SectionHeaders.SetZero();
   uint32 Symtabi = 0;                  // Index to symbol table

   // Find section headers
   SectionHeaderSize = FileHeader.e_shentsize;
   if (SectionHeaderSize <= 0) err.submit(2033);
   uint32 SectionOffset = uint32(FileHeader.e_shoff);

   for (i = 0; i < NSections; i++) {
      SectionHeaders[i] = Get<TELF_SectionHeader>(SectionOffset);
      SectionOffset += SectionHeaderSize;

      if (SectionHeaders[i].sh_type == SHT_SYMTAB) {
         // Symbol table found
         Symtabi = i;
      }
   }
   SecStringTable = Buf() + uint32(SectionHeaders[FileHeader.e_shstrndx].sh_offset);
   SecStringTableLen = uint32(SectionHeaders[FileHeader.e_shstrndx].sh_size);
   if (SectionOffset > GetDataSize()) {
      err.submit(2110);     // Section table points to outside file
   }
   if (Symtabi) {
      // Save offset to symbol table
      SymbolTableOffset = (uint32)(SectionHeaders[Symtabi].sh_offset);
      SymbolTableEntrySize = (uint32)(SectionHeaders[Symtabi].sh_entsize); // Entry size of symbol table
      if (SymbolTableEntrySize == 0) {err.submit(2034); return;} // Avoid division by zero
      SymbolTableEntries = uint32(SectionHeaders[Symtabi].sh_size) / SymbolTableEntrySize;
      // Find associated string table
      uint32 Stringtabi = SectionHeaders[Symtabi].sh_link;
      if (Stringtabi < NSections) {
         SymbolStringTableOffset = (uint32)(SectionHeaders[Stringtabi].sh_offset);
         SymbolStringTableSize = (uint32)(SectionHeaders[Stringtabi].sh_size);
      }
      else {
         Symtabi = 0;  // Error
      }   
   }
}
예제 #3
0
wxTarEntry *wxTarInputStream::GetNextEntry()
{
    m_lasterror = ReadHeaders();

    if (!IsOk())
        return NULL;

    wxTarEntryPtr entry(new wxTarEntry);

    entry->SetMode(GetHeaderNumber(TAR_MODE));
    entry->SetUserId(GetHeaderNumber(TAR_UID));
    entry->SetGroupId(GetHeaderNumber(TAR_UID));
    entry->SetSize(GetHeaderNumber(TAR_SIZE));

    entry->SetOffset(m_offset);

    entry->SetDateTime(GetHeaderDate(wxT("mtime")));
    entry->SetAccessTime(GetHeaderDate(wxT("atime")));
    entry->SetCreateTime(GetHeaderDate(wxT("ctime")));

    entry->SetTypeFlag(*m_hdr->Get(TAR_TYPEFLAG));
    bool isDir = entry->IsDir();

    entry->SetLinkName(GetHeaderString(TAR_LINKNAME));

    if (m_tarType != TYPE_OLDTAR) {
        entry->SetUserName(GetHeaderString(TAR_UNAME));
        entry->SetGroupName(GetHeaderString(TAR_GNAME));

        entry->SetDevMajor(GetHeaderNumber(TAR_DEVMAJOR));
        entry->SetDevMinor(GetHeaderNumber(TAR_DEVMINOR));
    }

    entry->SetName(GetHeaderPath(), wxPATH_UNIX);
    if (isDir)
        entry->SetIsDir();

    if (m_HeaderRecs)
        m_HeaderRecs->clear();

    m_size = GetDataSize(*entry);
    m_pos = 0;

    return entry.release();
}
예제 #4
0
// Read TGA format rgb or rgba image
ErrorCode Image::ReadTGA(FILE* fp)
{
	char pchIdentification[256] = "";
	TGAHeader header;
	if(	!fp || !fread(&header, sizeof(TGAHeader), 1, fp) )
		return "Failed to read the image header!";
	if( header.m_iImageTypeCode != 2 || header.m_iIdentificationFieldSize >= 256 || !SetSize(header.m_iWidth, header.m_iHeight, header.m_iBPP / 8))
		return "Unsupported image format!";
	if( header.m_iIdentificationFieldSize && (header.m_iIdentificationFieldSize >= 256 || !fread(pchIdentification, 1, header.m_iIdentificationFieldSize, fp)) )
		return "Failed to read the image identification!";
	if( !fread(GetDataPtr(), 1, GetDataSize(), fp) )
		return "Failed to read the image data!";
	if(GET_BIT(header.m_ImageDescriptorByte, 5))
		FlipV();
	// flip red and blue components
	FlipC();
	return NULL; 
}
예제 #5
0
bool wxTarInputStream::OpenEntry(wxTarEntry& entry)
{
    wxFileOffset offset = entry.GetOffset();

    if (GetLastError() != wxSTREAM_READ_ERROR
            && m_parent_i_stream->IsSeekable()
            && m_parent_i_stream->SeekI(offset) == offset)
    {
        m_offset = offset;
        m_size = GetDataSize(entry);
        m_pos = 0;
        m_lasterror = wxSTREAM_NO_ERROR;
        return true;
    } else {
        m_lasterror = wxSTREAM_READ_ERROR;
        return false;
    }
}
예제 #6
0
bool CNscPStackEntry::GetHasSideEffects (CNscContext *pCtx) const
{

	//
	// Walk the PCode tree, checking for any operations with side effects
	//

	CNscPCodeSideEffectChecker sSideEffectChecker (pCtx);
	bool fNoSideEffects;

	fNoSideEffects = sSideEffectChecker .ProcessPCodeBlock (GetData (),
		GetDataSize ());

	if (fNoSideEffects == false)
		return true;
	else
		return false;
}
예제 #7
0
BOOL KStasticFluxCacheMgr::VerifyCacheFile(BYTE* pData, DWORD nFileSize)
{
	if (nFileSize < GetDataSize())
	{
		kws_log(TEXT("file size smaller than data size"));
		return FALSE;
	}

	if (IsBadReadPtr(pData, nFileSize))
	{
		kws_log(TEXT("map data can not read filesize:%d"), nFileSize);
		return FALSE;
	}

	NetFluxStasticCacheFileHeader* pFileHeader = (NetFluxStasticCacheFileHeader*)pData;
	if (pFileHeader->m_nMagic != NET_FLEX_STASTIC_FILE_MAGIC)
	{
		kws_log(TEXT("file magic is not equal"));
		return FALSE;
	}

	if (pFileHeader->m_nFileVersion != NET_FLEX_STASTIC_FILE_FILE)
	{
		kws_log(TEXT("file version error"));
		return FALSE;
	}

	if (nFileSize < sizeof(NetFluxStasticCacheFileHeader))
		return FALSE;

	if (pFileHeader->m_nDataDirs > 20)
	{
		kws_log(TEXT("data dir too many"));
		return FALSE;
	}

	if (pFileHeader->m_nDataDirs >= 1)
	{
		if (!VerifyFluxListData((KStasticFluxProcessList*)(pData + pFileHeader->m_nDataOffset[0])))
			return FALSE;
	}

	return TRUE;
}
예제 #8
0
bool cgl::CD3D11Buffer::Update()
{
	if (GetDataSize() != GetBufferSize())
	{
		reset();
		return restore();
	}

	switch(m_desc.Usage)
	{
	case D3D11_USAGE_DEFAULT:
		{
			getDevice()->GetContext()->UpdateSubresource(get(), 0, NULL, m_data.data(), 0, 0);
			return true;

		} break;

	case D3D11_USAGE_IMMUTABLE:
	case D3D11_USAGE_STAGING:	
		{
			reset();
			return restore();

		} break;

	case D3D11_USAGE_DYNAMIC:
		{
			D3D11_MAPPED_SUBRESOURCE subresource;
			HRESULT result = getDevice()->GetContext()->Map(get(), 0, D3D11_MAP_WRITE_DISCARD, NULL, &subresource );
			if (SUCCEEDED(result))
			{
				memcpy(subresource.pData, m_data.data(), m_data.size());
				getDevice()->GetContext()->Unmap(get(), 0);

				return true;
			}
			
			return false;

		} break;		
	}

	return false;
}
예제 #9
0
BOOL KProcessPerfCacheMgr::VerifyCacheFile(BYTE* pData, DWORD nFileSize)
{
	if (nFileSize < GetDataSize())
	{
		kws_log(TEXT("file size smaller than data size"));
		return FALSE;
	}

	if (IsBadReadPtr(pData, nFileSize))
	{
		kws_log(TEXT("map data can not read filesize:%d"), nFileSize);
		return FALSE;
	}

	ProcPerfMonCacheFileHeader* pFileHeader = (ProcPerfMonCacheFileHeader*)pData;
	if (pFileHeader->m_nMagic != PROC_PERF_MON_FILE_MAGIC)
	{
		kws_log(TEXT("file magic is not equal"));
		return FALSE;
	}

	if (pFileHeader->m_nFileVersion != PROC_PERF_MON_FILE_FILE)
	{
		kws_log(TEXT("file version error"));
		return FALSE;
	}

	if (nFileSize < sizeof(ProcPerfMonCacheFileHeader))
		return FALSE;

	if (pFileHeader->m_nDataDirs > 20)
	{
		kws_log(TEXT("data dir too many"));
		return FALSE;
	}

	if (pFileHeader->m_nDataDirs >= 1)
	{
		if (!VerifyPerfListData((KPocessPerfList*)(pData + pFileHeader->m_nDataOffset[0])))
			return FALSE;
	}

	return TRUE;
}
예제 #10
0
bool SymbolMap::GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask) const {
	u32 functionAddress = INVALID_ADDRESS;
	u32 dataAddress = INVALID_ADDRESS;

	if (symmask & ST_FUNCTION)
		functionAddress = GetFunctionStart(address);

	if (symmask & ST_DATA)
		dataAddress = GetDataStart(address);

	if (functionAddress == INVALID_ADDRESS || dataAddress == INVALID_ADDRESS) {
		if (functionAddress != INVALID_ADDRESS) {
			if (info != NULL) {
				info->type = ST_FUNCTION;
				info->address = functionAddress;
				info->size = GetFunctionSize(functionAddress);
			}

			return true;
		}
		
		if (dataAddress != INVALID_ADDRESS) {
			if (info != NULL) {
				info->type = ST_DATA;
				info->address = dataAddress;
				info->size = GetDataSize(dataAddress);
			}

			return true;
		}

		return false;
	}

	// if both exist, return the function
	if (info != NULL) {
		info->type = ST_FUNCTION;
		info->address = functionAddress;
		info->size = GetFunctionSize(functionAddress);
	}

	return true;
}
예제 #11
0
파일: data.c 프로젝트: sergafts/softdevalg
double ComputeDJ(int oldCentr, int centroid) {
	// wakawaka wikiwikiwoooooosh

	int i = 0;
	double DJ = 0.0;
	value v1, v2;
	for (i = 0; i < GetDataSize() - dataAct.k; i++) {
		GetIthData(i, &v1);
		GetIthData(centroid, &v2);
		double iFromCentr = data.distance(&v1, &v2);
		if (GetClusterOf(i) == oldCentr) {
			if (iFromCentr >= GetDistSecCentr(i))
				DJ += GetDistSecCentr(i) - GetDistFirstCentr(i);
			else
				DJ += iFromCentr - GetDistFirstCentr(i);
		} else if (iFromCentr < GetDistFirstCentr(i))
			DJ += iFromCentr - GetDistFirstCentr(i);
	}
	double bestDist = 9999999999;
	int bestPos = -1;
	GetIthCentroid( oldCentr, &v2);
	for (i = 0; i < dataAct.k; ++i)
	{
		if ( i == oldCentr) 
			continue;
		GetIthCentroid(i, &v1);
		double dist = data.distance(&v1, &v2);
		if ( dist < bestDist)
		{
			bestDist = dist;
			bestPos = i;
		}
	}
	GetIthData( centroid, &v1);
	double dist = data.distance(&v1, &v2);
	if (dist >= bestDist)
		DJ += bestDist;
	else
		DJ += dist;
	return DJ;
	return -1;
}
예제 #12
0
cmd_data_t* CTDMHttpRequest::composeProtoPacketForDCMDownload()
{
	int dataLen = GetDataSize( &m_req );
	int headerLen = 3 * sizeof(int) + sizeof(pkg_type_t) + sizeof(protocol_type_t);
	int memLen = headerLen + dataLen;

	cmd_data_t* cmd = (cmd_data_t*) malloc( memLen );
	memset( cmd, 0, memLen );

	cmd->s_id = getSessionId();
	cmd->pkg_type = CMD_TDM_DCM_CONTENT_GET;
	cmd->pkg_len = dataLen + sizeof(protocol_type_t);
	cmd->pkg_data.type = PROTOCOL_HTTP;

	http_data_t* pd = (http_data_t*) ((char*) cmd + headerLen);

	memcpy( pd->urlhash, m_req.urlhash, 20 );

	char* buffer = (char*) cmd + headerLen + 20;
	char* p = buffer;
	strcpy( p, m_req.client_ip );

	p += strlen(p) + 1;
	strcpy( p, m_req.server_ip );

	p += strlen(p) + 1;
	strcpy( p, m_req.sitename );

	p += strlen(p) + 1;
	strcpy( p, m_req.req_url );

	p += strlen(p) + 1;
	strcpy( p, m_req.req_agent );

	p += strlen(p) + 1;
	strcpy( p, m_req.req_refer );

	p += strlen(p) + 1;
	strcpy( p, m_req.req_cookie );

	return cmd;
}
예제 #13
0
//----------------------------------------------------------//
// CPacket::Validate
//----------------------------------------------------------//
//-- Description
// Basic valid data test on header. Returns current header 
// version if header is valid.
//----------------------------------------------------------//
CPacket::Version::Enum CPacket::Validate(void) const
{
	switch (m_nVersion)
	{
		case Version::V1:
		{
			if ( (GetDataSize() > 0)
				&& (GetMessageCount() > 0) )
			{
				return (Version::Enum)m_nVersion;
			}
		}
		break;

		default:
		break;
	}

	return Version::Unknown;
}
예제 #14
0
void *CDataFileReader::GetData(int Index)
{
	// load it if needed
	if(!m_pDataFile->m_pData[Index].m_Loaded)
	{
		// fetch the data size
		int DataSize = GetDataSize(Index);
		int SwapSize = DataSize;
		
		if(m_pDataFile->m_Header.m_Version == 4)
		{
			// v4 has compressed data
			char *pCompressedData = (char *)malloc(DataSize);
			unsigned long int UncompressedSize = m_pDataFile->m_Info.m_pDataSizes[Index];
			unsigned long int s = UncompressedSize;
			
			m_pDataFile->m_pData[Index].m_pData = (char *)malloc(UncompressedSize);
			
			// read the compressed data
			m_pDataFile->m_File.seekg(m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], std::ios_base::beg);
			m_pDataFile->m_File.read(pCompressedData, DataSize);
			
			// decompress the data, TODO: check for errors
			uncompress((Bytef *)m_pDataFile->m_pData[Index].m_pData, &s, (Bytef *)pCompressedData, DataSize);
			
			// clean up the temporary buffers
			free(pCompressedData);
		}
		else
		{
			// load the data
			m_pDataFile->m_pData[Index].m_pData = (char *)malloc(DataSize);
			m_pDataFile->m_File.seekg(m_pDataFile->m_DataStartOffset+m_pDataFile->m_Info.m_pDataOffsets[Index], std::ios_base::beg);
			m_pDataFile->m_File.read(m_pDataFile->m_pData[Index].m_pData, DataSize);
		}
		
		m_pDataFile->m_pData[Index].m_Loaded = true;
	}
	
	return m_pDataFile->m_pData[Index].m_pData;
}
예제 #15
0
UnicodeString TRegistry::ReadString(const UnicodeString & Name)
{
  UnicodeString Result = L"";
  TRegDataType RegData = rdUnknown;
  intptr_t Len = GetDataSize(Name);
  if (Len > 0)
  {
    Result.SetLength(Len);
    GetData(Name, static_cast<void *>(const_cast<wchar_t *>(Result.c_str())), Len, RegData);
    if ((RegData == rdString) || (RegData == rdExpandString))
    {
      PackStr(Result);
    }
    else { ReadError(Name); }
  }
  else
  {
    Result = L"";
  }
  return Result;
}
예제 #16
0
/*------------------------------------------------------------------------*/
int set_user_data_property(void* _pvCtx, char* pobjUID, size_t stackPointer, int valueType, int nbRow, int nbCol)
{

    int iUserDataSize = GetDataSize((int)stackPointer) * 2; /* GetDataSize returns the size of the variable in double words */
    int *piUserData = GetData((int)stackPointer);

    BOOL status = FALSE;

    status = setGraphicObjectProperty(pobjUID, __GO_USER_DATA__, piUserData, jni_int_vector, iUserDataSize);

    if (status == TRUE)
    {
        return SET_PROPERTY_SUCCEED;
    }
    else
    {
        Scierror(999, _("'%s' property does not exist for this handle.\n"), "user_data");
        return SET_PROPERTY_ERROR;
    }

}
예제 #17
0
/***********************************************
Peek
	Reads data from the read pointer but does 
	not adjust the read pointer.
PARAM:
	pbBuffer - pointer to the buffer to receive
			   read data
	count    - the number of bytes to read
RETURN:
	The actual number of bytes read
************************************************/
int CUT_FIFO_Queue::Peek(LPBYTE pbBuffer, unsigned int count) {

	int iReadPointer = m_iReadPointer;
	int nNumToRead = min(GetDataSize(), (int)count);
	int nNumRead = 0;

	if(iReadPointer + nNumToRead > m_cbBuffer) {

		int nNumAtEnd = m_cbBuffer - iReadPointer;

		memcpy(pbBuffer, m_pbBuffer + iReadPointer, nNumAtEnd);
		nNumRead += nNumAtEnd;
		nNumToRead -= nNumAtEnd;
		iReadPointer = 0 ;
	}

	memcpy(pbBuffer + nNumRead, m_pbBuffer + iReadPointer, nNumToRead);

	nNumRead += nNumToRead;

	return nNumRead;
}
PBYTE CLibInfoMapObjectData::GetWriteData(PDWORD pdwSize)
{
    int i, j, nCount, nCount2;
    PBYTE pRet, pRetTmp, pTmp;
    DWORD dwSize, dwTmp;
    PCInfoMapObjectData pInfo;

    pRet		= NULL;
    dwSize		= GetDataSize ();
    *pdwSize	= dwSize;

    if (dwSize == 0) {
        goto Exit;
    }

    pRet = ZeroNew (dwSize);
    pRetTmp = pRet;

    nCount = m_paInfo->GetSize ();
    CopyMemoryRenew (pRetTmp, &nCount, sizeof (nCount), pRetTmp);		/* データ数 */
    for (i = 0; i < nCount; i ++) {
        pInfo = m_paInfo->GetAt (i);
        nCount2 = pInfo->GetElementCount ();
        CopyMemoryRenew (pRetTmp, &nCount2, sizeof (nCount2), pRetTmp);	/* 要素数 */

        for (j = 0; j < nCount2; j ++) {
            strcpyRenew ((LPSTR)pRetTmp, pInfo->GetName (j), pRetTmp); 	/* 要素名 */
            dwTmp = pInfo->GetDataSizeNo (j);
            CopyMemoryRenew (pRetTmp, &dwTmp, sizeof (dwTmp), pRetTmp);	/* データサイズ */
            pTmp = pInfo->GetWriteData (j, &dwTmp);
            CopyMemoryRenew (pRetTmp, pTmp, dwTmp, pRetTmp);			/* データ */
            SAFE_DELETE_ARRAY (pTmp);
        }
    }

Exit:
    return pRet;
}
void CXTPSyntaxEditUndoRedoManager::LimitDataSize(int nNewCommandData, int nDataSizeLimit)
{
    int nDataSize = GetDataSize();
    if (nDataSize + nNewCommandData < nDataSizeLimit)
        return;

    POSITION pos = m_CommandList.GetHeadPosition();
    while (pos)
    {
        if (pos == m_posFirstUndo)
        {
            Clear();
            return;
        }

        CXTPSyntaxEditCommand* pCmd = (CXTPSyntaxEditCommand*)m_CommandList.GetNext(pos);
        if (pCmd)
            nDataSize -= pCmd->GetDataSize();

        if (nDataSize + nNewCommandData < nDataSizeLimit)
            break;
    }
}
예제 #20
0
int Packet::SetDataSize(int len)
{
  if (len < 0)
    return -1;

  if (len <= GetDataSize()) {
    av_shrink_packet(m_Packet, len);
    return 0;
  }

  if (!m_Packet) {
    m_Packet = av_packet_alloc();
    if (av_new_packet(m_Packet, len) < 0)
      return -1;
  }
  else
  {
    if (av_grow_packet(m_Packet, (len - m_Packet->size)) < 0)
      return -1;
  }

  return 0;
}
예제 #21
0
bool SymbolMap::GetSymbolInfo(SymbolInfo *info, u32 address, SymbolType symmask) const {
	u32 functionAddress = INVALID_ADDRESS;
	u32 dataAddress = INVALID_ADDRESS;

	if (symmask & ST_FUNCTION) {
		functionAddress = GetFunctionStart(address);

		// If both are found, we always return the function, so just do that early.
		if (functionAddress != INVALID_ADDRESS) {
			if (info != NULL) {
				info->type = ST_FUNCTION;
				info->address = functionAddress;
				info->size = GetFunctionSize(functionAddress);
				info->moduleAddress = GetFunctionModuleAddress(functionAddress);
			}

			return true;
		}
	}

	if (symmask & ST_DATA) {
		dataAddress = GetDataStart(address);
		
		if (dataAddress != INVALID_ADDRESS) {
			if (info != NULL) {
				info->type = ST_DATA;
				info->address = dataAddress;
				info->size = GetDataSize(dataAddress);
				info->moduleAddress = GetDataModuleAddress(dataAddress);
			}

			return true;
		}
	}

	return false;
}
예제 #22
0
bool wxTarOutputStream::PutNextEntry(wxTarEntry *entry)
{
    wxTarEntryPtr e(entry);

    if (!CloseEntry())
        return false;

    if (!m_tarsize) {
        wxLogNull nolog;
        m_tarstart = m_parent_o_stream->TellO();
    }

    if (m_tarstart != wxInvalidOffset)
        m_headpos = m_tarstart + m_tarsize;

    if (WriteHeaders(*e)) {
        m_pos = 0;
        m_maxpos = 0;
        m_size = GetDataSize(*e);
        if (m_tarstart != wxInvalidOffset)
            m_datapos = m_tarstart + m_tarsize;

        // types that are not allowed any data
        const char nodata[] = {
            wxTAR_LNKTYPE, wxTAR_SYMTYPE, wxTAR_CHRTYPE, wxTAR_BLKTYPE,
            wxTAR_DIRTYPE, wxTAR_FIFOTYPE, 0
        };
        int typeflag = e->GetTypeFlag();

        // pax does now allow data for wxTAR_LNKTYPE
        if (!m_pax || typeflag != wxTAR_LNKTYPE)
            if (strchr(nodata, typeflag) != NULL)
                CloseEntry();
    }

    return IsOk();
}
예제 #23
0
파일: Blob.cpp 프로젝트: Antidote/dolphin
u32 SectorReader::ReadChunk(u8* buffer, u64 chunk_num)
{
  u64 block_num = chunk_num * m_chunk_blocks;
  u32 cnt_blocks = m_chunk_blocks;

  // If we are reading the end of a disk, there may not be enough blocks to
  // read a whole chunk. We need to clamp down in that case.
  u64 end_block = (GetDataSize() + m_block_size - 1) / m_block_size;
  if (end_block)
    cnt_blocks = static_cast<u32>(std::min<u64>(m_chunk_blocks, end_block - block_num));

  if (ReadMultipleAlignedBlocks(block_num, cnt_blocks, buffer))
  {
    if (cnt_blocks < m_chunk_blocks)
    {
      std::fill(buffer + cnt_blocks * m_block_size, buffer + m_chunk_blocks * m_block_size, 0u);
    }
    return cnt_blocks;
  }

  // end_block may be zero on real disks if we fail to get the media size.
  // We have to fallback to probing the disk instead.
  if (!end_block)
  {
    for (u32 i = 0; i < cnt_blocks; ++i)
    {
      if (!GetBlock(block_num + i, buffer))
      {
        std::fill(buffer, buffer + (cnt_blocks - i) * m_block_size, 0u);
        return i;
      }
      buffer += m_block_size;
    }
    return cnt_blocks;
  }
  return 0;
}
예제 #24
0
void *CAudioDecoder::GetData(unsigned int size)
{
  // calculate the maxsize in units
  unsigned int bufsize = OUTPUT_SAMPLES * (m_outputUnitSize == 1 ? 4 : 1);
  unsigned int maxsize = std::min<unsigned int>(bufsize, GetDataSize());

  if (size > maxsize)
  {
    CLog::Log(LOGWARNING, "CAudioDecoder::GetData() more bytes/samples (%i) requested than we have to give (%i)!", size, maxsize);
    size = maxsize;
  }
  // first copy anything from our gapless buffer
  // this is always a no-op in passthrough or hw decode modes
  if (m_gaplessBufferSize > size)
  {
    memcpy(m_outputBuffer, m_gaplessBuffer, size*sizeof(float));
    memcpy(m_gaplessBuffer, m_gaplessBuffer + size, (m_gaplessBufferSize - size)*sizeof(float));
    m_gaplessBufferSize -= size;
    return m_outputBuffer;
  }
  if (m_gaplessBufferSize)
    memcpy(m_outputBuffer, m_gaplessBuffer, m_gaplessBufferSize*sizeof(float));

  if (m_pcmBuffer.ReadData( (char *)(m_outputBuffer + m_gaplessBufferSize), (size - m_gaplessBufferSize) * m_outputUnitSize))
  {
    m_gaplessBufferSize = 0;
    // check for end of file + end of buffer
    if ( m_status == STATUS_ENDING && m_pcmBuffer.GetMaxReadSize() < (maxsize * m_outputUnitSize))
    {
      CLog::Log(LOGINFO, "CAudioDecoder::GetData() ending track - only have %lu samples left", (unsigned long)(m_pcmBuffer.GetMaxReadSize() / m_outputUnitSize));
      m_status = STATUS_ENDED;
    }
    return m_outputBuffer;
  }
  CLog::Log(LOGERROR, "CAudioDecoder::GetData() ReadData failed with %i samples", size - m_gaplessBufferSize);
  return NULL;
}
예제 #25
0
// バッファの空き容量を取得
DWORD CBuffer::GetBufferEmptySize()
{
	return GetBufferSize()-GetDataSize();
}
예제 #26
0
unsigned Texture::GetDataSize(int width, int height, int depth) const
{
    return depth * GetDataSize(width, height);
}
예제 #27
0
size_t wxBitmapDataObject::GetDataSize() const 
{ 
    return GetDataSize(GetPreferredFormat()); 
}
예제 #28
0
bool Texture2D::SetData(unsigned level, int x, int y, int width, int height, const void* data)
{
    URHO3D_PROFILE(SetTextureData);

    if (!object_ || !graphics_)
    {
        URHO3D_LOGERROR("No texture created, can not set data");
        return false;
    }

    if (!data)
    {
        URHO3D_LOGERROR("Null source for setting data");
        return false;
    }

    if (level >= levels_)
    {
        URHO3D_LOGERROR("Illegal mip level for setting data");
        return false;
    }

    if (graphics_->IsDeviceLost())
    {
        URHO3D_LOGWARNING("Texture data assignment while device is lost");
        dataPending_ = true;
        return true;
    }

    if (IsCompressed())
    {
        x &= ~3;
        y &= ~3;
    }

    int levelWidth = GetLevelWidth(level);
    int levelHeight = GetLevelHeight(level);
    if (x < 0 || x + width > levelWidth || y < 0 || y + height > levelHeight || width <= 0 || height <= 0)
    {
        URHO3D_LOGERROR("Illegal dimensions for setting data");
        return false;
    }

    graphics_->SetTextureForUpdate(this);

    bool wholeLevel = x == 0 && y == 0 && width == levelWidth && height == levelHeight;
    unsigned format = GetSRGB() ? GetSRGBFormat(format_) : format_;

    if (!IsCompressed())
    {
        if (wholeLevel)
            glTexImage2D(target_, level, format, width, height, 0, GetExternalFormat(format_), GetDataType(format_), data);
        else
            glTexSubImage2D(target_, level, x, y, width, height, GetExternalFormat(format_), GetDataType(format_), data);
    }
    else
    {
        if (wholeLevel)
            glCompressedTexImage2D(target_, level, format, width, height, 0, GetDataSize(width, height), data);
        else
            glCompressedTexSubImage2D(target_, level, x, y, width, height, format, GetDataSize(width, height), data);
    }

    graphics_->SetTexture(0, 0);
    return true;
}
예제 #29
0
DWORD CInfoMotionType::GetSendDataSize(void)
{
	return GetDataSize ();
}
void AvHParticleTemplateListClient::InitializeDemoRecording() const
{
	// Loop through all our particle templates, and write out each one 
	int theNumTemplates = this->GetNumberTemplates();
	for(int i = 0; i < theNumTemplates; i++)
	{
		const AvHParticleTemplate* theTemplate = this->GetTemplateAtIndex(i);
		ASSERT(theTemplate);

		int theTotalSize = 0;

		// Calculate total size needed to store template
		string theTemplateName = theTemplate->GetName();
		theTotalSize += GetDataSize(theTemplateName);

		uint32 theMaxParticles = theTemplate->GetMaxParticles();
		theTotalSize += sizeof(theMaxParticles);

		float theParticleSize = theTemplate->GetParticleSize();
		theTotalSize += sizeof(theParticleSize);

		float theParticleSystemLifetime = theTemplate->GetParticleSystemLifetime();
		theTotalSize += sizeof(theParticleSystemLifetime);

		float theParticleLifetime = theTemplate->GetParticleLifetime();
		theTotalSize += sizeof(theParticleLifetime);

		string theSpriteName = theTemplate->GetSprite();
		theTotalSize += GetDataSize(theSpriteName);

		ShapeType theGenerationShape = theTemplate->GetGenerationShape();
		theTotalSize += sizeof(theGenerationShape);

		string theGenerationEntityName = theTemplate->GetGenerationEntityName();
		theTotalSize += GetDataSize(theGenerationEntityName);

		string theParticleSystemToGenerate = theTemplate->GetParticleSystemToGenerate();
		theTotalSize += GetDataSize(theParticleSystemToGenerate);

		int theParticleSystemIndexToGenerate = theTemplate->GetParticleSystemIndexToGenerate();
		theTotalSize += sizeof(theParticleSystemIndexToGenerate);

		int theGenerationEntityIndex = theTemplate->GetGenerationEntityIndex();
		theTotalSize += sizeof(theGenerationEntityIndex);

		float theGenerationEntityParam = theTemplate->GetGenerationEntityParameter();
		theTotalSize += sizeof(theGenerationEntityParam);

		ShapeType theStartingVelocityShape = theTemplate->GetStartingVelocityShape();
		theTotalSize += sizeof(theStartingVelocityShape);

		ParticleParams theGenerationParams;
		theTemplate->GetGenerationParams(theGenerationParams);
		theTotalSize += sizeof(theGenerationParams);

		ParticleParams theStartingVelocityParams;
		theTemplate->GetStartingVelocityParams(theStartingVelocityParams);
		theTotalSize += sizeof(theStartingVelocityParams);

		uint32 theGenerationRate = theTemplate->GetGenerationRate();
		theTotalSize += sizeof(theGenerationRate);

		int theParticleFlags = theTemplate->GetFlags();
		theTotalSize += sizeof(theParticleFlags);

		PSVector theGravity;
		theTemplate->GetGravity(theGravity);
		theTotalSize += sizeof(theGravity);

		float theAnimationSpeed = theTemplate->GetAnimationSpeed();
		theTotalSize += sizeof(theAnimationSpeed);

		int theNumSpriteFrames = theTemplate->GetNumSpriteFrames();
		theTotalSize += sizeof(theNumSpriteFrames);

		float theParticleScaling = theTemplate->GetParticleScaling();
		theTotalSize += sizeof(theParticleScaling);

		int theRenderMode = theTemplate->GetRenderMode();
		theTotalSize += sizeof(theRenderMode);

		float theMaxAlpha = theTemplate->GetMaxAlpha();
		theTotalSize += sizeof(theMaxAlpha);

		// New memory 
		unsigned char* theCharArray = new unsigned char[theTotalSize];
		ASSERT(theCharArray);
		int theCounter = 0;

		// Write out each field
		SaveStringData(theCharArray, theTemplateName, theCounter);
		SAVE_DATA(theMaxParticles);
		SAVE_DATA(theParticleSize);
		SAVE_DATA(theParticleSystemLifetime);
		SAVE_DATA(theParticleLifetime);
		SaveStringData(theCharArray, theSpriteName, theCounter);
		SAVE_DATA(theGenerationShape);
		SaveStringData(theCharArray, theGenerationEntityName, theCounter);
		SaveStringData(theCharArray, theParticleSystemToGenerate, theCounter);
		SAVE_DATA(theParticleSystemIndexToGenerate);
		SAVE_DATA(theGenerationEntityIndex);
		SAVE_DATA(theGenerationEntityParam);
		SAVE_DATA(theStartingVelocityShape);
		SAVE_DATA(theGenerationParams);
		SAVE_DATA(theStartingVelocityParams);
		SAVE_DATA(theGenerationRate);
		SAVE_DATA(theParticleFlags);
		SAVE_DATA(theGravity);
		SAVE_DATA(theAnimationSpeed);
		SAVE_DATA(theNumSpriteFrames);
		SAVE_DATA(theParticleScaling);
		SAVE_DATA(theRenderMode);
		SAVE_DATA(theMaxAlpha);

		// Make sure we wrote exact amount of data we were supposed to
		ASSERT(theTotalSize == theCounter);
		
		Demo_WriteBuffer(TYPE_PARTICLES, theTotalSize, theCharArray);
	}
}