Ejemplo n.º 1
0
ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
{
	ImBuf *ibuf;
	ImFileType *type;
	char effective_colorspace[IM_MAX_SPACE] = "";

	if (mem == NULL) {
		fprintf(stderr, "%s: NULL pointer\n", __func__);
		return NULL;
	}

	if (colorspace)
		BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace));

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
		if (type->load) {
			ibuf = type->load(mem, size, flags, effective_colorspace);
			if (ibuf) {
				imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace);
				return ibuf;
			}
		}
	}

	if ((flags & IB_test) == 0)
		fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr);

	return NULL;
}
Ejemplo n.º 2
0
short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
{
	ImFileType *type;

	if (ibuf == NULL) return (false);
	ibuf->flags = flags;

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
		if (type->save && type->ftype(type, ibuf)) {
			ImBuf *write_ibuf;
			short result = false;

			write_ibuf = prepare_write_imbuf(type, ibuf);

			result = type->save(write_ibuf, name, flags);

			if (write_ibuf != ibuf)
				IMB_freeImBuf(write_ibuf);

			return result;
		}
	}

	fprintf(stderr, "Couldn't save picture.\n");

	return false;
}
Ejemplo n.º 3
0
ImBuf *IMB_ibImageFromMemory(unsigned char *mem, size_t size, int flags)
{
	ImBuf *ibuf;
	ImFileType *type;

	if(mem == NULL) {
		printf("Error in ibImageFromMemory: NULL pointer\n");
		return NULL;
	}

	for(type=IMB_FILE_TYPES; type->is_a; type++) {
		if(type->load) {
			ibuf= type->load(mem, size, flags);
			if(ibuf) {
				if(flags & IB_premul) {
					IMB_premultiply_alpha(ibuf);
					ibuf->flags |= IB_premul;
				}

				return ibuf;
			}
		}
	}

	fprintf(stderr, "Unknown fileformat\n");
	
	return NULL;
}
Ejemplo n.º 4
0
static int IMB_ispic_name(const char *name)
{
	ImFileType *type;
	struct stat st;
	int fp, buf[10];

	if(UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name);
	
	if(stat(name,&st) == -1)
		return FALSE;
	if(((st.st_mode) & S_IFMT) != S_IFREG)
		return FALSE;

	if((fp = open(name,O_BINARY|O_RDONLY)) < 0)
		return FALSE;

	if(read(fp, buf, 32) != 32) {
		close(fp);
		return FALSE;
	}

	close(fp);

	/* XXX move this exception */
	if((BIG_LONG(buf[0]) & 0xfffffff0) == 0xffd8ffe0)
		return JPG;

	for(type=IMB_FILE_TYPES; type->is_a; type++)
		if(type->is_a((uchar*)buf))
			return type->filetype;

	return FALSE;
}
Ejemplo n.º 5
0
void imb_filetypes_init(void)
{
	ImFileType *type;

	for(type=IMB_FILE_TYPES; type->is_a; type++)
		if(type->init)
			type->init();
}
Ejemplo n.º 6
0
void imb_filetypes_init(void)
{
	ImFileType *type;

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++)
		if (type->init)
			type->init();

#ifdef WITH_QUICKTIME
	quicktime_init();
#endif
}
Ejemplo n.º 7
0
int IMB_ispic(const char *name)
{
	/* increased from 32 to 64 because of the bitmaps header size */
#define HEADER_SIZE 64

	unsigned char buf[HEADER_SIZE];
	ImFileType *type;
	struct stat st;
	int fp;

	if (UTIL_DEBUG) printf("IMB_ispic_name: loading %s\n", name);
	
	if (BLI_stat(name, &st) == -1)
		return FALSE;
	if (((st.st_mode) & S_IFMT) != S_IFREG)
		return FALSE;

	if ((fp = BLI_open(name, O_BINARY | O_RDONLY, 0)) < 0)
		return FALSE;

	memset(buf, 0, sizeof(buf));
	if (read(fp, buf, HEADER_SIZE) <= 0) {
		close(fp);
		return FALSE;
	}

	close(fp);

	/* XXX move this exception */
	if ((BIG_LONG(((int *)buf)[0]) & 0xfffffff0) == 0xffd8ffe0)
		return JPG;

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
		if (type->is_a) {
			if (type->is_a(buf)) {
				return type->filetype;
			}
		}
		else if (type->is_a_filepath) {
			if (type->is_a_filepath(name)) {
				return type->filetype;
			}
		}
	}

	return FALSE;

#undef HEADER_SIZE
}
Ejemplo n.º 8
0
short IMB_saveiff(struct ImBuf *ibuf, const char *name, int flags)
{
	ImFileType *type;

	if(ibuf == NULL) return (FALSE);
	ibuf->flags = flags;

	for(type=IMB_FILE_TYPES; type->is_a; type++) {
		if(type->save && type->ftype(type, ibuf)) {
			if(!(type->flag & IM_FTYPE_FLOAT)) {
				if(ibuf->rect==NULL && ibuf->rect_float)
					IMB_rect_from_float(ibuf);
			}
			return type->save(ibuf, name, flags);
		}
	}

	fprintf(stderr, "Couldn't save picture.\n");

	return FALSE;
}
Ejemplo n.º 9
0
static void imb_loadtilefile(ImBuf *ibuf, int file, int tx, int ty, unsigned int *rect)
{
	ImFileType *type;
	unsigned char *mem;
	size_t size;

	if (file == -1) return;

	size = BLI_file_descriptor_size(file);

	mem = mmap(NULL, size, PROT_READ, MAP_SHARED, file, 0);
	if (mem == (unsigned char *) -1) {
		fprintf(stderr, "Couldn't get memory mapping for %s\n", ibuf->cachename);
		return;
	}

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++)
		if (type->load_tile && type->ftype(type, ibuf))
			type->load_tile(ibuf, mem, size, tx, ty, rect);

	if (munmap(mem, size))
		fprintf(stderr, "Couldn't unmap memory for %s.\n", ibuf->cachename);
}
Ejemplo n.º 10
0
static ImBuf *IMB_ibImageFromFile(const char *filepath, int flags, char colorspace[IM_MAX_SPACE], const char *descr)
{
	ImBuf *ibuf;
	ImFileType *type;
	char effective_colorspace[IM_MAX_SPACE] = "";

	if (colorspace)
		BLI_strncpy(effective_colorspace, colorspace, sizeof(effective_colorspace));

	for (type = IMB_FILE_TYPES; type < IMB_FILE_TYPES_LAST; type++) {
		if (type->load_filepath) {
			ibuf = type->load_filepath(filepath, flags, effective_colorspace);
			if (ibuf) {
				imb_handle_alpha(ibuf, flags, colorspace, effective_colorspace);
				return ibuf;
			}
		}
	}

	if ((flags & IB_test) == 0)
		fprintf(stderr, "%s: unknown fileformat (%s)\n", __func__, descr);

	return NULL;
}