Example #1
0
//---------- Begin of function ResourceIdx::read_into_user_buf ----------//
//!
//! Read a block of data into the buffer specified by the user.
//!
//! <char*> dataName    		 = name of the data going to read
//! <char*> userBuf     		 = pointer to the user buffer
//! <int>   userBufSize 		 = size of the user buffer.
//! [int]   userStartReadPos = the starting position of the data
//!										to be read into the buffer.
//!										(default:0)
//!
//! Return : <int> 1 - succeeded
//!						0 - failed
//!
int ResourceIdx::read_into_user_buf(char* dataName, char* userBuf, int userBufSize, int userStartReadPos) {
    err_when( !init_flag || !dataName );

    int indexId = get_index(dataName);

    if( !indexId )
	return 0;

    //----- set the user buffer and read into the data -----//

    set_user_buf(userBuf, userBufSize, userStartReadPos);

    int rc = get_data(indexId)!=NULL;               // ==NULL if actual data size > buffer size

    reset_user_buf();

    return rc;
}
Example #2
0
//-------- Start of function ImageRes::put_to_buf --------//
//
// Put the image to the specified Vga buffer.
//
// <VgaBuf*> vgaBufPtr = the pointer to the Vga buffer
// <int>     bitmapId  = id. of the bitmap in the resource file.
//
void ImageRes::put_to_buf(VgaBuf* vgaBufPtr, int bitmapId)
{
	set_user_buf( vgaBufPtr->buf_ptr(), vgaBufPtr->buf_size(), 4 );	// 4-by pass the width and height info of the source data, only read the bitmap into the buffer
	get_data(bitmapId);
	reset_user_buf();

	// ---------- move data if buf_pitch() > buf_width() ---------//
	if( vgaBufPtr->buf_pitch() > vgaBufPtr->buf_width() )
	{
		int y = vgaBufPtr->buf_height()-1;
		int p = vgaBufPtr->buf_pitch();
		int w = vgaBufPtr->buf_width();
		char *srcPtr = vgaBufPtr->buf_ptr() + w * y;
		char *destPtr = vgaBufPtr->buf_ptr() + p * y;

		for( ; y > 0; --y, srcPtr -= w, destPtr -= p  )         // no need to move the first line
			memmove( destPtr, srcPtr, w );
	}
}