コード例 #1
0
ファイル: fipImage.cpp プロジェクト: MrMasterplan/PIC-stuff
BOOL fipImage::adjustBrightness(double percentage) {
	if(_dib) {
		_bHasChanged = TRUE;

		return FreeImage_AdjustBrightness(_dib, percentage);
	}
	return FALSE;
}
コード例 #2
0
MOboolean
moTextureBuffer::LoadImage( moText p_ImageName, moBitmap* pImage, int indeximage  ) {

    MOboolean res = false;
    FIBITMAP* _pImage = (FIBITMAP*)pImage;
	FIBITMAP* pImageResult = NULL;
	FIBITMAP* pImageCropped = NULL;
	FIBITMAP* pImageScaled = NULL;
    /*
	if ( m_width!=FreeImage_GetWidth(_pImage) || m_height!=FreeImage_GetHeight(_pImage) ) {
		//CROP MODE
		pImageCropped = FreeImage_Copy( _pImage, m_XSource , m_YSource , m_XSource + m_SourceWidth , m_YSource+m_SourceHeight );
		pImageResult = pImageCropped;

	} else
	*/

	pImageResult = _pImage;

    int w, h;
	if ( ( FreeImage_GetWidth(_pImage) % 4 ) != 0 || ( FreeImage_GetHeight(_pImage) % 4) == 0 ) {

        w = FreeImage_GetWidth(_pImage) / 4;
        w = w * 4;

        h = FreeImage_GetHeight(_pImage) / 4;
        h = h * 4;

        pImageScaled = FreeImage_Rescale( pImageResult, w, h, FILTER_BICUBIC );
		if (pImageScaled) {
			//FreeImage_Unload(pImageResult);
			pImageResult = pImageScaled;
		}
	}


	FreeImage_AdjustContrast( pImageResult, 0 );
	FreeImage_AdjustBrightness( pImageResult, 0 );



	//RESCALE: NOTE NECESARRY HERE
	//quizas podamos definir un máximo para el tamaño tanto ancho como alto
	//o como proporción
	//forzar proporcion y esas cosas....
	/*
	if ( m_width != m_SourceWidth || m_height != m_SourceHeight ) {

		//FILTER_BOX Box, pulse, Fourier window, 1st order (constant) B-Spline
		//FILTER_BILINEAR Bilinear filter
		//FILTER_BSPLINE 4th order (cubic) B-Spline
		//FILTER_BICUBIC Mitchell and Netravali's two-param cubic filter
		//FILTER_CATMULLROM Catmull-Rom spline, Overhauser spline
		//FILTER_LANCZOS3
		pImageScaled = FreeImage_Rescale( pImageResult, m_width, m_height, FILTER_BICUBIC );
		if (pImageScaled) {
			FreeImage_Unload(pImageResult);
			pImageResult = pImageScaled;
		}
	}
	*/

    moTextureMemory* pTextureMemory = NULL;

    int idx = m_pResourceManager->GetTextureMan()->AddTexture( MO_TYPE_TEXTUREMEMORY, p_ImageName );

	if (idx>-1) {
	    pTextureMemory = (moTextureMemory*) m_pResourceManager->GetTextureMan()->GetTexture(idx);
        if (pTextureMemory) {
            if (pTextureMemory->BuildFromBitmap( pImageResult, m_BufferFormat )) {

                m_Frames.Add(pTextureMemory);

                int contrastlevel = pTextureMemory->GetContrast() / 2000;
                int luminancelevel = (int)((float)pTextureMemory->GetLuminance() / (float)2.56 ) - 1;

                MODebug2->Message( moText("moTextureBuffer::LoadImage success : ") + (moText)pTextureMemory->GetName());
                #ifdef _DEBUG
                MODebug2->Message( moText("moTextureBuffer::LoadImage success : ") + (moText)pTextureMemory->GetName()
                                + moText(" width:") + IntToStr(pTextureMemory->GetWidth())
                                + moText(" height:") + IntToStr(pTextureMemory->GetHeight())
                                + moText(" luminance:") + IntToStr(pTextureMemory->GetLuminance())
                                + moText(" luminancelevel:") + IntToStr(luminancelevel) +
                                + moText(" contrast:") + IntToStr(pTextureMemory->GetContrast())
                                + moText(" contrastlevel:") + IntToStr(contrastlevel) );
                #endif

                contrastlevel = 0;

                if (luminancelevel>=100) {
                        MODebug2->Error( moText("moTextureBuffer::LoadImage Error: luminance out of bound:")+ IntToStr(pTextureMemory->GetLuminance()) );
                } else {
                        if (max_luminance<luminancelevel) {
                            max_luminance = luminancelevel;
                        } else if (min_luminance>luminancelevel) {
                            min_luminance = luminancelevel;
                        }
                }
                if (contrastlevel>=10) {
                        MODebug2->Error( moText("moTextureBuffer::LoadImage Error: contrast out of bound:")+ IntToStr(pTextureMemory->GetContrast()) );
                }
                if (0<=luminancelevel && luminancelevel<100 && 0<=contrastlevel && contrastlevel<10) {

                    m_pBufferLevels[luminancelevel][contrastlevel].Add( pTextureMemory );

                    int icc = momin( m_pBufferLevels[luminancelevel][contrastlevel].Count(), 99 );
                    LevelDiagram[ (luminancelevel + icc*100)*3 ] = 250;
                    LevelDiagram[ (luminancelevel+1 + icc*100)*3 ] = 250;
                    LevelDiagram[ (luminancelevel+2 + icc*100)*3 ] = 250;
                }

                res = true;
            } else {
                res = false;
                MODebug2->Error( moText("moTextureBuffer::LoadImage Error loading image:")+(moText)pTextureMemory->GetName());
            }
        }
	}

	if (pImageResult!=_pImage)
		FreeImage_Unload(pImageResult);

	//m_nFrames = m_Frames.Count();
	//m_fFramesPerSecond = 25.0;

	return (res);
}