~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to source/blender/quicktime/apple/quicktime_import.c

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 *
3
 
 * quicktime_import.c
4
 
 *
5
 
 * Code to use Quicktime to load images/movies as texture.
6
 
 *
7
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
8
4
 * This program is free software; you can redistribute it and/or
9
5
 * modify it under the terms of the GNU General Public License
10
6
 * as published by the Free Software Foundation; either version 2
29
25
 
30
26
/** \file blender/quicktime/apple/quicktime_import.c
31
27
 *  \ingroup quicktime
 
28
 *
 
29
 * Code to use Quicktime to load images/movies as texture.
32
30
 */
33
31
 
34
32
#ifdef WITH_QUICKTIME
60
58
#include "quicktime_import.h"
61
59
#include "quicktime_export.h"
62
60
 
63
 
#define RECT_WIDTH(r)   (r.right-r.left)
64
 
#define RECT_HEIGHT(r)  (r.bottom-r.top)
 
61
#define RECT_WIDTH(r)   (r.right - r.left)
 
62
#define RECT_HEIGHT(r)  (r.bottom - r.top)
65
63
 
66
64
#define QTIME_DEBUG 0
67
65
 
68
66
typedef struct _QuicktimeMovie {
69
67
 
70
 
        GWorldPtr       offscreenGWorld;
71
 
        PixMapHandle    offscreenPixMap;
72
 
        Movie           movie;
73
 
        Rect            movieBounds;
74
 
        short           movieRefNum;
75
 
        short           movieResId;
76
 
        int                     movWidth, movHeight;
77
 
 
78
 
        
79
 
        int                     framecount;
80
 
        
81
 
        
82
 
        ImBuf           *ibuf;
83
 
        
84
 
 
85
 
        TimeValue       *frameIndex;
86
 
        Media           theMedia;
87
 
        Track           theTrack;
88
 
        long            trackIndex;
89
 
        short           depth;
90
 
        
91
 
        int                     have_gw;        //ugly
 
68
        GWorldPtr     offscreenGWorld;
 
69
        PixMapHandle  offscreenPixMap;
 
70
        Movie         movie;
 
71
        Rect          movieBounds;
 
72
        short         movieRefNum;
 
73
        short         movieResId;
 
74
        int           movWidth, movHeight;
 
75
 
 
76
        
 
77
        int framecount;
 
78
        
 
79
        
 
80
        ImBuf       *ibuf;
 
81
        
 
82
 
 
83
        TimeValue   *frameIndex;
 
84
        Media        theMedia;
 
85
        Track        theTrack;
 
86
        long         trackIndex;
 
87
        short        depth;
 
88
        
 
89
        int have_gw; /* ugly */
92
90
} QuicktimeMovie;
93
91
 
94
92
 
107
105
#endif /* _WIN32 */
108
106
 
109
107
        /* Initialize QuickTime */
110
 
#if defined(_WIN32) || defined (__APPLE__)
 
108
#if defined(_WIN32) || defined(__APPLE__)
111
109
        nerr = EnterMovies();
112
110
        if (nerr != noErr)
113
111
                G.have_quicktime = FALSE;
115
113
#endif /* _WIN32 || __APPLE__ */
116
114
#ifdef __linux__
117
115
        /* inititalize quicktime codec registry */
118
 
                lqt_registry_init();
 
116
        lqt_registry_init();
119
117
#endif
120
118
        G.have_quicktime = TRUE;
121
119
}
143
141
        TCHAR Buffer[MAX_PATH];
144
142
        DWORD dwRet;
145
143
        char *qtname;
146
 
        DynStr *ds= BLI_dynstr_new();
 
144
        DynStr *ds = BLI_dynstr_new();
147
145
 
148
146
        dwRet = GetCurrentDirectory(MAX_PATH, Buffer);
149
147
 
168
166
                BLI_dynstr_append(ds, name);
169
167
        }
170
168
 
171
 
        qtname= BLI_dynstr_get_cstring(ds);
 
169
        qtname = BLI_dynstr_get_cstring(ds);
172
170
        BLI_dynstr_free(ds);
173
171
 
174
172
        return qtname;
176
174
#endif /* _WIN32 */
177
175
 
178
176
 
179
 
int anim_is_quicktime (const char *name)
 
177
int anim_is_quicktime(const char *name)
180
178
{
181
 
        FSSpec  theFSSpec;
182
 
        char    theFullPath[255];
 
179
        FSSpec theFSSpec;
 
180
        char theFullPath[255];
183
181
 
184
 
        Boolean                                         isMovieFile = false;
185
 
        AliasHandle                                     myAlias = NULL;
186
 
        Component                                       myImporter = NULL;
 
182
        Boolean isMovieFile = false;
 
183
        AliasHandle myAlias = NULL;
 
184
        Component myImporter = NULL;
187
185
#ifdef __APPLE__
188
 
        FInfo                                           myFinderInfo;
189
 
        FSRef                                           myRef;
 
186
        FInfo myFinderInfo;
 
187
        FSRef myRef;
190
188
#else
191
189
        char *qtname;
192
 
        Str255  dst;
 
190
        Str255 dst;
193
191
#endif
194
 
        OSErr                                           err = noErr;
 
192
        OSErr err = noErr;
195
193
                        
196
194
        // don't let quicktime movie import handle these
197
 
        if ( BLI_testextensie(name, ".swf") ||
198
 
                BLI_testextensie(name, ".txt") ||
199
 
                BLI_testextensie(name, ".mpg") ||
200
 
                BLI_testextensie(name, ".avi") ||       // wouldnt be appropriate ;)
201
 
                BLI_testextensie(name, ".tga") ||
202
 
                BLI_testextensie(name, ".png") ||
203
 
                BLI_testextensie(name, ".bmp") ||
204
 
                BLI_testextensie(name, ".jpg") ||
205
 
                BLI_testextensie(name, ".wav") ||
206
 
                BLI_testextensie(name, ".zip") ||
207
 
                BLI_testextensie(name, ".mp3")) return 0;
 
195
        if (BLI_testextensie(name, ".swf") ||
 
196
            BLI_testextensie(name, ".txt") ||
 
197
            BLI_testextensie(name, ".mpg") ||
 
198
            BLI_testextensie(name, ".avi") ||  /* wouldn't be appropriate ;) */
 
199
            BLI_testextensie(name, ".tga") ||
 
200
            BLI_testextensie(name, ".png") ||
 
201
            BLI_testextensie(name, ".bmp") ||
 
202
            BLI_testextensie(name, ".jpg") ||
 
203
            BLI_testextensie(name, ".wav") ||
 
204
            BLI_testextensie(name, ".zip") ||
 
205
            BLI_testextensie(name, ".mp3"))
 
206
        {
 
207
                return 0;
 
208
        }
208
209
 
209
210
        if (QTIME_DEBUG) printf("qt: checking as movie: %s\n", name);
210
211
 
244
245
                }
245
246
        }
246
247
        
247
 
        if ((err == noErr) && (myImporter != NULL)) {           // this file is a movie file
 
248
        if ((err == noErr) && (myImporter != NULL)) {  /* this file is a movie file */
248
249
                isMovieFile = true;
249
250
        }
250
251
 
252
253
}
253
254
 
254
255
 
255
 
void free_anim_quicktime (struct anim *anim)
 
256
void free_anim_quicktime(struct anim *anim)
256
257
{
257
258
        if (anim == NULL) return;
258
259
        if (anim->qtime == NULL) return;
260
261
        UnlockPixels(anim->qtime->offscreenPixMap);
261
262
 
262
263
        if (anim->qtime->have_gw)
263
 
                DisposeGWorld( anim->qtime->offscreenGWorld );
 
264
                DisposeGWorld(anim->qtime->offscreenGWorld);
264
265
        if (anim->qtime->ibuf)
265
266
                IMB_freeImBuf(anim->qtime->ibuf);
266
267
 
267
 
        DisposeMovie( anim->qtime->movie );
268
 
        CloseMovieFile( anim->qtime->movieRefNum );
 
268
        DisposeMovie(anim->qtime->movie);
 
269
        CloseMovieFile(anim->qtime->movieRefNum);
269
270
 
270
 
        if (anim->qtime->frameIndex) MEM_freeN (anim->qtime->frameIndex);
271
 
        if (anim->qtime) MEM_freeN (anim->qtime);
 
271
        if (anim->qtime->frameIndex) MEM_freeN(anim->qtime->frameIndex);
 
272
        if (anim->qtime) MEM_freeN(anim->qtime);
272
273
 
273
274
        anim->qtime = NULL;
274
275
 
279
280
static OSErr QT_get_frameIndexes(struct anim *anim)
280
281
{
281
282
        int i;
282
 
        OSErr   anErr = noErr;
283
 
        OSType  media = VideoMediaType;
 
283
        OSErr anErr = noErr;
 
284
        OSType media = VideoMediaType;
284
285
        TimeValue nextTime = 0;
285
 
        TimeValue       startPoint;
286
 
        TimeValue       tmpstartPoint;
 
286
        TimeValue startPoint;
 
287
        TimeValue tmpstartPoint;
287
288
        long sampleCount = 0;
288
289
 
289
290
        startPoint = -1;
290
291
 
291
 
        GetMovieNextInterestingTime(anim->qtime->movie, nextTimeMediaSample+nextTimeEdgeOK, (TimeValue)1, &media, 0, 
292
 
                                                                1, &startPoint, NULL);
 
292
        GetMovieNextInterestingTime(anim->qtime->movie, nextTimeMediaSample + nextTimeEdgeOK, (TimeValue)1, &media, 0,
 
293
                                    1, &startPoint, NULL);
293
294
 
294
295
        tmpstartPoint = startPoint;
295
296
 
319
320
}
320
321
 
321
322
 
322
 
ImBuf * qtime_fetchibuf (struct anim *anim, int position)
 
323
ImBuf *qtime_fetchibuf(struct anim *anim, int position)
323
324
{
324
 
        PixMapHandle                    myPixMap = NULL;
325
 
        Ptr                                             myPtr;
326
 
 
327
 
        register int            index;
328
 
        register int            boxsize;
329
 
 
330
 
        register uint32_t       *readPos;
331
 
        register uint32_t       *changePos;
 
325
        PixMapHandle myPixMap = NULL;
 
326
        Ptr myPtr;
 
327
 
 
328
        register int index;
 
329
        register int boxsize;
 
330
 
 
331
        register uint32_t   *readPos;
 
332
        register uint32_t   *changePos;
332
333
 
333
334
        ImBuf *ibuf = NULL;
334
335
        unsigned int *rect;
343
344
                return (NULL);
344
345
        }
345
346
 
346
 
        ibuf = IMB_allocImBuf (anim->x, anim->y, 32, IB_rect);
 
347
        ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
347
348
        rect = ibuf->rect;
348
349
 
349
350
        SetMovieTimeValue(anim->qtime->movie, anim->qtime->frameIndex[position]);
355
356
        myPtr = GetPixBaseAddr(myPixMap);
356
357
 
357
358
        if (myPtr == NULL) {
358
 
                printf ("Error reading frame from Quicktime");
359
 
                IMB_freeImBuf (ibuf);
 
359
                printf("Error reading frame from Quicktime");
 
360
                IMB_freeImBuf(ibuf);
360
361
                return NULL;
361
362
        }
362
363
 
366
367
 
367
368
#ifdef __APPLE__
368
369
        // Swap alpha byte to the end, so ARGB become RGBA;
369
 
        from= (unsigned char *)readPos;
370
 
        to= (unsigned char *)changePos;
 
370
        from = (unsigned char *)readPos;
 
371
        to = (unsigned char *)changePos;
371
372
        
372
 
        for ( index = 0; index < boxsize; index++, from+=4, to+=4 ) {
 
373
        for (index = 0; index < boxsize; index++, from += 4, to += 4) {
373
374
                to[3] = from[0];
374
375
                to[0] = from[1];
375
376
                to[1] = from[2];
378
379
#endif
379
380
 
380
381
#ifdef _WIN32
381
 
        for ( index = 0; index < boxsize; index++, changePos++, readPos++ )
382
 
                *( changePos ) =  *(readPos );
 
382
        for (index = 0; index < boxsize; index++, changePos++, readPos++)
 
383
                *(changePos) =  *(readPos);
383
384
 
384
385
        if (anim->qtime->depth < 32) {
385
386
                //add alpha to ibuf
386
387
                boxsize = anim->x * anim->y * 4;
387
388
                crect = (unsigned char *) rect;
388
 
                for ( index = 0; index < boxsize; index+=4, crect+=4 ) {
 
389
                for (index = 0; index < boxsize; index += 4, crect += 4) {
389
390
                        crect[3] = 0xFF;
390
391
                }
391
392
        }
392
393
#endif
393
394
 
394
 
        ibuf->profile = IB_PROFILE_SRGB;
395
 
        
396
395
        IMB_flipy(ibuf);
397
396
        return ibuf;
398
397
}
402
401
 
403
402
static int GetFirstVideoMedia(struct anim *anim)
404
403
{
405
 
        long    numTracks;
406
 
        OSType  mediaType;
 
404
        long numTracks;
 
405
        OSType mediaType;
407
406
 
408
407
        numTracks = GetMovieTrackCount(anim->qtime->movie);
409
408
 
410
 
        for (anim->qtime->trackIndex=1; anim->qtime->trackIndex<=numTracks; (anim->qtime->trackIndex)++) {
 
409
        for (anim->qtime->trackIndex = 1; anim->qtime->trackIndex <= numTracks; (anim->qtime->trackIndex)++) {
411
410
                anim->qtime->theTrack = GetMovieIndTrack(anim->qtime->movie, anim->qtime->trackIndex);
412
411
 
413
412
                if (anim->qtime->theTrack)
414
413
                        anim->qtime->theMedia = GetTrackMedia(anim->qtime->theTrack);
415
414
 
416
415
                if (anim->qtime->theMedia)
417
 
                        GetMediaHandlerDescription(anim->qtime->theMedia,&mediaType, nil, nil);
 
416
                        GetMediaHandlerDescription(anim->qtime->theMedia, &mediaType, nil, nil);
418
417
                if (mediaType == VideoMediaType) return 1;
419
418
        }
420
419
 
424
423
 
425
424
static short GetFirstVideoTrackPixelDepth(struct anim *anim)
426
425
{
427
 
        SampleDescriptionHandle imageDescH =    (SampleDescriptionHandle)NewHandle(sizeof(Handle));
 
426
        SampleDescriptionHandle imageDescH =    (SampleDescriptionHandle)NewHandle(sizeof(Handle));
428
427
//      long    trackIndex = 0; /*unused*/
429
428
        
430
429
        if (!GetFirstVideoMedia(anim))
437
436
}
438
437
 
439
438
 
440
 
int startquicktime (struct anim *anim)
 
439
int startquicktime(struct anim *anim)
441
440
{
442
 
        FSSpec          theFSSpec;
 
441
        FSSpec theFSSpec;
443
442
 
444
 
        OSErr           err = noErr;
445
 
        char            theFullPath[255];
 
443
        OSErr err = noErr;
 
444
        char theFullPath[255];
446
445
#ifdef __APPLE__
447
 
        FSRef           myRef;
 
446
        FSRef myRef;
448
447
#else
449
 
        char            *qtname;
450
 
        Str255          dst;
 
448
        char        *qtname;
 
449
        Str255 dst;
451
450
#endif
452
451
        short depth = 0;
453
452
 
454
 
        anim->qtime = MEM_callocN (sizeof(QuicktimeMovie),"animqt");
 
453
        anim->qtime = MEM_callocN(sizeof(QuicktimeMovie), "animqt");
455
454
        anim->qtime->have_gw = FALSE;
456
455
 
457
456
        if (anim->qtime == NULL) {
480
479
        if (err == noErr) {
481
480
                if (QTIME_DEBUG) printf("qt: movie opened\n");
482
481
                err = NewMovieFromFile(&anim->qtime->movie,
483
 
                                                   anim->qtime->movieRefNum,
484
 
                                                   &anim->qtime->movieResId, NULL, newMovieActive, NULL);
 
482
                                       anim->qtime->movieRefNum,
 
483
                                       &anim->qtime->movieResId, NULL, newMovieActive, NULL);
485
484
        }
486
485
 
487
486
        if (err) {
505
504
                return -1;
506
505
        }
507
506
 
508
 
        anim->qtime->ibuf = IMB_allocImBuf (anim->x, anim->y, 32, IB_rect);
 
507
        anim->qtime->ibuf = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
509
508
 
510
509
#ifdef _WIN32
511
510
        err = NewGWorldFromPtr(&anim->qtime->offscreenGWorld,
512
 
                 k32RGBAPixelFormat,
513
 
                 &anim->qtime->movieBounds,
514
 
                 NULL, NULL, 0,
515
 
                (unsigned char *)anim->qtime->ibuf->rect,
516
 
                anim->x * 4);
 
511
                               k32RGBAPixelFormat,
 
512
                               &anim->qtime->movieBounds,
 
513
                               NULL, NULL, 0,
 
514
                               (unsigned char *)anim->qtime->ibuf->rect,
 
515
                               anim->x * 4);
517
516
#else
518
517
        err = NewGWorldFromPtr(&anim->qtime->offscreenGWorld,
519
 
                 k32ARGBPixelFormat,
520
 
                 &anim->qtime->movieBounds,
521
 
                 NULL, NULL, 0,
522
 
                (unsigned char *)anim->qtime->ibuf->rect,
523
 
                anim->x * 4);
 
518
                               k32ARGBPixelFormat,
 
519
                               &anim->qtime->movieBounds,
 
520
                               NULL, NULL, 0,
 
521
                               (unsigned char *)anim->qtime->ibuf->rect,
 
522
                               anim->x * 4);
524
523
#endif /* _WIN32 */
525
524
 
526
525
        if (err == noErr) {
553
552
        anim->curposition = 0;
554
553
 
555
554
        if (QTIME_DEBUG) printf("qt: load %s %dx%dx%d frames %d\n", anim->name, anim->qtime->movWidth,
556
 
                anim->qtime->movHeight, anim->qtime->depth, anim->qtime->framecount);
 
555
                                    anim->qtime->movHeight, anim->qtime->depth, anim->qtime->framecount);
557
556
 
558
557
        return 0;
559
558
}
560
559
 
561
 
int imb_is_a_quicktime (char *name)
 
560
int imb_is_a_quicktime(char *name)
562
561
{
563
 
        GraphicsImportComponent         theImporter = NULL;
 
562
        GraphicsImportComponent theImporter = NULL;
564
563
 
565
 
        FSSpec  theFSSpec;
 
564
        FSSpec theFSSpec;
566
565
#ifdef _WIN32
567
 
        Str255  dst; /*unused*/
 
566
        Str255 dst;  /*unused*/
568
567
#endif
569
 
        char    theFullPath[255];
 
568
        char theFullPath[255];
570
569
 
571
570
//      Boolean                                         isMovieFile = false; /*unused*/
572
571
//      AliasHandle                                     myAlias = NULL; /*unused*/
573
572
//      Component                                       myImporter = NULL; /*unused*/
574
573
#ifdef __APPLE__
575
574
//      FInfo                                           myFinderInfo; /*unused*/
576
 
        FSRef                                           myRef;
 
575
        FSRef myRef;
577
576
#endif
578
 
        OSErr                                           err = noErr;
 
577
        OSErr err = noErr;
579
578
 
580
579
        if (!G.have_quicktime) return 0;
581
580
 
582
581
        if (QTIME_DEBUG) printf("qt: checking as image %s\n", name);
583
582
 
584
583
        // don't let quicktime image import handle these
585
 
        if ( BLI_testextensie(name, ".swf") ||
586
 
                BLI_testextensie(name, ".txt") ||
587
 
                BLI_testextensie(name, ".mpg") ||
588
 
                BLI_testextensie(name, ".wav") ||
589
 
                BLI_testextensie(name, ".mov") ||       // not as image, doesn't work
590
 
                BLI_testextensie(name, ".avi") ||
591
 
                BLI_testextensie(name, ".mp3")) return 0;
 
584
        if (BLI_testextensie(name, ".swf") ||
 
585
            BLI_testextensie(name, ".txt") ||
 
586
            BLI_testextensie(name, ".mpg") ||
 
587
            BLI_testextensie(name, ".wav") ||
 
588
            BLI_testextensie(name, ".mov") ||   // not as image, doesn't work
 
589
            BLI_testextensie(name, ".avi") ||
 
590
            BLI_testextensie(name, ".mp3"))
 
591
        {
 
592
                return 0;
 
593
        }
592
594
 
593
595
        sprintf(theFullPath, "%s", name);
594
596
#ifdef __APPLE__
612
614
 
613
615
ImBuf  *imb_quicktime_decode(unsigned char *mem, int size, int flags)
614
616
{
615
 
        Rect                                            myRect;
616
 
        OSErr                                           err = noErr;
617
 
        GraphicsImportComponent         gImporter = NULL;
618
 
 
619
 
        ImageDescriptionHandle          desc;
620
 
 
621
 
        ComponentInstance                       dataHandler;
 
617
        Rect myRect;
 
618
        OSErr err = noErr;
 
619
        GraphicsImportComponent gImporter = NULL;
 
620
 
 
621
        ImageDescriptionHandle desc;
 
622
 
 
623
        ComponentInstance dataHandler;
622
624
        PointerDataRef dataref;
623
625
 
624
626
        int x, y, depth;
625
627
        int have_gw = FALSE;
626
628
        ImBuf *ibuf = NULL;
627
629
//      ImBuf *imbuf = NULL; /*unused*/
628
 
        GWorldPtr       offGWorld;
629
 
        PixMapHandle            myPixMap = NULL;
 
630
        GWorldPtr offGWorld;
 
631
        PixMapHandle myPixMap = NULL;
630
632
 
631
633
#ifdef __APPLE__
632
 
        Ptr                                     myPtr;
633
 
 
634
 
        register int            index;
635
 
        register int            boxsize;
636
 
 
637
 
        register uint32_t       *readPos;
638
 
        register uint32_t       *changePos;
 
634
        Ptr myPtr;
 
635
 
 
636
        register int index;
 
637
        register int boxsize;
 
638
 
 
639
        register uint32_t   *readPos;
 
640
        register uint32_t   *changePos;
639
641
 
640
642
        ImBuf *wbuf = NULL;
641
643
        unsigned int *rect;
647
649
        
648
650
        if (QTIME_DEBUG) printf("qt: attempt to load mem as image\n");
649
651
 
650
 
        dataref= (PointerDataRef)NewHandle(sizeof(PointerDataRefRecord));
 
652
        dataref = (PointerDataRef)NewHandle(sizeof(PointerDataRefRecord));
651
653
        (**dataref).data = mem;
652
654
        (**dataref).dataLength = size;
653
655
 
654
656
        err = OpenADataHandler((Handle)dataref,
655
 
                                                        PointerDataHandlerSubType,
656
 
                                                        nil,
657
 
                                                        (OSType)0,
658
 
                                                        nil,
659
 
                                                        kDataHCanRead,
660
 
                                                        &dataHandler);
 
657
                               PointerDataHandlerSubType,
 
658
                               nil,
 
659
                               (OSType)0,
 
660
                               nil,
 
661
                               kDataHCanRead,
 
662
                               &dataHandler);
661
663
        if (err != noErr) {
662
664
                if (QTIME_DEBUG) printf("no datahandler\n");
663
665
                goto bail;
675
677
                goto bail;
676
678
        }
677
679
 
678
 
        err = GraphicsImportGetImageDescription (gImporter, &desc );
 
680
        err = GraphicsImportGetImageDescription(gImporter, &desc);
679
681
        if (err != noErr) {
680
682
                if (QTIME_DEBUG) printf("no imagedescription\n");
681
683
                goto bail;
689
691
                ibuf = IMB_allocImBuf(x, y, depth, 0);
690
692
                ibuf->ftype = QUICKTIME;
691
693
                DisposeHandle((Handle)dataref);
692
 
                if (gImporter != NULL)  CloseComponent(gImporter);
 
694
                if (gImporter != NULL) CloseComponent(gImporter);
693
695
                return ibuf;
694
696
        }
695
697
 
696
698
#ifdef __APPLE__
697
 
        ibuf = IMB_allocImBuf (x, y, 32, IB_rect);
698
 
        wbuf = IMB_allocImBuf (x, y, 32, IB_rect);
 
699
        ibuf = IMB_allocImBuf(x, y, 32, IB_rect);
 
700
        wbuf = IMB_allocImBuf(x, y, 32, IB_rect);
699
701
 
700
702
        err = NewGWorldFromPtr(&offGWorld,
701
 
                                                k32ARGBPixelFormat,
702
 
                                                &myRect, NULL, NULL, 0,
703
 
                                                (unsigned char *)wbuf->rect, x * 4);
 
703
                               k32ARGBPixelFormat,
 
704
                               &myRect, NULL, NULL, 0,
 
705
                               (unsigned char *)wbuf->rect, x * 4);
704
706
#else
705
707
 
706
 
        ibuf = IMB_allocImBuf (x, y, 32, IB_rect);      
 
708
        ibuf = IMB_allocImBuf(x, y, 32, IB_rect);
707
709
 
708
710
        err = NewGWorldFromPtr(&offGWorld,
709
 
                                                        k32RGBAPixelFormat,
710
 
                                                        &myRect, NULL, NULL, 0,
711
 
                                                        (unsigned char *)ibuf->rect, x * 4);
 
711
                               k32RGBAPixelFormat,
 
712
                               &myRect, NULL, NULL, 0,
 
713
                               (unsigned char *)ibuf->rect, x * 4);
712
714
#endif
713
715
        
714
716
        if (err != noErr) {
730
732
        myPtr = GetPixBaseAddr(myPixMap);
731
733
 
732
734
        if (myPtr == NULL) {
733
 
                printf ("Error reading frame from Quicktime");
734
 
                IMB_freeImBuf (ibuf);
 
735
                printf("Error reading frame from Quicktime");
 
736
                IMB_freeImBuf(ibuf);
735
737
                return NULL;
736
738
        }
737
739
 
740
742
        changePos = (uint32_t *) rect;
741
743
 
742
744
        // Swap alpha byte to the end, so ARGB become RGBA;
743
 
        from= (unsigned char *)readPos;
744
 
        to= (unsigned char *)changePos;
 
745
        from = (unsigned char *)readPos;
 
746
        to = (unsigned char *)changePos;
745
747
        
746
 
        for ( index = 0; index < boxsize; index++, from+=4, to+=4 ) {
 
748
        for (index = 0; index < boxsize; index++, from += 4, to += 4) {
747
749
                to[3] = from[0];
748
750
                to[0] = from[1];
749
751
                to[1] = from[2];
759
761
 
760
762
#ifdef __APPLE__
761
763
        if (wbuf) {
762
 
                IMB_freeImBuf (wbuf);
 
764
                IMB_freeImBuf(wbuf);
763
765
                wbuf = NULL;
764
766
        }
765
767
#endif
766
768
 
767
 
        if (gImporter != NULL)  CloseComponent(gImporter);
 
769
        if (gImporter != NULL) CloseComponent(gImporter);
768
770
 
769
771
        if (err != noErr) {
770
772
                if (QTIME_DEBUG) printf("quicktime import unsuccesfull\n");
771
773
                if (ibuf) {
772
 
                        IMB_freeImBuf (ibuf);
 
774
                        IMB_freeImBuf(ibuf);
773
775
                        ibuf = NULL;
774
776
                }
775
777
        }
784
786
                int box = x * y;
785
787
                unsigned char *arect = (unsigned char *) ibuf->rect;
786
788
 
787
 
                if ( depth < 32 && (**desc).cType != kGIFCodecType) {
788
 
                        for (i = 0; i < box; i++, arect+=4)
 
789
                if (depth < 32 && (**desc).cType != kGIFCodecType) {
 
790
                        for (i = 0; i < box; i++, arect += 4)
789
791
                                arect[3] = 0xFF;
790
792
                }
791
793
#endif