forked from cellularmitosis/ADC-reference-library-2009-july
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisting6.html
More file actions
executable file
·695 lines (593 loc) · 29.7 KB
/
Copy pathlisting6.html
File metadata and controls
executable file
·695 lines (593 loc) · 29.7 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>ExampleIPBCodec - /ExampleIPBDecompressor.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/QuickTime/index.html">QuickTime</a> > <a href="../../samplecode/QuickTime/idxCompressionDecompression-date.html">Compression & Decompression</a> > <A HREF="javascript:location.replace('index.html');">ExampleIPBCodec</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">ExampleIPBCodec</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/ExampleIPBDecompressor.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/ExampleIPBCodec.r</option>
<option value="listing2.html">/ExampleIPBCodecUniversal.r</option>
<option value="listing3.html">/ExampleIPBCodecVersion.h</option>
<option value="listing4.html">/ExampleIPBCompressor.c</option>
<option value="listing5.html">/ExampleIPBCompressorDispatch.h</option>
<option value="listing6.html">/ExampleIPBDecompressor.c</option>
<option value="listing7.html">/ExampleIPBDecompressorDispatch.h</option>
<option value="listing8.html">/NaiveDecoder.c</option>
<option value="listing9.html">/NaiveDecoder.h</option>
<option value="listing10.html">/NaiveEncoder.c</option>
<option value="listing11.html">/NaiveEncoder.h</option>
<option value="listing12.html">/NaiveFormat.c</option>
<option value="listing13.html">/NaiveFormat.h</option>
<option value="listing14.html">/PixelUtilities.c</option>
<option value="listing15.html">/PixelUtilities.h</option>
<option value="listing16.html">/ReadMe-ExampleIPBCodec.txt</option></select>
</p>
</form>
<p><strong><a href="ExampleIPBCodec.zip">Download Sample</a></strong> (“ExampleIPBCodec.zip”, 81.3K)<BR>
<strong><a href="ExampleIPBCodec.dmg">Download Sample</a></strong> (“ExampleIPBCodec.dmg”, 128.2K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/*
File: ExampleIPBDecompressor.c, part of ExampleIPBCodec
Abstract: Example Image Decompressor component supporting IPB frame patterns under QuickTime 7.
Version: 1.0
© Copyright 2005 Apple Computer, Inc. All rights reserved.
IMPORTANT: This Apple software is supplied to
you by Apple Computer, Inc. ("Apple") in
consideration of your agreement to the following
terms, and your use, installation, modification
or redistribution of this Apple software
constitutes acceptance of these terms. If you do
not agree with these terms, please do not use,
install, modify or redistribute this Apple
software.
In consideration of your agreement to abide by
the following terms, and subject to these terms,
Apple grants you a personal, non-exclusive
license, under Apple's copyrights in this
original Apple software (the "Apple Software"),
to use, reproduce, modify and redistribute the
Apple Software, with or without modifications, in
source and/or binary forms; provided that if you
redistribute the Apple Software in its entirety
and without modifications, you must retain this
notice and the following text and disclaimers in
all such redistributions of the Apple Software.
Neither the name, trademarks, service marks or
logos of Apple Computer, Inc. may be used to
endorse or promote products derived from the
Apple Software without specific prior written
permission from Apple. Except as expressly
stated in this notice, no other rights or
licenses, express or implied, are granted by
Apple herein, including but not limited to any
patent rights that may be infringed by your
derivative works or by other works in which the
Apple Software may be incorporated.
The Apple Software is provided by Apple on an "AS
IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR
IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING
THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE
OR IN COMBINATION WITH YOUR PRODUCTS.
IN NO EVENT SHALL APPLE BE LIABLE FOR ANY
SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF
THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER
UNDER THEORY OF CONTRACT, TORT (INCLUDING
NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN
IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
*/
#if __APPLE_CC__
#include <QuickTime/QuickTime.h>
#else
#include <ConditionalMacros.h>
#include <Endian.h>
#include <ImageCodec.h>
#endif
#include "ExampleIPBCodecVersion.h"
#include "NaiveDecoder.h"
// Data structures
typedef struct {
ComponentInstance self;
ComponentInstance delegateComponent;
ComponentInstance target;
long width;
long height;
struct InternalPixelBuffer storedFrameArray[kMaxStoredFrames];
struct InternalPixelBuffer immediateFrame;
Handle wantedDestinationPixelTypes;
} ExampleIPBDecompressorGlobalsRecord, *ExampleIPBDecompressorGlobals;
typedef struct {
long width;
long height;
size_t dataSize;
int storageIndex; // index in storedFrameArray of where this frame will go, if applicable
Boolean willBeStored; // if true, frame will go in storedFrameArray[storageIndex]; if false, immediateFrame.
Boolean decoded;
char pad[2];
} ExampleIPBDecompressRecord;
// Setup required for ComponentDispatchHelper.c
#define IMAGECODEC_BASENAME() ExampleIPB_D
#define IMAGECODEC_GLOBALS() ExampleIPBDecompressorGlobals storage
#define CALLCOMPONENT_BASENAME() IMAGECODEC_BASENAME()
#define CALLCOMPONENT_GLOBALS() IMAGECODEC_GLOBALS()
#define QT_BASENAME() CALLCOMPONENT_BASENAME()
#define QT_GLOBALS() CALLCOMPONENT_GLOBALS()
#define COMPONENT_UPP_PREFIX() uppImageCodec
#define COMPONENT_DISPATCH_FILE "ExampleIPBDecompressorDispatch.h"
#define COMPONENT_SELECT_PREFIX() kImageCodec
#define GET_DELEGATE_COMPONENT() (storage->delegateComponent)
#if __APPLE_CC__
#include <CoreServices/Components.k.h>
#include <QuickTime/ImageCodec.k.h>
#include <QuickTime/ImageCompression.k.h>
#include <QuickTime/ComponentDispatchHelper.c>
#else
#include <Components.k.h>
#include <ImageCodec.k.h>
#include <ImageCompression.k.h>
#include <ComponentDispatchHelper.c>
#endif
/* -- This Image Decompressor User the Base Image Decompressor Component --
The base image decompressor is an Apple-supplied component
that makes it easier for developers to create new decompressors.
The base image decompressor does most of the housekeeping and
interface functions required for a QuickTime decompressor component,
including scheduling for asynchronous decompression.
*/
// Component Open Request - Required
pascal ComponentResult ExampleIPB_DOpen(ExampleIPBDecompressorGlobals glob, ComponentInstance self)
{
ComponentResult err;
// Allocate memory for our globals, set them up and inform the component manager that we've done so
glob = calloc( sizeof( ExampleIPBDecompressorGlobalsRecord ), 1 );
if( ! glob ) {
err = memFullErr;
goto bail;
}
SetComponentInstanceStorage(self, (Handle)glob);
glob->self = self;
glob->target = self;
// Open and target an instance of the base decompressor as we delegate
// most of our calls to the base decompressor instance
err = OpenADefaultComponent(decompressorComponentType, kBaseCodecType, &glob->delegateComponent);
if( err )
goto bail;
ComponentSetTarget(glob->delegateComponent, self);
bail:
return err;
}
// Component Close Request - Required
pascal ComponentResult ExampleIPB_DClose(ExampleIPBDecompressorGlobals glob, ComponentInstance self)
{
// Make sure to close the base component and dealocate our storage
if (glob) {
int frameIndex;
if (glob->delegateComponent) {
CloseComponent(glob->delegateComponent);
}
for( frameIndex = 0; frameIndex < kMaxStoredFrames; frameIndex++ ) {
freeInternalPixelBuffer( &glob->storedFrameArray[frameIndex] );
}
freeInternalPixelBuffer( &glob->immediateFrame );
DisposeHandle( glob->wantedDestinationPixelTypes );
glob->wantedDestinationPixelTypes = NULL;
free( glob );
}
return noErr;
}
// Component Version Request - Required
pascal ComponentResult ExampleIPB_DVersion(ExampleIPBDecompressorGlobals glob)
{
#pragma unused(glob)
return kExampleIPBDecompressorVersion;
}
// Component Target Request
// Allows another component to "target" you i.e., you call another component whenever
// you would call yourself (as a result of your component being used by another component)
pascal ComponentResult ExampleIPB_DTarget(ExampleIPBDecompressorGlobals glob, ComponentInstance target)
{
glob->target = target;
return noErr;
}
#pragma mark-
// ImageCodecInitialize
// The first function call that your image decompressor component receives from the base image
// decompressor is always a call to ImageCodecInitialize. In response to this call, your image decompressor
// component returns an ImageSubCodecDecompressCapabilities structure that specifies its capabilities.
pascal ComponentResult ExampleIPB_DInitialize(ExampleIPBDecompressorGlobals glob, ImageSubCodecDecompressCapabilities *cap)
{
#pragma unused(glob)
// Secifies the size of the ImageSubCodecDecompressRecord structure
// and say we can support asyncronous decompression
// With the help of the base image decompressor, any image decompressor
// that uses only interrupt-safe calls for decompression operations can
// support asynchronous decompression.
cap->decompressRecordSize = sizeof(ExampleIPBDecompressRecord);
cap->canAsync = true;
// These fields were added in QuickTime 7. Be safe.
if( cap->recordSize > offsetof(ImageSubCodecDecompressCapabilities, baseCodecShouldCallDecodeBandForAllFrames) ) {
// Tell the base codec that we are "multi-buffer aware".
// This promises that we always draw using the ImageSubCodecDecompressRecord.baseAddr/rowBytes
// passed to our ImageCodecDrawBand function, and that we always overwrite every pixel in the buffer.
// It is important to set this in order to get optimal performance when playing through CoreVideo.
cap->subCodecIsMultiBufferAware = true;
// Tell the base codec that we support "out-of-order display times".
// This is the same as saying that we support B frames, or frame reordering.
// It is important to set this or the ICM will assume we do not support B frames,
// and attempts to schedule frames in a display order that's different from their
// decode order will fail.
cap->subCodecSupportsOutOfOrderDisplayTimes = true;
// Ask the base codec to call our ImageCodecDecodeBand function for every frame.
// If you do not set this, then your ImageCodecDrawBand function must
// manually ensure that the frame is decoded before drawing it.
cap->baseCodecShouldCallDecodeBandForAllFrames = true;
}
return noErr;
}
// ImageCodecPreflight
// The base image decompressor gets additional information about the capabilities of your image
// decompressor component by calling ImageCodecPreflight. The base image decompressor uses this
// information when responding to a call to the ImageCodecPredecompress function,
// which the ICM makes before decompressing an image. You are required only to provide values for
// the wantedDestinationPixelSize and wantedDestinationPixelTypes fields and can also modify other
// fields if necessary.
pascal ComponentResult ExampleIPB_DPreflight(ExampleIPBDecompressorGlobals glob, CodecDecompressParams *p)
{
OSStatus err = noErr;
CodecCapabilities *capabilities = p->capabilities;
int widthRoundedUp, heightRoundedUp;
int frameIndex;
// Specify the minimum image band height supported by the component
// bandInc specifies a common factor of supported image band heights -
// if your component supports only image bands that are an even
// multiple of some number of pixels high report this common factor in bandInc
capabilities->bandMin = (**p->imageDescription).height;
capabilities->bandInc = capabilities->bandMin;
// Indicate the pixel depth the component can use with the specified image
capabilities->wantedPixelSize = 0; // set this to zero when using wantedDestinationPixelTypes
if( NULL == glob->wantedDestinationPixelTypes ) {
glob->wantedDestinationPixelTypes = NewHandleClear( 2 * sizeof(OSType) );
if( NULL == glob->wantedDestinationPixelTypes )
return memFullErr;
}
p->wantedDestinationPixelTypes = (OSType **)glob->wantedDestinationPixelTypes;
(*p->wantedDestinationPixelTypes)[0] = k422YpCbCr8PixelFormat; // also known as '2vuy'
(*p->wantedDestinationPixelTypes)[1] = 0;
// Specify the number of pixels the image must be extended in width and height if
// the component cannot accommodate the image at its given width and height.
// This codec must have output buffers that are rounded up to multiples of 16x16.
glob->width = (**p->imageDescription).width;
glob->height = (**p->imageDescription).height;
widthRoundedUp = glob->width;
heightRoundedUp = glob->height;
if( 0 != ( widthRoundedUp & 15 ) )
widthRoundedUp = ( widthRoundedUp + 15 ) & ~15;
if( 0 != ( heightRoundedUp & 15 ) )
heightRoundedUp = ( heightRoundedUp + 15 ) & ~15;
capabilities->extendWidth = widthRoundedUp - glob->width;
capabilities->extendHeight = heightRoundedUp - glob->height;
// Allocate our buffers.
for( frameIndex = 0; frameIndex < kMaxStoredFrames; frameIndex++ ) {
err = callocInternalPixelBuffer( widthRoundedUp, heightRoundedUp, &glob->storedFrameArray[frameIndex] );
if( err )
goto bail;
}
callocInternalPixelBuffer( widthRoundedUp, heightRoundedUp, &glob->immediateFrame );
if( err )
goto bail;
bail:
return err;
}
// ImageCodecBeginBand
// The ImageCodecBeginBand function allows your image decompressor component to save information about
// a band before decompressing it. This function is never called at interrupt time. The base image decompressor
// preserves any changes your component makes to any of the fields in the ImageSubCodecDecompressRecord
// or CodecDecompressParams structures. If your component supports asynchronous scheduled decompression, it
// may receive more than one ImageCodecBeginBand call before receiving an ImageCodecDrawBand call.
pascal ComponentResult ExampleIPB_DBeginBand(ExampleIPBDecompressorGlobals glob, CodecDecompressParams *p, ImageSubCodecDecompressRecord *drp, long flags)
{
#pragma unused(glob)
OSStatus err = noErr;
ExampleIPBDecompressRecord *myDrp = (ExampleIPBDecompressRecord *)drp->userDecompressRecord;
Boolean keyFrame, differenceFrame, droppableFrame;
int storageIndex;
myDrp->width = (**p->imageDescription).width;
myDrp->height = (**p->imageDescription).height;
// Unfortunately, the image decompressor API can not quite guarantee to tell the decompressor
// how much data is available, because the deprecated API DecompressSequenceFrame does not take
// a dataSize argument. (That's why you should call DecompressSequenceFrameS instead.)
// Here's the best effort we can make: if there's a data-loading proc, use the dataSize from the
// image description; otherwise, use the bufferSize.
if( drp->dataProcRecord.dataProc )
myDrp->dataSize = (**p->imageDescription).dataSize;
else
myDrp->dataSize = p->bufferSize;
// In some cases, a frame will be decoded and ready for display, but the display will be cancelled.
// QuickTime's video media handler will remember that the frame has already been decoded,
// and if appropriate, will schedule that frame for display without redecoding by using the
// icmFrameAlreadyDecoded flag.
// In that case, we should simply retrieve the frame from whichever buffer we put it in.
myDrp->decoded = p->frameTime ? (0 != (p->frameTime->flags & icmFrameAlreadyDecoded)) : false;
err = NaiveDecoder_DecodeFrameHeader( (const UInt8 *)drp->codecData, &keyFrame, &differenceFrame, &droppableFrame, &storageIndex );
if( err )
goto bail;
// Remember which internal buffer we're going to put this frame in when we decode it.
myDrp->storageIndex = storageIndex;
myDrp->willBeStored = ! droppableFrame;
// Classify the frame so that the base codec can do the right thing.
// It is very important to do this so that the base codec will know
// which frames it can drop if we're in danger of falling behind.
if( keyFrame ) {
// Key frames are resynchronization points in the sequence of frames.
// No frames following a key frame can depend on information from frames before a key frame.
// Note that the I frame at the start of an open GOP in MPEG-1/2 frame patterns is *not* a key frame.
drp->frameType = kCodecFrameTypeKey;
}
else if( droppableFrame ) {
// Droppable frames are not stored; no later frames depend on information in them.
// We decode them into the immediateFrame buffer, which is available for reuse
// as soon as the frame is drawn.
drp->frameType = kCodecFrameTypeDroppableDifference;
}
else {
// Other frames are difference frames.
drp->frameType = kCodecFrameTypeDifference;
}
bail:
return err;
}
pascal ComponentResult ExampleIPB_DDecodeBand(ExampleIPBDecompressorGlobals glob, ImageSubCodecDecompressRecord *drp, unsigned long flags)
{
OSErr err = noErr;
ExampleIPBDecompressRecord *myDrp = (ExampleIPBDecompressRecord *)drp->userDecompressRecord;
ICMDataProcRecordPtr dataProc = drp->dataProcRecord.dataProc ? &drp->dataProcRecord : NULL;
struct InternalPixelBuffer *destBuffer;
if( myDrp->willBeStored ) {
destBuffer = &glob->storedFrameArray[ myDrp->storageIndex ];
}
else {
destBuffer = &glob->immediateFrame;
}
err = NaiveDecoder_DecodeFramePayload( myDrp->width, myDrp->height, (const UInt8 **)&drp->codecData, dataProc, myDrp->dataSize,
glob->storedFrameArray, destBuffer );
myDrp->decoded = true;
bail:
return err;
}
// ImageCodecDrawBand
// The base image decompressor calls your image decompressor component's ImageCodecDrawBand function
// to decompress a band or frame. Your component must implement this function. If the ImageSubCodecDecompressRecord
// structure specifies a progress function or data-loading function, the base image decompressor will never call ImageCodecDrawBand
// at interrupt time. If the ImageSubCodecDecompressRecord structure specifies a progress function, the base image decompressor
// handles codecProgressOpen and codecProgressClose calls, and your image decompressor component must not implement these functions.
// If not, the base image decompressor may call the ImageCodecDrawBand function at interrupt time.
// When the base image decompressor calls your ImageCodecDrawBand function, your component must perform the decompression specified
// by the fields of the ImageSubCodecDecompressRecord structure. The structure includes any changes your component made to it
// when performing the ImageCodecBeginBand function. If your component supports asynchronous scheduled decompression,
// it may receive more than one ImageCodecBeginBand call before receiving an ImageCodecDrawBand call.
pascal ComponentResult ExampleIPB_DDrawBand(ExampleIPBDecompressorGlobals glob, ImageSubCodecDecompressRecord *drp)
{
#pragma unused(glob)
OSErr err = noErr;
ExampleIPBDecompressRecord *myDrp = (ExampleIPBDecompressRecord *)drp->userDecompressRecord;
struct InternalPixelBuffer *destBuffer;
if( ! myDrp->decoded ) {
// If you don't set the baseCodecShouldCallDecodeBandForAllFrames flag, or if you
// need QuickTime 6 compatibility, you should double-check that the frame has been decoded here,
// and decode if necessary:
err = ExampleIPB_DDecodeBand( glob, drp, 0 );
if( err ) goto bail;
}
if( myDrp->willBeStored ) {
destBuffer = &glob->storedFrameArray[ myDrp->storageIndex ];
}
else {
destBuffer = &glob->immediateFrame;
}
err = CopyPlanarYUV420ToChunkyYUV422(
myDrp->width, myDrp->height,
destBuffer->planeArray[0].planeBaseAddr, destBuffer->planeArray[0].planeRowBytes,
destBuffer->planeArray[1].planeBaseAddr, destBuffer->planeArray[1].planeRowBytes,
destBuffer->planeArray[2].planeBaseAddr, destBuffer->planeArray[2].planeRowBytes,
drp->baseAddr, drp->rowBytes );
bail:
return err;
}
// ImageCodecEndBand
// The ImageCodecEndBand function notifies your image decompressor component that decompression of a band has finished or
// that it was terminated by the Image Compression Manager. Your image decompressor component is not required to implement
// the ImageCodecEndBand function. The base image decompressor may call the ImageCodecEndBand function at interrupt time.
// After your image decompressor component handles an ImageCodecEndBand call, it can perform any tasks that are required
// when decompression is finished, such as disposing of data structures that are no longer needed. Because this function
// can be called at interrupt time, your component cannot use this function to dispose of data structures; this
// must occur after handling the function. The value of the result parameter should be set to noErr if the band or frame was
// drawn successfully. If it is any other value, the band or frame was not drawn.
pascal ComponentResult ExampleIPB_DEndBand(ExampleIPBDecompressorGlobals glob, ImageSubCodecDecompressRecord *drp, OSErr result, long flags)
{
#pragma unused(glob, drp,result, flags)
return noErr;
}
// ImageCodecQueueStarting
// If your component supports asynchronous scheduled decompression, the base image decompressor calls your image decompressor component's
// ImageCodecQueueStarting function before decompressing the frames in the queue. Your component is not required to implement this function.
// It can implement the function if it needs to perform any tasks at this time, such as locking data structures.
// The base image decompressor never calls the ImageCodecQueueStarting function at interrupt time.
pascal ComponentResult ExampleIPB_DQueueStarting(ExampleIPBDecompressorGlobals glob)
{
#pragma unused(glob)
return noErr;
}
// ImageCodecQueueStopping
// If your image decompressor component supports asynchronous scheduled decompression, the ImageCodecQueueStopping function notifies
// your component that the frames in the queue have been decompressed. Your component is not required to implement this function.
// After your image decompressor component handles an ImageCodecQueueStopping call, it can perform any tasks that are required when decompression
// of the frames is finished, such as disposing of data structures that are no longer needed.
// The base image decompressor never calls the ImageCodecQueueStopping function at interrupt time.
pascal ComponentResult ExampleIPB_DQueueStopping(ExampleIPBDecompressorGlobals glob)
{
#pragma unused(glob)
return noErr;
}
// ImageCodecGetCompressedImageSize
// Your component receives the ImageCodecGetCompressedImageSize request whenever an application calls the ICM's GetCompressedImageSize function.
// You can use the ImageCodecGetCompressedImageSize function when you are extracting a single image from a sequence; therefore, you don't have an
// image description structure and don't know the exact size of one frame. In this case, the Image Compression Manager calls the component to determine
// the size of the data. Your component should return a long integer indicating the number of bytes of data in the compressed image. You may want to store
// the image size somewhere in the image description structure, so that you can respond to this request quickly. Only decompressors receive this request.
pascal ComponentResult ExampleIPB_DGetCompressedImageSize(ExampleIPBDecompressorGlobals glob, ImageDescriptionHandle desc, Ptr data, long dataSize, ICMDataProcRecordPtr dataProc, long *size)
{
#pragma unused(glob,desc,dataSize,dataProc)
if (size == NULL)
return paramErr;
//••
return unimpErr;
}
// ImageCodecGetCodecInfo
// Your component receives the ImageCodecGetCodecInfo request whenever an application calls the Image Compression Manager's GetCodecInfo function.
// Your component should return a formatted compressor information structure defining its capabilities.
// Both compressors and decompressors may receive this request.
pascal ComponentResult ExampleIPB_DGetCodecInfo(ExampleIPBDecompressorGlobals glob, CodecInfo *info)
{
OSErr err = noErr;
if (info == NULL) {
err = paramErr;
}
else {
CodecInfo **tempCodecInfo;
err = GetComponentResource((Component)glob->self, codecInfoResourceType, 256, (Handle *)&tempCodecInfo);
if (err == noErr) {
*info = **tempCodecInfo;
DisposeHandle((Handle)tempCodecInfo);
}
}
return err;
}
#pragma mark-
// When building the *Application Version Only* make our component available for use by applications (or other clients).
// Once the Component Manager has registered a component, applications can find and open the component using standard
// Component Manager routines.
#if !STAND_ALONE && !TARGET_OS_WIN32
void RegisterExampleIPBDecompressor(void);
void RegisterExampleIPBDecompressor(void)
{
ComponentDescription td;
td.componentType = decompressorComponentType;
td.componentSubType = FOUR_CHAR_CODE('EIPB');
td.componentManufacturer = kAppleManufacturer;
td.componentFlags = cmpThreadSafe;
td.componentFlagsMask = 0;
RegisterComponent(&td,(ComponentRoutineUPP)ExampleIPB_DComponentDispatch, 0, NULL, NULL, NULL);
}
#endif // !STAND_ALONE && TARGET_OS_WIN32
</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/ExampleIPBCodec/listing6.html%3Fid%3DDTS10003589-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/ExampleIPBCodec/listing6.html%3Fid%3DDTS10003589-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/ExampleIPBCodec/listing6.html%3Fid%3DDTS10003589-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>