Example #1
0
int VFrame::allocate_data(unsigned char *data, 
	long y_offset,
	long u_offset,
	long v_offset,
	int w, 
	int h, 
	int color_model, 
	long bytes_per_line)
{
	this->w = w;
	this->h = h;
	this->color_model = color_model;
	this->bytes_per_pixel = calculate_bytes_per_pixel(color_model);
	this->y_offset = this->u_offset = this->v_offset = 0;

	if(bytes_per_line >= 0)
	{
		this->bytes_per_line = bytes_per_line;
	}
	else
		this->bytes_per_line = this->bytes_per_pixel * w;

// Allocate data + padding for MMX
	if(data)
	{
		shared = 1;
		this->data = data;
		this->y_offset = y_offset;
		this->u_offset = u_offset;
		this->v_offset = v_offset;
	}
	else
	{
		shared = 0;
		int size = calculate_data_size(this->w, 
			this->h, 
			this->bytes_per_line, 
			this->color_model);
		this->data = new unsigned char[size];

// Memory check
//if(size >= 720 * 480 * 3)
//BUFFER2(this->data, "VFrame::allocate_data");

if(!this->data)
printf("VFrame::allocate_data %dx%d: memory exhausted.\n", this->w, this->h);

//printf("VFrame::allocate_data %p %d %d\n", this, this->w, this->h);
//if(size > 1000000) printf("VFrame::allocate_data %d\n", size);
	}

// Create row pointers
	create_row_pointers();
	return 0;
}
Example #2
0
int VFrame::allocate_data(unsigned char *data, int shmid,
		long y_offset, long u_offset, long v_offset, int w, int h,
		int color_model, long bytes_per_line)
{
	this->w = w;
	this->h = h;
	this->color_model = color_model;
	this->bytes_per_pixel = calculate_bytes_per_pixel(color_model);
	this->y_offset = this->u_offset = this->v_offset = 0;
//	if(shmid == 0) {
//		printf("VFrame::allocate_data %d shmid == 0\n", __LINE__, shmid);
//	}

	this->bytes_per_line = bytes_per_line >= 0 ?
		bytes_per_line : this->bytes_per_pixel * w;

// Allocate data + padding for MMX
	if(data) {
//printf("VFrame::allocate_data %d %p\n", __LINE__, this->data);
		memory_type = VFrame::SHARED;
		this->data = data;
		this->shmid = -1;
		this->y_offset = y_offset;
		this->u_offset = u_offset;
		this->v_offset = v_offset;
	}
	else if(shmid >= 0) {
		memory_type = VFrame::SHMGET;
		this->data = (unsigned char*)shmat(shmid, NULL, 0);
//printf("VFrame::allocate_data %d shmid=%d data=%p\n", __LINE__, shmid, this->data);
		this->shmid = shmid;
		this->y_offset = y_offset;
		this->u_offset = u_offset;
		this->v_offset = v_offset;
	}
	else {
		memory_type = VFrame::PRIVATE;
		int size = calculate_data_size(this->w, this->h,
			this->bytes_per_line, this->color_model);
		if(BC_WindowBase::get_resources()->use_vframe_shm() && use_shm) {
			this->shmid = shmget(IPC_PRIVATE, size, IPC_CREAT | 0777);
			if(this->shmid < 0) {
				printf("VFrame::allocate_data %d could not allocate shared memory\n", __LINE__);
			}

			this->data = (unsigned char*)shmat(this->shmid, NULL, 0);
//printf("VFrame::allocate_data %d %d %d\n", __LINE__, size, this->shmid);

//printf("VFrame::allocate_data %d %p\n", __LINE__, this->data);
// This causes it to automatically delete when the program exits.
			shmctl(this->shmid, IPC_RMID, 0);
		}
		else {
// Have to use malloc for libpng
			this->data = (unsigned char *)malloc(size);
		}

// Memory check
// if(this->w * this->h > 1500 * 1100)
// printf("VFrame::allocate_data 2 this=%p w=%d h=%d this->data=%p\n",
// this, this->w, this->h, this->data);

		if(!this->data)
			printf("VFrame::allocate_data %dx%d: memory exhausted.\n", this->w, this->h);

//printf("VFrame::allocate_data %d %p data=%p %d %d\n", __LINE__, this, this->data, this->w, this->h);
//if(size > 1000000) printf("VFrame::allocate_data %d\n", size);
	}

// Create row pointers
	create_row_pointers();
	return 0;
}