Exemple #1
0
/**
 * Read a sprite filedata to an 'image' structure
 * @param img Pointer to destination 'image' structure 
 * @param num_of_sprites Number different sprites
 * @param num_of_anims Number of animations for a same sprite
 * @param addr Pointer to the source sprite filedata 
 * @param max_of_anims Maximum number of images per type of sprite
 * @return Pointer to source sprite filedata 
 */
char *
images_read (image * img, Uint32 num_of_sprites, Uint32 num_of_anims,
             char *addr, Uint32 max_of_anims)
{
  Uint32 i, j;
  for (i = 0; i < num_of_sprites; i++)
    {
      for (j = 0; j < num_of_anims; j++)
        {
          addr = image_extract (img + (i * max_of_anims) + j, addr);
          if (addr == NULL)
            {
              LOG_ERR ("image_extract failed!");
              return NULL;
            }
        }
    }
  return addr;
}
Exemple #2
0
/**
 * Load a sprite file (*.spr) with a single image
 * @param filename Filename the file *.spr which should be loaded 
 * @param img Pointer to destination 'image' structure 
 * @return TRUE if it completed successfully or FALSE otherwise
 */
bool
image_load_single (const char *filename, image * img)
{
  char *addr;
  char *filedata = load_file (filename);
  if (filedata == NULL)
    {
      return FALSE;
    }
  addr = image_extract (img, filedata);
  if (addr == NULL)
    {
      LOG_ERR ("image_extract() failed!");
      free_memory (filedata);
      return FALSE;
    }
  free_memory (filedata);
  return TRUE;
}
Exemple #3
0
int main(int argc, char *argv[])
{
	int action = -1, opt, verbose = 0;
	const char *input = NULL, *output = NULL,
		*payload = NULL, *bootmedia = NULL;
	uint32_t execaddr = ADDR_INVALID, dstaddr = ADDR_INVALID;

	while ((opt = getopt(argc, argv, "hxci:o:p:m:e:d:v")) != -1) {
		switch (opt) {
		case 'x':
			action = ACTION_EXTRACT;
			break;
		case 'c':
			action = ACTION_CREATE;
			break;
		case 'i':
			input = optarg;
			break;
		case 'o':
			output = optarg;
			break;
		case 'p':
			payload = optarg;
			break;
		case 'm':
			bootmedia = optarg;
			break;
		case 'e':
			execaddr = strtol(optarg, NULL, 0);
			break;
		case 'd':
			dstaddr = strtol(optarg, NULL, 0);
			break;
		case 'v':
			verbose = 1;
			break;
		case 'h':
			action = ACTION_HELP;
			break;
		}
	}

	/* We should have consumed all arguments */
	if (optind != argc) {
		usage(argv[0]);
		exit(1);
	}

	if (action != ACTION_HELP && !input) {
		fprintf(stderr, "Missing input file\n");
		usage(argv[0]);
		exit(1);
	}

	if ((action == ACTION_EXTRACT || action == ACTION_CREATE) &&
	    !output) {
		fprintf(stderr, "Missing output file\n");
		usage(argv[0]);
		exit(1);
	}

	if (action == ACTION_EXTRACT &&
	    (bootmedia || payload ||
	     (execaddr != ADDR_INVALID) || (dstaddr != ADDR_INVALID))) {
		fprintf(stderr,
			"-m, -p, -e or -d do not make sense when extracting an image");
		usage(argv[0]);
		exit(1);
	}

	switch (action) {
	case ACTION_EXTRACT:
		return image_extract(input, output);
	case ACTION_CREATE:
		return image_create(input, output, payload,
				    bootmedia, dstaddr, execaddr,
				    verbose);
	case ACTION_HELP:
		usage(argv[0]);
		return 0;
	default:
		fprintf(stderr, "No action specified\n");
		usage(argv[0]);
		exit(1);
	}

	return 0;
}