vid_get_viewport_fb() to screen - General Discussion and Assistance - CHDK Forum

vid_get_viewport_fb() to screen

  • 6 Replies
  • 4948 Views
*

gergilar

vid_get_viewport_fb() to screen
« on: 31 / December / 2007, 07:25:15 »
Advertisements
My goal is to flip what comes from the lenses and see it flipped in the screen (on the fly). 
I'm trying to get the viewport flipped on the screen.
I want to contribute solving myself the request related to my post - CHDK forum > CHDK Development > Feature Requests > Using old lenses, but I'm not a software developer, just amateur (newbie  :D), so any help will be wellcome.
I made some tests and is seems to be working. I can see something that is the flipped image, and that's what i need, but i don't know why the image is not correctly displayed...
It shows lots of dots in different colors, I can figure that the image is there and it's correctly flipped (when moving the camera it moves opposite), but is not the clean image that you can normally see in the screen.
I could not figure how to make the vid_get_viewport_fb() show correctly in the screen, how to get a complete pixel from vid_get_viewport_fb().
In the code from others, there is some 3 multiplying (color rgb / yuv) that i don't know where comes from or how to use it.
Sorry for being annoying (again i'm really newbie), but after some days of testing, i think that is better to ask the experts!.
Best wishes and a happy new year!.  :xmas
Part of my dirty and copied code is:
Code: [Select]
   if (!buf) {
       buf = malloc(screen_size);
       scr_buf = vid_get_bitmap_fb();
       }
   if (buf) {
               inv_buf=vid_get_viewport_fb();
               vp_h=vid_get_viewport_height();
               vp_w=screen_width;
               for (s=0, v=vp_h*vp_w*3; s<screen_size; ++s, v-=3) {
                       inverso_pixel=inv_buf[v];
                       buf[s]=inverso_pixel;
               }
               memcpy(scr_buf, buf, screen_size);
               memcpy(scr_buf+screen_size, buf, screen_size);
   }

*

Offline GrAnd

  • ****
  • 916
  • [A610, S3IS]
    • CHDK
Re: vid_get_viewport_fb() to screen
« Reply #1 on: 01 / January / 2008, 04:17:54 »
This buffer uses the following pixel encoding: UYVYYY. So, the problem is in the incorrect copying.
You have to copy 6 bytes as a chunk. Like this: the first chunk U_Y1_V_Y2_Y3_Y4 to the last U_Y4_V_Y3_Y2_Y1.

And, do not forget that the horizontal resolution of this buffer is 720, not 360.
« Last Edit: 01 / January / 2008, 04:22:59 by GrAnd »
CHDK Developer.

*

gergilar

Re: vid_get_viewport_fb() to screen
« Reply #2 on: 01 / January / 2008, 10:42:53 »
thanks GrAnd.
Your work in CHDK is amazing!.
Can you help me a little bit more with one example code line? i don't know how to copy 6 bytes as a chunk.
Tanks a lot and happy new year!.

*

Offline GrAnd

  • ****
  • 916
  • [A610, S3IS]
    • CHDK
Re: vid_get_viewport_fb() to screen
« Reply #3 on: 01 / January / 2008, 13:05:13 »
Something like this:
Code: [Select]
       int viewport_size = vid_get_viewport_height() * screen_width;
       char *inv_buf=vid_get_viewport_fb();

       for (s=0, v=viewport_size*3-6; s<viewport_size*3-6; s+=6, v-=6) {
                       buf[s  ]=inv_buf[v  ]; //U  -> U
                       buf[s+1]=inv_buf[v+5]; //Y4 -> Y1
                       buf[s+2]=inv_buf[v+2]; //V  -> V
                       buf[s+3]=inv_buf[v+4]; //Y3 -> Y2
                       buf[s+4]=inv_buf[v+3]; //Y2 -> Y3
                       buf[s+5]=inv_buf[v+1]; //Y1 -> Y4
       }

       memcpy(inv_buf, buf, viewport_size*3);
   }


But! You can't copy viewport buffer to screen buffer and vice versa. These buffers have incompatible formats: UYVYYY for viewport and palette-based for bitmap (screen) buffer. If you want to change the input picture you should copy new picture back to viewport buffer. I'm not sure if it's possible to do it in runtime. I think you will see flicking image (yours and original).
« Last Edit: 01 / January / 2008, 13:06:44 by GrAnd »
CHDK Developer.


*

gergilar

Re: vid_get_viewport_fb() to screen
« Reply #4 on: 01 / January / 2008, 19:24:47 »
ok, understand.
Lets see what can i do...
Thanks a lot from Uruguay, South America.
Regards and have a happy new year!

*

gergilar

Re: vid_get_viewport_fb() to screen
« Reply #5 on: 02 / January / 2008, 09:38:21 »
As you said, it's not working.
But the camera hangs with the code you send, or with this new (copied down) that i've written trying to copy the inverse image from viewport to viewport.
I did test this in different ways, using other buffer, using the same buffer and allways the camera freezes and i've to open batteries door to restart.
Can you check if i'm doing something wrong in this piece of code or it's just because it's not possible to copy to the viewport?
Sorry for being annoying, and tell me if this is an excess ???. As i said i'm a newbie :blink:.
Thanks.

Code: [Select]
unsigned int v, s;
        int viewport_size = vid_get_viewport_height() * screen_width;
        char *inv_buf = NULL;
        char *otro_buf = NULL;
img_buf=vid_get_viewport_fb();
memcpy(inv_buf, img_buf, viewport_size);
for (s=0, v=viewport_size; s<viewport_size; ++s, --v) {
otro_buf[s]=inv_buf[v];
        }
memcpy(img_buf, otro_buf, viewport_size);
return 1;

*

Offline GrAnd

  • ****
  • 916
  • [A610, S3IS]
    • CHDK
Re: vid_get_viewport_fb() to screen
« Reply #6 on: 02 / January / 2008, 16:38:37 »
1) In chars, size of yhr duffer is "viewport_size*3"
2) I do not see any malloc() in your piece of code. Did you allocate a memory or these pointers are NULL?
3) Do not forget that a camera do not have a lot of free memory for huge buffers.
CHDK Developer.

 

Related Topics


SimplePortal 2.3.6 © 2008-2014, SimplePortal