49 #include <QuickTime/QuickTimeStreaming.h>
68 m_sComponentName =
"";
71 m_sComponentName += pComponentName;
73 m_bImagePending =
false;
107 srcRect.right = width - 1;
109 srcRect.bottom = height - 1;
112 Handle grabberName = NewHandle(0);
113 Handle info = NewHandle(0);
114 ComponentDescription desc;
116 desc.componentType = SeqGrabComponentType;
117 desc.componentSubType = 0;
118 desc.componentManufacturer = 0;
119 desc.componentFlags = 0;
120 desc.componentFlagsMask = 0;
124 while (comp = FindNextComponent(comp, &desc))
126 if (GetComponentInfo(comp, &desc, grabberName, info, 0) != noErr)
128 printf(
"error: could not get info on component id = %i\n", comp);
132 printf(
"grabber: '%s'\n", *grabberName + 1);
134 if (m_sComponentName.length() == 0 || strcmp(m_sComponentName.c_str(), *grabberName + 1) == 0)
143 printf(
"error: could not find a sequence grabber named '%s'\n", m_sComponentName.c_str());
148 grabber = OpenComponent(comp);
152 printf(
"error: could not open sequence grabber\n");
156 if (SGInitialize(grabber) != noErr)
158 printf(
"errror: could not initialize the sequence grabber\n");
162 if (SGSetDataRef(grabber, 0, 0, seqGrabDontMakeMovie) != noErr)
164 printf(
"error: could not set data reference on sequence grabber\n");
168 if (QTNewGWorld(&gWorld, k24RGBPixelFormat, &srcRect, 0, 0, 0) != noErr)
170 printf(
"error: could not create new gworld\n");
174 if (!LockPixels(GetPortPixMap(gWorld)))
176 printf(
"error: could not lock pixels in new gworld\n");
180 if (SGSetGWorld(grabber, gWorld, 0) != noErr)
182 printf(
"error: could not set gworld\n");
187 if (SGNewChannel(grabber, VideoMediaType, &videoChannel) != noErr || !videoChannel)
189 printf(
"error: could not open video channel\n");
193 if (SGSetChannelUsage(videoChannel, seqGrabRecord) != noErr)
195 printf(
"error: could not set channel usage to 'record'\n");
199 if (SGSetChannelBounds(videoChannel, &srcRect) != noErr)
201 printf(
"error: could not set channel bounds to %ix%i\n", width, height);
205 if (SGSetDataProc(grabber, NewSGDataUPP(sDataProc), (
long)
this) != noErr)
207 printf(
"error: could not set data proc\n");
211 SGStartRecord(grabber);
224 SGDisposeChannel(grabber, videoChannel);
230 DisposeGWorld(gWorld);
237 m_bImagePending =
false;
249 while (!m_bImagePending)
252 ImageSequence image_sequence;
254 if (DecompressSequenceBegin(&image_sequence, imgDesc, gWorld, 0, &srcRect, 0, srcCopy, 0, 0, codecNormalQuality, bestSpeedCodec) != noErr)
256 printf(
"error: could not begin decompression\n");
262 DecompressSequenceFrameS(image_sequence, m_pBuffer, m_lImageLength, 0, &ignore, NULL);
264 const int nBytes = 3 * pImage->
width * pImage->
height;
265 const unsigned char *input = (
unsigned char *) GetPixBaseAddr(GetGWorldPixMap(gWorld));
266 unsigned char *output = pImage->
pixels;
267 for (
int i = 0, offset = 0; i < nBytes; i += 3, offset += 4)
269 output[i] = input[offset + 1];
270 output[i + 1] = input[offset + 2];
271 output[i + 2] = input[offset + 3];
274 CDSequenceEnd(image_sequence);
276 m_bImagePending =
false;
281 pascal OSErr CQuicktimeCapture::sDataProc(SGChannel channel, Ptr p,
long length,
long *offset,
long chRefCon, TimeValue time,
short writeType,
long refcon)
286 OSErr CQuicktimeCapture::dataProc(SGChannel channel, Ptr p,
long length)
290 imgDesc = (ImageDescriptionHandle) NewHandle(0);
291 SGGetChannelSampleDescription(videoChannel, (Handle) imgDesc);
295 m_lImageLength = length;
296 m_bImagePending =
true;
ImageType type
The type of the image.
int width
The width of the image in pixels.
int height
The height of the image in pixels.
CQuicktimeCapture(VideoMode mode, const char *pComponentName=0)
unsigned char * pixels
The pointer to the the pixels.
bool CaptureImage(CByteImage **ppImages)
Data structure for the representation of 8-bit grayscale images and 24-bit RGB (or HSV) color images ...