~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to source/blender/imbuf/intern/anim_movie.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:
42
42
#include <vfw.h>
43
43
#endif
44
44
 
45
 
#undef AVIIF_KEYFRAME // redefined in AVI_avi.h
46
 
#undef AVIIF_LIST // redefined in AVI_avi.h
 
45
#undef AVIIF_KEYFRAME /* redefined in AVI_avi.h */
 
46
#undef AVIIF_LIST /* redefined in AVI_avi.h */
47
47
 
48
48
#define FIXCC(fcc) \
49
49
        { \
50
50
                if (fcc == 0)       { fcc = mmioFOURCC('N', 'o', 'n', 'e'); } \
51
51
                if (fcc == BI_RLE8) { fcc = mmioFOURCC('R', 'l', 'e', '8'); } \
52
 
        }
 
52
        } (void)0
53
53
 
54
54
#endif
55
55
 
64
64
#include <io.h>
65
65
#endif
66
66
 
67
 
#include "BLI_blenlib.h" /* BLI_remlink BLI_filesize BLI_addtail
68
 
                          * BLI_countlist BLI_stringdec */
 
67
#include "BLI_string.h"
 
68
#include "BLI_path_util.h"
69
69
#include "BLI_utildefines.h"
70
70
#include "BLI_math_base.h"
71
71
 
73
73
 
74
74
#include "DNA_userdef_types.h"
75
75
 
76
 
 
77
76
#include "BKE_global.h"
78
77
#include "BKE_depsgraph.h"
79
78
 
80
79
#include "imbuf.h"
81
80
 
82
 
#include "AVI_avi.h"
 
81
#ifdef WITH_AVI
 
82
#  include "AVI_avi.h"
 
83
#endif
83
84
 
84
85
#ifdef WITH_QUICKTIME
85
86
#if defined(_WIN32) || defined(__APPLE__)
114
115
#endif
115
116
#endif
116
117
 
 
118
#include "IMB_colormanagement.h"
 
119
#include "IMB_colormanagement_intern.h"
 
120
 
117
121
int ismovie(const char *UNUSED(filepath))
118
122
{
119
123
        return 0;
120
124
}
121
125
 
122
 
        /* never called, just keep the linker happy */
123
 
static int startmovie(struct anim *UNUSED(anim)) { return 1; }
124
 
static ImBuf * movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position)) { return NULL; }
125
 
static void free_anim_movie(struct anim *UNUSED(anim)) { ; }
 
126
/* never called, just keep the linker happy */
 
127
static int startmovie(struct anim *UNUSED(anim))
 
128
{
 
129
        return 1;
 
130
}
 
131
static ImBuf *movie_fetchibuf(struct anim *UNUSED(anim), int UNUSED(position))
 
132
{
 
133
        return NULL;
 
134
}
 
135
static void free_anim_movie(struct anim *UNUSED(anim))
 
136
{
 
137
        /* pass */
 
138
}
126
139
 
127
140
 
128
141
#if defined(_WIN32)
131
144
# define PATHSEPERATOR '/'
132
145
#endif
133
146
 
134
 
static int an_stringdec(const char *string, char* head, char *tail, unsigned short *numlen)
 
147
static int an_stringdec(const char *string, char *head, char *tail, unsigned short *numlen)
135
148
{
136
 
        unsigned short len,nume,nums=0;
137
 
        short i,found=FALSE;
 
149
        unsigned short len, nume, nums = 0;
 
150
        short i, found = FALSE;
138
151
 
139
 
        len=strlen(string);
 
152
        len = strlen(string);
140
153
        nume = len;
141
154
 
142
 
        for (i=len-1;i>=0;i--) {
143
 
                if (string[i]==PATHSEPERATOR) break;
 
155
        for (i = len - 1; i >= 0; i--) {
 
156
                if (string[i] == PATHSEPERATOR) break;
144
157
                if (isdigit(string[i])) {
145
158
                        if (found) {
146
 
                                nums=i;
 
159
                                nums = i;
147
160
                        }
148
161
                        else {
149
 
                                nume=i;
150
 
                                nums=i;
151
 
                                found=TRUE;
 
162
                                nume = i;
 
163
                                nums = i;
 
164
                                found = TRUE;
152
165
                        }
153
166
                }
154
167
                else {
156
169
                }
157
170
        }
158
171
        if (found) {
159
 
                strcpy(tail ,&string[nume+1]);
 
172
                strcpy(tail, &string[nume + 1]);
160
173
                strcpy(head, string);
161
 
                head[nums]= '\0';
162
 
                *numlen=nume-nums+1;
 
174
                head[nums] = '\0';
 
175
                *numlen = nume - nums + 1;
163
176
                return ((int)atoi(&(string[nums])));
164
177
        }
165
 
        tail[0]= '\0';
 
178
        tail[0] = '\0';
166
179
        strcpy(head, string);
167
 
        *numlen=0;
 
180
        *numlen = 0;
168
181
        return TRUE;
169
182
}
170
183
 
174
187
        BLI_stringenc(string, head, tail, numlen, pic);
175
188
}
176
189
 
177
 
static void free_anim_avi (struct anim *anim)
 
190
#ifdef WITH_AVI
 
191
static void free_anim_avi(struct anim *anim)
178
192
{
179
193
#if defined(_WIN32) && !defined(FREE_WINDOWS)
180
194
        int i;
183
197
        if (anim == NULL) return;
184
198
        if (anim->avi == NULL) return;
185
199
 
186
 
        AVI_close (anim->avi);
187
 
        MEM_freeN (anim->avi);
 
200
        AVI_close(anim->avi);
 
201
        MEM_freeN(anim->avi);
188
202
        anim->avi = NULL;
189
203
 
190
204
#if defined(_WIN32) && !defined(FREE_WINDOWS)
208
222
 
209
223
        anim->duration = 0;
210
224
}
 
225
#endif  /* WITH_AVI */
211
226
 
212
227
#ifdef WITH_FFMPEG
213
 
static void free_anim_ffmpeg(struct anim * anim);
 
228
static void free_anim_ffmpeg(struct anim *anim);
214
229
#endif
215
230
#ifdef WITH_REDCODE
216
 
static void free_anim_redcode(struct anim * anim);
 
231
static void free_anim_redcode(struct anim *anim);
217
232
#endif
218
233
 
219
 
void IMB_free_anim(struct anim * anim)
 
234
void IMB_free_anim(struct anim *anim)
220
235
{
221
236
        if (anim == NULL) {
222
237
                printf("free anim, anim == NULL\n");
224
239
        }
225
240
 
226
241
        free_anim_movie(anim);
 
242
 
 
243
#ifdef WITH_AVI
227
244
        free_anim_avi(anim);
 
245
#endif
228
246
 
229
247
#ifdef WITH_QUICKTIME
230
248
        free_anim_quicktime(anim);
240
258
        MEM_freeN(anim);
241
259
}
242
260
 
243
 
void IMB_close_anim(struct anim * anim)
 
261
void IMB_close_anim(struct anim *anim)
244
262
{
245
263
        if (anim == NULL) return;
246
264
 
255
273
        IMB_free_indices(anim);
256
274
}
257
275
 
258
 
struct anim * IMB_open_anim( const char * name, int ib_flags, int streamindex)
 
276
struct anim *IMB_open_anim(const char *name, int ib_flags, int streamindex, char colorspace[IM_MAX_SPACE])
259
277
{
260
 
        struct anim * anim;
 
278
        struct anim *anim;
261
279
 
262
 
        anim = (struct anim*)MEM_callocN(sizeof(struct anim), "anim struct");
 
280
        anim = (struct anim *)MEM_callocN(sizeof(struct anim), "anim struct");
263
281
        if (anim != NULL) {
 
282
                if (colorspace) {
 
283
                        colorspace_set_default_role(colorspace, IM_MAX_SPACE, COLOR_ROLE_DEFAULT_BYTE);
 
284
                        BLI_strncpy(anim->colorspace, colorspace, sizeof(anim->colorspace));
 
285
                }
 
286
                else {
 
287
                        colorspace_set_default_role(anim->colorspace, sizeof(anim->colorspace), COLOR_ROLE_DEFAULT_BYTE);
 
288
                }
 
289
 
264
290
                BLI_strncpy(anim->name, name, sizeof(anim->name));
265
291
                anim->ib_flags = ib_flags;
266
292
                anim->streamindex = streamindex;
268
294
        return(anim);
269
295
}
270
296
 
271
 
 
272
 
static int startavi (struct anim *anim)
 
297
#ifdef WITH_AVI
 
298
static int startavi(struct anim *anim)
273
299
{
274
300
 
275
301
        AviError avierror;
276
302
#if defined(_WIN32) && !defined(FREE_WINDOWS)
277
 
        HRESULT hr;
 
303
        HRESULT hr;
278
304
        int i, firstvideo = -1;
279
305
        int streamcount;
280
306
        BYTE abFormat[1024];
285
311
        streamcount = anim->streamindex;
286
312
#endif
287
313
 
288
 
        anim->avi = MEM_callocN (sizeof(AviMovie),"animavi");
 
314
        anim->avi = MEM_callocN(sizeof(AviMovie), "animavi");
289
315
 
290
316
        if (anim->avi == NULL) {
291
317
                printf("Can't open avi: %s\n", anim->name);
292
318
                return -1;
293
319
        }
294
320
 
295
 
        avierror = AVI_open_movie (anim->name, anim->avi);
 
321
        avierror = AVI_open_movie(anim->name, anim->avi);
296
322
 
297
323
#if defined(_WIN32) && !defined(FREE_WINDOWS)
298
324
        if (avierror == AVI_ERROR_COMPRESSION) {
315
341
                                        if (anim->pgf) {
316
342
                                                firstvideo = i;
317
343
 
318
 
                                                // get stream length
 
344
                                                /* get stream length */
319
345
                                                anim->avi->header->TotalFrames = AVIStreamLength(anim->pavi[i]);
320
 
                                                
321
 
                                                // get information about images inside the stream
 
346
 
 
347
                                                /* get information about images inside the stream */
322
348
                                                l = sizeof(abFormat);
323
349
                                                AVIStreamReadFormat(anim->pavi[i], 0, &abFormat, &l);
324
350
                                                lpbi = (LPBITMAPINFOHEADER)abFormat;
329
355
                                                FIXCC(avis.fccHandler);
330
356
                                                FIXCC(avis.fccType);
331
357
                                                printf("Can't find AVI decoder for type : %4.4hs/%4.4hs\n",
332
 
                                                        (LPSTR)&avis.fccType,
333
 
                                                        (LPSTR)&avis.fccHandler);
 
358
                                                       (LPSTR)&avis.fccType,
 
359
                                                       (LPSTR)&avis.fccHandler);
334
360
                                        }
335
361
                                }
336
362
                        }
337
363
 
338
 
                        // register number of opened avistreams
 
364
                        /* register number of opened avistreams */
339
365
                        anim->avistreams = i;
340
366
 
341
 
                        //
342
 
                        // Couldn't get any video streams out of this file
343
 
                        //
 
367
                        /*
 
368
                         * Couldn't get any video streams out of this file
 
369
                         */
344
370
                        if ((anim->avistreams == 0) || (firstvideo == -1)) {
345
371
                                avierror = AVI_ERROR_FORMAT;
346
372
                        }
357
383
 
358
384
        if (avierror != AVI_ERROR_NONE) {
359
385
                AVI_print_error(avierror);
360
 
                printf ("Error loading avi: %s\n", anim->name);         
 
386
                printf("Error loading avi: %s\n", anim->name);
361
387
                free_anim_avi(anim);
362
388
                return -1;
363
389
        }
378
404
 
379
405
        return 0;
380
406
}
 
407
#endif  /* WITH_AVI */
381
408
 
382
 
static ImBuf * avi_fetchibuf (struct anim *anim, int position)
 
409
#ifdef WITH_AVI
 
410
static ImBuf *avi_fetchibuf(struct anim *anim, int position)
383
411
{
384
412
        ImBuf *ibuf = NULL;
385
413
        int *tmp;
386
414
        int y;
387
415
        
388
 
        if (anim == NULL) return (NULL);
 
416
        if (anim == NULL) {
 
417
                return NULL;
 
418
        }
389
419
 
390
420
#if defined(_WIN32) && !defined(FREE_WINDOWS)
391
421
        if (anim->avistreams) {
394
424
                if (anim->pgf) {
395
425
                        lpbi = AVIStreamGetFrame(anim->pgf, position + AVIStreamStart(anim->pavi[anim->firstvideo]));
396
426
                        if (lpbi) {
397
 
                                ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect, "<avi_fetchibuf>");
 
427
                                ibuf = IMB_ibImageFromMemory((unsigned char *) lpbi, 100, IB_rect, anim->colorspace, "<avi_fetchibuf>");
398
428
//Oh brother...
399
429
                        }
400
430
                }
403
433
#else
404
434
        if (1) {
405
435
#endif
406
 
                ibuf = IMB_allocImBuf (anim->x, anim->y, 24, IB_rect);
 
436
                ibuf = IMB_allocImBuf(anim->x, anim->y, 24, IB_rect);
407
437
 
408
 
                tmp = AVI_read_frame (anim->avi, AVI_FORMAT_RGB32, position,
409
 
                        AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
 
438
                tmp = AVI_read_frame(anim->avi, AVI_FORMAT_RGB32, position,
 
439
                                     AVI_get_stream(anim->avi, AVIST_VIDEO, 0));
410
440
                
411
441
                if (tmp == NULL) {
412
 
                        printf ("Error reading frame from AVI");
413
 
                        IMB_freeImBuf (ibuf);
 
442
                        printf("Error reading frame from AVI: '%s'\n", anim->name);
 
443
                        IMB_freeImBuf(ibuf);
414
444
                        return NULL;
415
445
                }
416
446
 
417
 
                for (y=0; y < anim->y; y++) {
418
 
                        memcpy (&(ibuf->rect)[((anim->y-y)-1)*anim->x],  &tmp[y*anim->x],  
419
 
                                anim->x * 4);
 
447
                for (y = 0; y < anim->y; y++) {
 
448
                        memcpy(&(ibuf->rect)[((anim->y - y) - 1) * anim->x],  &tmp[y * anim->x],
 
449
                               anim->x * 4);
420
450
                }
421
451
                
422
 
                MEM_freeN (tmp);
 
452
                MEM_freeN(tmp);
423
453
        }
424
454
        
425
 
        ibuf->profile = IB_PROFILE_SRGB;
426
 
        
 
455
        ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
 
456
 
427
457
        return ibuf;
428
458
}
 
459
#endif  /* WITH_AVI */
429
460
 
430
461
#ifdef WITH_FFMPEG
431
462
 
432
 
extern void do_init_ffmpeg(void);
433
 
 
434
 
static int startffmpeg(struct anim * anim)
 
463
static int startffmpeg(struct anim *anim)
435
464
{
436
 
        int            i, videoStream;
 
465
        int i, videoStream;
437
466
 
438
467
        AVCodec *pCodec;
439
 
        AVFormatContext *pFormatCtx;
 
468
        AVFormatContext *pFormatCtx = NULL;
440
469
        AVCodecContext *pCodecCtx;
441
470
        int frs_num;
442
471
        double frs_den;
453
482
 
454
483
        streamcount = anim->streamindex;
455
484
 
456
 
        do_init_ffmpeg();
457
 
 
458
 
        if (av_open_input_file(&pFormatCtx, anim->name, NULL, 0, NULL)!=0) {
 
485
        if (avformat_open_input(&pFormatCtx, anim->name, NULL, NULL) != 0) {
459
486
                return -1;
460
487
        }
461
488
 
462
 
        if (av_find_stream_info(pFormatCtx)<0) {
 
489
        if (avformat_find_stream_info(pFormatCtx, NULL) < 0) {
463
490
                av_close_input_file(pFormatCtx);
464
491
                return -1;
465
492
        }
471
498
        videoStream = -1;
472
499
 
473
500
        for (i = 0; i < pFormatCtx->nb_streams; i++)
474
 
                if (pFormatCtx->streams[i]->codec->codec_type
475
 
                   == AVMEDIA_TYPE_VIDEO) {
 
501
                if (pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
476
502
                        if (streamcount > 0) {
477
503
                                streamcount--;
478
504
                                continue;
481
507
                        break;
482
508
                }
483
509
 
484
 
        if (videoStream==-1) {
 
510
        if (videoStream == -1) {
485
511
                av_close_input_file(pFormatCtx);
486
512
                return -1;
487
513
        }
497
523
 
498
524
        pCodecCtx->workaround_bugs = 1;
499
525
 
500
 
        if (avcodec_open(pCodecCtx, pCodec) < 0) {
 
526
        if (avcodec_open2(pCodecCtx, pCodec, NULL) < 0) {
501
527
                av_close_input_file(pFormatCtx);
502
528
                return -1;
503
529
        }
504
530
 
505
 
        anim->duration = ceil(pFormatCtx->duration
506
 
                * av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate) 
507
 
                / AV_TIME_BASE);
 
531
        anim->duration = ceil(pFormatCtx->duration *
 
532
                              av_q2d(pFormatCtx->streams[videoStream]->r_frame_rate) /
 
533
                              AV_TIME_BASE);
508
534
 
509
 
        frs_num = pFormatCtx->streams[videoStream]->r_frame_rate.num;
 
535
        frs_num = pFormatCtx->streams[videoStream]->r_frame_rate.num;
510
536
        frs_den = pFormatCtx->streams[videoStream]->r_frame_rate.den;
511
537
 
512
538
        frs_den *= AV_TIME_BASE;
543
569
        anim->pFrameDeinterlaced = avcodec_alloc_frame();
544
570
        anim->pFrameRGB = avcodec_alloc_frame();
545
571
 
546
 
        if (avpicture_get_size(PIX_FMT_RGBA, anim->x, anim->y)
547
 
                != anim->x * anim->y * 4) {
548
 
                fprintf (stderr,
549
 
                         "ffmpeg has changed alloc scheme ... ARGHHH!\n");
 
572
        if (avpicture_get_size(PIX_FMT_RGBA, anim->x, anim->y) !=
 
573
            anim->x * anim->y * 4)
 
574
        {
 
575
                fprintf(stderr,
 
576
                        "ffmpeg has changed alloc scheme ... ARGHHH!\n");
550
577
                avcodec_close(anim->pCodecCtx);
551
578
                av_close_input_file(anim->pFormatCtx);
552
579
                av_free(anim->pFrameRGB);
557
584
        }
558
585
 
559
586
        if (anim->ib_flags & IB_animdeinterlace) {
560
 
                avpicture_fill((AVPicture*) anim->pFrameDeinterlaced,
 
587
                avpicture_fill((AVPicture *) anim->pFrameDeinterlaced,
561
588
                               MEM_callocN(avpicture_get_size(
562
589
                                               anim->pCodecCtx->pix_fmt,
563
590
                                               anim->x, anim->y),
573
600
        }
574
601
        
575
602
        anim->img_convert_ctx = sws_getContext(
576
 
                anim->pCodecCtx->width,
577
 
                anim->pCodecCtx->height,
578
 
                anim->pCodecCtx->pix_fmt,
579
 
                anim->pCodecCtx->width,
580
 
                anim->pCodecCtx->height,
581
 
                PIX_FMT_RGBA,
582
 
                SWS_FAST_BILINEAR | SWS_PRINT_INFO,
583
 
                NULL, NULL, NULL);
 
603
                anim->pCodecCtx->width,
 
604
                anim->pCodecCtx->height,
 
605
                anim->pCodecCtx->pix_fmt,
 
606
                anim->pCodecCtx->width,
 
607
                anim->pCodecCtx->height,
 
608
                PIX_FMT_RGBA,
 
609
                SWS_FAST_BILINEAR | SWS_PRINT_INFO,
 
610
                NULL, NULL, NULL);
584
611
                
585
612
        if (!anim->img_convert_ctx) {
586
 
                fprintf (stderr,
587
 
                         "Can't transform color space??? Bailing out...\n");
 
613
                fprintf(stderr,
 
614
                        "Can't transform color space??? Bailing out...\n");
588
615
                avcodec_close(anim->pCodecCtx);
589
616
                av_close_input_file(anim->pFormatCtx);
590
617
                av_free(anim->pFrameRGB);
596
623
 
597
624
#ifdef FFMPEG_SWSCALE_COLOR_SPACE_SUPPORT
598
625
        /* Try do detect if input has 0-255 YCbCR range (JFIF Jpeg MotionJpeg) */
599
 
        if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int**)&inv_table, &srcRange,
600
 
                &table, &dstRange, &brightness, &contrast, &saturation)) {
601
 
 
 
626
        if (!sws_getColorspaceDetails(anim->img_convert_ctx, (int **)&inv_table, &srcRange,
 
627
                                      &table, &dstRange, &brightness, &contrast, &saturation))
 
628
        {
602
629
                srcRange = srcRange || anim->pCodecCtx->color_range == AVCOL_RANGE_JPEG;
603
630
                inv_table = sws_getCoefficients(anim->pCodecCtx->colorspace);
604
631
 
605
632
                if (sws_setColorspaceDetails(anim->img_convert_ctx, (int *)inv_table, srcRange,
606
 
                        table, dstRange, brightness, contrast, saturation)) {
607
 
 
 
633
                                             table, dstRange, brightness, contrast, saturation))
 
634
                {
608
635
                        printf("Warning: Could not set libswscale colorspace details.\n");
609
 
                        }
 
636
                }
610
637
        }
611
638
        else {
612
639
                printf("Warning: Could not set libswscale colorspace details.\n");
622
649
 * Output is anim->last_frame
623
650
 */
624
651
 
625
 
static void ffmpeg_postprocess(struct anim * anim)
 
652
static void ffmpeg_postprocess(struct anim *anim)
626
653
{
627
 
        AVFrame * input = anim->pFrame;
628
 
        ImBuf * ibuf = anim->last_frame;
 
654
        AVFrame *input = anim->pFrame;
 
655
        ImBuf *ibuf = anim->last_frame;
629
656
        int filter_y = 0;
630
657
 
631
 
        ibuf->profile = IB_PROFILE_SRGB;
632
 
 
633
658
        if (!anim->pFrameComplete) {
634
659
                return;
635
660
        }
636
661
 
637
662
        /* This means the data wasnt read properly, 
638
663
         * this check stops crashing */
639
 
        if (input->data[0]==0 && input->data[1]==0 &&
640
 
            input->data[2]==0 && input->data[3]==0)
 
664
        if (input->data[0] == 0 && input->data[1] == 0 &&
 
665
            input->data[2] == 0 && input->data[3] == 0)
641
666
        {
642
667
                fprintf(stderr, "ffmpeg_fetchibuf: "
643
 
                        "data not read properly...\n");
 
668
                        "data not read properly...\n");
644
669
                return;
645
670
        }
646
671
 
652
677
 
653
678
        if (anim->ib_flags & IB_animdeinterlace) {
654
679
                if (avpicture_deinterlace(
655
 
                            (AVPicture*) 
656
 
                            anim->pFrameDeinterlaced,
657
 
                            (const AVPicture*)
658
 
                            anim->pFrame,
659
 
                            anim->pCodecCtx->pix_fmt,
660
 
                            anim->pCodecCtx->width,
661
 
                            anim->pCodecCtx->height)
662
 
                    < 0) {
 
680
                        (AVPicture *)
 
681
                        anim->pFrameDeinterlaced,
 
682
                        (const AVPicture *)
 
683
                        anim->pFrame,
 
684
                        anim->pCodecCtx->pix_fmt,
 
685
                        anim->pCodecCtx->width,
 
686
                        anim->pCodecCtx->height) < 0)
 
687
                {
663
688
                        filter_y = TRUE;
664
689
                }
665
690
                else {
667
692
                }
668
693
        }
669
694
        
670
 
        avpicture_fill((AVPicture*) anim->pFrameRGB,
671
 
                       (unsigned char*) ibuf->rect,
 
695
        avpicture_fill((AVPicture *) anim->pFrameRGB,
 
696
                       (unsigned char *) ibuf->rect,
672
697
                       PIX_FMT_RGBA, anim->x, anim->y);
673
698
 
674
699
        if (ENDIAN_ORDER == B_ENDIAN) {
675
 
                int * dstStride   = anim->pFrameRGB->linesize;
676
 
                uint8_t** dst     = anim->pFrameRGB->data;
 
700
                int *dstStride   = anim->pFrameRGB->linesize;
 
701
                uint8_t **dst     = anim->pFrameRGB->data;
677
702
                int dstStride2[4] = { dstStride[0], 0, 0, 0 };
678
 
                uint8_t* dst2[4]  = { dst[0], 0, 0, 0 };
679
 
                int x,y,h,w;
680
 
                unsigned char* bottom;
681
 
                unsigned char* top;
 
703
                uint8_t *dst2[4]  = { dst[0], 0, 0, 0 };
 
704
                int x, y, h, w;
 
705
                unsigned char *bottom;
 
706
                unsigned char *top;
682
707
                
683
708
                sws_scale(anim->img_convert_ctx,
684
 
                          (const uint8_t * const *)input->data,
 
709
                          (const uint8_t *const *)input->data,
685
710
                          input->linesize,
686
711
                          0,
687
712
                          anim->pCodecCtx->height,
688
713
                          dst2,
689
714
                          dstStride2);
690
715
                
691
 
                bottom = (unsigned char*) ibuf->rect;
692
 
                top = bottom + ibuf->x * (ibuf->y-1) * 4;
 
716
                bottom = (unsigned char *) ibuf->rect;
 
717
                top = bottom + ibuf->x * (ibuf->y - 1) * 4;
693
718
                
694
719
                h = (ibuf->y + 1) / 2;
695
720
                w = ibuf->x;
696
721
                
697
722
                for (y = 0; y < h; y++) {
698
723
                        unsigned char tmp[4];
699
 
                        unsigned int * tmp_l =
700
 
                                (unsigned int*) tmp;
 
724
                        unsigned int *tmp_l =
 
725
                            (unsigned int *) tmp;
701
726
                        
702
727
                        for (x = 0; x < w; x++) {
703
728
                                tmp[0] = bottom[0];
710
735
                                bottom[2] = top[2];
711
736
                                bottom[3] = top[3];
712
737
                                
713
 
                                *(unsigned int*) top = *tmp_l;
 
738
                                *(unsigned int *) top = *tmp_l;
714
739
                                
715
 
                                bottom +=4;
 
740
                                bottom += 4;
716
741
                                top += 4;
717
742
                        }
718
743
                        top -= 8 * w;
719
744
                }
720
745
        }
721
746
        else {
722
 
                int * dstStride   = anim->pFrameRGB->linesize;
723
 
                uint8_t** dst     = anim->pFrameRGB->data;
 
747
                int *dstStride   = anim->pFrameRGB->linesize;
 
748
                uint8_t **dst     = anim->pFrameRGB->data;
724
749
                int dstStride2[4] = { -dstStride[0], 0, 0, 0 };
725
 
                uint8_t* dst2[4]  = { dst[0] + (anim->y - 1)*dstStride[0],
726
 
                                      0, 0, 0 };
 
750
                uint8_t *dst2[4]  = { dst[0] + (anim->y - 1) * dstStride[0],
 
751
                                          0, 0, 0 };
727
752
                
728
753
                sws_scale(anim->img_convert_ctx,
729
 
                          (const uint8_t * const *)input->data,
 
754
                          (const uint8_t *const *)input->data,
730
755
                          input->linesize,
731
756
                          0,
732
757
                          anim->pCodecCtx->height,
741
766
 
742
767
/* decode one video frame also considering the packet read into next_packet */
743
768
 
744
 
static int ffmpeg_decode_video_frame(struct anim * anim)
 
769
static int ffmpeg_decode_video_frame(struct anim *anim)
745
770
{
746
771
        int rval = 0;
747
772
 
761
786
                       ? "->" : "  ",
762
787
                       anim->next_packet.stream_index, 
763
788
                       anim->videoStream,
764
 
                       (anim->next_packet.dts == AV_NOPTS_VALUE) ? -1:
 
789
                       (anim->next_packet.dts == AV_NOPTS_VALUE) ? -1 :
765
790
                       (long long int)anim->next_packet.dts,
766
 
                       (anim->next_packet.pts == AV_NOPTS_VALUE) ? -1:
 
791
                       (anim->next_packet.pts == AV_NOPTS_VALUE) ? -1 :
767
792
                       (long long int)anim->next_packet.pts,
768
793
                       (anim->next_packet.flags & AV_PKT_FLAG_KEY) ? 
769
794
                       " KEY" : "");
771
796
                        anim->pFrameComplete = 0;
772
797
 
773
798
                        avcodec_decode_video2(
774
 
                                anim->pCodecCtx, 
775
 
                                anim->pFrame, &anim->pFrameComplete, 
776
 
                                &anim->next_packet);
 
799
                            anim->pCodecCtx,
 
800
                            anim->pFrame, &anim->pFrameComplete,
 
801
                            &anim->next_packet);
777
802
 
778
803
                        if (anim->pFrameComplete) {
779
804
                                anim->next_pts = av_get_pts_from_frame(
780
 
                                        anim->pFormatCtx, anim->pFrame);
 
805
                                        anim->pFormatCtx, anim->pFrame);
781
806
 
782
807
                                av_log(anim->pFormatCtx,
783
808
                                       AV_LOG_DEBUG,
785
810
                                       "pkt_pts=%lld, guessed_pts=%lld\n",
786
811
                                       (anim->pFrame->pts == AV_NOPTS_VALUE) ?
787
812
                                       -1 : (long long int)anim->pFrame->pts,
788
 
                                       (anim->pFrame->pkt_pts 
789
 
                                        == AV_NOPTS_VALUE) ?
 
813
                                       (anim->pFrame->pkt_pts == AV_NOPTS_VALUE) ?
790
814
                                       -1 : (long long int)anim->pFrame->pkt_pts,
791
 
                                        (long long int)anim->next_pts);
 
815
                                       (long long int)anim->next_pts);
792
816
                                break;
793
817
                        }
794
818
                }
796
820
                anim->next_packet.stream_index = -1;
797
821
        }
798
822
        
 
823
        if (rval == AVERROR_EOF) {
 
824
                /* this sets size and data fields to zero,
 
825
                   which is necessary to decode the remaining data
 
826
                   in the decoder engine after EOF. It also prevents a memory
 
827
                   leak, since av_read_frame spills out a full size packet even
 
828
                   on EOF... (and: it's save to call on NULL packets) */
 
829
 
 
830
                av_free_packet(&anim->next_packet);
 
831
 
 
832
                anim->next_packet.size = 0;
 
833
                anim->next_packet.data = 0;
 
834
 
 
835
                anim->pFrameComplete = 0;
 
836
 
 
837
                avcodec_decode_video2(
 
838
                        anim->pCodecCtx,
 
839
                        anim->pFrame, &anim->pFrameComplete,
 
840
                        &anim->next_packet);
 
841
 
 
842
                if (anim->pFrameComplete) {
 
843
                        anim->next_pts = av_get_pts_from_frame(
 
844
                                anim->pFormatCtx, anim->pFrame);
 
845
 
 
846
                        av_log(anim->pFormatCtx,
 
847
                               AV_LOG_DEBUG,
 
848
                               "  FRAME DONE (after EOF): next_pts=%lld "
 
849
                               "pkt_pts=%lld, guessed_pts=%lld\n",
 
850
                               (anim->pFrame->pts == AV_NOPTS_VALUE) ?
 
851
                               -1 : (long long int)anim->pFrame->pts,
 
852
                               (anim->pFrame->pkt_pts == AV_NOPTS_VALUE) ?
 
853
                               -1 : (long long int)anim->pFrame->pkt_pts,
 
854
                               (long long int)anim->next_pts);
 
855
                        rval = 0;
 
856
                }
 
857
        }
 
858
 
799
859
        if (rval < 0) {
800
860
                anim->next_packet.stream_index = -1;
801
861
 
802
862
                av_log(anim->pFormatCtx,
803
863
                       AV_LOG_ERROR, "  DECODE READ FAILED: av_read_frame() "
804
 
                       "returned error: %d\n",  rval);
 
864
                       "returned error: %d\n",  rval);
805
865
        }
806
866
 
807
867
        return (rval >= 0);
808
868
}
809
869
 
810
870
static void ffmpeg_decode_video_frame_scan(
811
 
        struct anim * anim, int64_t pts_to_search)
 
871
        struct anim *anim, int64_t pts_to_search)
812
872
{
813
873
        /* there seem to exist *very* silly GOP lengths out in the wild... */
814
874
        int count = 1000;
845
905
        }
846
906
}
847
907
 
848
 
static int match_format(const char *name, AVFormatContext * pFormatCtx)
 
908
static int match_format(const char *name, AVFormatContext *pFormatCtx)
849
909
{
850
910
        const char *p;
851
911
        int len, namelen;
860
920
                len = MAX2(p - names, namelen);
861
921
                if (!BLI_strncasecmp(name, names, len))
862
922
                        return 1;
863
 
                names = p+1;
 
923
                names = p + 1;
864
924
        }
865
925
        return !BLI_strcasecmp(name, names);
866
926
}
867
927
 
868
928
static int ffmpeg_seek_by_byte(AVFormatContext *pFormatCtx)
869
929
{
870
 
        static const char * byte_seek_list [] = { "mpegts", 0 };
871
 
        const char ** p;
 
930
        static const char *byte_seek_list[] = { "mpegts", 0 };
 
931
        const char **p;
872
932
 
873
933
        if (pFormatCtx->iformat->flags & AVFMT_TS_DISCONT) {
874
934
                return TRUE;
885
945
        return FALSE;
886
946
}
887
947
 
888
 
static ImBuf * ffmpeg_fetchibuf(struct anim * anim, int position,
889
 
                                IMB_Timecode_Type tc) {
 
948
static ImBuf *ffmpeg_fetchibuf(struct anim *anim, int position,
 
949
                               IMB_Timecode_Type tc) {
890
950
        int64_t pts_to_search = 0;
891
951
        double frame_rate;
892
952
        double pts_time_base;
893
953
        long long st_time; 
894
 
        struct anim_index * tc_index = 0;
895
 
        AVStream * v_st;
 
954
        struct anim_index *tc_index = 0;
 
955
        AVStream *v_st;
896
956
        int new_frame_index = 0; /* To quite gcc barking... */
897
957
        int old_frame_index = 0; /* To quite gcc barking... */
898
958
 
913
973
 
914
974
        if (tc_index) {
915
975
                new_frame_index = IMB_indexer_get_frame_index(
916
 
                        tc_index, position);
 
976
                        tc_index, position);
917
977
                old_frame_index = IMB_indexer_get_frame_index(
918
 
                        tc_index, anim->curposition);
919
 
                pts_to_search = IMB_indexer_get_pts(
920
 
                        tc_index, new_frame_index);
 
978
                        tc_index, anim->curposition);
 
979
                pts_to_search = IMB_indexer_get_pts(
 
980
                        tc_index, new_frame_index);
921
981
        }
922
982
        else {
923
983
                pts_to_search = (long long) 
924
 
                        floor(((double) position) 
925
 
                              / pts_time_base / frame_rate + 0.5);
 
984
                                floor(((double) position) /
 
985
                                      pts_time_base / frame_rate + 0.5);
926
986
 
927
987
                if (st_time != AV_NOPTS_VALUE) {
928
 
                        pts_to_search += st_time / pts_time_base 
929
 
                                / AV_TIME_BASE;
 
988
                        pts_to_search += st_time / pts_time_base / AV_TIME_BASE;
930
989
                }
931
990
        }
932
991
 
933
992
        av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
934
993
               "FETCH: looking for PTS=%lld "
935
994
               "(pts_timebase=%g, frame_rate=%g, st_time=%lld)\n", 
936
 
               (long long int)pts_to_search,pts_time_base, frame_rate, st_time);
 
995
               (long long int)pts_to_search, pts_time_base, frame_rate, st_time);
937
996
 
938
997
        if (anim->last_frame && 
939
 
            anim->last_pts <= pts_to_search && anim->next_pts > pts_to_search) {
 
998
            anim->last_pts <= pts_to_search && anim->next_pts > pts_to_search)
 
999
        {
940
1000
                av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
941
1001
                       "FETCH: frame repeat: last: %lld next: %lld\n",
942
1002
                       (long long int)anim->last_pts, 
957
1017
                ffmpeg_decode_video_frame_scan(anim, pts_to_search);
958
1018
        }
959
1019
        else if (tc_index &&
960
 
                   IMB_indexer_can_scan(tc_index, old_frame_index,
961
 
                                        new_frame_index)) {
962
 
 
 
1020
                 IMB_indexer_can_scan(tc_index, old_frame_index,
 
1021
                                      new_frame_index))
 
1022
        {
963
1023
                av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
964
1024
                       "FETCH: within preseek interval "
965
1025
                       "(index tells us)\n");
974
1034
                        unsigned long long dts;
975
1035
 
976
1036
                        pos = IMB_indexer_get_seek_pos(
977
 
                                tc_index, new_frame_index);
 
1037
                            tc_index, new_frame_index);
978
1038
                        dts = IMB_indexer_get_seek_pos_dts(
979
 
                                tc_index, new_frame_index);
 
1039
                            tc_index, new_frame_index);
980
1040
 
981
1041
                        av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
982
1042
                               "TC INDEX seek pos = %lld\n", pos);
988
1048
                                       "... using BYTE pos\n");
989
1049
 
990
1050
                                ret = av_seek_frame(anim->pFormatCtx, 
991
 
                                                    -1,
992
 
                                                    pos, AVSEEK_FLAG_BYTE);
 
1051
                                                    -1,
 
1052
                                                    pos, AVSEEK_FLAG_BYTE);
993
1053
                                av_update_cur_dts(anim->pFormatCtx, v_st, dts);
994
1054
                        }
995
1055
                        else {
996
1056
                                av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
997
1057
                                       "... using DTS pos\n");
998
1058
                                ret = av_seek_frame(anim->pFormatCtx, 
999
 
                                                    anim->videoStream, 
1000
 
                                                    dts, AVSEEK_FLAG_BACKWARD);
 
1059
                                                    anim->videoStream,
 
1060
                                                    dts, AVSEEK_FLAG_BACKWARD);
1001
1061
                        }
1002
1062
                }
1003
1063
                else {
1004
 
                        pos = (long long) (position - anim->preseek) 
1005
 
                                * AV_TIME_BASE / frame_rate;
 
1064
                        pos = (long long) (position - anim->preseek) *
 
1065
                              AV_TIME_BASE / frame_rate;
1006
1066
 
1007
1067
                        av_log(anim->pFormatCtx, AV_LOG_DEBUG, 
1008
1068
                               "NO INDEX seek pos = %lld, st_time = %lld\n", 
1020
1080
                               "NO INDEX final seek pos = %lld\n", pos);
1021
1081
 
1022
1082
                        ret = av_seek_frame(anim->pFormatCtx, -1, 
1023
 
                                            pos, AVSEEK_FLAG_BACKWARD);
 
1083
                                            pos, AVSEEK_FLAG_BACKWARD);
1024
1084
                }
1025
1085
 
1026
1086
                if (ret < 0) {
1040
1100
                        anim->next_packet.stream_index = -1;
1041
1101
                }
1042
1102
 
1043
 
                /* memset(anim->pFrame,...) ?? */
 
1103
                /* memset(anim->pFrame, ...) ?? */
1044
1104
 
1045
1105
                if (ret >= 0) {
1046
1106
                        ffmpeg_decode_video_frame_scan(anim, pts_to_search);
1057
1117
 
1058
1118
        IMB_freeImBuf(anim->last_frame);
1059
1119
        anim->last_frame = IMB_allocImBuf(anim->x, anim->y, 32, IB_rect);
 
1120
        anim->last_frame->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
1060
1121
 
1061
1122
        ffmpeg_postprocess(anim);
1062
1123
 
1071
1132
        return anim->last_frame;
1072
1133
}
1073
1134
 
1074
 
static void free_anim_ffmpeg(struct anim * anim)
 
1135
static void free_anim_ffmpeg(struct anim *anim)
1075
1136
{
1076
1137
        if (anim == NULL) return;
1077
1138
 
1098
1159
 
1099
1160
#ifdef WITH_REDCODE
1100
1161
 
1101
 
static int startredcode(struct anim * anim)
 
1162
static int startredcode(struct anim *anim)
1102
1163
{
1103
1164
        anim->redcodeCtx = redcode_open(anim->name);
1104
1165
        if (!anim->redcodeCtx) {
1109
1170
        return 0;
1110
1171
}
1111
1172
 
1112
 
static ImBuf * redcode_fetchibuf(struct anim * anim, int position)
 
1173
static ImBuf *redcode_fetchibuf(struct anim *anim, int position)
1113
1174
{
1114
 
        struct ImBuf * ibuf;
1115
 
        struct redcode_frame * frame;
1116
 
        struct redcode_frame_raw * raw_frame;
 
1175
        struct ImBuf *ibuf;
 
1176
        struct redcode_frame *frame;
 
1177
        struct redcode_frame_raw *raw_frame;
1117
1178
 
1118
1179
        if (!anim->redcodeCtx) {
1119
1180
                return NULL;
1133
1194
                return NULL;
1134
1195
        }
1135
1196
        
1136
 
                ibuf = IMB_allocImBuf(raw_frame->width * 2, 
1137
 
                                      raw_frame->height * 2, 32, IB_rectfloat);
 
1197
        ibuf = IMB_allocImBuf(raw_frame->width * 2,
 
1198
                              raw_frame->height * 2, 32, IB_rectfloat);
1138
1199
 
1139
1200
        redcode_decode_video_float(raw_frame, ibuf->rect_float, 1);
1140
1201
 
1141
1202
        return ibuf;
1142
1203
}
1143
1204
 
1144
 
static void free_anim_redcode(struct anim * anim)
 
1205
static void free_anim_redcode(struct anim *anim)
1145
1206
{
1146
1207
        if (anim->redcodeCtx) {
1147
1208
                redcode_close(anim->redcodeCtx);
1152
1213
 
1153
1214
#endif
1154
1215
 
1155
 
/* probeer volgende plaatje te lezen */
1156
 
/* Geen plaatje, probeer dan volgende animatie te openen */
1157
 
/* gelukt, haal dan eerste plaatje van animatie */
 
1216
/* Try next picture to read */
 
1217
/* No picture, try to open next animation */
 
1218
/* Succeed, remove first image from animation */
1158
1219
 
1159
 
static struct ImBuf * anim_getnew(struct anim * anim)
 
1220
static ImBuf *anim_getnew(struct anim *anim)
1160
1221
{
1161
1222
        struct ImBuf *ibuf = NULL;
1162
1223
 
1163
1224
        if (anim == NULL) return(NULL);
1164
1225
 
1165
1226
        free_anim_movie(anim);
 
1227
 
 
1228
#ifdef WITH_AVI
1166
1229
        free_anim_avi(anim);
 
1230
#endif
 
1231
 
1167
1232
#ifdef WITH_QUICKTIME
1168
1233
        free_anim_quicktime(anim);
1169
1234
#endif
1176
1241
 
1177
1242
 
1178
1243
        if (anim->curtype != 0) return (NULL);
1179
 
        anim->curtype = imb_get_anim_type(anim->name);  
 
1244
        anim->curtype = imb_get_anim_type(anim->name);
1180
1245
 
1181
1246
        switch (anim->curtype) {
1182
 
        case ANIM_SEQUENCE:
1183
 
                ibuf = IMB_loadiffname(anim->name, anim->ib_flags);
1184
 
                if (ibuf) {
1185
 
                        BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
1186
 
                        anim->duration = 1;
1187
 
                }
1188
 
                break;
1189
 
        case ANIM_MOVIE:
1190
 
                if (startmovie(anim)) return (NULL);
1191
 
                ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0); /* fake */
1192
 
                break;
1193
 
        case ANIM_AVI:
1194
 
                if (startavi(anim)) {
1195
 
                        printf("couldnt start avi\n"); 
1196
 
                        return (NULL);
1197
 
                }
1198
 
                ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1199
 
                break;
 
1247
                case ANIM_SEQUENCE:
 
1248
                        ibuf = IMB_loadiffname(anim->name, anim->ib_flags, anim->colorspace);
 
1249
                        if (ibuf) {
 
1250
                                BLI_strncpy(anim->first, anim->name, sizeof(anim->first));
 
1251
                                anim->duration = 1;
 
1252
                        }
 
1253
                        break;
 
1254
                case ANIM_MOVIE:
 
1255
                        if (startmovie(anim)) return (NULL);
 
1256
                        ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0); /* fake */
 
1257
                        break;
 
1258
#ifdef WITH_AVI
 
1259
                case ANIM_AVI:
 
1260
                        if (startavi(anim)) {
 
1261
                                printf("couldnt start avi\n");
 
1262
                                return (NULL);
 
1263
                        }
 
1264
                        ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
 
1265
                        break;
 
1266
#endif
1200
1267
#ifdef WITH_QUICKTIME
1201
 
        case ANIM_QTIME:
1202
 
                if (startquicktime(anim)) return (0);
1203
 
                ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1204
 
                break;
 
1268
                case ANIM_QTIME:
 
1269
                        if (startquicktime(anim)) return (0);
 
1270
                        ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
 
1271
                        break;
1205
1272
#endif
1206
1273
#ifdef WITH_FFMPEG
1207
 
        case ANIM_FFMPEG:
1208
 
                if (startffmpeg(anim)) return (0);
1209
 
                ibuf = IMB_allocImBuf (anim->x, anim->y, 24, 0);
1210
 
                break;
 
1274
                case ANIM_FFMPEG:
 
1275
                        if (startffmpeg(anim)) return (0);
 
1276
                        ibuf = IMB_allocImBuf(anim->x, anim->y, 24, 0);
 
1277
                        break;
1211
1278
#endif
1212
1279
#ifdef WITH_REDCODE
1213
 
        case ANIM_REDCODE:
1214
 
                if (startredcode(anim)) return (0);
1215
 
                ibuf = IMB_allocImBuf (8, 8, 32, 0);
1216
 
                break;
 
1280
                case ANIM_REDCODE:
 
1281
                        if (startredcode(anim)) return (0);
 
1282
                        ibuf = IMB_allocImBuf(8, 8, 32, 0);
 
1283
                        break;
1217
1284
#endif
1218
1285
        }
1219
1286
        return(ibuf);
1220
1287
}
1221
1288
 
1222
 
struct ImBuf * IMB_anim_previewframe(struct anim * anim)
 
1289
struct ImBuf *IMB_anim_previewframe(struct anim *anim)
1223
1290
{
1224
 
        struct ImBuf * ibuf = NULL;
 
1291
        struct ImBuf *ibuf = NULL;
1225
1292
        int position = 0;
1226
1293
        
1227
1294
        ibuf = IMB_anim_absolute(anim, 0, IMB_TC_NONE, IMB_PROXY_NONE);
1229
1296
                IMB_freeImBuf(ibuf);
1230
1297
                position = anim->duration / 2;
1231
1298
                ibuf = IMB_anim_absolute(anim, position, IMB_TC_NONE,
1232
 
                                         IMB_PROXY_NONE);
 
1299
                                         IMB_PROXY_NONE);
1233
1300
        }
1234
1301
        return ibuf;
1235
1302
}
1236
1303
 
1237
 
struct ImBuf * IMB_anim_absolute(struct anim * anim, int position,
1238
 
                                 IMB_Timecode_Type tc,
1239
 
                                 IMB_Proxy_Size preview_size) {
1240
 
        struct ImBuf * ibuf = NULL;
 
1304
struct ImBuf *IMB_anim_absolute(struct anim *anim, int position,
 
1305
                                IMB_Timecode_Type tc,
 
1306
                                IMB_Proxy_Size preview_size) {
 
1307
        struct ImBuf *ibuf = NULL;
1241
1308
        char head[256], tail[256];
1242
1309
        unsigned short digits;
1243
1310
        int pic;
1246
1313
 
1247
1314
        filter_y = (anim->ib_flags & IB_animdeinterlace);
1248
1315
 
1249
 
        if (anim->curtype == 0) {
 
1316
        if (anim->curtype == 0) {
1250
1317
                ibuf = anim_getnew(anim);
1251
1318
                if (ibuf == NULL) {
1252
1319
                        return(NULL);
1253
1320
                }
1254
1321
 
1255
1322
                IMB_freeImBuf(ibuf); /* ???? */
1256
 
                ibuf= NULL;
 
1323
                ibuf = NULL;
1257
1324
        }
1258
1325
 
1259
1326
        if (position < 0) return(NULL);
1260
1327
        if (position >= anim->duration) return(NULL);
1261
1328
 
1262
1329
        if (preview_size != IMB_PROXY_NONE) {
1263
 
                struct anim * proxy = IMB_anim_open_proxy(anim, preview_size);
 
1330
                struct anim *proxy = IMB_anim_open_proxy(anim, preview_size);
1264
1331
 
1265
1332
                if (proxy) {
1266
1333
                        position = IMB_anim_index_get_frame_index(
1267
 
                                anim, tc, position);
 
1334
                            anim, tc, position);
1268
1335
                        return IMB_anim_absolute(
1269
 
                                proxy, position,
1270
 
                                IMB_TC_NONE, IMB_PROXY_NONE);
 
1336
                                   proxy, position,
 
1337
                                   IMB_TC_NONE, IMB_PROXY_NONE);
1271
1338
                }
1272
1339
        }
1273
1340
 
1274
 
        switch(anim->curtype) {
1275
 
        case ANIM_SEQUENCE:
1276
 
                pic = an_stringdec(anim->first, head, tail, &digits);
1277
 
                pic += position;
1278
 
                an_stringenc(anim->name, head, tail, digits, pic);
1279
 
                ibuf = IMB_loadiffname(anim->name, IB_rect);
1280
 
                if (ibuf) {
1281
 
                        anim->curposition = position;
1282
 
                }
1283
 
                break;
1284
 
        case ANIM_MOVIE:
1285
 
                ibuf = movie_fetchibuf(anim, position);
1286
 
                if (ibuf) {
1287
 
                        anim->curposition = position;
1288
 
                        IMB_convert_rgba_to_abgr(ibuf);
1289
 
                        ibuf->profile = IB_PROFILE_SRGB;
1290
 
                }
1291
 
                break;
1292
 
        case ANIM_AVI:
1293
 
                ibuf = avi_fetchibuf(anim, position);
1294
 
                if (ibuf)
1295
 
                        anim->curposition = position;
1296
 
                break;
 
1341
        switch (anim->curtype) {
 
1342
                case ANIM_SEQUENCE:
 
1343
                        pic = an_stringdec(anim->first, head, tail, &digits);
 
1344
                        pic += position;
 
1345
                        an_stringenc(anim->name, head, tail, digits, pic);
 
1346
                        ibuf = IMB_loadiffname(anim->name, IB_rect, anim->colorspace);
 
1347
                        if (ibuf) {
 
1348
                                anim->curposition = position;
 
1349
                        }
 
1350
                        break;
 
1351
                case ANIM_MOVIE:
 
1352
                        ibuf = movie_fetchibuf(anim, position);
 
1353
                        if (ibuf) {
 
1354
                                anim->curposition = position;
 
1355
                                IMB_convert_rgba_to_abgr(ibuf);
 
1356
                        }
 
1357
                        break;
 
1358
#ifdef WITH_AVI
 
1359
                case ANIM_AVI:
 
1360
                        ibuf = avi_fetchibuf(anim, position);
 
1361
                        if (ibuf)
 
1362
                                anim->curposition = position;
 
1363
                        break;
 
1364
#endif
1297
1365
#ifdef WITH_QUICKTIME
1298
 
        case ANIM_QTIME:
1299
 
                ibuf = qtime_fetchibuf(anim, position);
1300
 
                if (ibuf)
1301
 
                        anim->curposition = position;
1302
 
                break;
 
1366
                case ANIM_QTIME:
 
1367
                        ibuf = qtime_fetchibuf(anim, position);
 
1368
                        if (ibuf) {
 
1369
                                if (ibuf->rect) {
 
1370
                                        /* OCIO_TODO: should happen in quicktime module, but it currently doesn't have access
 
1371
                                         *            to color management's internals
 
1372
                                         */
 
1373
                                        ibuf->rect_colorspace = colormanage_colorspace_get_named(anim->colorspace);
 
1374
                                }
 
1375
 
 
1376
                                anim->curposition = position;
 
1377
                        }
 
1378
                        break;
1303
1379
#endif
1304
1380
#ifdef WITH_FFMPEG
1305
 
        case ANIM_FFMPEG:
1306
 
                ibuf = ffmpeg_fetchibuf(anim, position, tc);
1307
 
                if (ibuf)
1308
 
                        anim->curposition = position;
1309
 
                filter_y = 0; /* done internally */
1310
 
                break;
 
1381
                case ANIM_FFMPEG:
 
1382
                        ibuf = ffmpeg_fetchibuf(anim, position, tc);
 
1383
                        if (ibuf)
 
1384
                                anim->curposition = position;
 
1385
                        filter_y = 0; /* done internally */
 
1386
                        break;
1311
1387
#endif
1312
1388
#ifdef WITH_REDCODE
1313
 
        case ANIM_REDCODE:
1314
 
                ibuf = redcode_fetchibuf(anim, position);
1315
 
                if (ibuf) anim->curposition = position;
1316
 
                break;
 
1389
                case ANIM_REDCODE:
 
1390
                        ibuf = redcode_fetchibuf(anim, position);
 
1391
                        if (ibuf) anim->curposition = position;
 
1392
                        break;
1317
1393
#endif
1318
1394
        }
1319
1395
 
1329
1405
 
1330
1406
int IMB_anim_get_duration(struct anim *anim, IMB_Timecode_Type tc)
1331
1407
{
1332
 
        struct anim_index * idx;
 
1408
        struct anim_index *idx;
1333
1409
        if (tc == IMB_TC_NONE) {
1334
1410
                return anim->duration;
1335
1411
        }
1342
1418
        return IMB_indexer_get_duration(idx);
1343
1419
}
1344
1420
 
1345
 
int IMB_anim_get_fps(struct anim * anim, 
1346
 
                     short * frs_sec, float * frs_sec_base)
 
1421
int IMB_anim_get_fps(struct anim *anim,
 
1422
                     short *frs_sec, float *frs_sec_base)
1347
1423
{
1348
1424
        if (anim->frs_sec) {
1349
1425
                *frs_sec = anim->frs_sec;
1353
1429
        return FALSE;
1354
1430
}
1355
1431
 
1356
 
void IMB_anim_set_preseek(struct anim * anim, int preseek)
 
1432
void IMB_anim_set_preseek(struct anim *anim, int preseek)
1357
1433
{
1358
1434
        anim->preseek = preseek;
1359
1435
}
1360
1436
 
1361
 
int IMB_anim_get_preseek(struct anim * anim)
 
1437
int IMB_anim_get_preseek(struct anim *anim)
1362
1438
{
1363
1439
        return anim->preseek;
1364
1440
}