forked from NatronGitHub/openfx-misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeinterlace.cpp
727 lines (619 loc) · 30.7 KB
/
Deinterlace.cpp
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
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
/*
OFX Deinterlace plugin.
Copyright (C) 2014 INRIA
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of the {organization} nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
INRIA
Domaine de Voluceau
Rocquencourt - B.P. 105
78153 Le Chesnay Cedex - France
The skeleton for this source file is from:
OFX Genereator example plugin, a plugin that illustrates the use of the OFX Support library.
Copyright (C) 2004-2005 The Open Effects Association Ltd
Author Bruno Nicoletti [email protected]
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name The Open Effects Association Ltd, nor the names of its
contributors may be used to endorse or promote products derived from this
software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The Open Effects Association Ltd
1 Wardour St
London W1D 6PA
England
*/
#include "Deinterlace.h"
#include <cstring>
#include <cmath>
#include <algorithm>
#include "ofxsImageEffect.h"
#include "ofxsMultiThread.h"
#include "ofxsProcessing.H"
#include "ofxsMacros.h"
#define kPluginName "DeinterlaceOFX"
#define kPluginGrouping "Time"
#define kPluginDescription \
"Deinterlace input stream.\n" \
"The following deinterlacing algorithms are supported:\n" \
"- Weave: This is what 100fps.com calls \"do nothing\". Other names: \"disabled\" or \"no deinterlacing\". Should be used for PsF content.\n" \
"- Blend: Blender (full resolution). Each line of the picture is created as the average of a line from the odd and a line from the even half-pictures. This ignores the fact that they are supposed to be displayed at different times.\n" \
"- Bob: Doubler. Display each half-picture like a full picture, by simply displaying each line twice. Preserves temporal resolution of interlaced video.\n" \
"- Discard: Only display one of the half-pictures, discard the other. Other name: \"single field\". Both temporal and vertical spatial resolutions are halved. Can be used for slower computers or to give interlaced video movie-like look with characteristic judder.\n" \
"- Linear: Doubler. Bob with linear interpolation: instead of displaying each line twice, line 2 is created as the average of line 1 and 3, etc.\n" \
"- Mean: Blender (half resolution). Display a half-picture that is created as the average of the two original half-pictures.\n" \
"- Yadif: Interpolator (Yet Another DeInterlacing Filter) from MPlayer by Michael Niedermayer (http://www.mplayerhq.hu). It checks pixels of previous, current and next frames to re-create the missed field by some local adaptive method (edge-directed interpolation) and uses spatial check to prevent most artifacts." \
#define kPluginIdentifier "net.sf.openfx.Deinterlace"
#define kPluginVersionMajor 1 // Incrementing this number means that you have broken backwards compatibility of the plug-in.
#define kPluginVersionMinor 0 // Increment this when you have fixed a bug or made it faster.
#define kSupportsTiles 0
#define kSupportsMultiResolution 0
#define kSupportsRenderScale 1 // are images still fielded at any renderscale?
#define kRenderThreadSafety eRenderFullySafe
#define kParamMode "mode"
#define kParamModeLabel "Deinterlacing Mode"
#define kParamModeHint "Choice of the deinterlacing mode/algorithm"
#define kParamModeOptionWeave "Weave"
#define kParamModeOptionWeaveHint "This is what 100fps.com calls \"do nothing\". Other names: \"disabled\" or \"no deinterlacing\". Should be used for PsF content."
#define kParamModeOptionBlend "Blend"
#define kParamModeOptionBlendHint "Blender (full resolution). Each line of the picture is created as the average of a line from the odd and a line from the even half-pictures. This ignores the fact that they are supposed to be displayed at different times."
#define kParamModeOptionBob "Bob"
#define kParamModeOptionBobHint "Doubler. Display each half-picture like a full picture, by simply displaying each line twice. Preserves temporal resolution of interlaced video."
#define kParamModeOptionDiscard "Discard"
#define kParamModeOptionDiscardHint "Only display one of the half-pictures, discard the other. Other name: \"single field\". Both temporal and vertical spatial resolutions are halved. Can be used for slower computers or to give interlaced video movie-like look with characteristic judder."
#define kParamModeOptionLinear "Linear"
#define kParamModeOptionLinearHint "Doubler. Bob with linear interpolation: instead of displaying each line twice, line 2 is created as the average of line 1 and 3, etc."
#define kParamModeOptionMean "Mean"
#define kParamModeOptionMeanHint "Blender (half resolution). Display a half-picture that is created as the average of the two original half-pictures."
#define kParamModeOptionYadif "Yadif"
#define kParamModeOptionYadifHint "Interpolator (Yet Another DeInterlacing Filter) from MPlayer by Michael Niedermayer (http://www.mplayerhq.hu). It checks pixels of previous, current and next frames to re-create the missed field by some local adaptive method (edge-directed interpolation) and uses spatial check to prevent most artifacts."
enum DeinterlaceModeEnum {
eDeinterlaceModeWeave,
eDeinterlaceModeBlend,
eDeinterlaceModeBob,
eDeinterlaceModeDiscard,
eDeinterlaceModeLinear,
eDeinterlaceModeMean,
eDeinterlaceModeYadif,
};
#define kParamFieldOrder "fieldOrder"
#define kParamFieldOrderLabel "Field Order"
#define kParamFieldOrderHint "Interlaced field order"
#define kParamFieldOrderOptionLower "Lower field first"
#define kParamFieldOrderOptionUpper "Upper field first"
#define kParamFieldOrderOptionAuto "HD=upper,SD=lower"
enum FieldOrderEnum {
eFieldOrderLower,
eFieldOrderUpper,
eFieldOrderAuto,
};
#define kParamParity "parity"
#define kParamParityLabel "Parity"
#define kParamParityHint "Interpolate which field"
#define kParamParityOptionLower "Lower"
#define kParamParityOptionUpper "Upper"
enum ParityEnum {
eParityLower,
eParityUpper,
};
#define kParamDoubleFramerate "doubleFramerate"
#define kParamDoubleFramerateLabel "Double Framerate"
#define kParamDoubleFramerateHint "Each input frame produces two output frames, and the framerate is doubled."
#define kParamYadifMode "yadifMode"
#define kParamYadifModeLabel "Yadif Processing Mode"
#define kParamYadifModeHint "Mode of checking fields"
#define kParamYadifModeOptionTemporalSpatial "Temporal & spatial"
#define kParamYadifModeOptionTemporalSpatialHint "temporal and spatial interlacing check (default)."
#define kParamYadifModeOptionTemporal "Temporal only"
#define kParamYadifModeOptionTemporalHint "skips spatial interlacing check."
enum YadifModeEnum {
eYadifModeTemporalSpatial,
eYadifModeTemporal,
};
class DeinterlacePlugin : public OFX::ImageEffect
{
public:
DeinterlacePlugin(OfxImageEffectHandle handle) : ImageEffect(handle), dstClip_(0), srcClip_(0)
{
dstClip_ = fetchClip(kOfxImageEffectOutputClipName);
srcClip_ = fetchClip(kOfxImageEffectSimpleSourceClipName);
mode = fetchChoiceParam("mode");
fieldOrder = fetchChoiceParam("fieldOrder");
parity = fetchChoiceParam("parity");
}
private:
virtual void render(const OFX::RenderArguments &args) OVERRIDE FINAL;
/** @brief get the clip preferences */
virtual void getClipPreferences(OFX::ClipPreferencesSetter &clipPreferences) OVERRIDE FINAL;
// override the rod call
virtual bool getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args, OfxRectD &rod) OVERRIDE FINAL;
/* override is identity */
virtual bool isIdentity(const OFX::IsIdentityArguments &args, OFX::Clip * &identityClip, double &identityTime) OVERRIDE FINAL;
private:
// do not need to delete these, the ImageEffect is managing them for us
OFX::Clip *dstClip_;
OFX::Clip *srcClip_;
OFX::ChoiceParam *fieldOrder, *mode, *parity;
};
// =========== GNU Lesser General Public License code start =================
// Yadif (yet another deinterlacing filter)
// http://avisynth.org.ru/yadif/yadif.html
// http://mplayerhq.hu
// Original port to OFX/Vegas by George Yohng http://yohng.com
// Rewritten after yadif relicensing to LGPL:
// http://git.videolan.org/?p=ffmpeg.git;a=commit;h=194ef56ba7e659196fe554782d797b1b45c3915f
// Copyright notice and licence from the original libavfilter/vf_yadif.c file:
/*
* Copyright (C) 2006-2011 Michael Niedermayer <[email protected]>
* 2010 James Darnley <[email protected]>
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
//#define FFMAX(a,b) ((a) < (b) ? (b) : (a))
//#define FFABS(a) ((a) > 0 ? (a) : (-(a)))
#define FFMIN(a,b) std::min(a,b)
#define FFMAX(a,b) std::max(a,b)
#define FFABS(a) std::abs(a)
#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
inline float halven(float f) { return f*0.5f; }
inline int halven(int i) { return i>>1; }
inline int one1(unsigned char *) { return 1; }
inline int one1(unsigned short *) { return 1; }
inline float one1(float *) { return 0.; }
#define CHECK(j)\
{ Diff score = FFABS(cur[mrefs - ch + (j)] - cur[prefs - ch - (j)])\
+ FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\
+ FFABS(cur[mrefs + ch + (j)] - cur[prefs + ch - (j)]);\
if(score < spatial_score){\
spatial_score= score;\
spatial_pred= halven(cur[mrefs +(j)] + cur[prefs -(j)]);\
/* The is_not_edge argument here controls when the code will enter a branch
* which reads up to and including x-3 and x+3. */
#define FILTER(start, end, is_not_edge) \
for (x = start; x < end; x++) { \
Diff c= cur[mrefs]; \
Diff d= halven(prev2[0] + next2[0]); \
Diff e= cur[prefs]; \
Diff temporal_diff0= FFABS(prev2[0] - next2[0]); \
Diff temporal_diff1=halven( FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) ); \
Diff temporal_diff2=halven( FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) ); \
Diff diff= FFMAX3(halven(temporal_diff0), temporal_diff1, temporal_diff2); \
Diff spatial_pred= halven(c+e); \
\
if (is_not_edge) {\
Diff spatial_score = FFABS(cur[mrefs-ch] - cur[prefs-ch]) + FFABS(c-e) \
+ FFABS(cur[mrefs+ch] - cur[prefs+ch]) - one1((Comp*)0); \
CHECK(-ch) CHECK(-(ch*2)) }} }} \
CHECK( ch) CHECK( (ch*2)) }} }} \
}\
\
if (!(mode&2)) { \
Diff b = halven(prev2[2 * mrefs] + next2[2 * mrefs]); \
Diff f = halven(prev2[2 * prefs] + next2[2 * prefs]); \
Diff max = FFMAX3(d - e, d - c, FFMIN(b - c, f - e)); \
Diff min = FFMIN3(d - e, d - c, FFMAX(b - c, f - e)); \
\
diff = FFMAX3(diff, min, -max); \
} \
\
if (spatial_pred > d + diff) \
spatial_pred = d + diff; \
else if (spatial_pred < d - diff) \
spatial_pred = d - diff; \
\
dst[0] = (Comp)spatial_pred; \
\
dst += ch; \
cur += ch; \
prev += ch; \
next += ch; \
prev2 += ch; \
next2 += ch; \
}
template<int ch,typename Comp,typename Diff>
inline void filter_line_c(Comp *dst1,
const Comp *prev1, const Comp *cur1, const Comp *next1,
int w, int prefs, int mrefs, int parity, int mode)
{
Comp *dst = dst1;
const Comp *prev = prev1;
const Comp *cur = cur1;
const Comp *next = next1;
int x;
const Comp *prev2 = parity ? prev : cur ;
const Comp *next2 = parity ? cur : next;
/* The function is called with the pointers already pointing to data[3] and
* with 6 subtracted from the width. This allows the FILTER macro to be
* called so that it processes all the pixels normally. A constant value of
* true for is_not_edge lets the compiler ignore the if statement. */
FILTER(0, w, 1)
}
#if 0 // filter_edges is only necessary if we are using the assembly version of filter_line
#define MAX_ALIGN 8
template<int ch,typename Comp,typename Diff>
inline void filter_edges(Comp *dst1,
const Comp *prev1, const Comp *cur1, const Comp *next1,
int w, int prefs, int mrefs, int parity, int mode)
{
Comp *dst = dst1;
const Comp *prev = prev1;
const Comp *cur = cur1;
const Comp *next = next1;
int x;
const Comp *prev2 = parity ? prev : cur ;
const Comp *next2 = parity ? cur : next;
/* Only edge pixels need to be processed here. A constant value of false
* for is_not_edge should let the compiler ignore the whole branch. */
FILTER(0, 3, 0)
dst = dst1 + (w - (MAX_ALIGN/sizeof(Comp)-1))*ch;
prev = prev1 + (w - (MAX_ALIGN/sizeof(Comp)-1))*ch;
cur = cur1 + (w - (MAX_ALIGN/sizeof(Comp)-1))*ch;
next = next1 + (w - (MAX_ALIGN/sizeof(Comp)-1))*ch;
prev2 = parity ? prev : cur;
next2 = parity ? cur : next;
FILTER(w - (MAX_ALIGN/sizeof(Comp)-1), w - 3, 1)
FILTER(w - 3, w, 0)
}
#endif // 0
inline void interpolate(unsigned char *dst, const unsigned char *cur0, const unsigned char *cur2, int w)
{
int x;
for (x=0; x<w; x++) {
dst[x] = (cur0[x] + cur2[x] + 1)>>1; // simple average
}
}
inline void interpolate(float *dst, const float *cur0, const float *cur2, int w)
{
int x;
for (x=0; x<w; x++) {
dst[x] = (cur0[x] + cur2[x] )*0.5f; // simple average
}
}
template<int ch,typename Comp,typename Diff>
static void filter_plane(int mode, Comp *dst, int dst_stride,
const Comp *prev0, const Comp *cur0, const Comp *next0,
int refs, int w, int h, int parity, int tff)
{
for (int y = 0; y < h; ++y) {
if (((y ^ parity) & 1)) {
const Comp *prev= prev0 + y*refs;
const Comp *cur = cur0 + y*refs;
const Comp *next= next0 + y*refs;
Comp *dst2= dst + y*dst_stride;
for (int c = 0; c < ch; ++c) {
filter_line_c<ch,Comp,Diff>(dst2 + c, prev + c, cur + c, next + c, w,
y + 1 < h ? refs : -refs,
y ? -refs : refs,
parity ^ tff, mode);
}
} else {
memcpy(&dst[y * dst_stride],
&cur0[y * refs], w * ch * sizeof(Comp)); // copy original
}
}
}
template<int ch,typename Comp,typename Diff>
static void filter_plane_ofx(int mode,
OFX::Image *dst_,
const OFX::Image *srcp,
const OFX::Image *src,
const OFX::Image *srcn,
int parity, int tff)
{
Comp *dst = (Comp*)dst_->getPixelData(); // change this when we support renderWindow
int dst_stride = dst_->getRowBytes() / sizeof(Comp);
const Comp *prev0 = (const Comp*)(srcp ? srcp->getPixelData() : src->getPixelData());
const Comp *cur0 = (const Comp*)src->getPixelData();
const Comp *next0 = (const Comp*)(srcn ? srcn->getPixelData() : src->getPixelData());
int refs = src->getRowBytes() / sizeof(Comp);
const OfxRectI bounds = dst_->getBounds();
filter_plane<ch, Comp, Diff>(mode, dst, dst_stride,
prev0, cur0, next0,
refs,
bounds.x2 - bounds.x1, bounds.y2 - bounds.y1,
parity, tff);
}
// =========== GNU Lesser General Public License code end =================
void DeinterlacePlugin::render(const OFX::RenderArguments &args)
{
if (!kSupportsRenderScale && (args.renderScale.x != 1. || args.renderScale.y != 1.)) {
OFX::throwSuiteStatusException(kOfxStatFailed);
}
OFX::BitDepthEnum dstBitDepth = dstClip_->getPixelDepth();
OFX::PixelComponentEnum dstComponents = dstClip_->getPixelComponents();
std::auto_ptr<OFX::Image> dst(dstClip_->fetchImage(args.time));
std::auto_ptr<const OFX::Image> src(srcClip_->fetchImage(args.time)),
srcp(srcClip_->fetchImage(args.time-1.0)),
srcn(srcClip_->fetchImage(args.time+1.0));
if (!src.get() || !dst.get() || !srcp.get() || !srcn.get()) {
OFX::throwSuiteStatusException(kOfxStatFailed);
}
const OfxRectI rect = dst->getBounds();
int width=rect.x2-rect.x1;
int height=rect.y2-rect.y1;
int imode = 0;
int ifieldOrder = 2;
int iparity = 0;
mode->getValueAtTime(args.time,imode);
fieldOrder->getValueAtTime(args.time,ifieldOrder);
parity->getValueAtTime(args.time,iparity);
imode*=2;
if (ifieldOrder==2) {
if (width>1024) {
ifieldOrder=1;
} else {
ifieldOrder=0;
}
}
if (width < 3 || height < 3) {
// Video of less than 3 columns or lines is not supported
// just copy sc to dst
for (int y=0; y<height; y++) {
memcpy(dst->getPixelAddress(0,y),src->getPixelAddress(0,y),abs(src->getRowBytes()));
}
} else {
if (dstComponents == OFX::ePixelComponentRGBA) {
switch(dstBitDepth) {
case OFX::eBitDepthUByte:
filter_plane_ofx<4,unsigned char,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthUShort:
filter_plane_ofx<4,unsigned short,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthFloat:
filter_plane_ofx<4,float,float>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
default:
break;
}
} else if (dstComponents == OFX::ePixelComponentRGB) {
switch(dstBitDepth) {
case OFX::eBitDepthUByte:
filter_plane_ofx<3,unsigned char,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthUShort:
filter_plane_ofx<3,unsigned short,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthFloat:
filter_plane_ofx<3,float,float>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
default:
break;
}
} else if (dstComponents == OFX::ePixelComponentAlpha) {
switch(dstBitDepth) {
case OFX::eBitDepthUByte:
filter_plane_ofx<1,unsigned char,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthUShort:
filter_plane_ofx<1,unsigned short,int>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
case OFX::eBitDepthFloat:
filter_plane_ofx<1,float,float>(imode, // mode
dst.get(),
srcp.get(), src.get(), srcn.get(),
iparity,ifieldOrder); // parity, tff
break;
default:
break;
}
}
}
}
/* Override the clip preferences */
void
DeinterlacePlugin::getClipPreferences(OFX::ClipPreferencesSetter &clipPreferences)
{
// set the fielding of dstClip_
clipPreferences.setOutputFielding(OFX::eFieldNone);
}
bool
DeinterlacePlugin::getRegionOfDefinition(const OFX::RegionOfDefinitionArguments &args,
OfxRectD &/*rod*/)
{
if (!kSupportsRenderScale && (args.renderScale.x != 1. || args.renderScale.y != 1.)) {
OFX::throwSuiteStatusException(kOfxStatFailed);
}
return false;
}
bool
DeinterlacePlugin::isIdentity(const OFX::IsIdentityArguments &args,
OFX::Clip * &/*identityClip*/,
double &/*identityTime*/)
{
if (!kSupportsRenderScale && (args.renderScale.x != 1. || args.renderScale.y != 1.)) {
OFX::throwSuiteStatusException(kOfxStatFailed);
}
return false;
}
mDeclarePluginFactory(DeinterlacePluginFactory, {}, {});
using namespace OFX;
void DeinterlacePluginFactory::describe(OFX::ImageEffectDescriptor &desc)
{
// basic labels
desc.setLabels(kPluginName, kPluginName, kPluginName);
desc.setPluginGrouping(kPluginGrouping);
desc.setPluginDescription(kPluginDescription);
// add supported context
desc.addSupportedContext(eContextFilter);
desc.addSupportedContext(eContextGeneral);
// add supported pixel depths
desc.addSupportedBitDepth(eBitDepthUByte);
desc.addSupportedBitDepth(eBitDepthUShort);
desc.addSupportedBitDepth(eBitDepthFloat);
// set a few flags
desc.setSingleInstance(false);
desc.setHostFrameThreading(false);
desc.setSupportsMultiResolution(kSupportsMultiResolution);
desc.setSupportsTiles(kSupportsTiles);
desc.setTemporalClipAccess(true);
desc.setRenderTwiceAlways(false);
desc.setSupportsMultipleClipPARs(false);
desc.setRenderThreadSafety(kRenderThreadSafety);
}
void DeinterlacePluginFactory::describeInContext(OFX::ImageEffectDescriptor &desc, OFX::ContextEnum /*context*/)
{
// Source clip only in the filter context
// create the mandated source clip
ClipDescriptor *srcClip = desc.defineClip(kOfxImageEffectSimpleSourceClipName);
srcClip->addSupportedComponent(ePixelComponentRGBA);
srcClip->addSupportedComponent(ePixelComponentRGB);
srcClip->addSupportedComponent(ePixelComponentAlpha);
srcClip->setTemporalClipAccess(true);
srcClip->setSupportsTiles(kSupportsTiles);
srcClip->setIsMask(false);
srcClip->setFieldExtraction(OFX::eFieldExtractBoth);
// create the mandated output clip
ClipDescriptor *dstClip = desc.defineClip(kOfxImageEffectOutputClipName);
dstClip->addSupportedComponent(ePixelComponentRGBA);
srcClip->addSupportedComponent(ePixelComponentRGB);
dstClip->addSupportedComponent(ePixelComponentAlpha);
dstClip->setSupportsTiles(kSupportsTiles);
PageParamDescriptor *page = desc.definePageParam("Controls");
{
ChoiceParamDescriptor *param = desc.defineChoiceParam(kParamMode);
param->setLabels(kParamModeLabel, kParamModeLabel, kParamModeLabel);
param->setHint(kParamModeHint);
assert(param->getNOptions() == eDeinterlaceModeWeave);
param->appendOption(kParamModeOptionWeave, kParamModeOptionWeaveHint);
assert(param->getNOptions() == eDeinterlaceModeBlend);
param->appendOption(kParamModeOptionBlend, kParamModeOptionBlendHint);
assert(param->getNOptions() == eDeinterlaceModeBob);
param->appendOption(kParamModeOptionBob, kParamModeOptionBobHint);
assert(param->getNOptions() == eDeinterlaceModeDiscard);
param->appendOption(kParamModeOptionDiscard, kParamModeOptionDiscardHint);
assert(param->getNOptions() == eDeinterlaceModeLinear);
param->appendOption(kParamModeOptionLinear, kParamModeOptionLinearHint);
assert(param->getNOptions() == eDeinterlaceModeMean);
param->appendOption(kParamModeOptionMean, kParamModeOptionMeanHint);
assert(param->getNOptions() == eDeinterlaceModeYadif);
param->appendOption(kParamModeOptionYadif, kParamModeOptionYadifHint);
param->setDefault(int(eDeinterlaceModeYadif));
param->setAnimates(true); // can animate
param->setIsSecret(true); // Not yet implemented!
page->addChild(*param);
}
{
ChoiceParamDescriptor *param = desc.defineChoiceParam(kParamFieldOrder);
param->setLabels(kParamFieldOrderLabel, kParamFieldOrderLabel, kParamFieldOrderLabel);
param->setHint(kParamFieldOrderHint);
assert(param->getNOptions() == eFieldOrderLower);
param->appendOption(kParamFieldOrderOptionLower);
assert(param->getNOptions() == eFieldOrderUpper);
param->appendOption(kParamFieldOrderOptionUpper);
assert(param->getNOptions() == eFieldOrderAuto);
param->appendOption(kParamFieldOrderOptionAuto);
param->setDefault(int(eFieldOrderAuto));
param->setAnimates(true); // can animate
page->addChild(*param);
}
{
ChoiceParamDescriptor *param = desc.defineChoiceParam(kParamParity);
param->setLabels(kParamParityLabel, kParamParityLabel, kParamParityLabel);
param->setHint(kParamParityHint);
assert(param->getNOptions() == eParityLower);
param->appendOption(kParamParityOptionLower);
assert(param->getNOptions() == eParityUpper);
param->appendOption(kParamParityOptionUpper);
param->setDefault(int(eParityLower));
param->setAnimates(true); // can animate
page->addChild(*param);
}
{
ChoiceParamDescriptor *param = desc.defineChoiceParam(kParamYadifMode);
param->setLabels(kParamYadifModeLabel, kParamYadifModeLabel, kParamYadifModeLabel);
param->setHint(kParamYadifModeHint);
assert(param->getNOptions() == eYadifModeTemporalSpatial);
param->appendOption(kParamYadifModeOptionTemporalSpatial, kParamYadifModeOptionTemporalSpatialHint);
assert(param->getNOptions() == eYadifModeTemporal);
param->appendOption(kParamYadifModeOptionTemporal, kParamYadifModeOptionTemporalHint);
param->setDefault(eYadifModeTemporalSpatial);
param->setAnimates(true); // can animate
page->addChild(*param);
}
{
BooleanParamDescriptor *param = desc.defineBooleanParam(kParamDoubleFramerate);
param->setLabels(kParamDoubleFramerateLabel, kParamDoubleFramerateLabel, kParamDoubleFramerateLabel);
param->setHint(kParamDoubleFramerateHint);
param->setIsSecret(true); // Not yet implemented!
page->addChild(*param);
}
}
ImageEffect* DeinterlacePluginFactory::createInstance(OfxImageEffectHandle handle, OFX::ContextEnum /*context*/)
{
return new DeinterlacePlugin(handle);
}
void getDeinterlacePluginID(OFX::PluginFactoryArray &ids)
{
static DeinterlacePluginFactory p(kPluginIdentifier, kPluginVersionMajor, kPluginVersionMinor);
ids.push_back(&p);
}