Exemple #1
0
/* =======================================================================*
    Private Functions
 * =======================================================================*/
static void
s_ncc_fft_scorewin_alloc (FATM_Options* fopt)
{
    S_Ncc_Fft_Data* udp = (S_Ncc_Fft_Data*) fopt->alg_data;
    //int* sw_dims = fopt->sig_rect.dims;
    //int* pw_dims = fopt->pat_rect.dims;
    Image_Rect* srv = &fopt->sig_rect_valid;
    int ii_dims[2] = { srv->dims[0] + 1, srv->dims[1] + 1 };

    /* Compute integral images of signal.  Note that the integral image 
       has an extra row/column of zeros at the top/left. */
    image_malloc (&udp->integral_image, ii_dims);
    image_malloc (&udp->integral_sq_image, ii_dims);
}
Exemple #2
0
void *image_ptr(mess_image *image)
{
	UINT64 size;
	UINT64 pos;
	void *ptr;

	if (!image->ptr)
	{
		/* get the image size; bomb out if too big */
		size = image_length(image);
		if (size != (UINT32) size)
			return NULL;

		/* allocate the memory */
		ptr = image_malloc(image, (UINT32) size);
		if (!ptr)
			return NULL;

		/* save current position */
		pos = image_ftell(image);

		/* read all data */
		image_fseek(image, 0, SEEK_SET);
		if (image_fread(image, ptr, (UINT32) size) != size)
			return NULL;

		/* reset position */
		image_fseek(image, pos, SEEK_SET);

		/* success */
		image->ptr = ptr;
	}
	return image->ptr;
}
Exemple #3
0
void
image_malloc_rand (Image* image, int dims[2])
{
    int i;
    image_malloc (image, dims);
    for (i = 0; i < image_size(image); i++) {
        image_data(image)[i] = rand_kr() / 32768.0;
    }
}
Exemple #4
0
void
image_read (Image* image, char* fn)
{
    FILE* fp;
    int i;
    char buf[1024];

    image_init (image);  /* Leaks if image previously used */
    fp = fopen (fn, "rb");
    if (!fp) return;

    if (fgets (buf, 1024, fp) == NULL) {
        printf ("Error reading pfm file\n");
        return;
    }
    if (strcmp (buf, "Pf\n")) {
        fclose (fp);
        printf ("Error reading pfm file\n");
        return;
    }

    if (fgets (buf, 1024, fp) == NULL) {
        printf ("Error reading pfm file\n");
        return;
    }
    if (sscanf (buf, "%d %d", &image->dims[0], &image->dims[1]) != 2) {
        fclose (fp);
        printf ("Error reading pfm file\n");
        return;
    }

    if (fgets (buf, 1024, fp) == NULL) {
        printf ("Error reading pfm file\n");
        return;
    }
    if (strcmp (buf, "-1\n")) {
        fclose (fp);
        printf ("Error reading pfm file\n");
        return;
    }
    image_malloc (image, image->dims);
    for (i = 0; i < image_size(image); i++) {
        float fv;
        fread (&fv, sizeof(float), 1, fp);
        image_data(image)[i] = (double) fv;
    }
    fclose (fp);
}
Exemple #5
0
/* open an d64 image */
static DEVICE_LOAD(cbm_drive)
{
	int size;
	int id = image_index_in_device(image);

	cbm_drive[id].drive = 0;
	cbm_drive[id].image = NULL;

	size = mame_fsize(file);

	cbm_drive[id].image = (UINT8*) image_malloc(image, size);
	if (!cbm_drive[id].image)
		return INIT_FAIL;

	if (size != mame_fread (file, cbm_drive[id].image, size))
		return INIT_FAIL;

	cbm_drive[id].drive = D64_IMAGE;
	return 0;
}
Exemple #6
0
static DEVICE_LOAD(cbm_rom)
{
	int i;
	int size, j, read_;
	const char *filetype;
	int adr = 0;
	const struct IODevice *dev;

	for (i=0; (i<sizeof(cbm_rom) / sizeof(cbm_rom[0])) && (cbm_rom[i].size!=0); i++)
		;
	if (i >= sizeof(cbm_rom) / sizeof(cbm_rom[0]))
		return INIT_FAIL;

	dev = cbm_rom_find_device();

	size = image_length(image);

	filetype = image_filetype(image);
	if (filetype && !mame_stricmp(filetype, "prg"))
	{
		unsigned short in;

		image_fread (image, &in, 2);
		in = LITTLE_ENDIANIZE_INT16(in);
		logerror("rom prg %.4x\n", in);
		size -= 2;

		logerror("loading rom %s at %.4x size:%.4x\n", image_filename(image), in, size);

		cbm_rom[i].chip = (UINT8 *) image_malloc(image, size);
		if (!cbm_rom[i].chip)
			return INIT_FAIL;

		cbm_rom[i].addr=in;
		cbm_rom[i].size=size;
		read_ = image_fread (image, cbm_rom[i].chip, size);
		if (read_ != size)
			return INIT_FAIL;
	}
	else if (filetype && !mame_stricmp (filetype, "crt"))
	{
		unsigned short in;
		image_fseek(image, 0x18, SEEK_SET);
		image_fread(image, &cbm_c64_exrom, 1);
		image_fread(image, &cbm_c64_game, 1);
		image_fseek(image, 64, SEEK_SET);
		j = 64;

		logerror("loading rom %s size:%.4x\n", image_filename(image), size);

		while (j < size)
		{
			unsigned short segsize;
			unsigned char buffer[10], number;

			image_fread(image, buffer, 6);
			image_fread(image, &segsize, 2);
			segsize = BIG_ENDIANIZE_INT16(segsize);
			image_fread(image, buffer + 6, 3);
			image_fread(image, &number, 1);
			image_fread(image, &adr, 2);
			adr = BIG_ENDIANIZE_INT16(adr);
			image_fread(image, &in, 2);
			in = BIG_ENDIANIZE_INT16(in);
			logerror("%.4s %.2x %.2x %.4x %.2x %.2x %.2x %.2x %.4x:%.4x\n",
				buffer, buffer[4], buffer[5], segsize,
				buffer[6], buffer[7], buffer[8], number,
				adr, in);
			logerror("loading chip at %.4x size:%.4x\n", adr, in);

			cbm_rom[i].chip = (UINT8*) image_malloc(image, size);
			if (!cbm_rom[i].chip)
				return INIT_FAIL;

			cbm_rom[i].addr=adr;
			cbm_rom[i].size=in;
			read_ = image_fread(image, cbm_rom[i].chip, in);
			i++;
			if (read_ != in)
				return INIT_FAIL;

			j += 16 + in;
		}
	}
	else if (filetype)
	{
		if (mame_stricmp(filetype, "lo") == 0)
			adr = CBM_ROM_ADDR_LO;
		else if (mame_stricmp (filetype, "hi") == 0)
			adr = CBM_ROM_ADDR_HI;
		else if (mame_stricmp (filetype, "10") == 0)
			adr = 0x1000;
		else if (mame_stricmp (filetype, "20") == 0)
			adr = 0x2000;
		else if (mame_stricmp (filetype, "30") == 0)
			adr = 0x3000;
		else if (mame_stricmp (filetype, "40") == 0)
			adr = 0x4000;
		else if (mame_stricmp (filetype, "50") == 0)
			adr = 0x5000;
		else if (mame_stricmp (filetype, "60") == 0)
			adr = 0x6000;
		else if (mame_stricmp (filetype, "70") == 0)
			adr = 0x7000;
		else if (mame_stricmp (filetype, "80") == 0)
			adr = 0x8000;
		else if (mame_stricmp (filetype, "90") == 0)
			adr = 0x9000;
		else if (mame_stricmp (filetype, "a0") == 0)
			adr = 0xa000;
		else if (mame_stricmp (filetype, "b0") == 0)
			adr = 0xb000;
		else if (mame_stricmp (filetype, "e0") == 0)
			adr = 0xe000;
		else if (mame_stricmp (filetype, "f0") == 0)
			adr = 0xf000;
		else
			adr = CBM_ROM_ADDR_UNKNOWN;

		logerror("loading %s rom at %.4x size:%.4x\n",
				image_filename(image), adr, size);

		cbm_rom[i].chip = (UINT8*) image_malloc(image, size);
		if (!cbm_rom[i].chip)
			return INIT_FAIL;

		cbm_rom[i].addr=adr;
		cbm_rom[i].size=size;
		read_ = image_fread(image, cbm_rom[i].chip, size);

		if (read_ != size)
			return INIT_FAIL;
	}
	return INIT_PASS;
}
Exemple #7
0
static image_error_t load_zip_path(mess_image *image, const char *path)
{
	image_error_t err = IMAGE_ERROR_FILENOTFOUND;
	zip_file *zip = NULL;
	zip_error ziperr;
	const zip_file_header *header;
	const char *zip_extension = ".zip";
	char *path_copy;
	const char *zip_entry;
	void *ptr;
	int pos;

	/* create our own copy of the path */
	path_copy = mame_strdup(path);
	if (!path_copy)
	{
		err = IMAGE_ERROR_OUTOFMEMORY;
		goto done;
	}

	/* loop through the path and try opening zip files */
	ziperr = ZIPERR_FILE_ERROR;
	zip_entry = NULL;
	pos = strlen(path_copy);
	while(pos > strlen(zip_extension))
	{
		/* is this a potential zip path? */
		if ((path_copy[pos] == '\0') || !strncmp(&path_copy[pos], PATH_SEPARATOR, strlen(PATH_SEPARATOR)))
		{
			/* parse out the zip path */
			if (path_copy[pos] == '\0')
			{
				/* no zip path */
				zip_entry = NULL;
			}
			else
			{
				/* we are at a zip path */
				path_copy[pos] = '\0';
				zip_entry = &path_copy[pos + strlen(PATH_SEPARATOR)];
			}

			/* try to open the zip file */
			ziperr = zip_file_open(path_copy, &zip);
			if (ziperr != ZIPERR_FILE_ERROR)
				break;

			/* restore the path if we changed */
			if (zip_entry)
				path_copy[pos] = PATH_SEPARATOR[0];
		}
		pos--;
	}

	/* did we succeed in opening up a zip file? */
	if (ziperr == ZIPERR_NONE)
	{
		/* iterate through the zip file */
		header = zip_file_first_file(zip);

		/* if we specified a zip partial path, find it */
		if (zip_entry)
		{
			while(header)
			{
				if (!mame_stricmp(header->filename, zip_entry))
					break;
				header = zip_file_next_file(zip);
			}
		}

		/* were we successful? */
		if (header)
		{
			/* if no zip path was specified, we have to change the name */
			if (!zip_entry)
			{
				/* use the first entry; tough part is we have to change the name */
				err = set_image_filename(image, image->name, header->filename);
				if (err)
					goto done;
			}

			/* allocate space for this zip file */
			ptr = image_malloc(image, header->uncompressed_length);
			if (!ptr)
			{
				err = IMAGE_ERROR_OUTOFMEMORY;
				goto done;
			}

			ziperr = zip_file_decompress(zip, ptr, header->uncompressed_length);
			if (ziperr == ZIPERR_NONE)
			{
				/* success! */
				err = IMAGE_ERROR_SUCCESS;
				image->ptr = ptr;
				image->length = header->uncompressed_length;
			}
		}
	}

done:
	if (path_copy)
		free(path_copy);
	if (zip)
		zip_file_close(zip);
	return err;
}
Exemple #8
0
static mame_file *image_fopen_custom(mess_image *img, int filetype, int read_or_write)
{
	const char *sysname;
	char *lpExt;
	const game_driver *gamedrv = Machine->gamedrv;

	assert(img);

	if (!img->name)
		return NULL;

	if (img->fp)
	{
		/* If already open, we won't open the file again until it is closed. */
		return NULL;
	}

	do
	{
		sysname = gamedrv->name;
		logerror("image_fopen: trying %s for system %s\n", img->name, sysname);

		img->fp = mame_fopen(sysname, img->name, filetype, read_or_write);

		if (img->fp && (read_or_write == OSD_FOPEN_READ))
		{
			lpExt = strrchr( img->name, '.' );
			if (lpExt && (mame_stricmp( lpExt, ".ZIP" ) == 0))
			{
				int pathindex;
				int pathcount = osd_get_path_count(filetype);
				zip_file *zipfile;
				zip_entry *zipentry;
				char *newname;
				char *name;
				char *zipname;
				const char *ext;
				const struct IODevice *dev;

				mame_fclose( img->fp );
				img->fp = NULL;

				dev = image_device(img);
				assert(dev);

				newname = NULL;

				zipname = image_malloc( img, strlen( sysname ) + 1 + strlen( img->name ) + 1 );
				if( osd_is_absolute_path( img->name ) )
				{
					strcpy( zipname, img->name );
				}
				else
				{
					strcpy( zipname, sysname );
					strcat( zipname, osd_path_separator() );
					strcat( zipname, img->name );
				}

				for (pathindex = 0; pathindex < pathcount; pathindex++)
				{
					zipfile = openzip(filetype, pathindex, zipname);
					if (zipfile)
					{
						zipentry = readzip(zipfile);
						while( zipentry )
						{
							/* mess doesn't support paths in zip files */
							name = osd_basename( zipentry->name );
							lpExt = strrchr(name, '.');
							if (lpExt)
							{
								lpExt++;

								ext = dev->file_extensions;
								while(*ext)
								{
									if( mame_stricmp( lpExt, ext ) == 0 )
									{
										if( newname )
										{
											image_freeptr( img, newname );
										}
										newname = image_malloc(img, strlen(img->name) + 1 + strlen(name) + 1);
										if (!newname)
											return NULL;

										strcpy(newname, img->name);
										strcat(newname, osd_path_separator());
										strcat(newname, name);
									}
									ext += strlen(ext) + 1;
								}
							}
							zipentry = readzip(zipfile);
						}
						closezip(zipfile);
					}
					if( !newname )
					{
						return NULL;
					}
					img->fp = mame_fopen(sysname, newname, filetype, read_or_write);
					if (img->fp)
					{
						image_freeptr(img, img->name);
						img->name = newname;
						break;
					}
				}
				image_freeptr( img, zipname );
			}
		}
		gamedrv = mess_next_compatible_driver(gamedrv);
	}
	while(!img->fp && gamedrv);

	if (img->fp)
	{
		logerror("image_fopen: found image %s for system %s\n", img->name, sysname);
		img->length = mame_fsize(img->fp);
		img->hash = NULL;
	}

	return img->fp;
}