Exemple #1
0
 inline UL& get_spiral( UL x )
 {
     UL all = 0;
     UL be = 0;
     if( x > size_max() ) std::cout << "INFINITE LOOP WARNING" << std::endl;
     while( true )
     {
         UL db = ( all%2 ? size_x() : size_y() ) - 1 - be*2;
         //std::cout << x << " " << db << std::endl;
         if( x < db )
         {
             switch( all )
             {
             case 0 : return (*this)[be][be + x];
             case 1 : return (*this)[be+x][size_y()-be-1];
             case 2 : return (*this)[size_x()-be-1][size_y()-be-1-x];
             case 3 : return (*this)[size_x()-be-1-x][be];
             }
         }
         else
         {
             x-=db;
             if(++all == 4)
             {
                 all = 0;
                 ++be;
             }
         }
     }
 }
Exemple #2
0
/* Check/create surface that can be accessed by the hardware */
static int get_hw_surface(
	UIOMux * uiomux,
	uiomux_resource_t resource,
	struct ren_vid_surface *out,
	const struct ren_vid_surface *in)
{
	int alloc = 0;

	if (in == NULL || out == NULL)
		return 0;

	*out = *in;
	if (in->py) alloc |= !uiomux_all_virt_to_phys(in->py);
	if (in->pc) alloc |= !uiomux_all_virt_to_phys(in->pc);

	if (alloc) {
		/* One of the supplied buffers is not usable by the hardware! */
		size_t len = size_y(in->format, in->h * in->w);
		if (in->pc) len += size_c(in->format, in->h * in->w);

		out->py = uiomux_malloc(uiomux, resource, len, 32);
		if (!out->py)
			return -1;

		if (in->pc) {
			out->pc = out->py + size_y(in->format, in->h * in->w);
		}
	}

	return 0;
}
Exemple #3
0
 inline UL& get_rev_diag( UL x )
 {
     if( x <size_max()/2 )
     {
         PUL ind = tri_ind(x , size_x() , size_y() );
         return get_x_y( ind.first , size_y() - ind.second - 1 );
     }
     else
     {
         UL xm = size_max() - x -1;
         PUL ind = tri_ind(xm , size_x() , size_y() );
         return get_x_y( size_x() - ind.first - 1 , ind.second );
     }
 }
Exemple #4
0
void
region::set_offset( int ox, int oy )
{
	if ( empty() )
	{
		myL = ox;
		myB = oy;
		myR = ox - 1;
		myT = oy - 1;
	}
	else
	{
		if ( infinite_x() )
		{
			myL = ox;
		}
		else
		{
			value_type s = size_x();
			myL = ox;
			myR = ox + s - 1;
		}

		if ( infinite_y() )
		{
			myB = oy;
		}
		else
		{
			value_type s = size_y();
			myB = oy;
			myT = oy + s - 1;
		}
	}
}
Exemple #5
0
    inline void csere( UL f , UL s , T fun )
    {
        ++count;

        UL& firref = (this->*fun)(f);
        UL& secref = (this->*fun)(s);

        std::swap( firref, secref );

        for( UL i = 0 ; i < size_x() ; ++i )
        {
            for( UL j = 0 ; j < size_y() ; ++j )
            {
                if( &this->get_x_y(i,j) == &firref )
                {
                    ss << i << " " << j << " ";
                }
                if( &this->get_x_y(i,j) == &secref )
                {
                    ss << i << " " << j << " ";
                }
            }
        }
        ss << std::endl;
    }
Exemple #6
0
	bool logical_world::is_yedge(int y) const
	{
		if(y >= 0 && y < size_y()) {
			return false;
		}
		return true;
	}
Exemple #7
0
    inline UL& get_double_spiral( UL x )
    {

        UL all = 0;
        UL be = 0;
        if( size_max() % 2 )
        {
            if( size_max()/2 == x ) return get_x_y( size_x()/2 , size_y()/2 );
        }
        bool v = x < size_max()/2;
        if( !v ) x = size_max() - x - 1;

        PUL p;
        while( true )
        {
            UL db = ( all%2 ? size_x() : size_y() ) - 1 - be*2 + !!be;

            if( x <= db )
            {
                switch( all )
                {
                case 0 : p = PUL{be,(be? be-1:0) + x}; break;
                case 1 : p = PUL{be-1+x,size_y()-be}; break;
                case 2 : p = PUL{size_x()-be-1,size_y()-be-x}; break;
                case 3 : p = PUL{size_x()-be-x,be-1}; break;
                }
                break;
            }
            else
            {
                x-=db;
                if(++all == 4)
                {
                    all = 0;
                }
                if( all%2 )
                {
                    ++be;
                }
            }
        }
        if( v ) return get_x_y(p);
        else return get_x_y( size_x() - 1 - p.first , size_y() - 1 - p.second );
    }
Exemple #8
0
void asf::parameter_float_image::data_alloc(src_t src_,band_t *data_,int xd_,int yd_)
{
	data_free();
	src=src_;
	data=data_;
	xd=xd_;
	yd=yd_;
	if (data==NULL && src==src_alloc) 
		data=new band_t[size_y()*yd];
}
Exemple #9
0
/// Error-checking pixel access.  Aborts if x,y, or band are out of bounds.
asf::parameter_float_image::band_t &asf::parameter_float_image::at_careful(int x,int y,int band) const
{
	if (!pixels().inbounds(x,y)) {
		char buf[1024];
		sprintf(buf,"at_careful pixel access: pixel (%d,%d) is not in-bounds on a %d x %d pixel image",
			x,y,size_x(),size_y());
		die(buf);
	}
	if (band<0) die("at_careful pixel access: Bogus negative band number");
	if (band>=bands()) die("at_careful pixel access: Bogus too-big band number");
	return data[x*xd+y*yd+band];
}
Exemple #10
0
int
shveu_wait(SHVEU *veu)
{
	void *base_addr = veu->uio_mmio.iomem;
	uint32_t vevtr;
	uint32_t vstar;
	int complete = 0;

	uiomux_sleep(veu->uiomux, veu->uiores);

	vevtr = read_reg(base_addr, VEVTR);
	write_reg(base_addr, 0, VEVTR);   /* ack interrupts */

	/* End of VEU operation? */
	if (vevtr & 1) {
		dbg(__func__, __LINE__, "src_hw", &veu->src_hw);
		dbg(__func__, __LINE__, "dst_hw", &veu->dst_hw);
		copy_surface(&veu->dst_user, &veu->dst_hw);

		/* free locally allocated surfaces */
		if (veu->src_hw.py != veu->src_user.py) {
			size_t len = size_y(veu->src_hw.format, veu->src_hw.h * veu->src_hw.w);
			len += size_c(veu->src_hw.format, veu->src_hw.h * veu->src_hw.w);
			uiomux_free(veu->uiomux, veu->uiores, veu->src_hw.py, len);
		}
		if (veu->dst_hw.py != veu->dst_user.py) {
			size_t len = size_y(veu->dst_hw.format, veu->dst_hw.h * veu->dst_hw.w);
			len += size_c(veu->dst_hw.format, veu->dst_hw.h * veu->dst_hw.w);
			uiomux_free(veu->uiomux, veu->uiores, veu->dst_hw.py, len);
		}

		uiomux_unlock(veu->uiomux, veu->uiores);
		complete = 1;
	}

	return complete;
}
Exemple #11
0
/**
 * @brief Calculate maximum motion across all the frames
 */
void OpticalFlowModule::update_max_motion()
{
	if (_max_motion > 0.0f) {
		return;
	}

	for (auto it = _forward_optical_flow_list.begin(); it != _forward_optical_flow_list.end(); ++it) {
		const float *flow_data = it->raw();
		for (uint i = 0; i < it->size_x() * it->size_y(); i++) {
			float len = flow_data[2 * i] * flow_data[2 * i] + flow_data[2 * i + 1] * flow_data[2 * i + 1];
			_max_motion = std::max(_max_motion, len);
		}
	}

	for (auto it = _backward_optical_flow_list.begin(); it != _backward_optical_flow_list.end(); ++it) {
		const float *flow_data = it->raw();
		for (uint i = 0; i < it->size_x() * it->size_y(); i++) {
			float len = flow_data[2 * i] * flow_data[2 * i] + flow_data[2 * i + 1] * flow_data[2 * i + 1];
			_max_motion = std::max(_max_motion, len);
		}
	}

	_max_motion = std::sqrt(_max_motion);
}
Exemple #12
0
 inline UL& get_x( UL x )
 {
     return (*this)[x/size_y()][x%size_y()];
 }
Exemple #13
0
static off_t imgsize (ren_vid_format_t colorspace, int w, int h)
{
	return (off_t)(size_y(colorspace, w*h, 0) + size_c(colorspace, w*h, 0));
}
Exemple #14
0
 inline UL size_max() const { return size_x() * size_y(); }
Exemple #15
0
 UL transpose( UL n )
 {
     UL x = n/size_y();
     UL y = n%size_y();
     return y*size_y() + x;
 }
Exemple #16
0
	pathfinding::directed_graph_ptr logical_world::create_directed_graph(bool allow_diagonals) const
	{
		profile::manager pman("logical_world::create_directed_graph");

		std::vector<variant> vertex_list;
		std::map<std::pair<int,int>, int> vlist;

		for(auto p : heightmap_) {
			int x = p.first.first;
			int y = p.second;
			int z = p.first.second;

			if(y < size_y() - 1) {
				if(is_solid(x, y+1, z) == false) {
					vertex_list.push_back(variant_list_from_position(x,y+1,z));
					vlist[std::make_pair(x,z)] = y+1;
				}
			} else {
				vertex_list.push_back(variant_list_from_position(x,y+1,z));
				vlist[std::make_pair(x,z)] = y+1;
			}
		}
	
		pathfinding::graph_edge_list edges;
		for(auto p : vertex_list) {
			const int x = p[0].as_int();
			const int y = p[1].as_int();
			const int z = p[2].as_int();

			std::vector<variant> current_edges;
			
			auto it = vlist.find(std::make_pair(x+1,z));
			if(it != vlist.end() && !is_xedge(x+1) && !is_solid(x+1,it->second,z)) {
				current_edges.push_back(variant_list_from_position(x+1,it->second,z));
			}
			it = vlist.find(std::make_pair(x-1,z));
			if(it != vlist.end() && !is_xedge(x-1) && !is_solid(x-1,it->second,z)) {
				current_edges.push_back(variant_list_from_position(x-1,it->second,z));
			}
			it = vlist.find(std::make_pair(x,z+1));
			if(it != vlist.end() && !is_zedge(z+1) && !is_solid(x,it->second,z+1)) {
				current_edges.push_back(variant_list_from_position(x,it->second,z+1));
			}
			it = vlist.find(std::make_pair(x,z-1));
			if(it != vlist.end() && !is_zedge(z-1) && !is_solid(x,it->second,z-1)) {
				current_edges.push_back(variant_list_from_position(x,it->second,z-1));
			}
			if(allow_diagonals) {
				it = vlist.find(std::make_pair(x+1,z+1));
				if(it != vlist.end() && !is_xedge(x+1) && !is_zedge(z+1) && !is_solid(x+1,it->second,z+1)) {
					current_edges.push_back(variant_list_from_position(x+1,it->second,z+1));
				}
				it = vlist.find(std::make_pair(x+1,z-1));
				if(it != vlist.end() && !is_xedge(x+1) && !is_zedge(z-1) && !is_solid(x+1,it->second,z-1)) {
					current_edges.push_back(variant_list_from_position(x+1,it->second,z-1));
				}
				it = vlist.find(std::make_pair(x-1,z+1));
				if(it != vlist.end() && !is_xedge(x-1) && !is_zedge(z+1) && !is_solid(x-1,it->second,z+1)) {
					current_edges.push_back(variant_list_from_position(x-1,it->second,z+1));
				}
				it = vlist.find(std::make_pair(x-1,z-1));
				if(it != vlist.end() && !is_xedge(x-1) && !is_zedge(z-1) && !is_solid(x-1,it->second,z-1)) {
					current_edges.push_back(variant_list_from_position(x-1,it->second,z-1));
				}
			}
			edges[variant_list_from_position(x, y, z)] = current_edges;
		}
		return pathfinding::directed_graph_ptr(new pathfinding::directed_graph(&vertex_list, &edges));
	}
Exemple #17
0
int
shveu_setup(
	SHVEU *veu,
	const struct ren_vid_surface *src_surface,
	const struct ren_vid_surface *dst_surface,
	shveu_rotation_t filter_control)
{
	float scale_x, scale_y;
	uint32_t temp;
	uint32_t Y, C;
	const struct veu_format_info *src_info;
	const struct veu_format_info *dst_info;
	struct ren_vid_surface local_src;
	struct ren_vid_surface local_dst;
	struct ren_vid_surface *src = &local_src;
	struct ren_vid_surface *dst = &local_dst;
	void *base_addr;

	if (!veu || !src_surface || !dst_surface) {
		debug_info("ERR: Invalid input - need src and dest");
		return -1;
	}

	src_info = fmt_info(src_surface->format);
	dst_info = fmt_info(dst_surface->format);

	dbg(__func__, __LINE__, "src_user", src_surface);
	dbg(__func__, __LINE__, "dst_user", dst_surface);

	/* scale factors */
	scale_x = (float)dst_surface->w / src_surface->w;
	scale_y = (float)dst_surface->h / src_surface->h;

	if (!format_supported(src_surface->format) || !format_supported(dst_surface->format)) {
		debug_info("ERR: Invalid surface format!");
		return -1;
	}

	/* Scaling limits */
	if (veu_is_veu2h(veu)) {
		if ((scale_x > 8.0) || (scale_y > 8.0)) {
			debug_info("ERR: Outside scaling limits!");
			return -1;
		}
	} else {
		if ((scale_x > 16.0) || (scale_y > 16.0)) {
			debug_info("ERR: Outside scaling limits!");
			return -1;
		}
	}
	if ((scale_x < 1.0/16.0) || (scale_y < 1.0/16.0)) {
		debug_info("ERR: Outside scaling limits!");
		return -1;
	}

	/* source - use a buffer the hardware can access */
	if (get_hw_surface(veu->uiomux, veu->uiores, src, src_surface) < 0) {
		debug_info("ERR: src is not accessible by hardware");
		return -1;
	}
	copy_surface(src, src_surface);

	/* destination - use a buffer the hardware can access */
	if (get_hw_surface(veu->uiomux, veu->uiores, dst, dst_surface) < 0) {
		debug_info("ERR: dest is not accessible by hardware");
		return -1;
	}

	uiomux_lock (veu->uiomux, veu->uiores);

	base_addr = veu->uio_mmio.iomem;

	/* Keep track of the requested surfaces */
	veu->src_user = *src_surface;
	veu->dst_user = *dst_surface;

	/* Keep track of the actual surfaces used */
	veu->src_hw = local_src;
	veu->dst_hw = local_dst;

	/* Software reset */
	if (read_reg(base_addr, VESTR) & 0x1)
		write_reg(base_addr, 0, VESTR);
	while (read_reg(base_addr, VESTR) & 1)
		;

	/* Clear VEU end interrupt flag */
	write_reg(base_addr, 0, VEVTR);

	/* VEU Module reset */
	write_reg(base_addr, 0x100, VBSRR);

	/* default to not using bundle mode */
	write_reg(base_addr, 0, VBSSR);

	/* source */
	Y = uiomux_all_virt_to_phys(src->py);
	C = uiomux_all_virt_to_phys(src->pc);
	write_reg(base_addr, Y, VSAYR);
	write_reg(base_addr, C, VSACR);
	write_reg(base_addr, (src->h << 16) | src->w, VESSR);
	write_reg(base_addr, size_y(src->format, src->pitch), VESWR);

	/* destination */
	Y = uiomux_all_virt_to_phys(dst->py);
	C = uiomux_all_virt_to_phys(dst->pc);

	if (filter_control & 0xFF) {
		if ((filter_control & 0xFF) == 0x10) {
			/* Horizontal Mirror (A) */
			Y += size_y(dst->format, src->w);
			C += size_y(dst->format, src->w);
		} else if ((filter_control & 0xFF) == 0x20) {
			/* Vertical Mirror (B) */
			Y += size_y(dst->format, (src->h-1) * dst->pitch);
			C += size_c(dst->format, (src->h-2) * dst->pitch);
		} else if ((filter_control & 0xFF) == 0x30) {
			/* Rotate 180 (C) */
			Y += size_y(dst->format, src->w);
			C += size_y(dst->format, src->w);
			Y += size_y(dst->format, src->h * dst->pitch);
			C += size_c(dst->format, src->h * dst->pitch);
		} else if ((filter_control & 0xFF) == 1) {
			/* Rotate 90 (D) */
			Y += size_y(dst->format, src->h-16);
			C += size_y(dst->format, src->h-16);
		} else if ((filter_control & 0xFF) == 2) {
			/* Rotate 270 (E) */
			Y += size_y(dst->format, (src->w-16) * dst->pitch);
			C += size_c(dst->format, (src->w-16) * dst->pitch);
		} else if ((filter_control & 0xFF) == 0x11) {
			/* Rotate 90 & Mirror Horizontal (F) */
			/* Nothing to do */
		} else if ((filter_control & 0xFF) == 0x21) {
			/* Rotate 90 & Mirror Vertical (G) */
			Y += size_y(dst->format, src->h-16);
			C += size_y(dst->format, src->h-16);
			Y += size_y(dst->format, (src->w-16) * dst->pitch);
			C += size_c(dst->format, (src->w-16) * dst->pitch);
		}
	}
	write_reg(base_addr, Y, VDAYR);
	write_reg(base_addr, C, VDACR);
	write_reg(base_addr, size_y(dst->format, dst->pitch), VEDWR);

	/* byte/word swapping */
	temp = 0;
#ifdef __LITTLE_ENDIAN__
	temp |= src_info->vswpr;
	temp |= dst_info->vswpr << 4;
#endif
	write_reg(base_addr, temp, VSWPR);

	/* transform control */
	temp = src_info->vtrcr_src;
	temp |= dst_info->vtrcr_dst;
	if (is_rgb(src_surface->format))
		temp |= VTRCR_RY_SRC_RGB;
	if (different_colorspace(src_surface->format, dst_surface->format))
		temp |= VTRCR_TE_BIT_SET;
	if (veu->bt709)
		temp |= VTRCR_BT709;
	if (veu->full_range)
		temp |= VTRCR_FULL_COLOR_CONV;
	write_reg(base_addr, temp, VTRCR);

	if (veu_is_veu2h(veu)) {
		/* color conversion matrix */
		write_reg(base_addr, 0x0cc5, VMCR00);
		write_reg(base_addr, 0x0950, VMCR01);
		write_reg(base_addr, 0x0000, VMCR02);
		write_reg(base_addr, 0x397f, VMCR10);
		write_reg(base_addr, 0x0950, VMCR11);
		write_reg(base_addr, 0x3cdd, VMCR12);
		write_reg(base_addr, 0x0000, VMCR20);
		write_reg(base_addr, 0x0950, VMCR21);
		write_reg(base_addr, 0x1023, VMCR22);
		write_reg(base_addr, 0x00800010, VCOFFR);
	}

	/* Clipping */
	write_reg(base_addr, 0, VRFSR);
	set_clip(base_addr, 0, dst->w);
	set_clip(base_addr, 1, dst->h);

	/* Scaling */
	write_reg(base_addr, 0, VRFCR);
	if (!(filter_control & 0x3)) {
		/* Not a rotate operation */
		set_scale(veu, base_addr, 0, src->w, dst->w, 0);
		set_scale(veu, base_addr, 1, src->h, dst->h, 0);
	}

	/* Filter control - directly pass user arg to register */
	write_reg(base_addr, filter_control, VFMCR);

	return 0;

fail:
	uiomux_unlock(veu->uiomux, veu->uiores);
	return -1;
}
Exemple #18
0
int main (int argc, char * argv[])
{
	UIOMux * uiomux;
	uiomux_resource_t uiores;

	char * infilename[2] = {NULL, NULL}, * outfilename = NULL;
	FILE * infile[2], * outfile = NULL;
	size_t nread;
	size_t input_size[2], output_size;
	SHVIO *vio;
	struct ren_vid_surface src[2];
	const struct ren_vid_surface *srclist[2] = {
		&src[0], &src[1]
	};
	struct ren_vid_surface dst;
	void *inbuf[2], *outbuf;
	int ret;
	int frameno=0;

	int show_version = 0;
	int show_help = 0;
	int show_list_vio = 0;
	char * progname;
	char * viodev = NULL;
	int error = 0;

	int c;
	char * optstring = "hvo:O:c:s:C:S:f:u:l";

#ifdef HAVE_GETOPT_LONG
	static struct option long_options[] = {
		{"help", no_argument, 0, 'h'},
		{"version", no_argument, 0, 'v'},
		{"output", required_argument, 0, 'o'},
		{"overlay", required_argument, 0, 'O'},
		{"input-colorspace", required_argument, 0, 'c'},
		{"input-size", required_argument, 0, 's'},
		{"output-colorspace", required_argument, 0, 'C'},
		{"output-size", required_argument, 0, 'S'},
		{"filter", required_argument, 0, 'f'},
		{"vio", required_argument, 0, 'u'},
		{"list", no_argument, 0, 'l'},
		{NULL,0,0,0}
	};
#endif

#if defined(USE_MERAM_RA) || defined(USE_MERAM_WB)
#define ALIGN16(_x)	(((_x) + 15) / 16 * 16)
#define ADJUST_PITCH(_p, _w)			\
	{					\
		(_p) = ((_w) - 1) | 1023;	\
		(_p) = (_p) | ((_p) >> 1);	\
		(_p) = (_p) | ((_p) >> 2);	\
		(_p) += 1;			\
	}

	unsigned long val;
	MERAM *meram = meram_open();
	MERAM_REG *regs = meram_lock_reg(meram);
	size_t sz;
	unsigned long mblock;
	ICB *icbr, *icbw;
#endif /* defined(USE_MERAM_RA) || defined(USE_MERAM_WB) */
	memset(src, 0, sizeof (src[0]) * 2);
	src[0].w = -1;
	src[0].h = -1;
	dst.w = -1;
	dst.h = -1;
	src[0].format = REN_UNKNOWN;
	dst.format = REN_UNKNOWN;
	src[0].bpitchy = src[0].bpitchc = src[0].bpitcha = 0;
	dst.bpitchy = dst.bpitchc = dst.bpitcha = 0;

	memcpy((void *)&src[1], (void *)&src[0], sizeof(src[0]));

	src[1].blend_out.x = 0;
	src[1].blend_out.y = 0;
	src[1].blend_out.w = 220;
	src[1].blend_out.h = 440;

	progname = argv[0];

	if (argc < 2) {
		usage (progname);
		return (1);
	}

	while (1) {
#ifdef HAVE_GETOPT_LONG
		c = getopt_long (argc, argv, optstring, long_options, NULL);
#else
		c = getopt (argc, argv, optstring);
#endif
		if (c == -1) break;
		if (c == ':') {
			usage (progname);
			goto exit_err;
		}

		switch (c) {
		case 'h': /* help */
			show_help = 1;
			break;
		case 'v': /* version */
			show_version = 1;
			break;
		case 'o': /* output */
			outfilename = optarg;
			break;
		case 'O': /* ovalery */
			infilename[1] = optarg;
			break;
		case 'c': /* input colorspace */
			set_colorspace (optarg, &src[0].format);
			break;
		case 's': /* input size */
			set_size (optarg, &src[0].w, &src[0].h);
			break;
		case 'C': /* output colorspace */
			set_colorspace (optarg, &dst.format);
			break;
		case 'S': /* output size */
			set_size (optarg, &dst.w, &dst.h);
			break;
		case 'f': /* filter mode */
			rotation = strtoul(optarg, NULL, 0);
			break;
		case 'l':
			show_list_vio = 1;
			break;
		case 'u':
			viodev = optarg;
			break;
		default:
			break;
		}
	}

	if (show_version) {
		printf ("%s version " VERSION "\n", progname);
	}

	if (show_help) {
		usage (progname);
	}
#if 0
	if (show_list_vio) {
		char **vio;
		int i, n;

		if (shvio_list_vio(&vio, &n) < 0) {
			printf ("Can't get a list of VIO available...\n");
		} else {
			for(i = 0; i < n; i++)
				printf("%s", vio[i]);
			printf("Total: %d VIOs available.\n", n);
		}
	}
#endif

	if (show_version || show_help || show_list_vio) {
		goto exit_ok;
	}

	if (optind >= argc) {
		usage (progname);
		goto exit_err;
	}

	infilename[0] = argv[optind++];

	if (optind < argc) {
		outfilename = argv[optind++];
	}

	printf ("Input file: %s\n", infilename[0]);
	if (infilename[1] != NULL)
		printf ("Overlay file: %s\n", infilename[1]);
	printf ("Output file: %s\n", outfilename);

	guess_colorspace (infilename[0], &src[0].format);
	if (infilename[1])
		guess_colorspace (infilename[1], &src[1].format);
	guess_colorspace (outfilename, &dst.format);
	/* If the output colorspace isn't given and can't be guessed, then default to
	 * the input colorspace (ie. no colorspace conversion) */
	if (dst.format == REN_UNKNOWN)
		dst.format = src[0].format;

	guess_size (infilename[0], src[0].format, &src[0].w, &src[0].h);
	if (rotation & 0xF) {
		/* Swap width/height for rotation */
		dst.w = src[0].h;
		dst.h = src[0].w;
	} else if (dst.w == -1 && dst.h == -1) {
		/* If the output size isn't given and can't be guessed, then default to
		 * the input size (ie. no rescaling) */
		dst.w = src[0].w;
		dst.h = src[0].h;
	}
	if (infilename[1])
		guess_size (infilename[1], src[1].format, &src[1].w, &src[1].h);

	/* Setup memory pitch */
	src[0].pitch = src[0].w;
	src[1].pitch = src[1].w;
	dst.pitch = dst.w;

	/* Check that all parameters are set */
	if (src[0].format == REN_UNKNOWN) {
		fprintf (stderr, "ERROR: Input colorspace unspecified\n");
		error = 1;
	}
	if (src[0].w == -1) {
		fprintf (stderr, "ERROR: Input width unspecified\n");
		error = 1;
	}
	if (src[0].h == -1) {
		fprintf (stderr, "ERROR: Input height unspecified\n");
		error = 1;
	}

	if (dst.format == REN_UNKNOWN) {
		fprintf (stderr, "ERROR: Output colorspace unspecified\n");
		error = 1;
	}
	if (dst.w == -1) {
		fprintf (stderr, "ERROR: Output width unspecified\n");
		error = 1;
	}
	if (dst.h == -1) {
		fprintf (stderr, "ERROR: Output height unspecified\n");
		error = 1;
	}

	if (error) goto exit_err;

	printf ("Input colorspace:\t%s\n", show_colorspace (src[0].format));
	printf ("Input size:\t\t%dx%d %s\n", src[0].w, src[0].h, show_size (src[0].w, src[0].h));
	printf ("Output colorspace:\t%s\n", show_colorspace (dst.format));
	printf ("Output size:\t\t%dx%d %s\n", dst.w, dst.h, show_size (dst.w, dst.h));
	printf ("Rotation:\t\t%s\n", show_rotation (rotation));

	input_size[0] = imgsize (src[0].format, src[0].w, src[0].h);
	if (infilename[1] != NULL)
		input_size[1] = imgsize (src[1].format, src[1].w, src[1].h);
	output_size = imgsize (dst.format, dst.w, dst.h);

	if (/*viodev*/ 1) {
		const char *blocks[2] = { "VPU5", NULL };
		uiomux = uiomux_open_named(blocks);
		uiores = 1 << 0;

	} else {
		uiomux = uiomux_open ();
		uiores = UIOMUX_SH_VEU;
	} 

	/* Set up memory buffers */
	src[0].py = inbuf[0] = uiomux_malloc (uiomux, uiores, input_size[0], 32);
	if (src[0].format == REN_RGB565) {
		src[0].pc = 0;
	} else if (src[0].format == REN_YV12) {
		src[0].pc2 = src[0].py + (src[0].w * src[0].h);	/* Cr(V) */
		src[0].pc = src[0].pc2 + (src[0].w * src[0].h) / 4;	/* Cb(U) */
	} else if (src[0].format == REN_YV16) {
		src[0].pc2 = src[0].py + (src[0].w * src[0].h);	/* Cr(V) */
		src[0].pc = src[0].pc2 + (src[0].w * src[0].h) / 2;	/* Cb(U) */
	} else {
		src[0].pc = src[0].py + (src[0].w * src[0].h);	/* CbCr(UV) */
	}

	if (infilename[1] != NULL) {
		src[1].py = inbuf[1] = uiomux_malloc (uiomux, uiores, input_size[1], 32);
		if (src[1].format == REN_RGB565) {
			src[1].pc = 0;
		} else if (src[1].format == REN_YV12) {
			src[1].pc2 = src[1].py + (src[1].w * src[1].h);	/* Cr(V) */
			src[1].pc = src[1].pc2 + (src[1].w * src[1].h) / 4;	/* Cb(U) */
		} else if (src[1].format == REN_YV16) {
			src[1].pc2 = src[1].py + (src[1].w * src[1].h);	/* Cr(V) */
			src[1].pc = src[1].pc2 + (src[1].w * src[1].h) / 2;	/* Cb(U) */
		} else {
			src[1].pc = src[1].py + (src[1].w * src[1].h);	/* CbCr(UV) */
		}
	}

	dst.py = outbuf = uiomux_malloc (uiomux, uiores, output_size, 32);
	if (dst.format == REN_RGB565) {
		dst.pc = 0;
	} else if (dst.format == REN_YV12) {
		dst.pc2 = dst.py + (dst.w * dst.h);	/* Cr(V) */
		dst.pc = dst.pc2 + (dst.w * dst.h) / 4;	/* Cb(U) */
	} else if (dst.format == REN_YV16) {
		dst.pc2 = dst.py + (dst.w * dst.h);	/* Cr(V) */
		dst.pc = dst.pc2 + (dst.w * dst.h) / 2;	/* Cb(U) */
	} else {
		dst.pc = dst.py + (dst.w * dst.h);	/* CbCr(UV) */
	}

#if defined(USE_MERAM_RA) || defined(USE_MERAM_WB)
#error aaaa
	meram_read_reg(meram, regs, MEVCR1, &val);
	val |= 1 << 29;		/* use 0xc0000000-0xdfffffff */
	meram_write_reg(meram, regs, MEVCR1, val);
	meram_unlock_reg(meram, regs);
#endif /* defined(USE_MERAM_RA) || defined(USE_MERAM_WB) */

#if defined(USE_MERAM_RA)
#error bbbb
	/* calcurate byte-pitch */
	src[0].bpitchy = size_y(src[0].format, src[0].pitch, 0);

	/* set up read-ahead cache for input */
	icbr = meram_lock_icb(meram, 0);
	val = (3 << 24) |		/* KRBNM: ((3+1) << 1) = 8 lines */
		((16 - 1) << 16);	/* BNM: 16 = KRBNM * 2 lines */
	ADJUST_PITCH(sz, src[0].bpitchy);
	sz *= 16;			/* 16 lines */
	if (src[0].format == REN_NV12) {
		val |= 2 << 12;	/* CPL: YCbCr420 */
		sz = sz * 3 / 2;
	} else if (src[0].format == REN_NV16) {
		val |= 3 << 12;	/* CPL: YCbCr422 */
		sz = sz * 2;
	}
	meram_write_icb(meram, icbr, MExxMCNF, val);

	sz = (sz + 1023) / 1024;
	mblock = meram_alloc_icb_memory(meram, icbr,
					    (sz == 0) ? 1 : sz);
	val = (1 << 28) |		/* BSZ: 2^1 line/block */
		(mblock << 16) |	/* MSAR */
		(3 << 9) |		/* WD: (constant) */
		(1 << 8) |		/* WS: (constant) */
		(1 << 3) |		/* CM: address mode 1 */
		1;			/* MD: read buffer mode */
	meram_write_icb(meram, icbr, MExxCTRL, val);

	val = ((src[0].h - 1) << 16) |	/* YSZM1 */
		(src[0].bpitchy - 1);	/* XSZM1 */
	meram_write_icb(meram, icbr, MExxBSIZE, val);
	val = ALIGN16(src[0].bpitchy);	/* SBSIZE: 16 bytes aligned */
	meram_write_icb(meram, icbr, MExxSBSIZE, val);

	ADJUST_PITCH(src[0].bpitchy, src[0].bpitchy);
	src[0].bpitchc = src[0].bpitcha = src[0].bpitchy;

	val = uiomux_all_virt_to_phys(src[0].py);
	meram_write_icb(meram, icbr, MExxSSARA, val);

	src[0].py = (void *)meram_get_icb_address(meram, icbr, 0);
	uiomux_register(src[0].py, (unsigned long)src[0].py, 8 << 20);
	if (is_ycbcr(src[0].format)) {
		val = uiomux_all_virt_to_phys(src[0].pc);
		meram_write_icb(meram, icbr, MExxSSARB, val);
		src[0].pc = (void *)meram_get_icb_address(meram, icbr, 1);
		uiomux_register(src[0].pc, (unsigned long)src[0].pc, 8 << 20);
	} else {
		meram_write_icb(meram, icbr, MExxSSARB, 0);
	}
#endif /* defined(USE_MERAM_RA) */

#if defined(USE_MERAM_WB)
	/* calcurate byte-pitch */
	dst.bpitchy = size_y(dst.format, dst.pitch, 0);

	/* set up write-back cache for input */
	icbw = meram_lock_icb(meram, 1);
	val = (3 << 28) |		/* KWBNM: ((3+1) << 1) = 8 lines */
		((16 - 1) << 16);	/* BNM: 16 = KWBNM * 2 lines */
	ADJUST_PITCH(sz, dst.bpitchy);
	sz *= 16;			/* 16 lines */
	if (dst.format == REN_NV12) {
		val |= 2 << 12;	/* CPL: YCbCr420 */
		sz = sz * 3 / 2;
	} else if (dst.format == REN_NV16) {
		val |= 3 << 12;	/* CPL: YCbCr422 */
		sz = sz * 2;
	}
	meram_write_icb(meram, icbw, MExxMCNF, val);
	sz = (sz + 1023) / 1024;
	mblock = meram_alloc_icb_memory(meram, icbw,
					(sz == 0) ? 1 : sz);
	val = (1 << 28) |		/* BSZ: 2^1 line/block */
		(mblock << 16) |	/* MSAR */
		(3 << 9) |		/* WD: (constant) */
		(1 << 8) |		/* WS: (constant) */
		(1 << 3) |		/* CM: address mode 1 */
		2;			/* MD: write buffer mode */
	meram_write_icb(meram, icbw, MExxCTRL, val);

	val = ((dst.h - 1) << 16) |	/* YSZM1 */
		(dst.bpitchy - 1);	/* XSZM1 */
	meram_write_icb(meram, icbw, MExxBSIZE, val);
	val = ALIGN16(dst.bpitchy);	/* SBSIZE: 16 bytes aligned */
	meram_write_icb(meram, icbw, MExxSBSIZE, val);

	ADJUST_PITCH(dst.bpitchy, dst.bpitchy);
	dst.bpitchc = dst.bpitcha = dst.bpitchy;

	val = uiomux_all_virt_to_phys(dst.py);
	meram_write_icb(meram, icbw, MExxSSARA, val);

	dst.py = (void *)meram_get_icb_address(meram, icbw, 0);
	uiomux_register(dst.py, (unsigned long)dst.py, 8 << 20);
	if (is_ycbcr(dst.format)) {
		val = uiomux_all_virt_to_phys(dst.pc);
		meram_write_icb(meram, icbw, MExxSSARB, val);
		dst.pc = (void *)meram_get_icb_address(meram, icbw, 1);
		uiomux_register(dst.pc, (unsigned long)dst.pc, 8 << 20);
	} else {
		meram_write_icb(meram, icbw, MExxSSARB, 0);
	}
#endif /* defined(USE_MERAM_WB) */

	if (strcmp (infilename[0], "-") == 0) {
		infile[0] = stdin;
	} else {
		infile[0] = fopen (infilename[0], "rb");
		if (infile[0] == NULL) {
			fprintf (stderr, "%s: unable to open input file %s\n",
				 progname, infilename[0]);
			goto exit_err;
		}
	}

	if (infilename[1] != NULL) {
		infile[1] = fopen (infilename[1], "rb");
		if (infile[1] == NULL) {
			fprintf (stderr, "%s: unable to open input file %s\n",
				 progname, infilename[1]);
			goto exit_err;
		}
	}

	if (outfilename != NULL) {
		if (strcmp (outfilename, "-") == 0) {
			outfile = stdout;
		} else {
			outfile = fopen (outfilename, "wb");
			if (outfile == NULL) {
				fprintf (stderr, "%s: unable to open output file %s\n",
					 progname, outfilename);
				goto exit_err;
			}
		}
	}

	if (!viodev)
		vio = shvio_open();
	else
		vio = shvio_open_named(viodev);

	if (vio == 0) {
		fprintf (stderr, "Error opening VIO\n");
		goto exit_err;
	}

	while (1) {
#ifdef DEBUG
		fprintf (stderr, "%s: Converting frame %d\n", progname, frameno);
#endif

		/* Read input */
		if ((nread = fread (inbuf[0], 1, input_size[0], infile[0])) != input_size[0]) {
			if (nread == 0 && feof (infile[0])) {
				break;
			} else {
				fprintf (stderr, "%p, %s: errors reading input file %s %d %d %d\n", inbuf[0],
					 progname, infilename[0], nread, input_size[0], ferror(infile[0]));
			}
		}
#if 1
		if (infilename[1] != NULL) {
			if ((nread = fread (inbuf[1], 1, input_size[1], infile[1])) != input_size[1]) {
				if (nread == 0 && feof (infile[1])) {
					break;
				} else {
					fprintf (stderr, "%s: error reading input file %s\n",
						 progname, infilename[1]);
				}
			}

			printf("invoke shvio_setup_blend()...\n");
			ret = shvio_setup_blend(vio, NULL, srclist, 2, &dst);
			shvio_start(vio);
			printf("shvio_start_blend() = %d\n", ret);
			ret = shvio_wait(vio);
		} else {
#endif
			if (rotation) {
				ret = shvio_rotate(vio, &src[0], &dst, rotation);
			} else {
				ret = shvio_resize(vio, &src[0], &dst);
			}
		}

#if defined(USE_MERAM_WB)
		meram_read_icb(meram, icbw, MExxCTRL, &val);
		val |= 1 << 5;	/* WF: flush data */
		meram_write_icb(meram, icbw, MExxCTRL, val);
#endif
#if defined(USE_MERAM_RA)
		meram_read_icb(meram, icbr, MExxCTRL, &val);
		val |= 1 << 4;	/* RF: flush data */
		meram_write_icb(meram, icbr, MExxCTRL, val);
#endif

		/* Write output */
		if (outfile && fwrite (outbuf, 1, output_size, outfile) != output_size) {
				fprintf (stderr, "%s: error writing input file %s\n",
					 progname, outfilename);
		}

		frameno++;
	}

	shvio_close (vio);

#if defined(USE_MERAM_RA)
	/* finialize the read-ahead cache */
	uiomux_unregister(src[0].py);
	if (is_ycbcr(src[0].format))
		uiomux_unregister(src[0].pc);
	meram_free_icb_memory(meram, icbr);
	meram_unlock_icb(meram, icbr);
#endif
#if defined(USE_MERAM_WB)
	/* finialize the write-back cache */
	uiomux_unregister(dst.py);
	if (is_ycbcr(dst.format))
		uiomux_unregister(dst.pc);
	meram_free_icb_memory(meram, icbw);
	meram_unlock_icb(meram, icbw);
#endif
#if defined(USE_MERAM_RA) || defined(USE_MERAM_WB)
	meram_close(meram);
#endif

	uiomux_free (uiomux, uiores, src[0].py, input_size[0]);
	if (infilename[1] != NULL)
		uiomux_free (uiomux, uiores, src[1].py, input_size[1]);
	uiomux_free (uiomux, uiores, dst.py, output_size);
	uiomux_close (uiomux);

	if (infile[0] != stdin) fclose (infile[0]);
	if (infilename[1] != NULL)
		fclose (infile[1]);

	if (outfile == stdout) {
		fflush (stdout);
	} else if (outfile) {
		fclose (outfile);
	}

	printf ("Frames:\t\t%d\n", frameno);

exit_ok:
	exit (0);

exit_err:
	exit (1);
}