Ejemplo n.º 1
0
/* defines the background image that is used for alpha blending & transparent
   pixels */
BMGError SetBMGBackgroundImage( struct BMGImageStruct img )
{
    /* clean up the old background image */
    FreeBMGImage( GetBackgroundImage() );

    /* convert paletted and 16-BPP images to 24-BPP or 32-BPP images.  This
    // will simplify the alpha blending logic*/
    return ConvertPaletteToRGB( img, GetBackgroundImage() );
}
Ejemplo n.º 2
0
OP_STATUS OpPersona::InitL(OpFileDescriptor* skinfile)
{
	OP_STATUS s = OpSkin::LoadIniFileL(skinfile, UNI_L("persona.ini"));
	if(OpStatus::IsSuccess(s))
	{
		Image image = GetBackgroundImage();
		if(!image.IsEmpty())
		{
			OpBitmap *bitmap = image.GetBitmap(NULL);
			if(bitmap)
			{
				INT32 color_scheme_color = OpSkinUtils::GetAverageColorOfBitmap(bitmap);
				if(color_scheme_color)
				{
					color_scheme_color = ReadColorL("Options", "Tint Color", ReadColorL("Options", "Colorize Color", color_scheme_color, FALSE), FALSE);

					SetColorSchemeColor(color_scheme_color);
					SetColorSchemeMode(COLOR_SCHEME_MODE_CUSTOM);
					SetColorSchemeCustomType(COLOR_SCHEME_CUSTOM_NORMAL);
				}
				image.ReleaseBitmap();
			}
		}
		GenerateClearElementsList();
	}
	return s;
}
Ejemplo n.º 3
0
/* defines the background bitmap that is used for alpha blending & transparent
   pixels */
BMGError SetBMGBackgroundBitmap( HBITMAP hBitmap )
{
    BMGError out;
    struct BMGImageStruct tmp;
    InitBMGImage( &tmp );

    /* first we extract the data from the HBITMAP */
    out = GetDataFromBitmap( hBitmap, &tmp, 0 );
    if ( out == BMG_OK )
    {
        /* clean up the old background image */
        FreeBMGImage( GetBackgroundImage() );

        /* next, we convert paletted & 16-BPP images to 24 or 32-BPP images.
        // this will simplify the alpha blending. */
        out = ConvertPaletteToRGB( tmp, GetBackgroundImage() );
    }

    return out;
}
void CHandGestureRecognitionSystemDlg::OnClickedButtonPlayCamera()
{
    // TODO: Add your control notification handler code here
    // initialize camera and image
    if(!InitCameraAndImage())
        return;
    // set background
    GetBackgroundImage();
    // start timer;
    StartTimer();
}
Ejemplo n.º 5
0
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason,
                         void* lpReserved)
{
    switch( reason )
    {
    case DLL_PROCESS_ATTACH:
        InitBackground();
        break;
    case DLL_PROCESS_DETACH:
        FreeBMGImage( GetBackgroundImage() );
        break;
    }

    return 1;
}
Ejemplo n.º 6
0
BackgroundImage *
BackgroundImage::Refresh(BackgroundImage *oldBackgroundImage,
	const BNode *fromNode, bool desktop, BPoseView *poseView)
{
	if (oldBackgroundImage) {
		oldBackgroundImage->Remove();
		delete oldBackgroundImage;
	}
	
	BackgroundImage *result = GetBackgroundImage(fromNode, desktop);
	if (result && poseView->ViewMode() != kListMode)
		result->Show(poseView, current_workspace());

	return result;
}
Ejemplo n.º 7
0
/*******************************************************************************
// this function creates a bitmap from raw data. Returns an HBITMAP if it
// succeeds, otherwise NULL */
HBITMAP CreateBitmapFromData( struct BMGImageStruct img,
                              int alpha_blend )
{
    HBITMAP hBitmap = NULL;
    HDC hMemDC = NULL;
    HWND hWnd = GetForegroundWindow();
    HDC hDC = NULL;
    RGBQUAD *pColor = NULL;
    BITMAPINFO bmi;
    unsigned char *rbits;
    unsigned char *bits;
    unsigned char *lpBits;
    unsigned char alpha;
    unsigned int DIBScanWidth;
    int i;

    jmp_buf err_jmp;
    int error;

    /* error handler */
    error = setjmp( err_jmp );
    if ( error != 0 )
    {
        if ( hMemDC != NULL )
            DeleteDC( hMemDC );
        if ( hDC != NULL )
            ReleaseDC( hWnd, hDC );
        if ( pColor != NULL && img.bytes_per_palette_entry == 3U )
            free( pColor );
        SetLastBMGError( (BMGError)error );
        return 0;
    }

    SetLastBMGError( BMG_OK );

    /* create the DIB section that will hold this bitmap */
    bmi = InternalCreateBMI( (unsigned int)img.width, (unsigned int)img.height,
                              (unsigned short)img.bits_per_pixel, BI_RGB );
    bmi.bmiHeader.biClrUsed = bmi.bmiHeader.biClrImportant =
         img.palette_size;
    hDC = GetDC( hWnd );
    hBitmap = CreateDIBSection( hDC, &bmi, DIB_RGB_COLORS,
                                   (void **)&lpBits, NULL, 0 );

    if ( !hBitmap || !lpBits )
        longjmp( err_jmp, (int)errWindowsAPI );

    /* create a palette if needed */
    if ( img.palette != NULL )
    {
        /* copy pixel data to pColor */
        if ( img.bytes_per_palette_entry == 4U )
            pColor = (RGBQUAD *)img.palette;
        else /* bytes_per_palette_entry === 3 */
        {
            pColor = (RGBQUAD *)calloc(img.palette_size, sizeof(RGBQUAD) );
            if ( pColor == NULL )
                longjmp( err_jmp, (int)errMemoryAllocation );

            bits = img.palette;
            for ( i = 0; i < (int)bmi.bmiHeader.biClrUsed; i++, bits += 3 )
            {
                pColor[i].rgbRed   = bits[0];
                pColor[i].rgbGreen = bits[1];
                pColor[i].rgbBlue  = bits[2];
            }
        }

        if ( img.transparency_index > -1 )
        {
            unsigned char *color = GetBackgroundColor();
            rbits = img.palette + img.bytes_per_palette_entry *
                    img.transparency_index;
            rbits[0] = color[2];
            rbits[1] = color[1];
            rbits[2] = color[0];
        }
        /* save color table in bitmap */
        hMemDC = CreateCompatibleDC( hDC );
        SelectObject( hMemDC, hBitmap );
        if ( !SetDIBColorTable( hMemDC, 0, img.palette_size, pColor ) )
            longjmp( err_jmp, (int)errWindowsAPI );

        DeleteDC( hMemDC );
        hMemDC = NULL;
        if ( img.bytes_per_palette_entry == 3U )
            free( pColor );
        pColor = NULL;
    }

    /* calculate the scan line width */
    DIBScanWidth = img.scan_width;
    if ( DIBScanWidth % 4 )
        DIBScanWidth += 4 - DIBScanWidth % 4;

    if ( img.opt_for_bmp == 0 )
    {
        /* store bits into hBitmap */
        rbits = img.bits;
        for ( bits = lpBits;
              bits < lpBits + img.height * DIBScanWidth;
              bits += DIBScanWidth, rbits += img.scan_width )
        {
            memcpy( (void *)bits, (void *)rbits, img.scan_width );
        }
    }
    else
        memcpy( (void *)lpBits, (void *)img.bits, img.scan_width * img.height );

    /* blend the image with the window background if alpha pixels
    // are present */
    if ( img.bits_per_pixel == 32 )
    {
        /* blend with a bland background */
        if ( alpha_blend == 1 )
        {
            unsigned char *color = GetBackgroundColor();
            unsigned char red   = color[2];
            unsigned char green = color[1];
            unsigned char blue  = color[0];

            for ( rbits = lpBits;
                  rbits < lpBits + img.height*DIBScanWidth;
                  rbits += DIBScanWidth )
            {
                for ( bits = rbits; bits < rbits + DIBScanWidth; bits += 4 )
                {
                    alpha = bits[3];
                    bits[2] = AlphaComp( bits[2], alpha, blue );
                    bits[1] = AlphaComp( bits[1], alpha, green );
                    bits[0] = AlphaComp( bits[0], alpha, red );
                }
            }
        }
        /* blend with a background image */
        else if ( alpha_blend == 2 )
        {
            unsigned char *bg_bits;
            unsigned char *bg_bits_2;
            unsigned int bg_bytes_per_pixel;
            struct BMGImageStruct *bg = GetBackgroundImage();

            /* make sure we can blend with a background image
            // I assume that the background image is invalid if it does not
            // have a valid width */
            if ( bg->width <= 0 || bg->height <= 0 )
                longjmp( err_jmp, (int)errUndefinedBGImage );

            /* I cannot blend a foreground image with a background image that
            // is smaller than it */
            if ( bg->width < img.width || bg->height < img.height )
                longjmp( err_jmp, (int)errBGImageTooSmall );

            /* the background image was forced to be a 24 or 32-BPP image;
            // therefore, we can safely divide by 8 to determined the
            // bytes per pixel*/
            bg_bytes_per_pixel = bg->bits_per_pixel / 8;

            /* I will assume that the upper left corner of the input image
            // must be aligned with the upper left corner of the background
            // image.  This allows me to have background images that are bigger
            // than the input image. */
            bg_bits = bg->bits;
            for ( rbits = lpBits;
                  rbits < lpBits + img.height*DIBScanWidth;
                  rbits += DIBScanWidth, bg_bits += bg->scan_width )
            {
                bg_bits_2 = bg_bits;
                for ( bits = rbits; bits < rbits + DIBScanWidth;
                      bits += 4, bg_bits_2 += bg_bytes_per_pixel )
                {
                    alpha = bits[3];
                    bits[2] = AlphaComp( bits[2], alpha, bg_bits_2[2] );
                    bits[1] = AlphaComp( bits[1], alpha, bg_bits_2[1] );
                    bits[0] = AlphaComp( bits[0], alpha, bg_bits_2[0] );
                }
            }

        }
    }

    ReleaseDC( hWnd, hDC );

    return hBitmap;
}
Ejemplo n.º 8
0
int32 SProgressBar::OnPaint( const FPaintArgs& Args, const FGeometry& AllottedGeometry, const FSlateRect& MyClippingRect, FSlateWindowElementList& OutDrawElements, int32 LayerId, const FWidgetStyle& InWidgetStyle, bool bParentEnabled ) const
{
	// Used to track the layer ID we will return.
	int32 RetLayerId = LayerId;

	bool bEnabled = ShouldBeEnabled( bParentEnabled );
	const ESlateDrawEffect::Type DrawEffects = bEnabled ? ESlateDrawEffect::None : ESlateDrawEffect::DisabledEffect;
	
	const FSlateBrush* CurrentFillImage = GetFillImage();
	
	const FLinearColor FillColorAndOpacitySRGB(InWidgetStyle.GetColorAndOpacityTint() * FillColorAndOpacity.Get().GetColor(InWidgetStyle) * CurrentFillImage->GetTint(InWidgetStyle));
	const FLinearColor ColorAndOpacitySRGB = InWidgetStyle.GetColorAndOpacityTint();

	TOptional<float> ProgressFraction = Percent.Get();	

	// Paint inside the border only. 
	// Pre-snap the clipping rect to try and reduce common jitter, since the padding is typically only a single pixel.
	FSlateRect SnappedClippingRect = FSlateRect(FMath::RoundToInt(MyClippingRect.Left), FMath::RoundToInt(MyClippingRect.Top), FMath::RoundToInt(MyClippingRect.Right), FMath::RoundToInt(MyClippingRect.Bottom));
	const FSlateRect ForegroundClippingRect = SnappedClippingRect.InsetBy(FMargin(BorderPadding.Get().X, BorderPadding.Get().Y));
	
	const FSlateBrush* CurrentBackgroundImage = GetBackgroundImage();

	FSlateDrawElement::MakeBox(
		OutDrawElements,
		RetLayerId++,
		AllottedGeometry.ToPaintGeometry(),
		CurrentBackgroundImage,
		SnappedClippingRect,
		DrawEffects,
		InWidgetStyle.GetColorAndOpacityTint() * CurrentBackgroundImage->GetTint( InWidgetStyle )
	);	
	
	if( ProgressFraction.IsSet() )
	{
		const float ClampedFraction = FMath::Clamp(ProgressFraction.GetValue(), 0.0f, 1.0f);

		switch (BarFillType)
		{
			case EProgressBarFillType::RightToLeft:
			{
				FSlateRect ClippedAllotedGeometry = FSlateRect(AllottedGeometry.AbsolutePosition, AllottedGeometry.AbsolutePosition + AllottedGeometry.Size * AllottedGeometry.Scale);
				ClippedAllotedGeometry.Left = ClippedAllotedGeometry.Right - ClippedAllotedGeometry.GetSize().X * ClampedFraction;

				// Draw Fill
				FSlateDrawElement::MakeBox(
					OutDrawElements,
					RetLayerId++,
					AllottedGeometry.ToPaintGeometry(
						FVector2D::ZeroVector,
						FVector2D( AllottedGeometry.Size.X, AllottedGeometry.Size.Y )),
					CurrentFillImage,
					ForegroundClippingRect.IntersectionWith(ClippedAllotedGeometry),
					DrawEffects,
					FillColorAndOpacitySRGB
					);
				break;
			}
			case EProgressBarFillType::FillFromCenter:
			{
				// Draw Fill
				FSlateDrawElement::MakeBox(
					OutDrawElements,
					RetLayerId++,
					AllottedGeometry.ToPaintGeometry(
						FVector2D( (AllottedGeometry.Size.X * 0.5f) - ((AllottedGeometry.Size.X * ( ClampedFraction ))*0.5), 0.0f),
						FVector2D( AllottedGeometry.Size.X * ( ClampedFraction ) , AllottedGeometry.Size.Y )),
					CurrentFillImage,
					ForegroundClippingRect,
					DrawEffects,
					FillColorAndOpacitySRGB
					);
				break;
			}
			case EProgressBarFillType::TopToBottom:
			{
				FSlateRect ClippedAllotedGeometry = FSlateRect(AllottedGeometry.AbsolutePosition, AllottedGeometry.AbsolutePosition + AllottedGeometry.Size * AllottedGeometry.Scale);
				ClippedAllotedGeometry.Bottom = ClippedAllotedGeometry.Top + ClippedAllotedGeometry.GetSize().Y * ClampedFraction;

				// Draw Fill
				FSlateDrawElement::MakeBox(
					OutDrawElements,
					RetLayerId++,
					AllottedGeometry.ToPaintGeometry(
						FVector2D::ZeroVector,
						FVector2D( AllottedGeometry.Size.X, AllottedGeometry.Size.Y )),
					CurrentFillImage,
					ForegroundClippingRect.IntersectionWith(ClippedAllotedGeometry),
					DrawEffects,
					FillColorAndOpacitySRGB
					);
				break;
			}
			case EProgressBarFillType::BottomToTop:
			{
				FSlateRect ClippedAllotedGeometry = FSlateRect(AllottedGeometry.AbsolutePosition, AllottedGeometry.AbsolutePosition + AllottedGeometry.Size * AllottedGeometry.Scale);
				ClippedAllotedGeometry.Top = ClippedAllotedGeometry.Bottom - ClippedAllotedGeometry.GetSize().Y * ClampedFraction;

				// Draw Fill
				FSlateDrawElement::MakeBox(
					OutDrawElements,
					RetLayerId++,
					AllottedGeometry.ToPaintGeometry(
						FVector2D::ZeroVector,
						FVector2D( AllottedGeometry.Size.X, AllottedGeometry.Size.Y )),
					CurrentFillImage,
					ForegroundClippingRect.IntersectionWith(ClippedAllotedGeometry),
					DrawEffects,
					FillColorAndOpacitySRGB
					);
				break;
			}
			case EProgressBarFillType::LeftToRight:
			default:
			{
				FSlateRect ClippedAllotedGeometry = FSlateRect(AllottedGeometry.AbsolutePosition, AllottedGeometry.AbsolutePosition + AllottedGeometry.Size * AllottedGeometry.Scale);
				ClippedAllotedGeometry.Right = ClippedAllotedGeometry.Left + ClippedAllotedGeometry.GetSize().X * ClampedFraction;

				// Draw Fill
				FSlateDrawElement::MakeBox(
					OutDrawElements,
					RetLayerId++,
					AllottedGeometry.ToPaintGeometry(
						FVector2D::ZeroVector,
						FVector2D( AllottedGeometry.Size.X, AllottedGeometry.Size.Y )),
					CurrentFillImage,
					ForegroundClippingRect.IntersectionWith(ClippedAllotedGeometry),
					DrawEffects,
					FillColorAndOpacitySRGB
					);
				break;
			}
		}
	}
	else
	{
		const FSlateBrush* CurrentMarqueeImage = GetMarqueeImage();
		
		// Draw Marquee
		const float MarqueeAnimOffset = CurrentMarqueeImage->ImageSize.X * MarqueeOffset;
		const float MarqueeImageSize = CurrentMarqueeImage->ImageSize.X;

		FSlateDrawElement::MakeBox(
			OutDrawElements,
			RetLayerId++,
			AllottedGeometry.ToPaintGeometry(
				FVector2D( MarqueeAnimOffset - MarqueeImageSize, 0.0f ),
				FVector2D( AllottedGeometry.Size.X + MarqueeImageSize, AllottedGeometry.Size.Y )),
			CurrentMarqueeImage,
			ForegroundClippingRect,
			DrawEffects,
			ColorAndOpacitySRGB
			);

	}

	return RetLayerId - 1;
}
void CHandGestureRecognitionSystemDlg::OnClickedButtonRefreshBackground()
{
    // TODO: Add your control notification handler code here
    GetBackgroundImage();
}