Esempio n. 1
0
	BITMAPINFO * FreeImage::getInfos() {
		if ( isLoaded() ) {
			return FreeImage_GetInfo( this -> freeImage );
		} else {
			return NULL;
		}
	}
Esempio n. 2
0
// CPreview message handlers
void CPreview::OnPaint()
{
	CPaintDC dc(this); // device context for painting

	CRect rct;
	GetClientRect(&rct);

	dc.FillSolidRect(&rct, m_clr);   // Fill background first

	if (m_dib != NULL)
	{
		// Draw the thumbnail
		int width = (int)(FreeImage_GetWidth(m_dib)*theApp.thumb_zoom_);
		if (width > rct.Width()) width = rct.Width();
		int height = (int)(FreeImage_GetHeight(m_dib)*theApp.thumb_zoom_);
		if (height > rct.Height()) height = rct.Height();
		int left = (rct.Width() - width)/2;
		if (left < 0) left = 0;
		::StretchDIBits(dc.GetSafeHdc(),
					left, 0, width, height,
					0, 0, FreeImage_GetWidth(m_dib), FreeImage_GetHeight(m_dib),
					FreeImage_GetBits(m_dib), FreeImage_GetInfo(m_dib), DIB_RGB_COLORS, SRCCOPY);
	}
	else
	{
		// Just draw some text to say there is no preview
		dc.SetTextAlign(TA_CENTER);
		dc.TextOut(rct.Width()/2, 20, "No Preview      ", 12);
		dc.TextOut(rct.Width()/2, 40, "Available       ", 12);
	}
}
Esempio n. 3
0
int CPropertiesFiles::previewWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	static bool fDowned=false;

	switch (uMsg) {
		case WM_INITDIALOG:
			if (!fiBitmap) {
				FIMEMORY* fiMemory=FreeImage_OpenMemory((BYTE*)lParam,bitmapInfo->unc_size);
				RECT rect;
				POINT pt={0,0};

				if (fiBitmap=FreeImage_LoadFromMemory(_tcsicmp(bitmapInfo->name+_tcslen(bitmapInfo->name)-4,".tga")?_tcsicmp(bitmapInfo->name+_tcslen(bitmapInfo->name)-4,".bmp")?FIF_JPEG:FIF_BMP:FIF_TARGA,fiMemory)) {
					::GetWindowRect(hwndDlg,&rect);
					::ClientToScreen(hwndDlg,&pt);
					rect.right=FreeImage_GetWidth(fiBitmap)+(pt.x-rect.left);
					rect.bottom=FreeImage_GetHeight(fiBitmap)+(pt
						.y-rect.top);;
					::MoveWindow(hwndDlg,rect.left,rect.top,rect.right,rect.bottom,FALSE);
					FreeImage_CloseMemory(fiMemory);

					::SetWindowText(hwndDlg,_tcsrchr(bitmapInfo->name,'/')+1);
					fDowned=false;
				} else {
					fDowned=true;
					::EndDialog(hwndDlg,0);
				}
			}
			break;
		case WM_LBUTTONDOWN:
		case WM_RBUTTONDOWN:
			fDowned=true;
			break;
		case WM_CLOSE:
			fDowned=true;
		case WM_LBUTTONUP:
		case WM_RBUTTONUP:
			if (fDowned) {
				FreeImage_Unload(fiBitmap);
				fiBitmap=NULL;
				::EndDialog(hwndDlg,0);
			}
			break;
		case WM_PAINT:
			{
				HDC hDC=::GetDC(hwndDlg);
				::SetStretchBltMode(hDC, COLORONCOLOR);
				::StretchDIBits(hDC, 0,0,FreeImage_GetWidth(fiBitmap), FreeImage_GetHeight(fiBitmap), 
					0, 0, FreeImage_GetWidth(fiBitmap), FreeImage_GetHeight(fiBitmap),
					FreeImage_GetBits(fiBitmap), FreeImage_GetInfo(fiBitmap), DIB_RGB_COLORS, SRCCOPY);
				::ReleaseDC(hwndDlg,hDC);
			}
	}
	return FALSE;
}
Esempio n. 4
0
std::ostream &
operator <<(std::ostream &rOutputStream, const FIBITMAP &rBitmap)
{
    unsigned int nImageWidth    = FreeImage_GetWidth(const_cast<FIBITMAP *>(&rBitmap));
    unsigned int nImageHeight   = FreeImage_GetHeight(const_cast<FIBITMAP *>(&rBitmap));
    unsigned int nPitch         = FreeImage_GetPitch(const_cast<FIBITMAP *>(&rBitmap));
    unsigned int nBPP           = FreeImage_GetBPP(const_cast<FIBITMAP *>(&rBitmap));

    FREE_IMAGE_COLOR_TYPE eType = FreeImage_GetColorType(const_cast<FIBITMAP *>(&rBitmap));
    BITMAPINFO *pInfo          = FreeImage_GetInfo(const_cast<FIBITMAP *>(&rBitmap));

    rOutputStream << "Size  (" << FreeImage_GetWidth(const_cast<FIBITMAP *>(&rBitmap)) << ", "
                  << FreeImage_GetHeight(const_cast<FIBITMAP *>(&rBitmap)) << ")\n";
    rOutputStream << "Pitch "  << FreeImage_GetPitch(const_cast<FIBITMAP *>(&rBitmap)) << "\n";
    rOutputStream << "Type  ";

    switch (eType)
    {
        case FIC_MINISWHITE:
            rOutputStream << "FIC_MINISWHITE\n";
            break;

        case FIC_MINISBLACK:
            rOutputStream << "FIC_MINISBLACK\n";
            break;

        case FIC_RGB:
            rOutputStream << "FIC_RGB\n";
            break;

        case FIC_PALETTE:
            rOutputStream << "FIC_PALETTE\n";
            break;

        case FIC_RGBALPHA:
            rOutputStream << "FIC_RGBALPHA\n";
            break;

        case FIC_CMYK:
            rOutputStream << "FIC_CMYK\n";
            break;

        default:
            rOutputStream << "Unknown pixel format.\n";
    }

    rOutputStream << "BPP   " << nBPP << std::endl;

    return rOutputStream;
}
Esempio n. 5
0
	Bool FreeImageImage::_load(FIBITMAP* pFIBitmap)
	{
		BITMAPINFO* pBitmapInfo = FreeImage_GetInfo(pFIBitmap);

		_ptImgSize.x = (Int16) pBitmapInfo->bmiHeader.biWidth;
		_ptImgSize.y = (Int16) pBitmapInfo->bmiHeader.biHeight;

		Color* pImgData = (Color*) FreeImage_GetBits(pFIBitmap);
		//RGBQUAD* pPalette = FreeImage_GetPalette(pFIBitmap);

		_pImgData = CrabNewArray(Color, _ptImgSize.getArea());
		memcpy(_pImgData, pImgData, sizeof(Color) * _ptImgSize.getArea());

		return True;
	}
Esempio n. 6
0
BOOL fipWinImage::copyFromBitmap(HBITMAP hbmp) {
	if(hbmp) { 
		int Success;
        BITMAP bm;
		// Get informations about the bitmap
        GetObject(hbmp, sizeof(BITMAP), (LPSTR) &bm);
		// Create the image
        setSize(FIT_BITMAP, (WORD)bm.bmWidth, (WORD)bm.bmHeight, (WORD)bm.bmBitsPixel);

		// The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why) 
		// So we save these infos below. This is needed for palettized images only. 
		int nColors = FreeImage_GetColorsUsed(_dib);

		// Create a device context for the bitmap
        HDC dc = GetDC(NULL);
		// Copy the pixels
		Success = GetDIBits(dc,								// handle to DC
								hbmp,						// handle to bitmap
								0,							// first scan line to set
								FreeImage_GetHeight(_dib),	// number of scan lines to copy
								FreeImage_GetBits(_dib),	// array for bitmap bits
								FreeImage_GetInfo(_dib),	// bitmap data buffer
								DIB_RGB_COLORS				// RGB 
								);
		if(Success == 0) {
			FreeImage_OutputMessageProc(FIF_UNKNOWN, "Error : GetDIBits failed");
			ReleaseDC(NULL, dc);
			return FALSE;
        }
        ReleaseDC(NULL, dc);

		// restore BITMAPINFO members
		
		FreeImage_GetInfoHeader(_dib)->biClrUsed = nColors;
		FreeImage_GetInfoHeader(_dib)->biClrImportant = nColors;

		return TRUE;
    }

	return FALSE;
}
Esempio n. 7
0
static FIBITMAP *FreeImage_CreateDIBFromHBITMAP(HBITMAP hBmp)
{
	BITMAP bm;

	if(hBmp) {
		GetObject(hBmp, sizeof(BITMAP), (LPSTR) &bm);
		FIBITMAP *dib = FreeImage_Allocate(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel,0,0,0);
		// The GetDIBits function clears the biClrUsed and biClrImportant BITMAPINFO members (dont't know why)
		// So we save these infos below. This is needed for palettized images only.
		int nColors = FreeImage_GetColorsUsed(dib);
		HDC dc = GetDC(NULL);
		int Success = GetDIBits(dc, hBmp, 0, FreeImage_GetHeight(dib),
			FreeImage_GetBits(dib), FreeImage_GetInfo(dib), DIB_RGB_COLORS);
		ReleaseDC(NULL, dc);
		// restore BITMAPINFO members
		FreeImage_GetInfoHeader(dib)->biClrUsed = nColors;
		FreeImage_GetInfoHeader(dib)->biClrImportant = nColors;
		return dib;
	}
	return NULL;
}
Esempio n. 8
0
static HBITMAP FreeImage_CreateHBITMAPFromDIB(FIBITMAP *in)
{
    FIBITMAP *dib = NULL;
	int bpp = FreeImage_GetBPP(in);

	if (bpp == 48)
		dib = FreeImage_ConvertTo24Bits(in);
	else if (FreeImage_GetBPP(in) > 32)
		dib = FreeImage_ConvertTo32Bits(in);
    else
        dib = in;

	BYTE *ptPixels;
	BITMAPINFO *info = FreeImage_GetInfo(dib);
	HBITMAP hBmp = CreateDIBSection(NULL, info, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
	if (ptPixels != NULL)
		memmove(ptPixels, FreeImage_GetBits(dib), FreeImage_GetPitch(dib) * FreeImage_GetHeight(dib));

	if (dib != in)
		FreeImage_Unload(dib);

	return hBmp;
}
Esempio n. 9
0
BITMAPINFO* fipImage::getInfo() const {
	return FreeImage_GetInfo(_dib);
}
Esempio n. 10
0
void fipWinImage::drawEx(HDC hDC, RECT& rcDest, BOOL useFileBkg, RGBQUAD *appBkColor, FIBITMAP *bg) const {
	// Convert to a standard bitmap if needed
	if(_bHasChanged) {
		if(_bDeleteMe) {
			FreeImage_Unload(_display_dib);
			_display_dib = NULL;
			_bDeleteMe = FALSE;
		}

		FREE_IMAGE_TYPE image_type = getImageType();
		if(image_type == FIT_BITMAP) {
			BOOL bHasBackground = FreeImage_HasBackgroundColor(_dib);
			BOOL bIsTransparent = FreeImage_IsTransparent(_dib);

			if(!bIsTransparent && (!bHasBackground || !useFileBkg)) {
				// Copy pointer
				_display_dib = _dib;
			}
			else {
				// Create the transparent / alpha blended image
				_display_dib = FreeImage_Composite(_dib, useFileBkg, appBkColor, bg);
				if(_display_dib) {
					// Remember to delete _display_dib
					_bDeleteMe = TRUE;
				} else {
					// Something failed: copy pointers
					_display_dib = _dib;
				}
			}
		} else {
			// Convert to a standard dib for display

			if(image_type == FIT_COMPLEX) {
				// Convert to type FIT_DOUBLE
				FIBITMAP *dib_double = FreeImage_GetComplexChannel(_dib, FICC_MAG);
				// Convert to a standard bitmap (linear scaling)
				_display_dib = FreeImage_ConvertToStandardType(dib_double, TRUE);
				// Free image of type FIT_DOUBLE
				FreeImage_Unload(dib_double);
			} else if((image_type == FIT_RGBF) || (image_type == FIT_RGB16)) {
				// Apply a tone mapping algorithm and convert to 24-bit 
				_display_dib = FreeImage_ToneMapping(_dib, _tmo, _tmo_param_1, _tmo_param_2);
			} else if(image_type == FIT_RGBA16) {
				// Convert to 32-bit
				FIBITMAP *dib32 = FreeImage_ConvertTo32Bits(_dib);
				if(dib32) {
					// Create the transparent / alpha blended image
					_display_dib = FreeImage_Composite(dib32, useFileBkg, appBkColor, bg);
					FreeImage_Unload(dib32);
				}
			} else {
				// Other cases: convert to a standard bitmap (linear scaling)
				_display_dib = FreeImage_ConvertToStandardType(_dib, TRUE);
			}
			// Remember to delete _display_dib
			_bDeleteMe = TRUE;
		}

		_bHasChanged = FALSE;
	}

	// Draw the dib
	SetStretchBltMode(hDC, COLORONCOLOR);	
	StretchDIBits(hDC, rcDest.left, rcDest.top, 
		rcDest.right-rcDest.left, rcDest.bottom-rcDest.top, 
		0, 0, FreeImage_GetWidth(_display_dib), FreeImage_GetHeight(_display_dib),
		FreeImage_GetBits(_display_dib), FreeImage_GetInfo(_display_dib), DIB_RGB_COLORS, SRCCOPY);

}
Esempio n. 11
0
/*
 * Render a particular frame to a canvas (not gif specific).
 */
bool CAnimation::renderFileFrame(CCanvas *cnv, unsigned int frame)
{
	extern STRING g_projectPath;

    cnv->ClearScreen(TRANSP_COLOR);

	// Wrap around.
    frame %= m_data.frameCount;

    if (m_data.filename.empty()) return false;

	const STRING file = resolve(g_projectPath + MISC_PATH + m_data.filename);

	FIMULTIBITMAP *mbmp = FreeImage_OpenMultiBitmap(
		FreeImage_GetFileType(getAsciiString(file).c_str(), 16), 
		getAsciiString(file).c_str(), 
		FALSE, TRUE, TRUE
	);
	if (!mbmp) return false;

    CCanvas cnvImg;
	cnvImg.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);

	const int pageCount = FreeImage_GetPageCount(mbmp);
	if (frame < pageCount)
	{
		CONST HDC hdc = cnvImg.OpenDC();
		FIBITMAP *bmp = FreeImage_LockPage(mbmp, frame);

		SetDIBitsToDevice(
			hdc,
			0, 0,   
			m_data.pxWidth, m_data.pxHeight, 
			0, 0,
			0, FreeImage_GetHeight(bmp), 
			FreeImage_GetBits(bmp),   
			FreeImage_GetInfo(bmp), 
			DIB_RGB_COLORS
		); 

		/* No need to stretch gif.
		StretchDIBits(
			hdc, 
			0, 0, 
			m_data.pxWidth, m_data.pxHeight, 
			0, 0, 
			FreeImage_GetWidth(bmp), 
			FreeImage_GetHeight(bmp),
			FreeImage_GetBits(bmp), 
			FreeImage_GetInfo(bmp), 
			DIB_RGB_COLORS, SRCCOPY
		);*/

		FreeImage_UnlockPage(mbmp, bmp, FALSE);
		cnvImg.CloseDC(hdc);
	}
	FreeImage_CloseMultiBitmap(mbmp, 0);

	// Apply ambient level.
	extern AMBIENT_LEVEL g_ambientLevel;
	if (g_ambientLevel.color)
	{
		CCanvas cnvAl;
		cnvAl.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);
		cnvAl.ClearScreen(g_ambientLevel.color);
		cnvAl.BltAdditivePart(cnvImg.GetDXSurface(), 0, 0, 0, 0, m_data.pxWidth, m_data.pxHeight, g_ambientLevel.sgn, -1, m_data.transpColors[frame]);
	}

	cnvImg.BltTransparent(cnv, 0, 0, m_data.transpColors[frame]);

	return true;
}
Esempio n. 12
0
/*
 * Render all frames of a file (not gif specific).
 */
bool CAnimation::renderFileFrame(CCanvas *, unsigned int)
{
	extern STRING g_projectPath;

    if (m_data.filename.empty()) return false;

	const STRING file = resolve(g_projectPath + MISC_PATH + m_data.filename);

	FIMULTIBITMAP *mbmp = FreeImage_OpenMultiBitmap(
		FreeImage_GetFileType(getAsciiString(file).c_str(), 16), 
		getAsciiString(file).c_str(), 
		FALSE, TRUE, TRUE
	);
	if (!mbmp) return false;

	// Create ambient level canvas.
	extern AMBIENT_LEVEL g_ambientLevel;
	CCanvas cnvAl;
	if (g_ambientLevel.color)
	{
		cnvAl.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);
		cnvAl.ClearScreen(g_ambientLevel.color);
	}

	// Intermediate canvas.
	CCanvas cnv;
	cnv.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);

	freeCanvases();
	m_canvases.clear();
	for (int i = 0; i != m_data.frameCount; ++i)
	{
		CONST HDC hdc = cnv.OpenDC();
		FIBITMAP *bmp = FreeImage_LockPage(mbmp, i);

		SetDIBitsToDevice(
			hdc,
			0, 0,   
			m_data.pxWidth, m_data.pxHeight, 
			0, 0,
			0, FreeImage_GetHeight(bmp), 
			FreeImage_GetBits(bmp),   
			FreeImage_GetInfo(bmp), 
			DIB_RGB_COLORS
		); 

		/* No need to stretch gif.
		StretchDIBits(
			hdc, 
			0, 0, 
			0, 0, 
			FreeImage_GetWidth(bmp), 
			FreeImage_GetHeight(bmp),
			FreeImage_GetBits(bmp), 
			FreeImage_GetInfo(bmp), 
			DIB_RGB_COLORS, SRCCOPY
		);*/

		FreeImage_UnlockPage(mbmp, bmp, FALSE);
		cnv.CloseDC(hdc);

		// Apply ambient level.
		if (g_ambientLevel.color)
		{
			cnvAl.BltAdditivePart(cnv.GetDXSurface(), 0, 0, 0, 0, m_data.pxWidth, m_data.pxHeight, g_ambientLevel.sgn, -1, m_data.transpColors[i]);
		}

		// Blt to the member canvas.
		CCanvas *pCnv = new CCanvas();
		pCnv->CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);
		pCnv->ClearScreen(TRANSP_COLOR);
		cnv.BltTransparent(pCnv, 0, 0, m_data.transpColors[i]);

		m_canvases.push_back(pCnv);
	}
	FreeImage_CloseMultiBitmap(mbmp, 0);
	return true;
}
Esempio n. 13
0
/*
 * Render a particular frame to a canvas.
 */
bool CAnimation::renderAnmFrame(CCanvas *cnv, unsigned int frame)
{
	extern STRING g_projectPath;

    cnv->ClearScreen(TRANSP_COLOR);

	// Wrap around.
    frame %= m_data.frameCount;

	const STRING frameFile = m_data.frameFiles[frame];

    if (frameFile.empty()) return false;

	const STRING ext = parser::uppercase(getExtension(frameFile));
    if (ext == _T("TBM") || ext.substr(0, 3) == _T("TST") || ext == _T("GPH"))
	{
		TILE_BITMAP tbm;

		if (ext == _T("TBM"))
		{
			if (!tbm.open(g_projectPath + BMP_PATH + frameFile)) return false;
		}
		else
		{
			// Set up a 1x1 tile bitmap.
			tbm.resize(1, 1);
			tbm.tiles[0][0] = frameFile;
		}

        // Draw the tilebitmap and mask to new canvases.
		const int w = tbm.width * 32, h = tbm.height * 32;
		CCanvas cnvTbm, cnvMaskTbm;
		cnvTbm.CreateBlank(NULL, w, h, TRUE);
		cnvMaskTbm.CreateBlank(NULL, w, h, TRUE);

		if (tbm.draw(&cnvTbm, &cnvMaskTbm, 0, 0))
		{
			// Stretch the canvas and mask to an intermediate canvas.
			CCanvas cnvInt;
			cnvInt.CreateBlank(NULL, w, h, TRUE);
			cnvInt.ClearScreen(m_data.transpColors[frame]);

			cnvTbm.BltStretchMask(
				&cnvMaskTbm,
				&cnvInt,
				0, 0, 
				0, 0,
				w, h, 
				m_data.pxWidth, m_data.pxHeight
			);
			// Blt to the target canvas.
			cnvInt.BltTransparent(cnv, 0, 0, m_data.transpColors[frame]);
		}
	}
	else
	{
		// Image file.
		const STRING strFile = resolve(g_projectPath + BMP_PATH + frameFile);
		FIBITMAP *bmp = FreeImage_Load(
			FreeImage_GetFileType(getAsciiString(strFile).c_str(), 16), 
			getAsciiString(strFile).c_str()
		);

        CCanvas cnvImg;
		cnvImg.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);
		
		CONST HDC hdc = cnvImg.OpenDC();
		StretchDIBits(
			hdc, 
			0, 0, 
			m_data.pxWidth, m_data.pxHeight, 
			0, 0, 
			FreeImage_GetWidth(bmp), 
			FreeImage_GetHeight(bmp), 
			FreeImage_GetBits(bmp), 
			FreeImage_GetInfo(bmp), 
			DIB_RGB_COLORS, 
			SRCCOPY
		);
		FreeImage_Unload(bmp);
		cnvImg.CloseDC(hdc);

		// Apply ambient level.
		extern AMBIENT_LEVEL g_ambientLevel;
		if (g_ambientLevel.color)
		{
			CCanvas cnvAl;
			cnvAl.CreateBlank(NULL, m_data.pxWidth, m_data.pxHeight, TRUE);
			cnvAl.ClearScreen(g_ambientLevel.color);
			cnvAl.BltAdditivePart(cnvImg.GetDXSurface(), 0, 0, 0, 0, m_data.pxWidth, m_data.pxHeight, g_ambientLevel.sgn, -1, m_data.transpColors[frame]);
		}

		cnvImg.BltTransparent(cnv, 0, 0, m_data.transpColors[frame]);

    } // if (ext == TBM)
	return true;
}