summaryrefslogtreecommitdiff
path: root/avstream/avscamera/sys/NV12Synthesizer.h
blob: 1ef2f3e795955a849a702901820466a2c39b28b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**************************************************************************

    A/V Stream Camera Sample

    Copyright (c) 2001, Microsoft Corporation.

    File:

        CNV12Synthesizer.h

    Abstract:

        This file defines a class that implements NV12 image synthesis.
        
        CNV12Synthesis is derived from CYUVSynthesis.  It uses the YUV color
        space and defines a Commit() function that reformats pixels into the 
        NV12 format.  From MSDN:

            A format in which all Y samples are found first in memory as an 
            array of unsigned char with an even number of lines (possibly with 
            a larger stride for memory alignment). This is followed immediately 
            by an array of unsigned char containing interleaved Cb and Cr 
            samples. If these samples are addressed as a little-endian WORD 
            type, Cb would be in the least significant bits and Cr would be in 
            the most significant bits with the same total stride as the Y 
            samples. NV12 is the preferred 4:2:0 pixel format.

        A visual representation of the layout:
            YYYY
            YYYY
            UVUV


    History:
        created 4/16/2013

**************************************************************************/

#pragma once

class CNV12Synthesizer :
    public CYUVSynthesizer
{
public:
    //
    // DEFAULT CONSTRUCTOR
    //
    CNV12Synthesizer (
        ULONG Width=0,
        ULONG Height=0
    ) :
        CYUVSynthesizer("NV12", Width, Height)
    {
        NT_ASSERT( ( Width % 2 ) == 0 );
        NT_ASSERT( ( Height % 2 ) == 0 );
        m_OutputStride = Width * sizeof(BYTE);
    }

    //
    //  Commit
    //
    //  Copy (and reformat, if necessary) pixels from the internal scratch
    //  buffer.  If the output format decimates chrominance, do it here.
    //
    virtual
    _Success_(return > 0)
    ULONG
    Commit(
        _Out_writes_bytes_(Size)
        PUCHAR  Buffer,
        _In_    ULONG   Size,
        _In_    ULONG   Stride
    );
};