Exemplo n.º 1
0
image_t *ImageFind( const char *filename )
{
	int			i;
	char		name[ 1024 ];
	
	
	/* init */
	ImageInit();
	
	/* dummy check */
	if( filename == NULL || filename[ 0 ] == '\0' )
		return NULL;
	
	/* strip file extension off name */
	strcpy( name, filename );
	StripExtension( name );
	
	/* search list */
	for( i = 0; i < MAX_IMAGES; i++ )
	{
		if( images[ i ].name != NULL && !strcmp( name, images[ i ].name ) )
			return &images[ i ];
	}
	
	/* no matching image found */
	return NULL;
}
Exemplo n.º 2
0
int main(int argc,char * argv[])
{
    int iterTime  = 100;
    IplImage *imgSrc = ImageInit(iterTime);
    IplImage *imgDes = cvCreateImage(cvSize(imgSrc->width,imgSrc->height),IPL_DEPTH_8U, 1);
    imgDes           = cvCloneImage(imgSrc);
    
    clock_t sclock,eclock;
    time_t stime,etime;
    sclock = clock();
    stime=time(NULL);
    
//    SRAD(imgSrc,imgDes,iterTime);
    SRAD_GPU( imgSrc, imgDes, iterTime);
    etime=time(NULL);
    printf("time=%ld\n",etime-stime);
    eclock = clock();
    printf("Total compute time is %fs\n",(eclock-sclock)/(double)(CLOCKS_PER_SEC));
    
    ShowImage(imgSrc,imgDes);
    cvSaveImage(RESULT_DIR,imgDes);
    printf("result image has been saved in %s. \n",RESULT_DIR);
    cvWaitKey(0);
    cvReleaseImage(&imgSrc);
    cvReleaseImage(&imgDes);
    
    return 0;
}
Exemplo n.º 3
0
image_t *ImageLoad( const char *filename )
{
	int			i;
	image_t		*image;
	char		name[ 1024 ];
	int			size;
	byte		*buffer = NULL;
	qboolean	alphaHack = qfalse;

	
	/* init */
	ImageInit();
	
	/* dummy check */
	if( filename == NULL || filename[ 0 ] == '\0' )
		return NULL;
	
	/* strip file extension off name */
	strcpy( name, filename );
	StripExtension( name );
	
	/* try to find existing image */
	image = ImageFind( name );
	if( image != NULL )
	{
		image->refCount++;
		return image;
	}
	
	/* none found, so find first non-null image */
	image = NULL;
	for( i = 0; i < MAX_IMAGES; i++ )
	{
		if( images[ i ].name == NULL )
		{
			image = &images[ i ];
			break;
		}
	}
	
	/* too many images? */
	if( image == NULL )
		Error( "MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES );
	
	/* set it up */
	image->name = safe_malloc( strlen( name ) + 1 );
	strcpy( image->name, name );
	
	/* attempt to load tga */
	StripExtension( name );
	strcat( name, ".tga" );
	size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
	if( size > 0 )
		LoadTGABuffer( buffer, buffer + size, &image->pixels, &image->width, &image->height );
	else
	{
		/* attempt to load png */
		StripExtension( name );
		strcat( name, ".png" );
		size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
		if( size > 0 )
			LoadPNGBuffer( buffer, size, &image->pixels, &image->width, &image->height );
		else
		{
			/* attempt to load jpg */
			StripExtension( name );
			strcat( name, ".jpg" );
			size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
			if( size > 0 )
			{
				if( LoadJPGBuff( buffer, size, &image->pixels, &image->width, &image->height ) == -1 && image->pixels != NULL )
					Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
				alphaHack = qtrue;
			}
			else
			{
				/* attempt to load dds */
				StripExtension( name );
				strcat( name, ".dds" );
				size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
				if( size > 0 )
				{
					LoadDDSBuffer( buffer, size, &image->pixels, &image->width, &image->height );
					
					/* debug code */
					#if 1
					{
						ddsPF_t	pf;
						DDSGetInfo( (ddsBuffer_t*) buffer, NULL, NULL, &pf );
						Sys_Printf( "pf = %d\n", pf );
						if( image->width > 0 )
						{
							StripExtension( name );
							strcat( name, "_converted.tga" );
							WriteTGA( "C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width, image->height );
						}
					}
					#endif
				}
			}
		}
	}
	
	/* free file buffer */
	free( buffer );
	
	/* make sure everything's kosher */
	if( size <= 0 || image->width <= 0 || image->height <= 0 || image->pixels == NULL )
	{
		//%	Sys_Printf( "size = %d  width = %d  height = %d  pixels = 0x%08x (%s)\n",
		//%		size, image->width, image->height, image->pixels, name );
		free( image->name );
		image->name = NULL;
		return NULL;
	}
	
	/* set filename */
	image->filename = safe_malloc( strlen( name ) + 1 );
	strcpy( image->filename, name );
	
	/* set count */
	image->refCount = 1;
	numImages++;

	if(alphaHack)
	{
		StripExtension( name );
		strcat( name, "_alpha.jpg" );
		size = vfsLoadFile( (const char*) name, (void**) &buffer, 0 );
		if( size > 0 )
		{
			unsigned char *pixels;
			int width, height;
			if( LoadJPGBuff( buffer, size, &pixels, &width, &height ) == -1 && pixels != NULL )
				Sys_Printf( "WARNING: LoadJPGBuff: %s\n", (unsigned char*) image->pixels );
			if(pixels && width == image->width && height == image->height)
			{
				int i;
				for(i = 0; i < width*height; ++i)
					image->pixels[4*i+3] = pixels[4*i+2]; // copy alpha from blue channel
			}
			free(pixels);
			free(buffer);
		}
	}
	
	/* return the image */
	return image;
}
Exemplo n.º 4
0
void SkJS::InitializeDisplayables(const SkBitmap& bitmap, JSContext *cx, JSObject *obj, JSObject *proto) {
    SkJSDisplayable::gCanvas = new SkCanvas(bitmap);
    SkJSDisplayable::gPaint = new SkPaint();
#if SK_USE_CONDENSED_INFO == 0
    GenerateTables();
#else
    SkASSERT(0); // !!! compressed version hasn't been implemented
#endif
    AddInit(cx, obj, proto);
    AddCircleInit(cx, obj, proto);
    AddOvalInit(cx, obj, proto);
    AddPathInit(cx, obj, proto);
    AddRectangleInit(cx, obj, proto);
    AddRoundRectInit(cx, obj, proto);
//  AfterInit(cx, obj, proto);
    ApplyInit(cx, obj, proto);
    // AnimateInit(cx, obj, proto);
//  AnimateColorInit(cx, obj, proto);
    AnimateFieldInit(cx, obj, proto);
//  AnimateRotateInit(cx, obj, proto);
//  AnimateScaleInit(cx, obj, proto);
//  AnimateTranslateInit(cx, obj, proto);
    BitmapInit(cx, obj, proto);
//  BaseBitmapInit(cx, obj, proto);
//  BeforeInit(cx, obj, proto);
    BitmapShaderInit(cx, obj, proto);
    BlurInit(cx, obj, proto);
    ClipInit(cx, obj, proto);
    ColorInit(cx, obj, proto);
    CubicToInit(cx, obj, proto);
    DashInit(cx, obj, proto);
    DataInit(cx, obj, proto);
//  DimensionsInit(cx, obj, proto);
    DiscreteInit(cx, obj, proto);
    DrawToInit(cx, obj, proto);
    EmbossInit(cx, obj, proto);
    EventInit(cx, obj, proto);
//  FontInit(cx, obj, proto);
//  FocusInit(cx, obj, proto);
    ImageInit(cx, obj, proto);
    IncludeInit(cx, obj, proto);
//  InputInit(cx, obj, proto);
    LineInit(cx, obj, proto);
    LinearGradientInit(cx, obj, proto);
    LineToInit(cx, obj, proto);
    MatrixInit(cx, obj, proto);
    MoveInit(cx, obj, proto);
    MoveToInit(cx, obj, proto);
    OvalInit(cx, obj, proto);
    PathInit(cx, obj, proto);
    PaintInit(cx, obj, proto);
    DrawPointInit(cx, obj, proto);
    PolyToPolyInit(cx, obj, proto);
    PolygonInit(cx, obj, proto);
    PolylineInit(cx, obj, proto);
    PostInit(cx, obj, proto);
    QuadToInit(cx, obj, proto);
    RadialGradientInit(cx, obj, proto);
    RandomInit(cx, obj, proto);
    RectToRectInit(cx, obj, proto);
    RectangleInit(cx, obj, proto);
    RemoveInit(cx, obj, proto);
    ReplaceInit(cx, obj, proto);
    RotateInit(cx, obj, proto);
    RoundRectInit(cx, obj, proto);
    ScaleInit(cx, obj, proto);
    SetInit(cx, obj, proto);
    SkewInit(cx, obj, proto);
    // 3D_CameraInit(cx, obj, proto);
    // 3D_PatchInit(cx, obj, proto);
    SnapshotInit(cx, obj, proto);
//  StrokeInit(cx, obj, proto);
    TextInit(cx, obj, proto);
    TextOnPathInit(cx, obj, proto);
    TextToPathInit(cx, obj, proto);
    TranslateInit(cx, obj, proto);
//  UseInit(cx, obj, proto);
}
Exemplo n.º 5
0
int main()
{
	/*----------------------------Part 1------------------------------------*/
	int ysize = 342;
	int xsize = 546;
	int padding = 1;


	float	**inImage = ImageInit(xsize, ysize);
	float	**padImage = ImageInit(xsize + 2*padding, ysize + 2*padding);
	float	**sobelImage = ImageInit(xsize, ysize);
	float	**threshImage = ImageInit(xsize, ysize);

	
	OpenImage("porsche", xsize, ysize, inImage);
	PadImage(inImage, padImage, xsize, ysize, padding);
	Sobel(padImage, sobelImage, xsize + 2*padding, ysize + 2*padding);
	SaveImage("porsche", "_sobel", xsize, ysize, sobelImage);
	BinThresh(sobelImage, threshImage, xsize, ysize, 60);
	SaveImage("porsche", "_thresh60", xsize, ysize, threshImage);


	ysize = 256;
	xsize = 256;
	OpenImage("mri", xsize, ysize, inImage);
	PadImage(inImage, padImage, xsize, ysize, padding);
	Sobel(padImage, sobelImage, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("mri", "_sobel", xsize, ysize, sobelImage);
	BinThresh(sobelImage, threshImage, xsize, ysize, 50);
	SaveImage("mri", "_thresh50", xsize, ysize, threshImage);

	free(inImage);
	free(padImage);
	free(sobelImage);
	free(threshImage);

	/*----------------------------Part 2------------------------------------*/
	xsize = ysize = 256;
	float	**circImage = ImageInit(xsize, ysize);
	float	**padCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelCirc = ImageInit(xsize, ysize);
	float	**threshCirc = ImageInit(xsize, ysize);
	float	**noiseCirc = ImageInit(xsize, ysize);
	float	**padNoiseCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelNoiseCirc = ImageInit(xsize, ysize);
	float	**noiseGaussCirc = ImageInit(xsize, ysize);
	float	**padNoiseGaussCirc = ImageInit(xsize + 2 * padding, ysize + 2 * padding);
	float	**sobelNoiseGaussCirc = ImageInit(xsize, ysize);
	float	**sobelNoiseGaussThreshCirc = ImageInit(xsize, ysize);

	float **test = ImageInit(xsize + 2, ysize +2);

	int c = 256 / 2 - 1;
	CreateCircle(circImage, ysize, xsize, c, c, 50, 60);
	CreateCircle(circImage, ysize, xsize, c, c, 50, 40);
	CreateCircle(circImage, ysize, xsize, c, c, 50, 20);


	SaveImage("circles", "", xsize, ysize, circImage);
	PadImage(circImage, padCirc, xsize, ysize, padding);
	Sobel(padCirc, sobelCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_sobel", xsize, ysize, sobelCirc);

	BinThresh(sobelCirc, threshCirc, xsize, ysize, 100);
	SaveImage("circles", "_thresh100", xsize, ysize, threshCirc);

	// Noise = 10
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 10);
	SaveImage("circles", "_noise10", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel10", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss10", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh10", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);

	// Noise = 50
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 50);
	SaveImage("circles", "_noise50", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel50", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss50", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh50", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);


	// Noise = 100
	AddUniNoise(circImage, noiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise100", xsize, ysize, noiseCirc);

	PadImage(noiseCirc, padNoiseCirc, xsize, ysize, padding);
	Sobel(padNoiseCirc, sobelNoiseCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseCirc, sobelNoiseCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel100", xsize, ysize, sobelNoiseCirc);
	AccuracyReport(threshCirc, sobelNoiseCirc, xsize, ysize);

	GaussianSmooth(padNoiseCirc, noiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	SaveImage("circles", "_noise_gauss100", xsize, ysize, noiseGaussCirc);
	PadImage(noiseGaussCirc, padNoiseGaussCirc, xsize, ysize, padding);
	Sobel(padNoiseGaussCirc, sobelNoiseGaussCirc, xsize + 2 * padding, ysize + 2 * padding);
	BinThresh(sobelNoiseGaussCirc, sobelNoiseGaussThreshCirc, xsize, ysize, 100);
	SaveImage("circles", "_noise_sobel_gauss_thresh100", xsize, ysize, sobelNoiseGaussThreshCirc);
	AccuracyReport(threshCirc, sobelNoiseGaussThreshCirc, xsize, ysize);


	free(circImage);
	free(padCirc);
	free(sobelCirc);
	free(threshCirc);
	free(noiseCirc);
	free(padNoiseCirc);
	free(sobelNoiseCirc);
	free(noiseGaussCirc);
	free(padNoiseGaussCirc);
	free(sobelNoiseGaussCirc);
	free(sobelNoiseGaussThreshCirc);

	return 0;
}
Exemplo n.º 6
0
image_t        *ImageLoad(const char *filename)
{
    int             i;
    image_t        *image;
    char            name[1024];
    int             size;
    byte           *buffer = NULL;


    /* init */
    ImageInit();

    /* dummy check */
    if(filename == NULL || filename[0] == '\0')
        return NULL;

    /* strip file extension off name */
    strcpy(name, filename);
    StripExtension(name);

    /* try to find existing image */
    image = ImageFind(name);
    if(image != NULL)
    {
        image->refCount++;
        return image;
    }

    /* none found, so find first non-null image */
    image = NULL;
    for(i = 0; i < MAX_IMAGES; i++)
    {
        if(images[i].name == NULL)
        {
            image = &images[i];
            break;
        }
    }

    /* too many images? */
    if(image == NULL)
        Error("MAX_IMAGES (%d) exceeded, there are too many image files referenced by the map.", MAX_IMAGES);

    /* set it up */
    image->name = safe_malloc(strlen(name) + 1);
    strcpy(image->name, name);

#if 1
    /* attempt to load tga */
    StripExtension(name);
    strcat(name, ".tga");
    size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
    if(size > 0)
        LoadTGABuffer(buffer, &image->pixels, &image->width, &image->height);
    else
    {
#if 1
        /* attempt to load png */
        StripExtension(name);
        strcat(name, ".png");
        size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
        if(size > 0)
            LoadPNGBuffer(buffer, &image->pixels, &image->width, &image->height);
        else
        {
#if 1
            /* attempt to load jpg */
            StripExtension(name);
            strcat(name, ".jpg");
            size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
            if(size > 0)
            {
                LoadJPGBuffer((const char *)name, buffer, size, &image->pixels, &image->width, &image->height);
                if(image->pixels == NULL)
                    Sys_Printf("WARNING: LoadJPGBuffer: '%s'\n", image->name);
            }
            else
            {
#if 1
                /* attempt to load dds */
                StripExtension(name);
                strcat(name, ".dds");
                size = vfsLoadFile((const char *)name, (void **)&buffer, 0);
                if(size > 0)
                {
                    LoadDDSBuffer(buffer, size, &image->pixels, &image->width, &image->height);

                    /* debug code */
#if 0
                    {
                        ddsPF_t         pf;

                        DDSGetInfo((ddsBuffer_t *) buffer, NULL, NULL, &pf);
                        Sys_Printf("pf = %d\n", pf);
                        if(image->width > 0)
                        {
                            StripExtension(name);
                            strcat(name, "_converted.tga");
                            WriteTGA("C:\\games\\quake3\\baseq3\\textures\\rad\\dds_converted.tga", image->pixels, image->width,
                                     image->height);
                        }
                    }
#endif							// dds debug
                }
#endif							// ignore dds
            }
#endif							// ignore jpg dds
        }
#endif							// ignore png jpg dds
    }
#endif							// ignore all images

    /* free file buffer */
    free(buffer);

    /* make sure everything's kosher */
    if(size <= 0 || image->width <= 0 || image->height <= 0 || image->pixels == NULL)
    {
        //% Sys_Printf( "size = %d  width = %d  height = %d  pixels = 0x%08x (%s)\n",
        //%     size, image->width, image->height, image->pixels, name );
        free(image->name);
        image->name = NULL;
        return NULL;
    }

    /* set filename */
    image->filename = safe_malloc(strlen(name) + 1);
    strcpy(image->filename, name);

    /* set count */
    image->refCount = 1;
    numImages++;

    /* return the image */
    return image;
}
Exemplo n.º 7
0
void main(void){
  FILE*out, *tmp, *in;
  int xt, yt, height, angle; //танк
  double speed;
  int xa, ya; //цель
  int x1, x2, y1, y2, N;
  short i=0;
  int n=0; //количество обработанных строк лога
  sensor*S=(sensor*)malloc(sizeof(sensor));
 
  sensor*del;

  if(!ImageInit("./cover_hght.bmp")){
    printf("cannot open image\n");
    return;
  }

  out=fopen("out.txt", "w");
  tmp=fopen( TEMPLOG, "r");
  in=fopen("map.txt", "r");
  Parse("LogFile.log");
  
  while(fscanf(in, "%d %d %d %d %d\n", &x1, &y1, &x2, &y2, &N)!=EOF){ //считываем сенсоры
    if(i==0){
      i=1;
      Head=S;
    }
    
    S->next=(sensor*)malloc(sizeof(sensor));
    S->x1=x1;
    S->x2=x2;
    S->y1=y1;
    S->y2=y2;
    S->N=N;
    S=S->next;
  }
  
  if(i==0)
    S=NULL;
  else
    S->next=NULL;
  
  S=Head;


  while(fscanf(tmp, "%lf %d %d %d %d %d", &speed, &angle, &xt, &yt, &xa, &ya)){ //обход лога
    fprintf(out, "%lf; %d; %d; %d; %d; %d;", speed, angle, xt, yt, xa, ya);
    n++;
    
    while(S->next!=NULL){ //обход сенсоров
      
      
      fprintf(  out, " %d;", AverageHeight( *S, xt, yt, cos(angle), sin(angle) )  );
      S=S->next;
    
    }
    
    S=Head;
    fprintf(out, "\n");
    if(feof(tmp)) break;
  }
  
  printf("processed %d lines\n", n);
  fclose(tmp);
  fclose(out);
  fclose(in);
  free(pict.Image);
  
  //освобождаем память
  S=Head;
  while(S!=NULL){
    del=S;
    free(del);
    S=S->next;
  }
  getchar();
}