i
i
i
i
i
i
i
i
16.7. Making a Stereo Movie from Image Sequences 473
declaration of a member variable of type CPushPinOnBSF
*
which is used
to store a pointer to the filter’s output pin. Most of the work of the filter
takes place in the output pin object. This has to provide functions to tell
the downstream filters what type of media they can expect (in our case it is
24-bit RGB bitmaps) and how big the connecting buffer (between filters) has
to be. Most importantly, it must have a method to ll the output buffer with the
bitmap pixels from the image sequence and provide correct timing information.
Listing 16.20 shows the structure of the two classes that encapsulate the
filter’s behavior. Listing 16.21 provides an overview of the class methods.
Listing 16.22 details the class method which pushes the bitmap image pix els
into the downstream filters.
For the overridden methods in the
CPushPinOnBSF class, some brief
comments are warranted:
CPushPinOnBSF::GetMediaType(). This method reports back on
the format of the samples being fed out of the filter. In this context, a
sample is a video frame. We want the samples to match the format of
the input bitmaps (from the file sequences), so we must have a bitmap
loaded before this method can execute. Since it is called only once,
as the graph starts executing, we load the first bitmap in the classs
constructor m ethod.
CPushPinOnBSF::DecideBufferSize(). This method reports how
big the output sample buffer needs to be. For a video source filter,
the output sample buffer will need to hold the pixel image. So for a
24-bitRGBpixelformat,thisfunctionmustreportbackthatitneeds
w × h × 3 bytes, where w and h are the width and height of the input
bitmaps. (We are going to assume that all the bitmaps have the same
width and height.)
CPushPinOnBSF::FillBuffer(). This method does most of the work.
It has two primary duties:
1. To copy the image data from the left and right bitmaps into the
pins output buffer. It first copies the left image and then the
right. Our program will assume that the bitmaps width must
be a power of two, and we are going to use left-over-right stereo
format. Consequently, these copies can be done as a block.
2. To inform the filter what the reference time of the frame is. The
reference time embedded in the AVI file allows a player to syn-
i
i
i
i
i
i
i
i
474 16. Programming Stereopsis
// This is where we insert the bitmaps into the video stream.
// FillBuffer is called once for every sample in the stream.
//
HRESULT CPushPinOnBSF::FillBuffer(IMediaSample
*
pSample){
BYTE
*
pData;
long cbData;
// this tells the filter to STOP (we have all frames)
if(m_iFrameNumber== m_dFrames)return E_FAIL;
// first pair loaded in class constructor
if(m_iFrameNumber > 0)LoadNextBitmap();
if(!m_bFilesLoaded)return E_FAIL;
CheckPointer(pSample, E_POINTER);
// to make sure no-other filter messes with our data
CAutoLock cAutoLockShared(&m_cSharedState);
// Access the output pin’s data buffer
pSample->GetPointer(&pData);
cbData = pSample->GetSize(); // how many bytes to copy
//
// Copy the pixel data from the bitmaps into the pins’ output buffer - for
memcpy(pData, m_pImage2,cbData); // left image data
pData += (DWORD)cbData;
memcpy(pData, m_pImage1,cbData); // right image data
// calcuate the time in the movie at which this frame should appear
REFERENCE_TIME rtStart = m_iFrameNumber
*
m_rtDelta;
REFERENCE_TIME rtStop = rtStart + m_rtDelta;
// set the time stamp of this frame
pSample->SetTime(&rtStart, &rtStop);
// one more frame added
m_iFrameNumber++;
// to make sure we get all the frames
pSample->SetSyncPoint(TRUE);
return S_OK;
}
Listing 16.22. Pushing the bitmap pixeldata into the AVI data stream for further fil-
tering, compressing and ultimately archiving to disk.
chronize the movie with a real-time clock, dropping frames if
necessary. We must also ensure that the FilterGraph will not
ignore samples if we cannot read the bitmaps fast enough to
keep up in real time. This is done by calling the method
pSample->SetSyncPoint(TRUE).
When all the elements are brought together, the program will create stereo
movies from pairs of bitmap image files and write them into an AVI file using
any installed compression codec.
i
i
i
i
i
i
i
i
16.8. Summary 475
16.8 Summary
In this chapter, we have looked at the design and coding of a few Windows
application programs for stereopsis. There are many other stereoscopic appli-
cations we could have considered. For example, we could add a soundtrack
to the stereo movie or make a stereoscopic webcam [1]. Nevertheless, the
programs we have explored here cover a significant range of components that,
if assembled in other ways, should cover a lot of what one might want to do
for one’s own VR system.
Please do not forget that in the printed listings throughout this chap-
ter, we have omitted statements (such as error checking) which, while vitally
important, might have obfuscated the key structures we wanted to highlight.
Bibliography
[1] K. McMenemy and S. Ferguson. Real-Time Stereoscopic Video Streaming. Dr.
Dobbs Journal 382 (2006) 18–22.
[2] T. Riemersma. The FLIC File Format”. http://www.compuphase.com/flic.
htm, 2006.
[3] StereoGraphics Corporation. Stereo3D Hardware Developer’s Handbook ”.
http://www.reald-corporate.com/scientific/developer
tools.asp, 2001.
[4] J. Siragusa et al. “General Purpose Stereoscopic Data Descriptor”. http://www.
vrex.com/developer/sterdesc.pdf, 1997.
i
i
i
i
i
i
i
i
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.160.66