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 [C#] UI Update from Thread, Thread에서 UI 업데이트 하기 샘플 코드 lizard2019 2019.01.23 1041
44 [C#] 프로그램 종료 방법 lizard2019 2019.01.23 6789
43 [C#] 코드 실행 시간 측정 및 DateTime 스트링으로 변환 포맷 lizard2019 2019.01.23 23018
42 [Win32] HBITMAP Contrast 조절하는 코드 - RGB 이미지 보정 엉뚱도마뱀 2018.05.04 737
41 [Windows] DOS 명령어 실행하고 결과 스트링 가져오는 샘플 코드 digipine 2017.11.02 2689
40 VC++ UTF8 변환 관련 매크로 digipine 2017.11.02 8779
39 C# 으로 구현한 화면 캡춰 클래스 1 digipine 2017.11.02 33970
38 C# - 한글로된 폰트명 처리 방법 개선 (Font Name Localization) digipine 2017.11.02 1392
37 [C#] StreamReader 에서의 한글 Encoding 문제 digipine 2017.10.29 1000
36 [API Hooking] Dll Injection 하는 방법 digipine 2017.10.29 5226
35 [WIN32] 파일 핸들로 파일 명 구하기 digipine 2017.10.29 1066
34 [WIN32] Process ID로 HWND 구하기 digipine 2017.10.29 5019
33 MS의 Hot Fix API의 유형 연구 digipine 2017.10.29 312
32 [WIN32] 실행 중인 프로세스를 외부에서 강제로 종료, 안전한 TerminateProcess digipine 2017.10.29 3460
31 [WIN32] API Hook 정리 문서 digipine 2017.10.29 1970
30 [WIN32, WINCE] 디스크 용량 구하는 방법 API GetDiskFreeSpaceEx digipine 2017.10.29 1569
29 [WINCE] MulDiv 함수 구현 digipine 2017.10.29 699
» [DirectShow] 화면 원본 비율유지 digipine 2017.10.29 960
27 [VC++, WInAPI] 폴더를 통채로 지우기, 서브 폴더 포함, DeleteAllFiles digipine 2017.10.29 1763
26 [Win API]프로세스 아이디와 윈도우 핸들을 이용 파일명 구하기 digipine 2017.10.29 1393
Board Pagination Prev 1 2 3 Next
/ 3