Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Carrier: None

Re: Camera Sample Code

Thanks for the link.  I will try the various modes and report back.  But I don't understand what half of those modes mean.

Sucroid.com
Sweet Apps for the Fans
Please use plain text.
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Carrier: None

Re: Camera Sample Code

Ok.  Tried all the transparent settings one by one.  Nothing worked.

 

One thing I forgot to say is that the content of the viewfinder simply overrides the overlay window.  In other words, when one should expect a green transparent layer on top of the viewfinder, the viewfinder is crystal clear as if there is nothing on top.  HOWEVER, when I minimize the app and press close (the little X), the green overlay appears for a brief moment until the window disappears from the home screen.

 

So it seems that the viewfinder content is not blending with the overaly window.

Sucroid.com
Sweet Apps for the Fans
Please use plain text.
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Carrier: None

Re: Camera Sample Code

Finally got what I wanted. The solution has to do with the zorder value of the viewfinder window as well as the transparency property of the overlay window.

 

Here is the snippet in main of the NativeCamera sample:

 

int prop = SCREEN_TRANSPARENCY_SOURCE_COLOR;

    screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_TRANSPARENCY, &prop);

 

    // fill the window with black

    int attribs[] = { SCREEN_BLIT_COLOR, 0x00FF00, SCREEN_BLIT_GLOBAL_ALPHA, 150,

     SCREEN_BLIT_END };

    screen_fill(screen_ctx, screen_buf, attribs);

 

For this to work, the zorder of the viewfinder window has to be NEGATIVE.  In the sample code, the main window is given zorder 100 and viewfinder window 101.  Making the zorder of the viewfinder window to 99 does not work.  But making it -1 or anything more negative works.

Sucroid.com
Sweet Apps for the Fans
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 651
Registered: ‎11-29-2011
My Carrier: other

Re: Camera Sample Code

Can you query SCREEN_PROPERTY_ZORDER from both windows to confirm the ordering?

I used the following code in my face-detect demo at BB Jam in May:

 

    // create a window to display in front of this one
    screen_create_window_type(&over_win, screen_ctx, SCREEN_CHILD_WINDOW);
    screen_join_window_group(over_win, "CameraWindowGroup");
    screen_create_window_buffers(over_win, 1);
    screen_get_window_property_pv(over_win, SCREEN_PROPERTY_RENDER_BUFFERS,
                                  (void**)&over_buf);
    screen_get_window_property_iv(over_win, SCREEN_PROPERTY_BUFFER_SIZE,
                                  &rect[2]);
    i = +2;  // place overlay in front of viewfinder
    screen_set_window_property_iv(over_win, SCREEN_PROPERTY_ZORDER, &i);
    i = SCREEN_TRANSPARENCY_SOURCE_OVER;
    screen_set_window_property_iv(over_win, SCREEN_PROPERTY_TRANSPARENCY, &i);
    fprintf(stderr,"overlay window: %d x %d\n", rect[2], rect[3]);
    int attribs[] = {SCREEN_BLIT_COLOR, 0, SCREEN_BLIT_END};
    screen_fill(screen_ctx, over_buf, attribs);
    screen_post_window(over_win, over_buf, 1, rect, 0);

Then when I wanted to draw a box on this overlay window, I was using:

 

    int attribs[] = { SCREEN_BLIT_DESTINATION_X, x,
                      SCREEN_BLIT_DESTINATION_Y, y,
                      SCREEN_BLIT_DESTINATION_WIDTH, w,
                      SCREEN_BLIT_DESTINATION_HEIGHT, h,
                      SCREEN_BLIT_COLOR, 0xff4040ff,
                      SCREEN_BLIT_END };
    screen_fill(screen_ctx, over_buf, attribs);
    screen_post_window(over_win, over_buf, 1, rect, 0);

 

Maybe this will help you out.  I'd have to go fiddle with NativeCamera when I find some spare late-night time, in order to find the appropriate solution.   I would suggest you simplify and just write an app that creates 2 windows of different colours and transparencies just to make sure you've got that part right.

 

Cheers,

Sean

Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 651
Registered: ‎11-29-2011
My Carrier: other

Re: Camera Sample Code

Okay.  Maybe I have misunderstood how ZORDER works now.  It's entirely possible that child window ZORDER is taken to be relative to the parent window.  This is something I will ask the screen guys.

 

Cheers,

Sean

Please use plain text.
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Carrier: None

Re: Camera Sample Code

What is the behaviour of SCREEN_TRANSPARENCY_SOURCE_OVER?
Sucroid.com
Sweet Apps for the Fans
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 651
Registered: ‎11-29-2011
My Carrier: other

Re: Camera Sample Code

Here is what I managed to dig up:

 

SCREEN_TRANSPARENCY_SOURCE
Specifies that the destination pixels are replaced by source pixels, including the alpha channel.
SCREEN_TRANSPARENCY_TEST
Specifies that the destination pixels are replaced by source pixels when the alpha channel is greater than 0.
SCREEN_TRANSPARENCY_SOURCE_COLOR
Specifies that the destination pixels are replaced by source pixels when the color does not match a display-defined value.
SCREEN_TRANSPARENCY_SOURCE_OVER
Specifies alpha blending; the source pixels are blended over the destination pixels.
SCREEN_TRANSPARENCY_NONE
Specifies that the destination pixels are replaced by fully-visible source pixels.
SCREEN_TRANSPARENCY_DISCARD
Specifies that the source is considered completely transparent; the destination is not modified.
Please use plain text.
Trusted Contributor
sucroid
Posts: 195
Registered: ‎03-12-2012
My Carrier: None

Re: Camera Sample Code

Thanks for the descriptions.

It's kind of strange that on my test, the effects of SCREEN_TRANSPARENCY_SOURCE_COLOR and SCREEN_TRANSPARENCY_SOURCE_OVER seem to be reversed.
Sucroid.com
Sweet Apps for the Fans
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 651
Registered: ‎11-29-2011
My Carrier: other

Re: Camera Sample Code

To answer the earlier ZORDER question... I got confirmation that child window ZORDER is relative to the parent ZORDER, and not absolute.

 

So >0 means in front of parent and <0 means behind.

 

I will have to update the sample to reflect this :smileyhappy:

Please use plain text.
Developer
smiley
Posts: 1,360
Registered: ‎07-14-2008
My Carrier: Fido

Re: Camera Sample Code

HI

 

downloaded the native camera example and it compiled ok but when I tried to run it on the PB device it got this error:

 

Deployment Failed: Info: Sending request: Install and Launch
Info: Action: Install and Launch
Info: Debug native: on
Info: File size: 38405
Info: Installing com.example.NativeCamera.testDev_ativeCamerad5e7228d...
Info: Processing 38405 bytes

 

what is the problem?

Please use plain text.