Exemple #1
0
int VFrame::clear_frame()
{
	switch(color_model)
	{
		case BC_COMPRESSED:
			break;

		case BC_YUV888:
			ZERO_YUV(3, unsigned char, 0xff);
			break;
		
		case BC_YUVA8888:
			ZERO_YUV(4, unsigned char, 0xff);
			break;

		case BC_YUV161616:
			ZERO_YUV(3, uint16_t, 0xffff);
			break;
		
		case BC_YUVA16161616:
			ZERO_YUV(4, uint16_t, 0xffff);
			break;
		
		default:
			memset(data, 0, calculate_data_size(w, h, bytes_per_line, color_model));
			break;
	}
	return 0;
}
Exemple #2
0
void VFrame::rotate270()
{
// Allocate new frame
	int new_w = h, new_h = w, new_bytes_per_line = bytes_per_pixel * new_w;
	unsigned char *new_data = new unsigned char[calculate_data_size(new_w, new_h, new_bytes_per_line, color_model)];
	unsigned char **new_rows = new unsigned char*[new_h];
	for(int i = 0; i < new_h; i++)
		new_rows[i] = &new_data[new_bytes_per_line * i];

// Copy data
	for(int in_y = 0, out_x = 0; in_y < h; in_y++, out_x++)
	{
		for(int in_x = 0, out_y = new_h - 1; in_x < w; in_x++, out_y--)
		{
			for(int k = 0; k < bytes_per_pixel; k++)
			{
				new_rows[out_y][out_x * bytes_per_pixel + k] =
					rows[in_y][in_x * bytes_per_pixel + k];
			}
		}
	}

// Swap frames
	clear_objects(0);
	data = new_data;
	rows = new_rows;
	bytes_per_line = new_bytes_per_line;
	w = new_w;
	h = new_h;
}
Exemple #3
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;
}
Exemple #4
0
int VFrame::copy_from(VFrame *frame)
{
	int w = MIN(this->w, frame->get_w());
	int h = MIN(this->h, frame->get_h());
	

	switch(frame->color_model)
	{
		case BC_COMPRESSED:
			allocate_compressed_data(frame->compressed_size);
			memcpy(data, frame->data, frame->compressed_size);
			this->compressed_size = frame->compressed_size;
			break;

		case BC_YUV420P:
//printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v());
			memcpy(get_y(), frame->get_y(), w * h);
			memcpy(get_u(), frame->get_u(), w * h / 4);
			memcpy(get_v(), frame->get_v(), w * h / 4);
			break;

		case BC_YUV422P:
//printf("%d %d %p %p %p %p %p %p\n", w, h, get_y(), get_u(), get_v(), frame->get_y(), frame->get_u(), frame->get_v());
			memcpy(get_y(), frame->get_y(), w * h);
			memcpy(get_u(), frame->get_u(), w * h / 2);
			memcpy(get_v(), frame->get_v(), w * h / 2);
			break;

		default:
// printf("VFrame::copy_from %d\n", calculate_data_size(w, 
// 				h, 
// 				-1, 
// 				frame->color_model));
			memcpy(data, frame->data, calculate_data_size(w, 
				h, 
				-1, 
				frame->color_model));
			break;
	}

	return 0;
}
Exemple #5
0
int VFrame::clear_frame()
{
	int sz = w * h;
//printf("VFrame::clear_frame %d\n", __LINE__);
	switch(color_model) {
	case BC_COMPRESSED:
		break;

	case BC_YUV410P:
		bzero(get_y(), sz);
		bzero(get_u(), w / 4 * h / 4);
		bzero(get_v(), w / 4 * h / 4);
		break;

	case BC_YUV411P:
	case BC_YUV420P:
		bzero(get_y(), sz);
		bzero(get_u(), sz / 4);
		bzero(get_v(), sz / 4);
		break;

	case BC_YUV422P:
		bzero(get_y(), sz);
		bzero(get_u(), sz / 2);
		bzero(get_v(), sz / 2);
		break;

	case BC_RGBA_FLOATP: if( a ) {
		float *ap = (float *)a;
		for( int i=sz; --i>=0; ++ap ) *ap = 1.f; }
	case BC_RGB_FLOATP: {
		float *rp = (float *)y;
		for( int i=sz; --i>=0; ++rp ) *rp = 0.f;
		float *gp = (float *)u;
		for( int i=sz; --i>=0; ++gp ) *gp = 0.f;
		float *bp = (float *)v;
		for( int i=sz; --i>=0; ++bp ) *bp = 0.f;
		break; }
	case BC_YUV444P:
		bzero(get_y(), sz);
		bzero(get_u(), sz);
		bzero(get_v(), sz);
		break;

	case BC_YUV888:
		ZERO_YUV(3, unsigned char, 0xff);
		break;

	case BC_YUVA8888:
		ZERO_YUV(4, unsigned char, 0xff);
		break;

	case BC_YUV161616:
		ZERO_YUV(3, uint16_t, 0xffff);
		break;

	case BC_YUVA16161616:
		ZERO_YUV(4, uint16_t, 0xffff);
		break;

	default:
		bzero(data, calculate_data_size(w, h, bytes_per_line, color_model));
		break;
	}
	return 0;
}
Exemple #6
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;
}
Exemple #7
0
long VFrame::get_data_size()
{
	return calculate_data_size(w, h, bytes_per_line, color_model) - 4;
}