Exemplo n.º 1
0
Arquivo: targa.c Projeto: jinjoh/NOOR
short imb_savetarga(struct ImBuf * ibuf, char *name, int flags)
{
	char buf[20];
	FILE *fildes;
	int i;
	short ok = 0;

	if (ibuf == 0) return (0);
	if (ibuf->rect == 0) return (0);

	memset(buf,0,sizeof(buf));

	/* buf[0] = 0;  length string */

	buf[16] = (ibuf->depth + 0x7 ) & ~0x7;
	if (ibuf->cmap) {
		buf[1] = 1;
		buf[2] = 9;
		buf[3] = ibuf->mincol & 0xff;
		buf[4] = ibuf->mincol >> 8;
		buf[5] = ibuf->maxcol & 0xff;
		buf[6] = ibuf->maxcol >> 8;
		buf[7] = 24;
		if ((flags & IB_ttob) == 0) {
			IMB_flipy(ibuf);
			buf[17] = 0x20;
		}
	} else if (ibuf->depth > 8 ){
Exemplo n.º 2
0
static void QT_DoAddVideoSamplesToMedia (int frame, int *pixels, int rectx, int recty, ReportList *reports)
{
	OSErr	err = noErr;
	Rect	imageRect;

	int		index;
	int		boxsize;
	unsigned char *from, *to;

	short	syncFlag;
	long	dataSize;
	Handle	compressedData;
	Ptr		myPtr;


	//copy and flip renderdata
	memcpy(qtexport->ibuf2->rect, pixels, 4*rectx*recty);
	IMB_flipy(qtexport->ibuf2);

	//get pointers to parse bitmapdata
	myPtr = GetPixBaseAddr(qtexport->thePixMap);
	imageRect = (**qtexport->thePixMap).bounds;

	from = (unsigned char *) qtexport->ibuf2->rect;
	to = (unsigned char *) myPtr;

	//parse RGBA bitmap into Quicktime's ARGB GWorld
	boxsize = rectx * recty;
	for( index = 0; index < boxsize; index++) {
		to[0] = from[3];
		to[1] = from[0];
		to[2] = from[1];
		to[3] = from[2];
		to +=4, from += 4;
	}

	err = SCCompressSequenceFrame(qtdata->theComponent,
		qtexport->thePixMap,
		&imageRect,
		&compressedData,
		&dataSize,
		&syncFlag);
	CheckError(err, "SCCompressSequenceFrame error", reports);

	err = AddMediaSample(qtexport->theMedia,
		compressedData,
		0,
		dataSize,
		qtdata->duration,
		(SampleDescriptionHandle)qtexport->anImageDescription,
		1,
		syncFlag,
		NULL);
	CheckError(err, "AddMediaSample error", reports);
}
Exemplo n.º 3
0
static struct ImBuf *imb_load_dpx_cineon(unsigned char *mem, size_t size, int use_cineon, int flags,
                                         char colorspace[IM_MAX_SPACE])
{
	ImBuf *ibuf;
	LogImageFile *image;
	int width, height, depth;

	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);

	logImageSetVerbose((G.f & G_DEBUG) ? 1 : 0);

	image = logImageOpenFromMemory(mem, size);

	if (image == 0) {
		printf("DPX/Cineon: error opening image.\n");
		return 0;
	}

	logImageGetSize(image, &width, &height, &depth);

	if (width == 0 || height == 0) {
		logImageClose(image);
		return 0;
	}

	ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
	if (ibuf == 0) {
		logImageClose(image);
		return 0;
	}

	if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
		/* Conversion not possible (probably because the format is unsupported) */
		logImageClose(image);
		MEM_freeN(ibuf);
		return 0;
	}

	logImageClose(image);
	ibuf->ftype = use_cineon ? CINEON : DPX;
	IMB_flipy(ibuf);

	if (flags & IB_rect)
		IMB_rect_from_float(ibuf);

	if (flags & IB_alphamode_detect)
		ibuf->flags |= IB_alphamode_premul;

	return ibuf;
}
Exemplo n.º 4
0
static void index_rebuild_fallback(FallbackIndexBuilderContext *context,
                                   short *stop, short *do_update, float *progress)
{
	int cnt = IMB_anim_get_duration(context->anim, IMB_TC_NONE);
	int i, pos;
	struct anim *anim = context->anim;

	for (pos = 0; pos < cnt; pos++) {
		struct ImBuf *ibuf = IMB_anim_absolute(anim, pos, IMB_TC_NONE, IMB_PROXY_NONE);
		struct ImBuf *tmp_ibuf = IMB_dupImBuf(ibuf);
		float next_progress = (float) pos / (float) cnt;

		if (*progress != next_progress) {
			*progress = next_progress;
			*do_update = TRUE;
		}
		
		if (*stop) {
			break;
		}

		IMB_flipy(tmp_ibuf);

		for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
			if (context->proxy_sizes_in_use & proxy_sizes[i]) {
				int x = anim->x * proxy_fac[i];
				int y = anim->y * proxy_fac[i];

				struct ImBuf *s_ibuf = IMB_dupImBuf(tmp_ibuf);

				IMB_scalefastImBuf(s_ibuf, x, y);

				IMB_convert_rgba_to_abgr(s_ibuf);
	
				AVI_write_frame(context->proxy_ctx[i], pos,
				                AVI_FORMAT_RGB32,
				                s_ibuf->rect, x * y * 4);

				/* note that libavi free's the buffer... */
				s_ibuf->rect = NULL;

				IMB_freeImBuf(s_ibuf);
			}
		}

		IMB_freeImBuf(tmp_ibuf);
		IMB_freeImBuf(ibuf);
	}
}
Exemplo n.º 5
0
static struct ImBuf *imb_load_dpx_cineon(unsigned char *mem, size_t size, int use_cineon, int flags,
                                         char colorspace[IM_MAX_SPACE])
{
	ImBuf *ibuf;
	LogImageFile *image;
	int width, height, depth;

	colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);

	logImageSetVerbose((G.f & G_DEBUG) ? 1 : 0);

	image = logImageOpenFromMemory(mem, size);

	if (image == NULL) {
		printf("DPX/Cineon: error opening image.\n");
		return NULL;
	}

	logImageGetSize(image, &width, &height, &depth);

	ibuf = IMB_allocImBuf(width, height, 32, IB_rectfloat | flags);
	if (ibuf == NULL) {
		logImageClose(image);
		return NULL;
	}

	if (!(flags & IB_test)) {
		if (logImageGetDataRGBA(image, ibuf->rect_float, 1) != 0) {
			logImageClose(image);
			IMB_freeImBuf(ibuf);
			return NULL;
		}
		IMB_flipy(ibuf);
	}

	logImageClose(image);
	ibuf->ftype = use_cineon ? CINEON : DPX;

	if (flags & IB_alphamode_detect)
		ibuf->flags |= IB_alphamode_premul;

	return ibuf;
}
Exemplo n.º 6
0
struct ImBuf *imb_load_dds(unsigned char *mem, size_t size, int flags)
{
	struct ImBuf * ibuf = 0;
	DirectDrawSurface dds(mem, size); /* reads header */
	unsigned char bits_per_pixel;
	unsigned int *rect;
	Image img;
	unsigned int numpixels = 0;
	int col;
	unsigned char *cp = (unsigned char *) &col;
	Color32 pixel;
	Color32 *pixels = 0;

	if(!imb_is_a_dds(mem))
		return (0);

	/* check if DDS is valid and supported */
	if (!dds.isValid()) {
		/* no need to print error here, just testing if it is a DDS */
		if(flags & IB_test)
			return (0);

		printf("DDS: not valid; header follows\n");
		dds.printInfo();
		return(0);
	}
	if (!dds.isSupported()) {
		printf("DDS: format not supported\n");
		return(0);
	}
	if ((dds.width() > 65535) || (dds.height() > 65535)) {
		printf("DDS: dimensions too large\n");
		return(0);
	}

	/* convert DDS into ImBuf */
	// TODO use the image RGB or RGBA tag to determine the bits per pixel
	if (dds.hasAlpha()) bits_per_pixel = 32;
	else bits_per_pixel = 24;
	ibuf = IMB_allocImBuf(dds.width(), dds.height(), bits_per_pixel, 0);
	if (ibuf == 0) return(0); /* memory allocation failed */

	ibuf->ftype = DDS;
	ibuf->profile = IB_PROFILE_SRGB;

	if ((flags & IB_test) == 0) {
		if (!imb_addrectImBuf(ibuf)) return(ibuf);
		if (ibuf->rect == 0) return(ibuf);

		rect = ibuf->rect;
		dds.mipmap(&img, 0, 0); /* load first face, first mipmap */
		pixels = img.pixels();
		numpixels = dds.width() * dds.height();
		cp[3] = 0xff; /* default alpha if alpha channel is not present */

		for (unsigned int i = 0; i < numpixels; i++) {
			pixel = pixels[i];
			cp[0] = pixel.r; /* set R component of col */
			cp[1] = pixel.g; /* set G component of col */
			cp[2] = pixel.b; /* set B component of col */
			if (bits_per_pixel == 32)
				cp[3] = pixel.a; /* set A component of col */
			rect[i] = col;
		}
		IMB_flipy(ibuf);
	}

	return(ibuf);
}
Exemplo n.º 7
0
struct ImBuf *imb_loadhdr(unsigned char *mem, size_t size, int flags)
{
	struct ImBuf* ibuf;
	RGBE* sline;
	fCOLOR fcol;
	float* rect_float;
	int found=0;
	int width=0, height=0;
	int x, y;
	unsigned char* ptr;
	char oriY[80], oriX[80];

	if (imb_is_a_hdr((void*)mem))
	{
		/* find empty line, next line is resolution info */
		for (x=1;x<size;x++) {
			if ((mem[x-1]=='\n') && (mem[x]=='\n')) {
				found = 1;
				break;
			}
		}
		if (found && (x<(size + 2))) {
			if (sscanf((char *)&mem[x+1], "%79s %d %79s %d", (char*)&oriY, &height, 
				(char*)&oriX, &width) != 4) return NULL;

			/* find end of this line, data right behind it */
			ptr = (unsigned char *)strchr((char*)&mem[x+1], '\n');
			ptr++;

			if (flags & IB_test) ibuf = IMB_allocImBuf(width, height, 32, 0);
			else ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect)|IB_rectfloat);

			if (ibuf==NULL) return NULL;
			ibuf->ftype = RADHDR;
			ibuf->profile = IB_PROFILE_LINEAR_RGB;

			if (flags & IB_test) return ibuf;

			/* read in and decode the actual data */
			sline = (RGBE*)MEM_mallocN(sizeof(RGBE)*width, "radhdr_read_tmpscan");
			rect_float = (float *)ibuf->rect_float;
			
			for (y=0;y<height;y++) {
				ptr = freadcolrs(sline, ptr, width);
				if (ptr==NULL) {
					printf("HDR decode error\n");
					MEM_freeN(sline);
					return ibuf;
				}
				for (x=0;x<width;x++) {
					/* convert to ldr */
					RGBE2FLOAT(sline[x], fcol);
					*rect_float++ = fcol[RED];
					*rect_float++ = fcol[GRN];
					*rect_float++ = fcol[BLU];
					*rect_float++ = 1.0f;
				}
			}
			MEM_freeN(sline);
			if (oriY[0]=='-') IMB_flipy(ibuf);
			
			if (flags & IB_rect) {
				IMB_rect_from_float(ibuf);
			}
			
			return ibuf;
		}
		//else printf("Data not found!\n");
	}
	//else printf("Not a valid radiance HDR file!\n");

	return NULL;
}
Exemplo n.º 8
0
static void index_rebuild_fallback(struct anim * anim,
                                   IMB_Timecode_Type UNUSED(tcs_in_use),
                                   IMB_Proxy_Size proxy_sizes_in_use,
                                   int quality,
                                   short *stop, short *do_update,
                                   float *progress)
{
    int cnt = IMB_anim_get_duration(anim, IMB_TC_NONE);
    int i, pos;
    AviMovie * proxy_ctx[IMB_PROXY_MAX_SLOT];
    char fname[FILE_MAXDIR+FILE_MAXFILE];
    char fname_tmp[FILE_MAXDIR+FILE_MAXFILE];

    memset(proxy_ctx, 0, sizeof(proxy_ctx));

    /* since timecode indices only work with ffmpeg right now,
       don't know a sensible fallback here...

       so no proxies, no game to play...
    */
    if (proxy_sizes_in_use == IMB_PROXY_NONE) {
        return;
    }

    for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
        if (proxy_sizes_in_use & proxy_sizes[i]) {
            char fname[FILE_MAXDIR+FILE_MAXFILE];

            get_proxy_filename(anim, proxy_sizes[i], fname, TRUE);
            BLI_make_existing_file(fname);

            proxy_ctx[i] = alloc_proxy_output_avi(
                               anim, fname,
                               anim->x * proxy_fac[i],
                               anim->y * proxy_fac[i],
                               quality);
        }
    }

    for (pos = 0; pos < cnt; pos++) {
        struct ImBuf * ibuf = IMB_anim_absolute(
                                  anim, pos, IMB_TC_NONE, IMB_PROXY_NONE);
        int next_progress = (int) ((double) pos / (double) cnt);

        if (*progress != next_progress) {
            *progress = next_progress;
            *do_update = 1;
        }

        if (*stop) {
            break;
        }

        IMB_flipy(ibuf);

        for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
            if (proxy_sizes_in_use & proxy_sizes[i]) {
                int x = anim->x * proxy_fac[i];
                int y = anim->y * proxy_fac[i];

                struct ImBuf * s_ibuf = IMB_scalefastImBuf(
                                            ibuf, x, y);

                IMB_convert_rgba_to_abgr(s_ibuf);

                AVI_write_frame (proxy_ctx[i], pos,
                                 AVI_FORMAT_RGB32,
                                 s_ibuf->rect, x * y * 4);

                /* note that libavi free's the buffer... */
                s_ibuf->rect = 0;

                IMB_freeImBuf(s_ibuf);
            }
        }
    }

    for (i = 0; i < IMB_PROXY_MAX_SLOT; i++) {
        if (proxy_sizes_in_use & proxy_sizes[i]) {
            AVI_close_compress (proxy_ctx[i]);
            MEM_freeN (proxy_ctx[i]);

            get_proxy_filename(anim, proxy_sizes[i],
                               fname_tmp, TRUE);
            get_proxy_filename(anim, proxy_sizes[i],
                               fname, FALSE);

            if (*stop) {
                unlink(fname_tmp);
            } else {
                rename(fname_tmp, fname);
            }
        }
    }
}
struct ImBuf *imb_loadhdr(const unsigned char *mem, size_t size, int flags, char colorspace[IM_MAX_SPACE])
{
	struct ImBuf *ibuf;
	RGBE *sline;
	fCOLOR fcol;
	float *rect_float;
	int found = 0;
	int width = 0, height = 0;
	int x, y;
	const unsigned char *ptr, *mem_eof = mem + size;
	char oriY[80], oriX[80];

	if (imb_is_a_hdr((void *)mem)) {
		colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_FLOAT);

		/* find empty line, next line is resolution info */
		for (x = 1; x < size; x++) {
			if ((mem[x - 1] == '\n') && (mem[x] == '\n')) {
				found = 1;
				break;
			}
		}
		if (found && (x < (size + 2))) {
			if (sscanf((char *)&mem[x + 1], "%79s %d %79s %d", (char *)&oriY, &height,
			           (char *)&oriX, &width) != 4)
			{
				return NULL;
			}

			/* find end of this line, data right behind it */
			ptr = (unsigned char *)strchr((char *)&mem[x + 1], '\n');
			ptr++;

			if (flags & IB_test) ibuf = IMB_allocImBuf(width, height, 32, 0);
			else ibuf = IMB_allocImBuf(width, height, 32, (flags & IB_rect) | IB_rectfloat);

			if (ibuf == NULL) return NULL;
			ibuf->ftype = IMB_FTYPE_RADHDR;

			if (flags & IB_alphamode_detect)
				ibuf->flags |= IB_alphamode_premul;

			if (flags & IB_test) return ibuf;

			/* read in and decode the actual data */
			sline = (RGBE *)MEM_mallocN(sizeof(*sline) * width, __func__);
			rect_float = ibuf->rect_float;
			
			for (y = 0; y < height; y++) {
				ptr = freadcolrs(sline, ptr, width, mem_eof);
				if (ptr == NULL) {
					printf("WARNING! HDR decode error, image may be just truncated, or completely wrong...\n");
					break;
				}
				for (x = 0; x < width; x++) {
					/* convert to ldr */
					RGBE2FLOAT(sline[x], fcol);
					*rect_float++ = fcol[RED];
					*rect_float++ = fcol[GRN];
					*rect_float++ = fcol[BLU];
					*rect_float++ = 1.0f;
				}
			}
			MEM_freeN(sline);
			if (oriY[0] == '-') IMB_flipy(ibuf);
			
			if (flags & IB_rect) {
				IMB_rect_from_float(ibuf);
			}
			
			return ibuf;
		}
		//else printf("Data not found!\n");
	}
	//else printf("Not a valid radiance HDR file!\n");

	return NULL;
}