Changeset 704:ca4d7f83b4c0 in mediastreamer2


Ignore:
Timestamp:
Oct 2, 2009 5:02:24 PM (4 years ago)
Author:
aymeric <aymeric@…>
Branch:
default
Message:

fix windows display to keep ratio and fill with black.

git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@692 3f6dc0c8-ddfe-455d-9043-3cd528dc4637

File:
1 edited

Legend:

Unmodified
Added
Removed
  • linphone/mediastreamer2/src/videoout.c

    r683 r704  
    255255        MSDisplayEvent last_rsz; 
    256256        uint8_t *rgb; 
     257        uint8_t *black; 
     258        int last_rect_w; 
     259        int last_rect_h; 
    257260        int rgb_len; 
    258261        struct SwsContext *sws; 
     
    347350                wd->fb.planes[3]=NULL; 
    348351                if (wd->rgb) ms_free(wd->rgb); 
     352                if (wd->black) ms_free(wd->black); 
    349353                wd->rgb=NULL; 
     354                wd->black=NULL; 
    350355                wd->rgb_len=0; 
    351356                sws_freeContext(wd->sws); 
    352357                wd->sws=NULL; 
     358                wd->last_rect_w=0; 
     359                wd->last_rect_h=0; 
    353360        } 
    354361        else 
     
    390397        if (wd->fb.planes[0]) ms_free(wd->fb.planes[0]); 
    391398        if (wd->rgb) ms_free(wd->rgb); 
     399        if (wd->black) ms_free(wd->black); 
    392400        ysize=wd->fb.w*wd->fb.h; 
    393401        usize=ysize/4; 
     
    403411        wd->rgb_len=ysize*3; 
    404412        wd->rgb=(uint8_t*)ms_malloc0(wd->rgb_len); 
     413        wd->black = (uint8_t*)ms_malloc0(wd->rgb_len); 
     414        wd->last_rect_w=0; 
     415        wd->last_rect_h=0; 
    405416        return TRUE; 
    406417} 
     
    430441                ms_error("Error in 420->rgb sws_scale()."); 
    431442        } 
     443} 
     444 
     445int gcd(int m, int n) 
     446{ 
     447   if(n == 0) 
     448     return m; 
     449   else 
     450     return gcd(n, m % n); 
     451} 
     452    
     453void reduce(int *num, int *denom) 
     454{ 
     455   int divisor = gcd(*num, *denom); 
     456   *num /= divisor; 
     457   *denom /= divisor; 
    432458} 
    433459 
     
    448474        bi.biSize=sizeof(bi); 
    449475        GetClientRect(wd->window,&rect); 
    450         /* 
    451         bi.biWidth=wd->fb.w; 
    452         bi.biHeight=wd->fb.h; 
    453         bi.biPlanes=3; 
    454         bi.biBitCount=12; 
    455         bi.biCompression=MAKEFOURCC('I','4','2','0'); 
    456         bi.biSizeImage=(wd->fb.w*wd->fb.h*3)/2; 
    457         */ 
     476 
    458477        bi.biWidth=wd->fb.w; 
    459478        bi.biHeight=wd->fb.h; 
     
    463482        bi.biSizeImage=wd->rgb_len; 
    464483 
    465         //if (bi.biHeight>rect.bottom) 
    466         //      bi.biHeight=rect.bottom; 
    467         //bi.biSizeImage=(bi.biWidth*bi.biHeight)*3; 
    468  
    469         ret=DrawDibDraw(wd->ddh,hdc,0,0, 
    470                 //bi.biWidth,bi.biHeight, 
    471                 rect.right,rect.bottom, 
     484        if (wd->last_rect_w!=rect.right || wd->last_rect_h!=rect.bottom) 
     485        { 
     486                ret=DrawDibDraw(wd->ddh,hdc,00,00, 
     487                        rect.right,rect.bottom, 
     488                        &bi,wd->black, 
     489                        0,0,bi.biWidth,bi.biHeight,0); 
     490                wd->last_rect_w=rect.right; 
     491                wd->last_rect_h=rect.bottom; 
     492        } 
     493 
     494        int ratiow=wd->fb.w; 
     495        int ratioh=wd->fb.h; 
     496        reduce(&ratiow, &ratioh); 
     497        int w = rect.right/ratiow*ratiow; 
     498        int h = rect.bottom/ratioh*ratioh; 
     499 
     500        if (h*ratiow>w*ratioh) 
     501        { 
     502                w = w; 
     503                h = w*ratioh/ratiow; 
     504        } 
     505        else 
     506        { 
     507                h = h; 
     508                w = h*ratiow/ratioh; 
     509        } 
     510 
     511        if (h*wd->fb.w!=w*wd->fb.h) 
     512                ms_error("wrong ratio"); 
     513 
     514        ret=DrawDibDraw(wd->ddh,hdc, 
     515                rect.right/2-(w/2), 
     516                rect.bottom/2-(h/2), 
     517                w, 
     518                h, 
    472519                &bi,wd->rgb, 
    473                 //0,0,rect.right,rect.bottom,0); 
    474520                0,0,bi.biWidth,bi.biHeight,0); 
     521 
    475522         
    476523        if (!ret) ms_error("DrawDibDraw failed."); 
     
    486533        if (wd->fb.planes[0]) ms_free(wd->fb.planes[0]); 
    487534        if (wd->rgb) ms_free(wd->rgb); 
     535        if (wd->black) ms_free(wd->black); 
    488536        if (wd->sws) sws_freeContext(wd->sws); 
    489537        ms_free(wd); 
Note: See TracChangeset for help on using the changeset viewer.