Ejemplo n.º 1
0
Archivo: image.c Proyecto: burito/voxel
int main(int argc, char *argv[])
{
	img_buf *i;

	if(!argv[1])
	{
		printf("USAGE: %s name\n\t reads name where name is an image.\n",
				argv[0]);
		return 1;
	}

	printf("Loading file \"%s\"\n", argv[1]);

	i = img_load(argv[1]);

	if(!i)
	{
		printf("Failed to load.\n");
		return 2;
	}

	img_free(i);
	printf("Happily free.\n");
	return 0;
}
Ejemplo n.º 2
0
void		serv_seg(t_on_screen *screen, char *msg)
{
  char		*team;
  SDL_Color	color;
  SDL_Rect	pos;
  SDL_Surface	*victory;

  pos.x = 0;
  pos.y = 0;
  team = get_argument(msg, 2);
  team[n_strlen(team, 1)] = '\0';
  victory = img_load("images/victory.png");
  xsdl_blitsurface(victory, NULL, screen->window, &pos);
  if (TTF_Init() != -1)
    {
      color.r = 250;
      color.g = 250;
      color.b = 0;
      send_team(screen, team, &pos, &color);
      TTF_Quit();
    }
  SDL_FreeSurface(victory);
  xsdl_flip(screen->window);
  SDL_Delay(10000);
}
Ejemplo n.º 3
0
char		*exec_menu()
{
  SDL_Surface	*screen;
  SDL_Surface	*background;
  SDL_Rect	pos;
  int		continuer;
  char		*ret;

  if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
    err_SDL("Can't init SDL", 1);
  SDL_WM_SetIcon(SDL_LoadBMP("image/DonkeyKong2.bmp"), NULL);
  screen = SDL_SetVideoMode(MWIN_WIDTH, MWIN_HEIGHT, WIN_COLOR,
			    SDL_HWSURFACE | SDL_DOUBLEBUF );
  SDL_WM_SetCaption("Epikong", NULL);
  background = img_load(MENU_BACK);
  pos.x = 0;
  pos.y = 0;
  while (continuer)
    {
      SDL_BlitSurface(background, NULL, screen, &pos);
      disp_menu(screen);
      ret = menu_loop(screen);
      if (ret)
	continuer = 0;
    }
  SDL_Quit();
  return (ret);
}
Ejemplo n.º 4
0
void main()
{
	int i = 0;
	int x;
	struct img_resource *r;
	
	volatile unsigned int *num_clock_cycles = 0x86000000;
	unsigned int **frame_start = 0x82000000;
	unsigned int *start = 0x00600000;
	
	int fat16_start;
	struct fat16_handle h;

	printf("Reading partition table... ");
	fat16_start = fat16_find_partition();
	if (fat16_start < 0)
	{
		puts("no FAT16 partition found!");
		return;
	}
	printf("found starting at sector %d.\r\n", fat16_start);
	
	printf("Opening FAT16 partition... ");
	if (fat16_open(&h, fat16_start) < 0)
	{
		puts("FAT16 boot sector read failed!");
		return;
	}
	puts("OK");

	
	*frame_start = start;
	r = img_load(&h, "LEFT_4  RES");
	
	printf("in main...\r\n");
	x = 0;
	accel_fill(start, 0x80808080, 640*480);
	while (1)
	{
		int y;
		if ((i % 64) == 0)
			printf("iters: %d, i %% 100 = %d, clock cycles: %d\r\n", i, ((unsigned int)i) % 100U, *num_clock_cycles);
		for (y = 0; y < 448; y += 64)
			accel_blit(start + y * 640 + x, r->pixels, r->w, r->h);
		x += 16;
		if (x == 512)
			x = 0;	
		i++;
	}
}
Ejemplo n.º 5
0
void system_opengl( void )
{
    glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
    glBlendFunc( GL_SRC_ALPHA, GL_ONE );
    glEnable( GL_BLEND );
    glEnable( GL_TEXTURE_2D );
    img_debug( 1 );
    img_load( img_file, &img );
    glBindTexture( GL_TEXTURE_2D, 1 );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexImage2D( GL_TEXTURE_2D, 0, img.bpp, img.width, img.height, 0,
        img.c_format, GL_UNSIGNED_BYTE, img.data );
    free( img.data );
}
Ejemplo n.º 6
0
unsigned int img_gltexture_load(const char *fname)
{
	struct img_pixmap img;
	unsigned int tex;

	img_init(&img);
	if(img_load(&img, fname) == -1) {
		img_destroy(&img);
		return 0;
	}

	tex = img_gltexture(&img);
	img_destroy(&img);
	return tex;
}
Ejemplo n.º 7
0
void fdi_load(int drive, wchar_t *fn)
{
	char header[26];

        writeprot[drive] = fwriteprot[drive] = 1;
        fdi[drive].f = _wfopen(fn, L"rb");
        if (!fdi[drive].f)
	{
		memset(discfns[drive], 0, sizeof(discfns[drive]));
		return;
	}

	d86f_unregister(drive);

	fread(header, 1, 25, fdi[drive].f);
	fseek(fdi[drive].f, 0, SEEK_SET);
	header[25] = 0;
	if (strcmp(header, "Formatted Disk Image file") != 0)
	{
		/* This is a Japanese FDI file. */
		pclog("fdi_load(): Japanese FDI file detected, redirecting to IMG loader\n");
		fclose(fdi[drive].f);
		img_load(drive, fn);
		return;
	}

        fdi[drive].h = fdi2raw_header(fdi[drive].f);
        fdi[drive].lasttrack = fdi2raw_get_last_track(fdi[drive].h);
        fdi[drive].sides = fdi2raw_get_last_head(fdi[drive].h) + 1;

	d86f_register_fdi(drive);

        drives[drive].seek        = fdi_seek;
	d86f_common_handlers(drive);

        pclog("Loaded as FDI\n");
}
Ejemplo n.º 8
0
int parse_args(int argc, char **argv)
{
	int i;
	char *endp;
	struct list_node *head = 0, *tail = 0;

	for(i=1; i<argc; i++) {
		if(argv[i][0] == '-' && argv[i][2] == 0) {
			switch(argv[i][1]) {
			case 'f':
				fullscreen = !fullscreen;
				break;

			case 's':
				stereo = !stereo;
				break;

			case 't':
				threshold = strtod(argv[++i], &endp);
				if(endp == argv[i]) {
					fprintf(stderr, "-t must be followed by a number\n");
					return -1;
				}
				break;

			case 'h':
				printf("usage: %s [opt]\n", argv[0]);
				printf("options:\n");
				printf("  -f    start in fullscreen\n");
				printf("  -s    enable stereoscopic rendering\n");
				printf("  -h    print usage and exit\n");
				exit(0);

			default:
				fprintf(stderr, "unrecognized option: %s\n", argv[i]);
				return -1;
			}
		} else {
			struct list_node *slice;

			if(!(slice = malloc(sizeof *slice))) {
				fprintf(stderr, "failed to allocate volume slice: %d\n", num_slices);
				return -1;
			}
			slice->next = 0;

			img_init(&slice->img);
			if(img_load(&slice->img, argv[i]) == -1) {
				fprintf(stderr, "failed to load volume slice %d: %s\n", num_slices, argv[i]);
				free(slice);
				return -1;
			}
			img_convert(&slice->img, IMG_FMT_GREY8);

			if(num_slices > 0 && (xres != slice->img.width || yres != slice->img.height)) {
				fprintf(stderr, "error: slice %d (%s) is %dx%d, up to now we had %dx%d images\n", num_slices, argv[i],
						slice->img.width, slice->img.height, xres, yres);
				img_destroy(&slice->img);
				free(slice);
				return -1;
			}
			xres = slice->img.width;
			yres = slice->img.height;

			if(head) {
				tail->next = slice;
				tail = slice;
			} else {
				head = tail = slice;
			}
			printf("loaded volume slice %d: %s\n", num_slices++, argv[i]);
		}
	}

	if(!head) {
		fprintf(stderr, "you must specify a list of images for the volume data slices\n");
		return -1;
	}

	if(!(volume = malloc(num_slices * sizeof *volume))) {
		fprintf(stderr, "failed to allocate volume data (%d slices)\n", num_slices);
		return -1;
	}

	for(i=0; i<num_slices; i++) {
		void *tmp;

		assert(head);
		volume[i] = head->img;

		tmp = head;
		head = head->next;
		free(tmp);
	}

	return 0;
}
Ejemplo n.º 9
0
int		img_init(t_image *img)
{
  img->white = img_load(WHIT_DIR);
  img->blood = img_load(BLOOD_DIR);
  img->wall = img_load(WALL_DIR);
  img->ladder = img_load(LAD_DIR);
  img->exit = img_load(EXIT_DIR);
  img->enter = img_load(ENT_DIR);
  img->monster1 = img_load(MON_DIR1);
  img->monster2 = img_load(MON_DIR2);
  img->monster3 = img_load(MON_DIR3);
  img->monster4 = img_load(MON_DIR4);
  img->monster5 = img_load(MON_DIR5);
  img->monster6 = img_load(MON_DIR6);
  img->hero1 = img_load(HERO_DIR1);
  img->hero2 = img_load(HERO_DIR2);
  img->hero3 = img_load(HERO_DIR3);
  img->hero4 = img_load(HERO_DIR4);
  img->hero5 = img_load(HERO_DIR5);
  img->hero6 = img_load(HERO_DIR6);
  img->key = img_load(KEY_DIR);
  img_init_suite(img);
  img->tab = init_da_tab();
  return (EXIT_SUCCESS);
}
Ejemplo n.º 10
0
int main( int argc, char *argv[] ) {
  IMAGE *img;
  IMAGE *find;
  int off_x, off_y, tolerance;
  int start_x, start_y;
  int total_match;
  IMAGE **matches;
  
  POINT pt, tmp_pt;

  int cnt, gotmatch, tmp_i, find_next, final_exit;
  int opt;

  off_x = off_y = 0;
  start_x = start_y = 0;
  tolerance = 0;
  final_exit = 1;
  
  while( ( opt = getopt( argc, argv, "hX:Y:x:d:y:t:" ) ) != EOF ) {
    switch( opt ) {
    case 'h':
      printf( "visgrep v" VERSION "\n"
	      "visual grep, greps for images in another image\n"
	      "Author: Steve Slaven - http://hoopajoo.net\n"
	      "\n"
	      "usage: %s [-h] [-x x_off] [-y y_off] [-X start x_off] [-Y start y_off]\n"
	      "          [-d debuglevel] [-t tolerance] image.png detect.pat match.pat ...\n"
	      "\n"
	      "  -h   This help\n"
	      "  -x   Set x offset for detection matching\n"
	      "  -y   Set y offset for detection matching\n"
	      "  -X   Start scanning at X\n"
	      "  -Y   Start scanning at Y\n"
	      "  -t   Set tolerance for 'fuzzy' matches, higher numbers are more tolerant\n"
	      "\n"
	      "All .pat files are created using png2pat or rgb2pat.  The image.png is\n"
	      "scanned for detect.pat starting from X,Y specified above.  When detect.pat\n"
	      "is found, then all the match.pat files are scanned at an offset of x,y as\n"
	      "specified above.  If a match is found, then visgrep prints the x,y and\n"
	      "index of the item.\n"
	      "\n"
	      "image.png must be an 8 bit deep RGB or RGBA png file."
	      "\n"
	      "For example, image.png is a screenshot and match1.pat .. to match5.pat are\n"
	      "images of letters a to e.  Each of these letters is enclosed in a blue box,\n"
	      "so detect.pat is an image of the upper left corner of the box.  This box is\n"
	      "not included in the match*.pat files, so they are actually offset 5 pixels\n"
	      "down and 4 pixels to the left.  You might run it like this then:\n"
	      "\n"
	      "  visgrep -x-4 -y5 image.png match_corner.pat match_a.pat match_b.bat ...\n"
	      "\n"
	      "Etc, with all matches listed.  Now suppose the screen showed 'ace' so\n"
	      "visgrep might output:\n"
	      "\n"
	      "10,10 0\n"
	      "50,10 2\n"
	      "90,10 4\n"
	      "\n"
	      "Showing that match_a.pat (index 0) is at 10,10 on the screen.  If no match\n"
	      "is found even though the detection image is found, the index will be -1.\n"
	      "\n"
	      "Exit status is 0 for successful match, 1 for no match, and 2 for error.\n"
	      , argv[ 0 ] );
      exit( 0 );
      break;
      
    case 'x':
      sscanf( optarg, "%d", &off_x );
      dmsg( 2, "X offset is %d\n", off_x );
      break;
      
    case 'y':
      sscanf( optarg, "%d", &off_y );
      dmsg( 2, "Y offset is %d\n", off_y );
      break;

    case 'X':
      sscanf( optarg, "%d", &start_x );
      dmsg( 2, "Start X offset is %d\n", start_x );
      break;
      
    case 'Y':
      sscanf( optarg, "%d", &start_y );
      dmsg( 2, "Start Y offset is %d\n", start_y );
      break;
      
    case 't':
      sscanf( optarg, "%d", &tolerance );
      dmsg( 2, "Tolerance is %d\n", tolerance );
      break;

    case 'd':
      sscanf( optarg, "%d", &tmp_i );
      dmsg( 2, "Debug set to %d\n", tmp_i );
      debug_level( tmp_i );
      break;
      
    case '?':
      fprintf( stderr, "Unknown option '%c'\n", optopt );
      break;
      
    default:
      fprintf( stderr, "Unhandled option '%c'\n", opt );
      break;
    }
  }

  if( argc - optind < 2 ) {
    fprintf( stderr, "Error, not enough args, try -h\n" );
    exit( 2 );
  }
  
  dmsg( 1, "Loading main PNG image '%s'\n", argv[ optind ] );
  img = img_load_from_png( argv[ optind ] );
  optind++;
  if( img == NULL ) {
    fprintf( stderr, "Error, unable to load png, try -h\n" );
    exit( 2 );
  }
  
  dmsg( 1, "Loading detection image '%s'\n", argv[ optind ] );
  find = img_load( argv[ optind ] );
  dmsg( 1, "Loaded %dx%d\n", find -> width, find -> height );
  optind++;
  
  total_match = argc - optind;
  dmsg( 1, "Now optind=%d : argc=%d : total_match=%d\n", optind, argc, total_match );

  matches = (IMAGE **)malloc( total_match * sizeof( IMAGE * ) );
  
  /* Load actual scoreboxes */
  dmsg( 1, "Loading match data....\n" );
  for( cnt = 0; cnt < total_match; cnt++ ) {
    dmsg( 1, " -- %s\n", argv[ optind ] );
    matches[ cnt ] = img_load( argv[ optind ] );
    if( ! matches[ cnt ] ) {
      printf( "Error loading '%s'\n", argv[ optind ] );
      exit( 2 );
    }
    optind++;
  }

  dmsg( 1, "Detecting offsets...\n" );
  pt.x = start_x;
  pt.y = start_y;
  find_next = 0;
  while( pt.x != -1 ) {
    pt = img_subimage_find( img, find, pt, tolerance, find_next );

    /* Not first time anymore */
    find_next = 1;
    
    if( pt.x != -1 ) {
      dmsg( 1, "  Found match at %d,%d\n", pt.x, pt.y );

      /* Try and identify what thing it is */
      gotmatch = 0;
      tmp_pt.x = pt.x + off_x;
      tmp_pt.y = pt.y + off_y;
      for( cnt = 0; cnt < total_match; cnt++ ) {
	if( matches[ cnt ] != NULL ) {
	  dmsg( 1, " Testing for %d  ", cnt );
	  dmsg( 1, " (%d,%d) ", tmp_pt.x, tmp_pt.y );
	  if( img_subimage_cmp( img, matches[ cnt ], tmp_pt, tolerance ) <= tolerance ) {
	    dmsg( 1, "  YES\n" );
	    
	    printf( "%d,%d %d\n", tmp_pt.x, tmp_pt.y, cnt );
	    gotmatch = 1;
	    final_exit = 0;

	    /* Fall out */
	    cnt = total_match;
	  }else{
	    dmsg( 1, "  NO\n" );
	  }
	}else{
	  dmsg( 1, " No image in slot %d\n", cnt );
	}
      }

      /* Notify of no match */
      if( ! gotmatch ) {
	dmsg( 1, " NO ITEMS MATCHED!\n" );
	printf( "%d,%d %d\n", tmp_pt.x, tmp_pt.y, -1 );
      }
    }
  }

  exit( final_exit );
}
Ejemplo n.º 11
0
gboolean pipe_event(GIOChannel chan, GIOCondition cond, gpointer data) {
    static char *path;
    char name[TMPNAMELEN];
    ssize_t rr;
    int nimgs = 0;

    if (!path)
        path = xmalloc(strlen(tmpdir) + 64);

    /* We are sent messages of size TMPNAMELEN containing a null-terminated
     * file name. */
    while (nimgs < 4 && (rr = xread(dpychld_fd, name, sizeof name)) == sizeof name) {
        int saveimg = 0;
        struct stat st;

        ++nimgs;
        
        sprintf(path, "%s/%s", tmpdir, name);

        if (stat(path, &st) == -1)
            continue;
           
        if (verbose)
            fprintf(stderr, PROGNAME": received image %s of size %d\n", name, (int)st.st_size);
        /* Check to see whether this looks like an image we're interested in. */
        if (st.st_size > 100) {
            /* Small images are probably bollocks. */
            img i = img_new();
            if (!img_load_file(i, path, header, unknown))
                fprintf(stderr, PROGNAME": %s: bogus image (err = %d)\n", name, i->err);
            else {
                if (i->width > 8 && i->height > 8) {
                    if (img_load(i, full, i->type)) {
                        /* slot in the new image at some plausible place. */
                        int w, h;
                        if (i->width > width - 2 * BORDER) w = width - 2 * BORDER;
                        else w = i->width;
                        if (i->height > height - 2 * BORDER) h = height - 2 * BORDER;
                        else h = i->height;

                        /* is there space on this row? */
                        if (width - wrx < w) {
                            /* no */
                            scroll_backing_image(h + BORDER);
                            wrx = BORDER;
                            rowheight = h + BORDER;
                        }
                        if (rowheight < h + BORDER) {
                            scroll_backing_image(h + BORDER - rowheight);
                            rowheight = h + BORDER;
                        }

                        img_simple_blt(backing_image, wrx, wry - h, i, 0, 0, w, h);
                        add_image_rectangle(path, wrx, wry - h, w, h);
                        saveimg = 1;

                        if (beep)
                            write(1, "\a", 1);

                        update_window();

                        wrx += w + BORDER;
                    } else fprintf(stderr, PROGNAME": %s: bogus image (err = %d)\n", name, i->err);
                } else if (verbose) fprintf(stderr, PROGNAME": %s: image dimensions (%d x %d) too small to bother with\n", name, i->width, i->height);
            }

            img_delete(i);
        } else if (verbose) fprintf(stderr, PROGNAME": image data too small (%d bytes) to bother with\n", (int)st.st_size);

        if (!saveimg)
            unlink(name);
    }
    if (rr == -1 && errno != EINTR && errno != EAGAIN) {
        perror(PROGNAME": read");
        gtk_main_quit();
    } else if (rr == 0) {
        /* pipe closed, exit. */
        gtk_main_quit();
    }
    return TRUE;
}