示例#1
0
// changed to return original frame instead of returning converted frame even if convert_func is not null.
uvc_frame_t *UVCPreview::draw_preview_one(uvc_frame_t *frame, ANativeWindow **window, convFunc_t convert_func, int pixcelBytes) {
	// ENTER();

	int b = 0;
	pthread_mutex_lock(&preview_mutex);
	{
		b = *window != NULL;
	}
	pthread_mutex_unlock(&preview_mutex);
	if (LIKELY(b)) {
		uvc_frame_t *converted;
		if (convert_func) {
			converted = uvc_allocate_frame(frame->width * frame->height * pixcelBytes);
			if LIKELY(converted) {
				b = convert_func(frame, converted);
				if (!b) {
					pthread_mutex_lock(&preview_mutex);
					copyToSurface(converted, window);
					pthread_mutex_unlock(&preview_mutex);
				} else {
					LOGE("failed converting");
				}
				uvc_free_frame(converted);
			}
		} else {
			pthread_mutex_lock(&preview_mutex);
			copyToSurface(frame, window);
			pthread_mutex_unlock(&preview_mutex);
		}
	}
示例#2
0
文件: tofb.c 项目: xingskycn/tofb
static int file_to_fb(const char * srcpath)
{
	int ret = -1;
	BMP_READ * bmp = NULL;
	struct FB * fb = NULL;
	int sw, sh;
	int srcbpp, dstbpp;
	void * pdata = NULL, * bmpdata = NULL;
	RGB_CONVERT_FUN convert_func = NULL;
	
	do 
	{
		bmp = bmp_open(srcpath);
		if (!bmp) {
			break;
		}
		fb = fb_create(0);
		if (!fb) {
			break;
		}
		
		sw = bmp_width(bmp);
		sh = bmp_height(bmp);
		bmpdata = bmp_data(bmp);
		srcbpp = bmp_bpp(bmp);
		dstbpp = fb_bpp(fb);
		
		convert_func = get_convert_func(srcbpp, dstbpp);
		if (convert_func) {
			pdata = convert_func(bmpdata, sw, sh);
			bmpdata = pdata;
		}
		
		if (!bmp_forward(bmp)) {
			line_reversal(bmpdata, sw, sh, dstbpp);
		}
		
		rgb_copy(bmpdata, fb_bits(fb), sw, sh, fb_width(fb), fb_height(fb), dstbpp);
		ret = 0;
	} while (0);
	
	fb_destory(fb);
	bmp_close(bmp);
	if (pdata) {
		free(pdata);
	}
	return ret;	
}
示例#3
0
	void StencilScopeOGL::applySettings(const StencilSettings& settings)
	{
		if(settings.enabled()) {
			glEnable(GL_STENCIL_TEST);
			glStencilOpSeparate(convert_face(settings.face()), 
				convert_stencil_op(settings.sfail()),
				convert_stencil_op(settings.dpfail()),
				convert_stencil_op(settings.dppass()));
			glStencilFuncSeparate(convert_face(settings.face()), 
				convert_func(settings.func()),
				settings.ref(),
				settings.ref_mask());
			glStencilMaskSeparate(convert_face(settings.face()), settings.mask());
		} else {
			glDisable(GL_STENCIL_TEST);
			glStencilMask(0);
		}
	}
示例#4
0
char *str_convert(const char *str, int (*convert_func) (int))
{
    char *p;
    int len, i;

    if (!convert_func)
        return NULL;
    len = strlen(str);
    if (len < 0)
        return NULL;
    p = malloc(len + 1);
    if (!p)
        return NULL;
    for (i = 0; i < len; i++)
        p[i] = convert_func((int)str[i]);
    p[i + 1]  = '\0';
    return p;
}
示例#5
0
文件: tofb.c 项目: xingskycn/tofb
static int file_to_file(const char * srcpath, const char * dstpath, int output_rgb)
{
	int ret = -1;
	BMP_READ * bmp = NULL;
	int w, h;
	int srcbpp, dstbpp;
	void * pdata = NULL, * bmpdata = NULL;
	RGB_CONVERT_FUN convert_func = NULL;

	do 
	{
		bmp = bmp_open(srcpath);
		if (!bmp) {
			break;
		}
		
		w = bmp_width(bmp);
		h = bmp_height(bmp);
		bmpdata = bmp_data(bmp);
		srcbpp = bmp_bpp(bmp);
		dstbpp = g_rgbbpp[output_rgb];

		convert_func = get_convert_func(srcbpp, dstbpp);
		if (convert_func) {
			pdata = convert_func(bmpdata, w, h);
			bmpdata = pdata;
		}

		if (!bmp_forward(bmp)) {
			line_reversal(bmpdata, w, h, dstbpp);
		}
		
		ret = save_bmp(dstpath, w, h, bmpdata, dstbpp);
	} while (0);

	bmp_close(bmp);
	if (pdata) {
		free(pdata);
	}
	return ret;	
}
示例#6
0
uvc_frame_t *UVCPreview::draw_preview_one(uvc_frame_t *frame, ANativeWindow **window, convFunc_t convert_func, int pixcelBytes) {
	// ENTER();

	uvc_error_t ret;
	ANativeWindow_Buffer buffer;

	int b = 0;
	pthread_mutex_lock(&preview_mutex);
	{
		b = *window != NULL;
	}
	pthread_mutex_unlock(&preview_mutex);
	if (LIKELY(b)) {
		uvc_frame_t *converted;
		if (convert_func) {
			converted = uvc_allocate_frame(frame->width * frame->height * pixcelBytes);
			if LIKELY(converted) {
				b = convert_func(frame, converted);
				if (UNLIKELY(b)) {
					LOGE("failed converting");
					uvc_free_frame(converted);
					converted = NULL;
				}
			}
			// release original frame data(YUYV)
			uvc_free_frame(frame);
			frame = NULL;
		} else {
			converted = frame;
		}
		if (LIKELY(converted)) {
			// draw a frame to the view when success to convert
			pthread_mutex_lock(&preview_mutex);
			copyToSurface(converted, window);
			pthread_mutex_unlock(&preview_mutex);
			return converted; // RETURN(converted, uvc_frame_t *);
		} else {
			LOGE("draw_preview_one:unable to allocate converted frame!");
		}
	}
示例#7
0
文件: tofb.c 项目: xingskycn/tofb
static int fb_to_file(const char * dstpath, int output_rgb)
{
	int ret = -1;
	int w, h;
	int srcbpp, dstbpp;
	void * pdata = NULL, * fbdata = NULL;
	RGB_CONVERT_FUN convert_func = NULL;

	struct FB * fb = NULL;

	do 
	{
		fb = fb_create(1);
		if (!fb) {
			break;
		}

		w = fb_width(fb);
		h = fb_height(fb);
		fbdata = fb_bits(fb);
		srcbpp = fb_bpp(fb);
		dstbpp = g_rgbbpp[output_rgb];

		convert_func = get_convert_func(srcbpp, dstbpp);
		if (convert_func) {
			pdata = convert_func(fbdata, w, h);
			fbdata = pdata;
		}

		ret = save_bmp(dstpath, w, h, fbdata, dstbpp);
	} while (0);

	if (pdata) {
		free(pdata);
	}
	fb_destory(fb);
	
	return ret;
}
示例#8
0
int main(int argc, char *argv[])
{
   char *unit_vals[] = { "si" , "mercalli" , "omori" , "g" , NULL };
   char *info_vals[] = { "mercalli" , "omori" , NULL };
   int i;
   int n, units, info;
   double dt, mag;
   gboolean verbose;
   double average_quake;
   double acceleration;
   double (*convert_func)(double);
   double (*convert_inv_func)(double);
   Eh_args *args;

   args = eh_opts_init( argc , argv );
   if ( eh_check_opts( args , NULL , NULL , help_msg )!=0 )
     eh_exit(-1);

   n       = eh_get_opt_int ( args , "n"     , DEFAULT_N   );
   dt      = eh_get_opt_dbl ( args , "dt"    , DEFAULT_DT  );
   mag     = eh_get_opt_dbl ( args , "mag"   , DEFAULT_MAG );
   verbose = eh_get_opt_bool( args , "v"     , FALSE       );
   units   = eh_get_opt_key ( args , "units" , 0  ,  unit_vals );
   info    = eh_get_opt_key ( args , "info"  , -1 ,  info_vals );
 
   switch ( info )
   {
      case INFO_MERCALLI:
         eh_print_message( stderr , mercalli_msg );
         eh_exit(0);
      case INFO_OMORI:
         eh_print_message( stderr , omori_msg );
         eh_exit(0);
   }

   if ( verbose )
   {
      fprintf(stderr,"Magnitude : %f\n",mag);
      fprintf(stderr,"Dt        : %f\n",dt);
      fprintf(stderr,"n         : %d\n",n);
   }

   switch ( units )
   {
      case SI_UNITS:
         convert_func = &convert_accel_to_si;
         convert_inv_func = &convert_si_to_accel;
         break;
      case MERCALLI_UNITS:
         convert_func = &convert_accel_to_mercalli;
         convert_inv_func = &convert_mercalli_to_accel;
         break;
      case OMORI_UNITS:
         convert_func = &convert_accel_to_omori;
         convert_inv_func = &convert_omori_to_accel;
         break;
      case G_UNITS:
         convert_func = &convert_accel_to_g;
         convert_inv_func = &convert_g_to_accel;
         break;
   }

   if ( strcmp(g_basename(argv[0]),"quakeconvert_to")==0 )
   {
      while ( fscanf(stdin,"%lf",&acceleration)==1 )
         fprintf(stdout,"%f\n",convert_func(acceleration));
      return 0;
   }
   else if ( strcmp(g_basename(argv[0]),"quakeconvert_from")==0 )
   {
      while ( fscanf(stdin,"%lf",&acceleration)==1 )
         fprintf(stdout,"%f\n",convert_inv_func(acceleration));
      return 0;
   }

   average_quake = convert_inv_func(mag);

   for ( i=0 ; i<n ; i++ )
   {
      acceleration = earthquake(exp(-1./average_quake),dt);
      fprintf(stdout,"%f\n",convert_func(acceleration));
   }

   return 0;
}