void FreeImageGifData::add24bitBGRDataPage(int width, int height, BYTE* pData)
{
    FIBITMAP* newBitmap = FreeImage_Allocate(width, height, 24, 0x0000FF, 0x00FF00, 0xFF0000);
    BYTE* bitmapData = FreeImage_GetBits(newBitmap);
    memcpy(bitmapData, pData, width * height * 3);
    
    //Set metadata
    FIBITMAP* convBitmap = FreeImage_ColorQuantizeEx(newBitmap, FIQ_WUQUANT, 256);

    FITAG* delayTag = FreeImage_CreateTag();
    
    FreeImage_SetMetadata(FIMD_ANIMATION, convBitmap, NULL, NULL);

    LONG delayVal = 20;
    if (delayTag) {
        FreeImage_SetTagKey(delayTag, "FrameTime");
        FreeImage_SetTagType(delayTag, FIDT_LONG);
        FreeImage_SetTagCount(delayTag, 1);
        FreeImage_SetTagLength(delayTag, 4);
        FreeImage_SetTagValue(delayTag, &delayVal);
        FreeImage_SetMetadata(FIMD_ANIMATION, convBitmap, FreeImage_GetTagKey(delayTag), delayTag);
        FreeImage_DeleteTag(delayTag);
    }

    FreeImage_AppendPage(m_gifHandle, convBitmap);
    
    int pCount = FreeImage_GetPageCount(m_gifHandle);
    FreeImage_Unload(newBitmap);
    FreeImage_Unload(convBitmap);
}
Пример #2
0
void ofxGifEncoder::doSave() {
	// create a multipage bitmap
	FIMULTIBITMAP *multi = FreeImage_OpenMultiBitmap(FIF_GIF, ofToDataPath(fileName).c_str(), TRUE, FALSE); 
	FIBITMAP * bmp = NULL;
	
	for(int i = 0; i < frames.size(); i++ ) { 
		// we need to swap the channels if we're on little endian (see ofImage::swapRgb);
#ifdef TARGET_LITTLE_ENDIAN
        swapRgb(frames[i]);
#endif
		// get the pixel data
		bmp	= FreeImage_ConvertFromRawBits(
            frames[i]->pixels, 
            frames[i]->width,
            frames[i]->height, 
            frames[i]->width*(frames[i]->bitsPerPixel/8), 
            frames[i]->bitsPerPixel, 
            0, 0, 0, true // in of006 this (topdown) had to be false.
        );	 
        
#ifdef TARGET_LITTLE_ENDIAN
        swapRgb(frames[i]);
#endif
        
        DWORD frameDuration = (DWORD) (frames[i]->duration * 1000.f);

        bmp = FreeImage_ColorQuantizeEx(bmp, FIQ_NNQUANT, nColors);
		
		// dithering :)
        if(ditherMode > OFX_GIF_DITHER_NONE) bmp = FreeImage_Dither(bmp, (FREE_IMAGE_DITHER)ditherMode);
        
		// clear any animation metadata used by this dib as we’ll adding our own ones 
		FreeImage_SetMetadata(FIMD_ANIMATION, bmp, NULL, NULL); 
		// add animation tags to dib[i] 
		FITAG *tag = FreeImage_CreateTag(); 
		
		if(tag) { 
			FreeImage_SetTagKey(tag, "FrameTime"); 
			FreeImage_SetTagType(tag, FIDT_LONG); 
			FreeImage_SetTagCount(tag, 1); 
			FreeImage_SetTagLength(tag, 4); 
			FreeImage_SetTagValue(tag, &frameDuration); 
			FreeImage_SetMetadata(FIMD_ANIMATION, bmp, FreeImage_GetTagKey(tag), tag); 
			FreeImage_DeleteTag(tag); 
		} 
		FreeImage_AppendPage(multi, bmp); 
	} 
	
	FreeImage_Unload(bmp);
	FreeImage_CloseMultiBitmap(multi); 
}
Пример #3
0
void
FreeImageStack::appendImage(const npp::ImageNPP_32f_C1 & rImage)
{
    NPP_ASSERT(rImage.width() == nWidth_);
    NPP_ASSERT(rImage.height() == nHeight_);
    
            // create the result image storage using FreeImage so we can easily 
            // save
    unsigned int nResultPitch   = FreeImage_GetPitch(pBitmap_32f_);
    float * pResultData = reinterpret_cast<float *>(FreeImage_GetBits(pBitmap_32f_));

    NPP_CHECK_CUDA(cudaMemcpy2D(pResultData, nResultPitch, rImage.data(), rImage.pitch(),
                                nWidth_ * 4, nHeight_, cudaMemcpyDeviceToHost));
    FreeImage_AppendPage(pImageStack_, pBitmap_32f_);

    appendAzimuthalAnalysis(pResultData, nResultPitch);
}
Пример #4
0
bool CloneMultiPage(FREE_IMAGE_FORMAT fif, char *input, char *output, int output_flag) {

	BOOL bMemoryCache = TRUE;

	// Open src file (read-only, use memory cache)
	FIMULTIBITMAP *src = FreeImage_OpenMultiBitmap(fif, input, FALSE, TRUE, bMemoryCache);

	if(src) {
		// Open dst file (creation, use memory cache)
		FIMULTIBITMAP *dst = FreeImage_OpenMultiBitmap(fif, output, TRUE, FALSE, bMemoryCache);

		// Get src page count
		int count = FreeImage_GetPageCount(src);

		// Clone src to dst
		for(int page = 0; page < count; page++) {
			// Load the bitmap at position 'page'
			FIBITMAP *dib = FreeImage_LockPage(src, page);
			if(dib) {
				// add a new bitmap to dst
				FreeImage_AppendPage(dst, dib);
				// Unload the bitmap (do not apply any change to src)
				FreeImage_UnlockPage(src, dib, FALSE);
			}
		}

		// Close src
		FreeImage_CloseMultiBitmap(src, 0);
		// Save and close dst
		FreeImage_CloseMultiBitmap(dst, output_flag);

		return true;
	}

	return false;
}
Пример #5
0
static FIMULTIBITMAP* ReadFromAvi(const char* filename) {
	int err=0;
	AVIFileInit();
	
	PAVISTREAM pavi; // Handle To An Open Stream
	if( AVIStreamOpenFromFile(&pavi, filename, streamtypeVIDEO, 0, OF_READ, NULL) != 0) {
		AVIFileExit();
		return NULL;
	}



	AVISTREAMINFO		psi;				// Pointer To A Structure Containing Stream Info
	AVIStreamInfo(pavi, &psi, sizeof(psi));				// Reads Information About The Stream Into psi
	int width  = psi.rcFrame.right-psi.rcFrame.left;			// Width Is Right Side Of Frame Minus Left
	int height = psi.rcFrame.bottom-psi.rcFrame.top;			// Height Is Bottom Of Frame Minus Top
	int frameCount = AVIStreamLength(pavi);							// The Last Frame Of The Stream

	double mpf = AVIStreamSampleToTime(pavi, frameCount) / (double)frameCount;		// Calculate Rough Milliseconds Per Frame

	PGETFRAME pgf = AVIStreamGetFrameOpen(pavi, NULL);				// Create The PGETFRAME Using Our Request Mode
	if (pgf==NULL)
	{
		// An Error Occurred Opening The Frame
		error("Failed To Open frame from AVI");
	}

	//HDC hdc = GetDC(0);

	HDRAWDIB hdd = DrawDibOpen();													// Handle For Our Dib

	BITMAPINFOHEADER bmih;										// Header Information For DrawDibDraw Decoding
	bmih.biSize = sizeof (BITMAPINFOHEADER);					// Size Of The BitmapInfoHeader
	bmih.biPlanes = 1;											// Bitplanes	
	bmih.biBitCount = 24;										// Bits Format We Want (24 Bit, 3 Bytes)
	bmih.biWidth = width;										// Width We Want (256 Pixels)
	bmih.biHeight = height;										// Height We Want (256 Pixels)
	bmih.biCompression = BI_RGB;								// Requested Mode = RGB

	char		*data;						// Pointer To Texture Data
	HBITMAP hBitmap = CreateDIBSection(hdc, (BITMAPINFO*)(&bmih), DIB_RGB_COLORS, (void**)(&data), NULL, NULL);
	SelectObject(hdc, hBitmap);								// Select hBitmap Into Our Device Context (hdc)

	// create a new freeimage anim
	someError=false;
	FIMULTIBITMAP* ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", TRUE, FALSE);
	if (!ret || someError) {
		error("Couldnt create multibitmap");
	}

	for (int frame=0; frame<frameCount; frame++) {
		fprintf(stderr, "Loading frame %i\n", frame);
		// Grab Data From The AVI Stream
		LPBITMAPINFOHEADER lpbi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(pgf, frame);	
		// Pointer To Data Returned By AVIStreamGetFrame
		// (Skip The Header Info To Get To The Data)
		char* pdata = (char *)lpbi + lpbi->biSize + lpbi->biClrUsed * sizeof(RGBQUAD);	
		
		// Convert Data To Requested Bitmap Format
		DrawDibDraw(hdd, hdc, 0, 0, width, height, lpbi, pdata, 0, 0, width, height, 0);

		// copy into the freeimage thing
		FIBITMAP* fiBitmap = FreeImage_ConvertFromRawBits((BYTE*)data, width, height, width*3, 24, 0xFF0000, 0x00FF00, 0x0000FF);
/*		BYTE* src = (BYTE*)data;
		for (int y=0; y<height; y++) {
			BYTE* dst = FreeImage_GetScanLine(fiBitmap, y);
			for (int x=0; x<width; x++) {
				//src++;
				*dst++ = *src++;
				*dst++ = *src++;
				*dst++ = *src++;
			}
		}
*/
		FIBITMAP* grayBitmap = FreeImage_ConvertToGreyscale(fiBitmap);
		FreeImage_Unload(fiBitmap);

		FreeImage_AppendPage(ret, grayBitmap);
	}
	FreeImage_CloseMultiBitmap(ret);
	ret = FreeImage_OpenMultiBitmap(FIF_TIFF, "temp.tiff", FALSE, TRUE);

	DeleteObject(hBitmap);										// Delete The Device Dependant Bitmap Object
	DrawDibClose(hdd);											// Closes The DrawDib Device Context
	AVIStreamGetFrameClose(pgf);								// Deallocates The GetFrame Resources
	AVIStreamRelease(pavi);										// Release The Stream
	AVIFileExit();												// Release The File

	return ret;
}
Пример #6
0
void fipMultiPage::appendPage(fipImage& image) {
	if(_mpage)
		FreeImage_AppendPage(_mpage, image);
}
Пример #7
0
//--------------------------------------------------------------
void ofxGifEncoder::save (vector <ofxGifFrame *> frames, string fileName, int nColors) {
    
    if (nColors < 2 || nColors > 256) {
        ofLog(OF_LOG_WARNING, "nColors must be between 2 and 256. your gif won't be saved");
        return;
    }
    
	// create a multipage bitmap
	FIMULTIBITMAP *multi = FreeImage_OpenMultiBitmap(FIF_GIF, ofToDataPath(fileName).c_str(), TRUE, FALSE); 
	
	FIBITMAP * bmp = NULL;
	
	for(int i = 0; i < frames.size(); i++ ) { 
		// we need to swap the channels if we're on little endian (see ofImage::swapRgb);
#ifdef TARGET_LITTLE_ENDIAN
        swapRgb(frames[i]);
#endif
		
		// get the pixel data
		bmp	= FreeImage_ConvertFromRawBits(
            frames[i]->pixels, 
            frames[i]->width,
            frames[i]->height, 
            frames[i]->width*(frames[i]->bitsPerPixel/8), 
            frames[i]->bitsPerPixel, 
            0,
            0,
            0, 
            true // in of006 this (topdown) had to be false.
        );	 
		
		
#ifdef TARGET_LITTLE_ENDIAN
        swapRgb(frames[i]);
#endif
    		
        DWORD frameDuration = (DWORD) frames[i]->duration * 1000.f;
		
        // bmp =  FreeImage_ColorQuantize(bmp, FIQ_NNQUANT);
		
		// if we want to set a reduced color palette (2 to 256);
        bmp = FreeImage_ColorQuantizeEx(bmp, FIQ_NNQUANT, nColors);
		
		// dithering :)
		// you can set a different dither pattern for each frame
        // bmp = FreeImage_Dither(bmp, (FREE_IMAGE_DITHER)((i+1)%6));
        //bmp = FreeImage_Dither(bmp, FID_BAYER8x8);
        
		// clear any animation metadata used by this dib as we’ll adding our own ones 
		FreeImage_SetMetadata(FIMD_ANIMATION, bmp, NULL, NULL); 
		// add animation tags to dib[i] 
		FITAG *tag = FreeImage_CreateTag(); 
		
		if(tag) { 
			FreeImage_SetTagKey(tag, "FrameTime"); 
			FreeImage_SetTagType(tag, FIDT_LONG); 
			FreeImage_SetTagCount(tag, 1); 
			FreeImage_SetTagLength(tag, 4); 
			FreeImage_SetTagValue(tag, &frameDuration); 
			FreeImage_SetMetadata(FIMD_ANIMATION, bmp, FreeImage_GetTagKey(tag), tag); 
			FreeImage_DeleteTag(tag); 
		} 
		FreeImage_AppendPage(multi, bmp); 
	} 
	
	FreeImage_Unload(bmp);
	FreeImage_CloseMultiBitmap(multi); 
}
Пример #8
0
void ofxGifEncoder::processFrame(ofxGifFrame * frame, FIMULTIBITMAP *multi){
    FIBITMAP * bmp = NULL;
    // we need to swap the channels if we're on little endian (see ofImage::swapRgb);

    
    if (frame->bitsPerPixel ==32){
        ofLog() << "image is transaprent!";
        frame = convertTo24BitsWithGreenScreen(frame);
    }
    
#ifdef TARGET_LITTLE_ENDIAN
    swapRgb(frame);
#endif
    
    
    // from here on, we can only deal with 24 bits
    
    // get the pixel data
    bmp	= FreeImage_ConvertFromRawBits(
                                       frame->pixels,
                                       frame->width,
                                       frame->height,
                                       frame->width*(frame->bitsPerPixel/8),
                                       frame->bitsPerPixel,
                                       0, 0, 0, true // in of006 this (topdown) had to be false.
                                       );
    
    FIBITMAP * bmpConverted;
    
#ifdef TARGET_LITTLE_ENDIAN
    swapRgb(frame);
#endif
    
    FIBITMAP * quantizedBmp = NULL;
    FIBITMAP * ditheredBmp  = NULL;
    FIBITMAP * processedBmp = NULL;
    
    
    quantizedBmp = FreeImage_ColorQuantizeEx(bmp, FIQ_WUQUANT, nColors);
    processedBmp = quantizedBmp;
    
    if (nChannels == 4){
        calculatePalette(processedBmp);
        FreeImage_SetTransparentIndex(processedBmp,getClosestToGreenScreenPaletteColorIndex());
    }


    
    // dithering :)
    if(ditherMode > OFX_GIF_DITHER_NONE) {
        ditheredBmp = FreeImage_Dither(processedBmp, (FREE_IMAGE_DITHER)ditherMode);
        processedBmp = ditheredBmp;
    }
    
    DWORD frameDuration = (DWORD) (frame->duration * 1000.f);
    
    // clear any animation metadata used by this dib as we’ll adding our own ones
    FreeImage_SetMetadata(FIMD_ANIMATION, processedBmp, NULL, NULL);
    // add animation tags to dib[frameNum]
    FITAG *tag = FreeImage_CreateTag();
    if(tag) {
        FreeImage_SetTagKey(tag, "FrameTime");
        FreeImage_SetTagType(tag, FIDT_LONG);
        FreeImage_SetTagCount(tag, 1);
        FreeImage_SetTagLength(tag, 4);
        FreeImage_SetTagValue(tag, &frameDuration);
        FreeImage_SetMetadata(FIMD_ANIMATION, processedBmp, FreeImage_GetTagKey(tag), tag);
        FreeImage_DeleteTag(tag);
    }
    
    FreeImage_AppendPage(multi, processedBmp);
    
    // clear freeimage stuff
    if(bmp          != NULL) FreeImage_Unload(bmp);
    if(quantizedBmp != NULL) FreeImage_Unload(quantizedBmp);
    if(ditheredBmp  != NULL) FreeImage_Unload(ditheredBmp);
    
    // no need to unload processedBmp, as it points to either of the above

}