logo

English

이곳의 프로그래밍관련 정보와 소스는 마음대로 활용하셔도 좋습니다. 다만 쓰시기 전에 통보 정도는 해주시는 것이 예의 일것 같습니다. 질문이나 오류 수정은 siseong@gmail.com 으로 주세요. 감사합니다.

[DirectShow] 화면 원본 비율유지

by digipine posted Oct 29, 2017
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print

비디오 화면 크기를 조정할 때 원본 비율을 유지하고 싶을 때가 많이 있습니다.
그럴때는 아래의 방법을 사용하시면 쉽게 해결 할 수 있습니다.
DirectShow (dsshowutil.h/cpp)에서 제공하는 원본 비율유지 구현 소스입니다.


///////////////////////////////////////////////////////////////////////
// Name: LetterBoxRect
// Desc: Find the largest rectangle that fits inside rcDest and has
//       the specified aspect ratio.
//
// aspectRatio: Desired aspect ratio
// rcDest:      Destination rectangle (defines the bounds)
// prcResult:   Pointer to a RECT struct. The method fills in the
//              struct with the letterboxed rectangle.
//
///////////////////////////////////////////////////////////////////////
HRESULT LetterBoxRect(const SIZE &aspectRatio, const RECT &rcDest, RECT *prcResult)
{
    if (prcResult == NULL)
    {
        return E_POINTER;
    }

    // Avoid divide by zero (even though MulDiv handles this)
    if (aspectRatio.cx == 0 || aspectRatio.cy == 0)
    {
        return E_INVALIDARG;
    }

    LONG width, height;

    LONG SrcWidth = aspectRatio.cx;
    LONG SrcHeight = aspectRatio.cy;
    LONG DestWidth = rcDest.right - rcDest.left;
    LONG DestHeight = rcDest.bottom - rcDest.top;


    if (MulDiv(SrcWidth, DestHeight, SrcHeight) <= DestWidth)
    {
        // src width / src height <= dest width / dest height
        // Letterbox along the sides. ("pillarbox")
        width = MulDiv(DestHeight, SrcWidth, SrcHeight);
        height = DestHeight;
    }
    else
    {
        // src width / src height > dest width / dest height
        // Letterbox along the top and bottom.
        width = DestWidth;
        height = MulDiv(DestWidth, SrcHeight, SrcWidth);
    }

    if (width == -1 || height == -1)
    {
        // MulDiv caught an overflow or divide by zero)
        return E_FAIL;
    }

    assert(width <= DestWidth);
    assert(height <= DestHeight);

    // Fill in the rectangle
    prcResult->left = rcDest.left + ((DestWidth - width) / 2);
    prcResult->right = prcResult->left + width;
    prcResult->top = rcDest.top + ((DestHeight - height) / 2);
    prcResult->bottom = prcResult->top + height;

    return S_OK;
}

TAG •

List of Articles
No. Subject Author Date Views
45 VS2005 ConvertBSTRToString 에서 LNK2019 에러 대처법 digipine 2017.10.29 192
44 VS2003 이상에서 iostream 구현의 문제점 digipine 2017.10.29 256
43 [C#] Convert char[] to string digipine 2017.10.29 301
42 VC++ 에서 대소문자 변경하는 함수 digipine 2017.10.29 311
41 MS의 Hot Fix API의 유형 연구 digipine 2017.10.29 312
40 [WINCE] 메모리카드 상태 감시 digipine 2017.10.29 327
39 Mutex, Critical Section Class 만들기 digipine 2017.10.29 392
38 CreateSemaphore Semaphore Manager digipine 2017.10.29 447
37 Serialize를 이용한 객체 복사하기 (Copy constructor) digipine 2017.10.29 499
36 RPC에 대하여... (3) : RPC 작동을 위한 테스트 방법 digipine 2017.10.29 543
35 [WINCE] IAT Hooking 방법과 소스 코드 digipine 2017.10.29 659
34 Windows API 멀티 쓰레드 구현법 digipine 2017.10.29 697
33 [WINCE] MulDiv 함수 구현 digipine 2017.10.29 702
32 [Win32] HBITMAP Contrast 조절하는 코드 - RGB 이미지 보정 엉뚱도마뱀 2018.05.04 738
31 RegEnumKeyEx 함수 사용법 digipine 2017.10.29 756
30 세마포어의 개념과 사용법 digipine 2017.10.29 765
29 [WINCE] 키보드 및 마우스 메시지 후킹하기 digipine 2017.10.29 809
28 DLL과 EXE간의 데이타 공유하기 digipine 2017.10.29 837
27 [MFC] Dialog에서 부모 윈도우 알아내기 digipine 2017.10.28 924
26 [WINCE] Process, Thread API 함수 사용법 digipine 2017.10.29 960
Board Pagination Prev 1 2 3 Next
/ 3