当前位置: 首页>>代码示例>>C++>>正文


C++ FillBuffer函数代码示例

本文整理汇总了C++中FillBuffer函数的典型用法代码示例。如果您正苦于以下问题:C++ FillBuffer函数的具体用法?C++ FillBuffer怎么用?C++ FillBuffer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了FillBuffer函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: while

PRUint8
FCGXStream::RecvByte()
{
    // See if the current block is exhausted.
    while (mRecvBytesLeftInBlock == 0) {
        if (!RecvNextBlock(PR_TRUE))
            return 0;
    }

    // Next, see if we need to receive more bytes from the socket.
    if (mRecvIn == mRecvOut) {
        mRecvIn = 0;
        FillBuffer();
        if (mFD == INVALID_SOCKET)
            return 0;
    }

    mRecvBytesLeftInBlock--;
    g_recv.LogContents(mRecvBuf + mRecvOut, 1);
    return mRecvBuf[mRecvOut++];
}
开发者ID:aptana,项目名称:Jaxer,代码行数:21,代码来源:FCGXStream.cpp

示例2: DirectSoundDrv_PCM_BeginPlayback

int DirectSoundDrv_PCM_BeginPlayback(char *BufferStart, int BufferSize,
						int NumDivisions, void ( *CallBackFunc )( void ) )
{
    HRESULT err;
    
    if (!Initialised) {
        ErrorCode = DSErr_Uninitialised;
        return DSErr_Error;
    }
    
    DirectSoundDrv_PCM_StopPlayback();
    
	MixBuffer = BufferStart;
	MixBufferSize = BufferSize;
	MixBufferCount = NumDivisions;
	MixBufferCurrent = 0;
	MixBufferUsed = 0;
	MixCallBack = CallBackFunc;

	// prime the buffer
	FillBuffer(0);
	
	mixThread = CreateThread(NULL, 0, fillDataThread, 0, 0, 0);
	if (!mixThread) {
        ErrorCode = DSErr_CreateThread;
        return DSErr_Error;
    }

    SetThreadPriority(mixThread, THREAD_PRIORITY_HIGHEST);
    
    err = IDirectSoundBuffer_Play(lpdsbsec, 0, 0, DSBPLAY_LOOPING);
    if (FAILED( err )) {
        ErrorCode = DSErr_PlaySecondary;
        return DSErr_Error;
    }
    
    Playing = 1;
    
	return DSErr_Ok;
}
开发者ID:DanielGibson,项目名称:jfaudiolib,代码行数:40,代码来源:driver_directsound.c

示例3: file

/* Given:   DataFile    A text file stream already opened for input.
            FileName    The name of this text file (as a char array string).
   Task:    To copy data from this file stream into sorted files (runs).
   Return:  DataFile    The modified file stream is trivially modified by reading from it.
            In the function name the number of runs is returned.
            The sorted runs themselves are created and stored under the file names:
            ExtSortTemp.0, ExtSortTemp.1, etc.
*/
int MakeSortedRuns(fstream & DataFile, PathType FileName)
   {
   fstream OutFile;
   StringType Word, Extension;
   PathType OutFileName;
   int NumWords, k, NumFiles = 0;
   BufType Buffer;
   bool MoreData;

   // Repeatedly fill one buffer and quicksort it, writing the buffer out to a temp file.
   DataFile.getline(Word, MaxString);
   if (DataFile.fail())
      MoreData = false;
   else
      MoreData = true;

   while (MoreData)
      {
      // Fill one buffer.
      NumWords = FillBuffer(DataFile, Buffer, MoreData, Word);
      QuickSort(Buffer, 0, NumWords - 1);

      // Construct the temp file name.
      strcpy(OutFileName, "ExtSortTemp.");
      _itoa(NumFiles, Extension, 10);   // Convert the int in NumFiles to a char array string.
      strcat(OutFileName, Extension);

      OutFile.open(OutFileName, ios::out);
      if (OutFile.fail())
         Error("Could not open the file named ", OutFileName);

      for (k = 0; k < NumWords; k++)
         OutFile << Buffer[k] << endl;

      OutFile.close();
      NumFiles++;
      }

   return NumFiles;
   }
开发者ID:monish001,项目名称:CPP-Programs,代码行数:48,代码来源:extsort.cpp

示例4: BC_Example_Bridge

int BC_Example_Bridge(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
	int err = -EFAULT;
	int command = _IOC_NR(cmd);
	BC_Example_ioctl_package sBridge;

	if (copy_from_user(&sBridge, (void *)arg, sizeof(sBridge)) != 0)
	{
		return err;
	}

	switch(command)
	{
		case _IOC_NR(BC_Example_ioctl_fill_buffer):
		{
			if(FillBuffer(sBridge.inputparam) == -1)
			{
				return err;
			}
			break;
		}
		case _IOC_NR(BC_Example_ioctl_get_buffer_count):
		{
			if(GetBufferCount(&sBridge.outputparam) == -1)
			{
				return err;
			}
			break;
		}
		default:
			return err;
	}

	if (copy_to_user((void *)arg, &sBridge, sizeof(sBridge)) != 0)
	{
		return err;
	}

	return 0;
}
开发者ID:andreimironenko,项目名称:graphics-sdk,代码行数:40,代码来源:bufferclass_example_linux.c

示例5: HR

HRESULT D3D9RenderImpl::Display(BYTE* pYplane, BYTE* pVplane, BYTE* pUplane)
{
    if(!pYplane)
    {
        return E_POINTER;
    }

    if(m_format == D3DFMT_NV12 && !pVplane)
    {
        return E_POINTER;
    }

    if(m_format == D3DFMT_YV12 && (!pVplane || !pUplane))
    {
        return E_POINTER;
    }

    HR(CheckDevice());
    HR(FillBuffer(pYplane, pVplane, pUplane));
    HR(CreateScene());
    return Present();
}
开发者ID:RajibTheKing,项目名称:DesktopClient,代码行数:22,代码来源:D3D9RenderImpl.cpp

示例6: ov_info

bool CWinGlkOGGSound::Play(int iRepeat, int iVolume, bool PauseState)
{
  m_pReadPtr = m_pData;
  if (m_pReadPtr == NULL)
    return false;

  // Open the stream
  ov_callbacks VorbisCBs;
  VorbisCBs.read_func = VorbisRead;
  VorbisCBs.close_func = VorbisClose;
  VorbisCBs.seek_func = VorbisSeek;
  VorbisCBs.tell_func = VorbisTell;
  if (ov_open_callbacks(this,&m_Stream,NULL,0,VorbisCBs) < 0)
    return false;
  m_StreamOpen = true;
  vorbis_info* Info = ov_info(&m_Stream,-1);

  // Create a buffer
  if (CreateBuffer(Info->channels,Info->rate,16) == false)
    return false;

  // Set the duration of the sample
  if (iRepeat > 0)
    m_Duration = (DWORD)ceil(1000.0 * iRepeat * ov_time_total(&m_Stream,-1));
  else
    m_Duration = -1;

  // Fill the buffer with sample data
  m_iRepeat = (iRepeat < 0) ? -1 : iRepeat - 1;
  if (FillBuffer(GetBufferSize()) == false)
    return false;

  // Set the volume for the buffer
  SetVolume(iVolume);

  // Start the buffer playing
  return PlayBuffer(PauseState);
}
开发者ID:DavidKinder,项目名称:Windows-Glk,代码行数:38,代码来源:GlkSoundOGG.cpp

示例7: Play

bool DART::Play ()
{
  Stopped = WaitStreamEnd = false;
  BytesPlayed = 0;
  int buffcount;
  for (buffcount = 0; buffcount < BufferCount; buffcount++)
    if (!FillBuffer (&MixBuffers [buffcount]))
      break;

  if (buffcount == 0)
    Stopped = WaitStreamEnd = true;
  else
  {
    APIRET rc = MixSetupParms.pmixWrite (MixSetupParms.ulMixHandle,
      &MixBuffers [0], buffcount);
    if (rc)
    {
      mciGetErrorString (rc, (PSZ) ErrorCode, sizeof (ErrorCode));
      return FALSE;
    }
  }
  return TRUE;
}
开发者ID:OS2World,项目名称:MM-SOUND-DevAudio,代码行数:23,代码来源:libDART.cpp

示例8: cObjectLock

int CAudioRenderer::OutputAudio(BYTE* pData, UINT nDataByteSize)
{
    CAutoLock cObjectLock(this);
    
    if (GetState() & STATE_WAITFORRESOURCES) {
        memset(pData, 0, nDataByteSize);
        return S_OK;
    }
    
    //Log("nDataByteSize = %d\n", nDataByteSize);
    if (!(GetState() & STATE_EXECUTE)) {
        memset(pData, 0, nDataByteSize);
        //Log("audio 1\n");
        return E_FAIL;
    }
    
    if (m_vecInObjs[0]->IsEOS() && m_PcmPool.GetSize() < nDataByteSize) {
        SetEOS();
        memset(pData, 0, nDataByteSize);
        //Log("audio 2\n");
        return E_FAIL;
    }
    
    FillBuffer(pData, nDataByteSize);
    
    while (!m_pRefClock->IsStarted()) {
        m_ASync.Wait(10000);
        if (m_bFlush || m_bClose || m_bInterrupt) break;
    }
    
    if (m_bInterrupt) {
        memset(pData, 0, nDataByteSize);
    }

    //Log("audio 3\n");
    return S_OK;
}
开发者ID:bigbugbb,项目名称:video-player-infrastructure,代码行数:37,代码来源:AudioRenderer.cpp

示例9: GetBufferSceMp3

int GetBufferSceMp3(short* buf,int length,float amp,int channel)
{
	int byteLength = length<<2,i=0;
	if (streamsSceMp3[channel].paused || !streamsSceMp3[channel].initialized) 
	{
		memset(buf,0,byteLength);
		return PSPAALIB_WARNING_PAUSED_BUFFER_REQUESTED;
	}
	while(streamsSceMp3[channel].bufSize<byteLength)
	{
		if(sceMp3CheckStreamDataNeeded(streamsSceMp3[channel].handle))
		{
			FillBuffer(channel);
		}
		short* decodeBuf;
		int bytesDecoded=sceMp3Decode(streamsSceMp3[channel].handle,&decodeBuf);
        if (bytesDecoded <= 0) break; 
		streamsSceMp3[channel].buf=(u8*)realloc(streamsSceMp3[channel].buf,streamsSceMp3[channel].bufSize+bytesDecoded);
		memcpy(streamsSceMp3[channel].buf+streamsSceMp3[channel].bufSize,decodeBuf,bytesDecoded);
		streamsSceMp3[channel].bufSize+=bytesDecoded;
	}
    
    unsigned char byte1, byte2;
    int how_many = (streamsSceMp3[channel].bufSize > byteLength ? byteLength : streamsSceMp3[channel].bufSize);
	for (i=0;i<2*length;i++)
	{
        byte1 = (2*i >= how_many) ? 0 : streamsSceMp3[channel].buf[2*i];
        byte2 = (2*i+1 >= how_many) ? 0 : streamsSceMp3[channel].buf[2*i+1];

		buf[i]=((short)(byte1 | byte2<<8))*amp;
	}

	streamsSceMp3[channel].bufSize-=how_many;
	memmove(streamsSceMp3[channel].buf,streamsSceMp3[channel].buf+how_many,streamsSceMp3[channel].bufSize);
	return PSPAALIB_SUCCESS;
}
开发者ID:mariodon,项目名称:psp-taikoclone,代码行数:36,代码来源:pspaalibscemp3.c

示例10: fillDataThread

static DWORD WINAPI fillDataThread(LPVOID lpParameter)
{
    DWORD waitret, waitret2;
    HANDLE handles[] = { handles[0] = notifyPositions[0].hEventNotify, 
                         handles[1] = notifyPositions[1].hEventNotify,
                         handles[2] = notifyPositions[2].hEventNotify };
    
    UNREFERENCED_PARAMETER(lpParameter);

	do {
        waitret = WaitForMultipleObjects(3, handles, FALSE, INFINITE); 
        switch (waitret) {
            case WAIT_OBJECT_0:
            case WAIT_OBJECT_0+1:
                waitret2 = WaitForSingleObject(mutex, INFINITE);
                if (waitret2 == WAIT_OBJECT_0) {
                    FillBuffer(WAIT_OBJECT_0 + 1 - waitret);
                    ReleaseMutex(mutex);
                } else {
                    if (MV_Printf)
                        MV_Printf( "DirectSound fillDataThread: wfso err %d\n", (int32_t) waitret2);
                }
                break;
            case WAIT_OBJECT_0+2:
//                initprintf( "DirectSound fillDataThread: exiting\n");
                ExitThread(0);
                break;
            default:
                if (MV_Printf)
                    MV_Printf( "DirectSound fillDataThread: wfmo err %d\n", (int32_t) waitret);
                break;
        }
	} while (1);
	
	return 0;
}
开发者ID:sbrown345,项目名称:edukejs,代码行数:36,代码来源:driver_directsound.c

示例11: Peek

/**
 *  Consume characters until you find the terminal char
 *  
 *  @update  gess 3/25/98
 *  @param   aString receives new data from stream
 *  @param   addTerminal tells us whether to append terminal to aString
 *  @return  error code
 */
nsresult nsScanner::ReadWhitespace(nsScannerSharedSubstring& aString,
                                   PRInt32& aNewlinesSkipped,
                                   PRBool& aHaveCR) {

  aHaveCR = PR_FALSE;

  if (!mSlidingBuffer) {
    return kEOF;
  }

  PRUnichar theChar = 0;
  nsresult  result = Peek(theChar);
  
  if (NS_FAILED(result)) {
    return result;
  }
  
  nsScannerIterator origin, current, end;
  PRBool done = PR_FALSE;  

  origin = mCurrentPosition;
  current = origin;
  end = mEndPosition;

  PRBool haveCR = PR_FALSE;

  while(!done && current != end) {
    switch(theChar) {
      case '\n':
      case '\r':
        {
          ++aNewlinesSkipped;
          PRUnichar thePrevChar = theChar;
          theChar = (++current != end) ? *current : '\0';
          if ((thePrevChar == '\r' && theChar == '\n') ||
              (thePrevChar == '\n' && theChar == '\r')) {
            theChar = (++current != end) ? *current : '\0'; // CRLF == LFCR => LF
            haveCR = PR_TRUE;
          } else if (thePrevChar == '\r') {
            // Lone CR becomes CRLF; callers should know to remove extra CRs
            AppendUnicodeTo(origin, current, aString);
            aString.writable().Append(PRUnichar('\n'));
            origin = current;
            haveCR = PR_TRUE;
          }
        }
        break;
      case ' ' :
      case '\t':
        theChar = (++current != end) ? *current : '\0';
        break;
      default:
        done = PR_TRUE;
        AppendUnicodeTo(origin, current, aString);
        break;
    }
  }

  SetPosition(current);
  if (current == end) {
    AppendUnicodeTo(origin, current, aString);
    result = FillBuffer();
  }

  aHaveCR = haveCR;
  return result;
}
开发者ID:rn10950,项目名称:RetroZilla,代码行数:75,代码来源:nsScanner.cpp

示例12: LVExtractFilenameWithoutExtension

/// parses input stream
bool LVRtfParser::Parse()
{
    //m_conv_table = GetCharsetByte2UnicodeTable( L"cp1251" );

    bool errorFlag = false;
    m_callback->OnStart(this);

    // make fb2 document structure
    m_callback->OnTagOpen( NULL, L"?xml" );
    m_callback->OnAttribute( NULL, L"version", L"1.0" );
    m_callback->OnAttribute( NULL, L"encoding", L"utf-8" );
    //m_callback->OnEncoding( GetEncodingName().c_str(), GetCharsetTable( ) );
    m_callback->OnTagBody();
    m_callback->OnTagClose( NULL, L"?xml" );
    m_callback->OnTagOpenNoAttr( NULL, L"FictionBook" );
      // DESCRIPTION
      m_callback->OnTagOpenNoAttr( NULL, L"description" );
        m_callback->OnTagOpenNoAttr( NULL, L"title-info" );
          //
            lString16 bookTitle = LVExtractFilenameWithoutExtension( getFileName() ); //m_stream->GetName();
            m_callback->OnTagOpenNoAttr( NULL, L"book-title" );
                if ( !bookTitle.empty() )
                    m_callback->OnText( bookTitle.c_str(), bookTitle.length(), 0 );
          //queue.DetectBookDescription( m_callback );
        m_callback->OnTagOpenNoAttr( NULL, L"title-info" );
      m_callback->OnTagClose( NULL, L"description" );
      // BODY
      m_callback->OnTagOpenNoAttr( NULL, L"body" );
        //m_callback->OnTagOpen( NULL, L"section" );
          // process text
          //queue.DoTextImport( m_callback );
        //m_callback->OnTagClose( NULL, L"section" );

    txtbuf = new lChar16[ MAX_TXT_SIZE+1 ];
    txtpos = 0;
    txtfstart = 0;
    char cwname[33];
    while ( !Eof() && !errorFlag && !m_stopped ) {
        // load next portion of data if necessary
        if ( m_buf_len - m_buf_pos < MIN_BUF_DATA_SIZE ) {
            if ( !FillBuffer( MIN_BUF_DATA_SIZE*2 ) ) {
                errorFlag = true;
                break;
            }
        }
        int len = (int)m_buf_len - (int)m_buf_pos;
        // check end of file
        if ( len <=0 )
            break; //EOF
        const lUInt8 * p = m_buf + m_buf_pos;
        lUInt8 ch = *p++;
        if ( ch=='{' ) {
            OnBraceOpen();
            m_buf_pos++;
            continue;
        } else if ( ch=='}' ) {
            OnBraceClose();
            m_buf_pos++;
            continue;
        }
        lUInt8 ch2 = *p;
        if ( ch=='\\' && *p!='\'' ) {
            // control
            bool asteriskFlag = false;
            if ( ch2=='*' ) {
                ch = *(++p);
                ch2 = *(++p);
                asteriskFlag = true;
            }
            if ( (ch2>='A' && ch2<='Z') || (ch2>='a' && ch2<='z') ) {
                // control word
                int cwi = 0;
                do {
                    cwname[cwi++] = ch2;
                    ch2 = *++p;
                } while ( ( (ch2>='A' && ch2<='Z') || (ch2>='a' && ch2<='z') ) && cwi<32 );
                cwname[cwi] = 0;
                int param = PARAM_VALUE_NONE;
                if ( ch2==' ' ) {
                    p++;
                } else {
                    if ( ch2 == '-' ) {
                        p++;
                        param = 0;
                        for ( ;; ) {
                            ch2 = *++p;
                            if ( ch2<'0' || ch2>'9' )
                                break;
                            param = param * 10 + (ch2-'0');
                        }
                        param = -param;
                    } else if ( ch2>='0' && ch2<='9' ) {
                        param = 0;
                        while ( ch2>='0' && ch2<='9' ) {
                            param = param * 10 + (ch2-'0');
                            ch2 = *++p;
                        }
                    }
                    if ( *p == ' ' )
//.........这里部分代码省略.........
开发者ID:dxwts,项目名称:coolreader3,代码行数:101,代码来源:rtfimp.cpp

示例13: SysRead

size_t SysRead( b_file *io, char *b, size_t len )
//===============================================
{
    size_t      bytes_read;
    size_t      amt;
    size_t      offs_in_b;
    size_t      max_valid;

    if( io->attrs & BUFFERED ) {
        // determine the maximum valid position in the buffer
        max_valid = io->read_len;
        if( max_valid < io->high_water ) {
            max_valid = io->high_water;
        }
        // if we're beyond that position then we must fill the buffer
        if( io->b_curs >= max_valid ) {
            if( FillBuffer( io ) < 0 )
                return( READ_ERROR );
            max_valid = io->read_len;
        }
        amt = max_valid - io->b_curs;
        if( amt > len ) {
            amt = len;
        }
        memcpy( b, &io->buffer[io->b_curs], amt );
        offs_in_b = amt;
        io->b_curs += amt;
        len -= amt;
        if( len ) {
            // flush the buffer
            if( FlushBuffer( io ) < 0 )
                return( READ_ERROR );
            if( len > io->buff_size ) {
                // read a multiple of io->buff_size bytes
                amt = len - len % io->buff_size;
                bytes_read = readbytes( io, b + offs_in_b, amt );
                if( bytes_read == READ_ERROR )
                    return( READ_ERROR );
                offs_in_b += bytes_read;
                if( bytes_read < amt )
                    return( offs_in_b );
                len -= amt;
            }
            if( len ) {
                // first fill the buffer
                bytes_read = readbytes( io, io->buffer, io->buff_size );
                if( bytes_read == READ_ERROR )
                    return( READ_ERROR );
                io->attrs |= READ_AHEAD;
                io->read_len = bytes_read;
                // then grab our bytes from it
                if( len > bytes_read ) {
                    len = bytes_read;
                }
                memcpy( b + offs_in_b, io->buffer, len );
                io->b_curs = len;
                offs_in_b += len;
            }
        }
        return( offs_in_b );
    } else {
        return( readbytes( io, b, len ) );
    }
}
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:64,代码来源:posget.c

示例14: GetTextRec

static size_t GetTextRec( b_file *io, char *b, size_t len )
//=========================================================
// Get a record from a TEXT file.
{
    char        ch;
    size_t      read;
    char        rs[2];

    if( io->attrs & SEEK ) { // direct access
        if( SysRead( io, b, len ) == READ_ERROR )
            return( 0 );
        if( SysRead( io, rs, sizeof( char ) ) == READ_ERROR )
            return( 0 );
        if( rs[0] == LF )
            return( len );
#if ! defined( __UNIX__ )
        if( rs[0] == CR ) {
            if( SysRead( io, &rs[1], sizeof( char ) ) == READ_ERROR ) {
                return( 0 );
            }
            if( rs[1] == LF )
                return( len );
            if( ( io->attrs & CARRIAGE_CONTROL ) && ( rs[1] == FF ) ) {
                return( len );
            }
        }
#endif
        FSetErr( IO_BAD_RECORD, io );
        return( 0 );
    } else if( io->attrs & BUFFERED ) {
        char            *ptr;
        char            *stop;
        bool            seen_cr;
        bool            trunc;
        size_t          max_valid;

        // determine maximum valid position in the buffer
        max_valid = io->read_len;
        if( max_valid < io->high_water ) {
            max_valid = io->high_water;
        }
        stop = io->buffer + max_valid;
        ptr = io->buffer + io->b_curs;
        read = 0;
        seen_cr = false;
        trunc = false;
        for( ;; ) {
            if( ptr >= stop ) {
                io->b_curs = ptr - io->buffer;
                if( FillBuffer( io ) < 0 ) {
                    // we have to do this so that io->b_curs is set properly
                    // on end of file
                    ptr = io->buffer + io->b_curs;
                    if( read > 0 && io->stat == IO_EOF ) {
                        IOOk( io );
                    }
                    break;
                }
                stop = io->buffer + io->read_len;
                ptr = io->buffer + io->b_curs;
            }
            ch = *ptr;
            ++ptr;
            if( ch == LF )
                break;
            if( !seen_cr ) {
                if( ch == CTRL_Z ) {
                    --ptr; // give back char so we don't read past EOF
                    if( read == 0 )
                        FSetEof( io );
                    break;
                }
                if( ch == CR ) {
                    seen_cr = true;
                } else if( read < len ) {
                    b[read] = ch;
                    ++read;
                } else {
                    trunc = true;
                }
            } else {
                if( ch == FF && (io->attrs & CARRIAGE_CONTROL) )
                    break;
                --ptr;  // give back the char
                seen_cr = false;
                if( read < len ) {
                    b[read] = CR;
                    ++read;
                } else {
                    trunc = true;
                }
            }
        }
        io->b_curs = ptr - io->buffer;
        if( trunc ) {
            FSetTrunc( io );
        }
        return( read );
    } else {    // device (CON)
        read = 0;
//.........这里部分代码省略.........
开发者ID:Azarien,项目名称:open-watcom-v2,代码行数:101,代码来源:posget.c

示例15: LFA_Seek

void PSIR_FileWriter::ParseFileResources ( LFA_FileRef fileRef, XMP_Uns32 length )
{
	bool ok;

	this->DeleteExistingInfo();
	this->fileParsed = true;
	if ( length == 0 ) return;

	// Parse the image resource block.

	IOBuffer ioBuf;
	ioBuf.filePos = LFA_Seek ( fileRef, 0, SEEK_CUR );

	XMP_Int64 psirOrigin = ioBuf.filePos;	// Need this to determine the resource data offsets.
	XMP_Int64 fileEnd = ioBuf.filePos + length;

	std::string rsrcPName;

	while ( (ioBuf.filePos + (ioBuf.ptr - ioBuf.data)) < fileEnd ) {

		ok = CheckFileSpace ( fileRef, &ioBuf, 12 );	// The minimal image resource takes 12 bytes.
		if ( ! ok ) break;	// Bad image resource. Throw instead?

		XMP_Int64 thisRsrcPos = ioBuf.filePos + (ioBuf.ptr - ioBuf.data);

		XMP_Uns32 type = GetUns32BE(ioBuf.ptr);
		XMP_Uns16 id   = GetUns16BE(ioBuf.ptr+4);
		ioBuf.ptr += 6;	// Advance to the resource name.

		XMP_Uns16 nameLen = ioBuf.ptr[0];	// ! The length for the Pascal string.
		XMP_Uns16 paddedLen = (nameLen + 2) & 0xFFFE;	// ! Round up to an even total. Yes, +2!
		ok = CheckFileSpace ( fileRef, &ioBuf, paddedLen+4 );	// Get the name text and the data length.
		if ( ! ok ) break;	// Bad image resource. Throw instead?

		if ( nameLen > 0 ) rsrcPName.assign ( (char*)(ioBuf.ptr), paddedLen );	// ! Include the length byte and pad.

		ioBuf.ptr += paddedLen;	// Move to the data length.
		XMP_Uns32 dataLen   = GetUns32BE(ioBuf.ptr);
		XMP_Uns32 dataTotal = ((dataLen + 1) & 0xFFFFFFFEUL);	// Round up to an even total.
		ioBuf.ptr += 4;	// Advance to the resource data.

		XMP_Int64 thisDataPos = ioBuf.filePos + (ioBuf.ptr - ioBuf.data);
		XMP_Int64 nextRsrcPos = thisDataPos + dataTotal;

		if ( type != k8BIM ) {
			XMP_Uns32 fullRsrcLen = (XMP_Uns32) (nextRsrcPos - thisRsrcPos);
			this->otherRsrcs.push_back ( OtherRsrcInfo ( (XMP_Uns32)thisRsrcPos, fullRsrcLen ) );
			MoveToOffset ( fileRef, nextRsrcPos, &ioBuf );
			continue;
		}

		InternalRsrcMap::value_type mapValue ( id, InternalRsrcInfo ( id, dataLen, kIsFileBased ) );
		InternalRsrcMap::iterator newRsrc = this->imgRsrcs.insert ( this->imgRsrcs.end(), mapValue );
		InternalRsrcInfo* rsrcPtr = &newRsrc->second;

		rsrcPtr->origOffset = (XMP_Uns32)thisDataPos;

		if ( nameLen > 0 ) {
			rsrcPtr->rsrcName = (XMP_Uns8*) malloc ( paddedLen );
			if ( rsrcPtr->rsrcName == 0 ) XMP_Throw ( "Out of memory", kXMPErr_NoMemory );
			memcpy ( (void*)rsrcPtr->rsrcName, rsrcPName.c_str(), paddedLen );	// AUDIT: Safe, allocated enough bytes above.
		}

		if ( ! IsMetadataImgRsrc ( id ) ) {
			MoveToOffset ( fileRef, nextRsrcPos, &ioBuf );
			continue;
		}

		rsrcPtr->dataPtr = malloc ( dataLen );	// ! Allocate after the IsMetadataImgRsrc check.
		if ( rsrcPtr->dataPtr == 0 ) XMP_Throw ( "Out of memory", kXMPErr_NoMemory );

		if ( dataTotal <= kIOBufferSize ) {
			// The image resource data fits within the I/O buffer.
			ok = CheckFileSpace ( fileRef, &ioBuf, dataTotal );
			if ( ! ok ) break;	// Bad image resource. Throw instead?
			memcpy ( (void*)rsrcPtr->dataPtr, ioBuf.ptr, dataLen );	// AUDIT: Safe, malloc'ed dataLen bytes above.
			ioBuf.ptr += dataTotal;	// ! Add the rounded length.
		} else {
			// The image resource data is bigger than the I/O buffer.
			LFA_Seek ( fileRef, (ioBuf.filePos + (ioBuf.ptr - ioBuf.data)), SEEK_SET );
			LFA_Read ( fileRef, (void*)rsrcPtr->dataPtr, dataLen );
			FillBuffer ( fileRef, nextRsrcPos, &ioBuf );
		}

	}

	#if 0
	{
		printf ( "\nPSIR_FileWriter::ParseFileResources, count = %d\n", this->imgRsrcs.size() );
		InternalRsrcMap::iterator irPos = this->imgRsrcs.begin();
		InternalRsrcMap::iterator irEnd = this->imgRsrcs.end();
		for ( ; irPos != irEnd; ++irPos ) {
			InternalRsrcInfo& thisRsrc = irPos->second;
			printf ( "  #%d, dataLen %d, origOffset %d (0x%X)%s\n",
					 thisRsrc.id, thisRsrc.dataLen, thisRsrc.origOffset, thisRsrc.origOffset,
					 (thisRsrc.changed ? ", changed" : "") );
		}
	}
	#endif

//.........这里部分代码省略.........
开发者ID:JanX2,项目名称:exempi,代码行数:101,代码来源:PSIR_FileWriter.cpp


注:本文中的FillBuffer函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。