== FFMPEG ==
[blender-staging.git] / source / blender / src / buttons_scene.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19  *
20  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21  * All rights reserved.
22  *
23  * The Original Code is: all of this file.
24  *
25  * Contributor(s): none yet.
26  *
27  * ***** END GPL LICENSE BLOCK *****
28  */
29
30 #include <time.h>
31 #include <math.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "MEM_guardedalloc.h"
36 #include "BLO_sys_types.h" // for intptr_t support
37 #include "DNA_node_types.h"
38 #include "DNA_screen_types.h"
39 #include "DNA_space_types.h"
40 #include "DNA_scene_types.h"
41 #include "DNA_sound_types.h"
42 #include "DNA_sequence_types.h"
43 #include "DNA_userdef_types.h"
44 #include "DNA_packedFile_types.h"
45
46 #include "BKE_global.h"
47 #include "BKE_main.h"
48 #include "BKE_node.h"
49 #include "BKE_library.h"
50 #include "BKE_scene.h"
51 #include "BKE_sound.h"
52 #include "BKE_packedFile.h"
53 #include "BKE_utildefines.h"
54 #include "BKE_idprop.h"
55
56 #include "BLI_blenlib.h"
57
58 #include "BSE_filesel.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_graphics.h"
62 #include "BIF_glutil.h"
63 #include "BIF_interface.h"
64 #include "BIF_imasel.h"
65 #include "BIF_keyval.h"
66 #include "BIF_mainqueue.h"
67 #include "BIF_mywindow.h"
68 #include "BIF_meshtools.h"
69 #include "BIF_resources.h"
70 #include "BIF_renderwin.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toolbox.h"
74 #include "BIF_editseq.h"
75
76 #include "BIF_butspace.h"
77
78 #include "mydevice.h"
79 #include "blendef.h"
80
81 /* -----includes for this file specific----- */
82
83 #include "DNA_image_types.h"
84
85 #include "BKE_writeavi.h"
86 #include "BKE_writeffmpeg.h"
87 #include "BKE_image.h"
88 #include "BKE_plugin_types.h"
89
90 #include "BLI_threads.h"
91
92 #include "BIF_editsound.h"
93 #include "BIF_writeimage.h"
94 #include "BIF_writeavicodec.h"
95
96 #include "BSE_headerbuttons.h"
97 #include "BSE_sequence.h"
98 #include "BSE_seqeffects.h"
99 #include "BSE_seqscopes.h"
100 #include "BSE_seqaudio.h"
101
102 #include "RE_pipeline.h"
103
104 #include "butspace.h" // own module
105
106 #ifdef WITH_QUICKTIME
107 #include "quicktime_export.h"
108 #endif
109
110 #ifdef WITH_FFMPEG
111
112 #include <ffmpeg/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
113 #include <ffmpeg/avformat.h>
114 #include <ffmpeg/opt.h>
115
116 static int ffmpeg_preset_sel = 0;
117
118 extern int is_container(int);
119
120 extern void makeffmpegstring(char* string);
121
122 #endif
123
124 /* here the calls for scene buttons
125    - render
126    - world
127    - anim settings, audio
128 */
129
130 /* prototypes */
131 void playback_anim(void);
132
133 /* ************************ SOUND *************************** */
134 static void load_new_sample(char *str)  /* called from fileselect */
135 {
136         char name[FILE_MAX];
137         bSound *sound;
138         bSample *sample, *newsample;
139
140         sound = G.buts->lockpoin;
141         
142         /* No Sound or Selected the same sample as we alredy have, just ignore */
143         if (sound==NULL || str==sound->name)
144                 return;
145                 
146         if (sizeof(sound->sample->name) < strlen(str)) {
147                 error("Path too long: %s", str);
148                 return;
149         }
150                 
151         // save values
152         sample = sound->sample;
153         strcpy(name, sound->sample->name);      
154         strcpy(sound->name, str);
155         sound_set_sample(sound, NULL);
156         sound_initialize_sample(sound);
157
158         if (sound->sample->type == SAMPLE_INVALID) {
159                 error("Not a valid sample: %s", str);
160
161                 newsample = sound->sample;
162
163                 // restore values
164                 strcpy(sound->name, name);
165                 sound_set_sample(sound, sample);
166
167                 // remove invalid sample
168
169                 sound_free_sample(newsample);
170                 BLI_remlink(samples, newsample);
171                 MEM_freeN(newsample);
172                 return;
173         }
174         
175         BIF_undo_push("Load new audio file");
176         allqueue(REDRAWBUTSSCENE, 0);
177 }
178
179
180 void do_soundbuts(unsigned short event)
181 {
182         char name[FILE_MAX];
183         bSound *sound;
184         bSample *sample;
185         bSound* tempsound;
186         ID *id;
187         
188         sound = G.buts->lockpoin;
189         
190         switch(event) {
191         case B_SOUND_REDRAW:
192                 allqueue(REDRAWBUTSSCENE, 0);
193                 break;
194
195         case B_SOUND_LOAD_SAMPLE:
196                 if (sound) strcpy(name, sound->name);
197                 else strcpy(name, U.sounddir);
198                         
199                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
200                 break;
201
202         case B_SOUND_PLAY_SAMPLE:
203                 if (sound) {
204                         if (sound->sample->type != SAMPLE_INVALID) {
205                                 sound_play_sound(sound);
206                                 allqueue(REDRAWBUTSSCENE, 0);
207                         }
208                 }
209                 break;
210
211         case B_SOUND_MENU_SAMPLE:
212                 if (G.buts->menunr > 0) {
213                         sample = BLI_findlink(samples, G.buts->menunr - 1);
214                         if (sample && sound && sound->sample != sample) {
215                                 int wasrelative = (strncmp(sound->name, "//", 2)==0);
216                                 
217                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
218                                 sound_set_sample(sound, sample);
219                                 
220                                 if (wasrelative)
221                                         BLI_makestringcode(G.sce, sound->name);
222                                         
223                                 do_soundbuts(B_SOUND_REDRAW);
224                         }
225                 }
226                         
227                 break;
228         case B_SOUND_NAME_SAMPLE:
229                 load_new_sample(sound->name);
230                 break;
231         
232         case B_SOUND_UNPACK_SAMPLE:
233                 if(sound && sound->sample) {
234                         sample = sound->sample;
235                         
236                         if (sample->packedfile) {
237                                 if (G.fileflags & G_AUTOPACK) {
238                                         if (okee("Disable AutoPack ?")) {
239                                                 G.fileflags &= ~G_AUTOPACK;
240                                         }
241                                 }
242                                 
243                                 if ((G.fileflags & G_AUTOPACK) == 0) {
244                                         unpackSample(sample, PF_ASK);
245                                 }
246                         } else {
247                                 sound_set_packedfile(sample, newPackedFile(sample->name));
248                         }
249                         allqueue(REDRAWHEADERS, 0);
250                         do_soundbuts(B_SOUND_REDRAW);
251                 }
252                 break;
253
254         case B_SOUND_COPY_SOUND:
255                 if (sound) {
256                         tempsound = sound_make_copy(sound);
257                         sound = tempsound;
258                         id = &sound->id;
259                         G.buts->lockpoin = (bSound*)id;
260                         BIF_undo_push("Copy sound");
261                         do_soundbuts(B_SOUND_REDRAW);
262                 }
263                 break;
264
265         case B_SOUND_RECALC:
266                 waitcursor(1);
267                 sound = G.main->sound.first;
268                 while (sound) {
269                         free(sound->stream);
270                         sound->stream = 0;
271                         audio_makestream(sound);
272                         sound = (bSound *) sound->id.next;
273                 }
274                 waitcursor(0);
275                 allqueue(REDRAWSEQ, 0);
276                 break;
277
278         case B_SOUND_RATECHANGED:
279
280                 allqueue(REDRAWBUTSSCENE, 0);
281                 allqueue(REDRAWSEQ, 0);
282                 break;
283
284         case B_SOUND_MIXDOWN:
285                 audio_mixdown();
286                 break;
287
288         default: 
289                 if (G.f & G_DEBUG) {
290                         printf("do_soundbuts: unhandled event %d\n", event);
291                 }
292         }
293 }
294
295
296 static void sound_panel_listener(void)
297 {
298         uiBlock *block;
299         int xco= 100, yco=100, mixrate;
300         char mixrateinfo[256];
301         
302         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
303         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
304
305         mixrate = sound_get_mixrate();
306         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
307         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
308
309         yco -= 30;
310         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
311
312         yco -= 30;
313         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
314                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
315         
316         yco -= 30;
317         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
318
319         yco -= 30;
320         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
321         xco,yco,195,24,&G.listener->dopplerfactor, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
322         
323         yco -=30;
324         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Velocity: ",
325         xco,yco,195,24,&G.listener->dopplervelocity,0.0,10000.0, 1.0,0, "Sets the propagation speed of sound");
326
327         
328 }
329
330 static void sound_panel_sequencer(void)
331 {
332         uiBlock *block;
333         short xco, yco;
334         char mixrateinfo[256];
335         
336         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSS, UI_HELV, curarea->win);
337         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
338
339         /* audio sequence engine settings ------------------------------------------------------------------ */
340
341         xco = 1010;
342         yco = 195;
343
344         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
345
346         yco -= 25;
347         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
348         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
349
350         yco -= 25;              
351         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "44.1 kHz",  xco,yco,75,20, &G.scene->audio.mixrate, 2.0, 44100.0, 0, 0, "Mix at 44.1 kHz");
352         uiDefButI(block, ROW, B_SOUND_RATECHANGED, "48.0 kHz",          xco+80,yco,75,20, &G.scene->audio.mixrate, 2.0, 48000.0, 0, 0, "Mix at 48 kHz");
353         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
354
355         yco -= 25;
356         uiDefButBitS(block, TOG, AUDIO_SYNC, B_SOUND_CHANGED, "Sync",   xco,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
357         uiDefButBitS(block, TOG, AUDIO_SCRUB, B_SOUND_CHANGED, "Scrub",         xco+120,yco,115,20, &G.scene->audio.flag, 0, 0, 0, 0, "Scrub when changing frames");
358
359         yco -= 25;
360         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
361
362         yco -= 25;              
363         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
364                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
365
366         yco -= 25;
367         uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
368         
369         yco -= 35;
370         uiDefBut(block, BUT, B_SOUND_MIXDOWN, "MIXDOWN",        xco,yco,235,24, 0, 0, 0, 0, 0, "Create WAV file from sequenced audio (output goes to render output dir)");
371         
372 }
373
374 static char *make_sample_menu(void)
375 {
376         int len= BLI_countlist(samples);        /* BKE_sound.h */
377         
378         if(len) {
379                 bSample *sample;
380                 char *str;
381                 int nr, a=0;
382                 
383                 str= MEM_callocN(32*len, "menu");
384                 
385                 for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
386                         a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
387                 }
388                 return str;
389         }
390         return NULL;
391 }
392
393 static void sound_panel_sound(bSound *sound)
394 {
395         static int packdummy=0;
396         ID *id, *idfrom;
397         uiBlock *block;
398         bSample *sample;
399         char *strp, ch[256];
400
401         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
402         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
403         
404         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
405         
406         // warning: abuse of texnr here! (ton didnt code!)
407         buttons_active_id(&id, &idfrom);
408         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, ID_SO, 0, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
409
410         if (sound) {
411         
412                 uiDefBut(block, BUT, B_SOUND_COPY_SOUND, "Copy sound", 220,160,90,20, 0, 0, 0, 0, 0, "Make another copy (duplicate) of the current sound");
413
414                 uiSetButLock(sound->id.lib!=0, ERROR_LIBDATA_MESSAGE);
415                 sound_initialize_sample(sound);
416                 sample = sound->sample;
417
418                 /* info string */
419                 if (sound->sample && sound->sample->len && sound->sample->channels && sound->sample->bits) {
420                         char *tmp;
421                         if (sound->sample->channels == 1) tmp= "Mono";
422                         else if (sound->sample->channels == 2) tmp= "Stereo";
423                         else tmp= "Unknown";
424                         
425                         sprintf(ch, "Sample: %s, %d bit, %d Hz, %d samples", tmp, sound->sample->bits, sound->sample->rate, (sound->sample->len/(sound->sample->bits/8)/sound->sample->channels));
426                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
427                 }
428                 else {
429                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
430                 }
431
432                 /* sample browse buttons */
433                 uiBlockBeginAlign(block);
434                 strp= make_sample_menu();
435                 if (strp) {
436                         uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
437                         MEM_freeN(strp);
438                 }
439                 uiDefBut(block, TEX, B_SOUND_NAME_SAMPLE, "",           35,120,250,20, sound->name, 0.0, 79.0, 0, 0, "The sample file used by this Sound");
440                 
441                 if (sound->sample->packedfile) packdummy = 1;
442                 else packdummy = 0;
443                 
444                 uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
445                         285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
446                 
447                 uiBlockBeginAlign(block);
448                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
449
450                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
451                 
452                 uiBlockBeginAlign(block);
453                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
454                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
455
456                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
457                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
458
459                 /* looping */
460                 uiBlockBeginAlign(block);
461                 uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
462                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
463
464                 if (sound->flags & SOUND_FLAGS_LOOP) {
465                         uiDefButBitI(block, TOG, SOUND_FLAGS_BIDIRECTIONAL_LOOP, B_SOUND_REDRAW, "Ping Pong",
466                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between A->B and A->B->A looping");
467                         
468                 }
469         
470
471                 /* 3D settings ------------------------------------------------------------------ */
472                 uiBlockBeginAlign(block);
473
474                 if (sound->sample->channels == 1) {
475                         uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
476                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Game engine only: Turns 3D sound on");
477                         
478                         if (sound->flags & SOUND_FLAGS_3D) {
479                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
480                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Game engine only: Sets the surround scaling factor for this sound");
481                                 
482                         }
483                 }
484         }
485 }
486
487 /* ************************* Sequencer *********************** */
488
489 #define SEQ_PANEL_EDITING 1
490 #define SEQ_PANEL_INPUT   2
491 #define SEQ_PANEL_FILTER  4
492 #define SEQ_PANEL_EFFECT  8
493 #define SEQ_PANEL_PROXY   16
494
495 static char* seq_panel_blend_modes()
496 {
497         static char string[2048];
498
499         Sequence *last_seq = get_last_seq();
500
501         sprintf(string, "Blend mode: %%t|%s %%x%d",
502                 "Replace", SEQ_BLEND_REPLACE);
503
504         /*
505           Blending can only work without effect strips. 
506           Otherwise, one would have
507           to decide, what the effect strips IPO should do:
508           - drive the effect _or_
509           - drive the blend mode ?
510
511           Also: effectdata is used by these implicit effects,
512           so that would collide also.
513         */
514
515         if ( seq_can_blend(last_seq) ) {
516                 int i;
517
518                 for (i = SEQ_EFFECT; i <= SEQ_EFFECT_MAX; i++) {
519                         if (get_sequence_effect_num_inputs(i) == 2) {
520                                 sprintf(string + strlen(string), 
521                                         "|%s %%x%d", 
522                                         give_seqname_by_type(i), i);
523                         }
524                 }
525         }
526         return string;
527 }
528
529 static char* seq_panel_scenes()
530 {
531         static char rstr[8192];
532         char * str;
533
534         IDnames_to_pupstring(&str, NULL, NULL, 
535                              &G.main->scene, (ID *)G.scene, NULL);
536
537         strncpy(rstr, str, 8192);
538         MEM_freeN(str);
539
540         return rstr;
541 }
542
543 static void seq_update_scenenr(Sequence * seq)
544 {
545         Scene * sce;
546         int nr;
547         if (seq->type != SEQ_SCENE) {
548                 return;
549         }
550
551         seq->scenenr = 0;
552
553         sce = G.main->scene.first;
554         nr = 1;
555         while(sce) {
556                 if (sce == seq->scene) {
557                         seq->scenenr = nr;
558                         break;
559                 }
560                 nr++;
561                 sce = sce->id.next;
562         }
563 }
564
565
566 static void seq_panel_editing()
567 {
568         Sequence *last_seq = get_last_seq();
569         uiBlock *block;
570         static char strdata[1024];
571         char * str = strdata;
572         char * p;
573         int yco;
574
575         block = uiNewBlock(&curarea->uiblocks, "seq_panel_editing", 
576                            UI_EMBOSS, UI_HELV, curarea->win);
577
578         if(uiNewPanel(curarea, block, "Edit", "Sequencer", 
579                       10, 230, 318, 204) == 0) return;
580
581         uiDefBut(block, LABEL, 
582                  0, give_seqname(last_seq), 
583                  10,140,60,19, 0, 
584                  0, 0, 0, 0, "");
585
586         uiDefBut(block, TEX, 
587                  B_NOP, "Name: ", 
588                  70,140,180,19, last_seq->name+2, 
589                  0.0, 21.0, 100, 0, "");
590
591         uiDefButI(block, MENU, B_SEQ_BUT_RELOAD, seq_panel_blend_modes(), 
592                   10, 120, 120, 19, &last_seq->blend_mode, 
593                   0,0,0,0, "Strip Blend Mode");
594
595         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Blend:",
596                   130, 120, 120, 19, &last_seq->blend_opacity, 
597                   0.0, 100.0, 100.0, 0, 
598                   "Blend opacity");
599
600         uiDefButBitI(block, TOG, SEQ_MUTE,
601                      B_SEQ_BUT_RELOAD_ALL, "Mute",
602                      10,100,60,19, &last_seq->flag,
603                      0.0, 1.0, 0, 0,
604                      "Mute the current strip.");
605
606         uiDefButBitI(block, TOG, SEQ_LOCK,
607                      B_REDR, "Lock",
608                      70,100,60,19, &last_seq->flag,
609                      0.0, 1.0, 0, 0,
610                      "Lock strip, so that it can't be transformed.");
611         
612         uiDefButBitI(block, TOG, SEQ_IPO_FRAME_LOCKED,
613                      B_SEQ_BUT_RELOAD_ALL, "IPO Frame locked",
614                      130,100,120,19, &last_seq->flag,
615                      0.0, 1.0, 0, 0,
616                      "Lock the IPO coordinates to the "
617                      "global frame counter.");
618         
619         if (!(last_seq->flag & SEQ_LOCK)) {
620                 uiDefButI(block, NUM, 
621                           B_SEQ_BUT_TRANSFORM, "Start", 
622                           10, 80, 120, 20, &last_seq->start, 
623                           -MAXFRAMEF, MAXFRAMEF, 0.0, 0.0, "Start of strip");
624                 uiDefButI(block, NUM, 
625                           B_SEQ_BUT_TRANSFORM, "Chan", 
626                           130, 80, 120, 20, &last_seq->machine, 
627                           0.0, MAXSEQ, 0.0, 0.0, "Channel used (Y position)");
628                 
629                 if (check_single_seq(last_seq) || last_seq->len == 0) {
630                         uiDefButI(block, NUM, 
631                                 B_SEQ_BUT_TRANSFORM, "End-Still", 
632                                 130, 60, 120, 19, &last_seq->endstill, 
633                                 0.0, MAXFRAMEF, 0.0, 0.0, "End still");
634                 } else {
635                         uiDefButI(block, NUM, 
636                                   B_SEQ_BUT_TRANSFORM, "Start-Still", 
637                                   10, 60, 120, 20, &last_seq->startstill, 
638                                   0.0, MAXFRAMEF, 0.0, 0.0, "Start still");
639                         uiDefButI(block, NUM, 
640                                   B_SEQ_BUT_TRANSFORM, "End-Still", 
641                                   130, 60, 120, 19, &last_seq->endstill, 
642                                   0.0, MAXFRAMEF, 0.0, 0.0, "End still");
643                         uiDefButI(block, NUM, 
644                                   B_SEQ_BUT_TRANSFORM, "Start-Ofs", 
645                                   10, 40, 120, 20, &last_seq->startofs, 
646                                   0.0, last_seq->len - last_seq->endofs, 
647                                   0.0, 0.0, "Start offset");
648                         uiDefButI(block, NUM, 
649                                   B_SEQ_BUT_TRANSFORM, "End-Ofs", 
650                                   130, 40, 120, 19, &last_seq->endofs, 
651                                   0.0, last_seq->len - last_seq->startofs, 
652                                   0.0, 0.0, "End offset");
653                 }
654         }
655
656
657         if(last_seq->type & SEQ_EFFECT)
658                 sprintf(str, "Len: %d\nFrom %d - %d\n", last_seq->len, last_seq->startdisp, last_seq->enddisp-1);
659         else
660                 sprintf(str, "Len: %d(%d)\n", last_seq->enddisp-last_seq->startdisp, last_seq->len);
661
662         str += strlen(str);
663
664         if(last_seq->type==SEQ_IMAGE) {
665                 if (last_seq->len > 1) {
666                         /* CURRENT */
667                         StripElem * se= give_stripelem(last_seq, CFRA);
668                         StripElem * last;
669
670                         /* FIRST AND LAST */
671         
672                         if(last_seq->strip) {
673                                 se= last_seq->strip->stripdata;
674                                 last= se+last_seq->len-1;
675                                 if(last_seq->startofs) se+= last_seq->startofs;
676                                 if(last_seq->endofs) last-= last_seq->endofs;
677         
678                                 sprintf(str, "First: %s at %d\nLast: %s at %d\n", se->name, last_seq->startdisp, last->name, last_seq->enddisp-1);
679                         }
680                 } else { /* single image */
681                         if (last_seq->strip) {
682                                 sprintf(str, "Len: %d\n", last_seq->enddisp-last_seq->startdisp);
683                         }
684                 }
685
686                 str += strlen(str);
687
688                 /* orig size */
689                 if(last_seq->strip) {
690                         sprintf(str, "OrigSize: %d x %d\n", last_seq->strip->orx, last_seq->strip->ory);
691                 }
692         }
693         else if(last_seq->type==SEQ_MOVIE) {
694                 int sta= last_seq->startofs;
695                 int end= last_seq->len-1-last_seq->endofs;
696
697                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
698                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
699                         (G.scene->r.cfra)-last_seq->startdisp);
700
701                 str += strlen(str);
702                 /* orig size */
703                 if(last_seq->strip) {
704                         sprintf(str, "OrigSize: %d x %d\n", 
705                                 last_seq->strip->orx, last_seq->strip->ory);
706                 }
707         }
708         else if(last_seq->type==SEQ_SCENE) {
709                 TStripElem * se= give_tstripelem(last_seq,  (G.scene->r.cfra));
710                 if(se && last_seq->scene) {
711                         sprintf(str, "First: %d\nLast: %d\nCur: %d\n", last_seq->sfra+se->nr, last_seq->sfra, last_seq->sfra+last_seq->len-1); 
712                 }
713                 str += strlen(str);
714                 /* orig size */
715                 if(last_seq->strip) {
716                         sprintf(str, "OrigSize: %d x %d\n", 
717                                 last_seq->strip->orx, last_seq->strip->ory);
718                 }
719         }
720         else if(last_seq->type==SEQ_RAM_SOUND
721                 || last_seq->type == SEQ_HD_SOUND) {
722
723                 int sta= last_seq->startofs;
724                 int end= last_seq->len-1-last_seq->endofs;
725
726                 sprintf(str, "First: %d at %d\nLast: %d at %d\nCur: %d\n",
727                         sta, last_seq->startdisp, end, last_seq->enddisp-1,  
728                         (G.scene->r.cfra)-last_seq->startdisp);
729         }
730         else if(last_seq->type == SEQ_SPEED) {
731                 SpeedControlVars * vars = 
732                         (SpeedControlVars*) last_seq->effectdata;
733
734                 if (vars) {
735                         sprintf(str, "Last mapped frame: %d at %d\n", 
736                                 vars->lastValidFrame, 
737                                 vars->lastValidFrame 
738                                 + last_seq->startdisp);
739                 }
740         }
741
742         str = strdata;
743         yco = 20;
744
745         while ((p = strchr(str, '\n'))) {
746                 *p = 0;
747                 uiDefBut(block, LABEL, 0, str, 10,yco,240,17, 0, 
748                          0, 0, 0, 0, "");
749                 str = p+1;
750                 yco -= 18;
751         }
752 }
753
754 static void seq_panel_input()
755 {
756         Sequence *last_seq = get_last_seq();
757         uiBlock *block;
758
759         block = uiNewBlock(&curarea->uiblocks, "seq_panel_input", 
760                            UI_EMBOSS, UI_HELV, curarea->win);
761
762         if(uiNewPanel(curarea, block, "Input", "Sequencer", 
763                       10, 230, 318, 204) == 0) return;
764
765         if (SEQ_HAS_PATH(last_seq)) {
766                 uiDefBut(block, TEX, 
767                          B_SEQ_BUT_RELOAD_FILE, "Dir: ", 
768                          10,140,240,19, last_seq->strip->dir, 
769                          0.0, 160.0, 100, 0, "");
770         }
771
772         if (last_seq->type == SEQ_IMAGE) {
773                 int cfra = CFRA;
774                 StripElem * se;
775
776                 if(last_seq->startdisp >cfra) {
777                         cfra = last_seq->startdisp;
778                 } else if (last_seq->enddisp <= cfra) {
779                         cfra = last_seq->enddisp - 1;
780                 }
781
782                 se = give_stripelem(last_seq, cfra);
783
784                 if (se) {
785                         uiDefBut(block, TEX, 
786                                  B_SEQ_BUT_RELOAD_FILE, "File: ", 
787                                  10, 120, 190,19, se->name, 
788                                  0.0, 80.0, 100, 0, "");
789                 }
790
791         } else if (last_seq->type == SEQ_MOVIE || 
792                    last_seq->type == SEQ_HD_SOUND ||
793                    last_seq->type == SEQ_RAM_SOUND) {
794                 uiDefBut(block, TEX, 
795                          B_SEQ_BUT_RELOAD_FILE, "File: ", 
796                          10,120,190,19, last_seq->strip->stripdata->name, 
797                          0.0, 80.0, 100, 0, "");
798         } else if (last_seq->type == SEQ_SCENE) {
799                 seq_update_scenenr(last_seq);
800                 uiDefButI(block, MENU, B_SEQ_BUT_RELOAD_FILE, 
801                           seq_panel_scenes(), 
802                           10, 120, 190, 19, &last_seq->scenenr, 
803                           0,0,0,0, "Linked Scene");
804         }
805
806         uiDefBut(block, BUT, B_SEQ_BUT_RELOAD_FILE, 
807                  "Reload",
808                  200,120,50,19, 0, 0, 0, 0, 0, 
809                  "Reload files/scenes from disk and update strip length.");
810
811         if (last_seq->type == SEQ_MOVIE 
812             || last_seq->type == SEQ_IMAGE 
813             || last_seq->type == SEQ_SCENE
814             || last_seq->type == SEQ_META) {
815                 uiDefButBitI(block, TOG, SEQ_USE_CROP,
816                              B_SEQ_BUT_RELOAD, "Use Crop",
817                              10,100,240,19, &last_seq->flag,
818                              0.0, 1.0, 0, 0,
819                              "Crop image before processing.");
820
821                 if (last_seq->flag & SEQ_USE_CROP) {
822                         if (!last_seq->strip->crop) {
823                                 last_seq->strip->crop = 
824                                         MEM_callocN(sizeof(struct StripCrop), 
825                                                     "StripCrop");
826                         }
827                         uiDefButI(block, NUM, 
828                                   B_SEQ_BUT_RELOAD, "Top", 
829                                   10, 80, 120, 20, 
830                                   &last_seq->strip->crop->top, 
831                                   0.0, 4096, 0.0, 0.0, "Top of source image");
832                         uiDefButI(block, NUM, 
833                                   B_SEQ_BUT_RELOAD, "Bottom", 
834                                   130, 80, 120, 20, 
835                                   &last_seq->strip->crop->bottom, 
836                                   0.0, 4096, 0.0, 0.0,
837                                   "Bottom of source image");
838                         
839                         uiDefButI(block, NUM, 
840                                   B_SEQ_BUT_RELOAD, "Left", 
841                                   10, 60, 120, 20,
842                                   &last_seq->strip->crop->left, 
843                                   0.0, 4096, 0.0, 0.0, "Left");
844                         uiDefButI(block, NUM, 
845                                   B_SEQ_BUT_RELOAD, "Right", 
846                                   130, 60, 120, 19, 
847                                   &last_seq->strip->crop->right, 
848                                   0.0, 4096, 0.0, 0.0, "Right");
849                 }
850                 
851                 uiDefButBitI(block, TOG, SEQ_USE_TRANSFORM,
852                              B_SEQ_BUT_RELOAD, "Use Translate",
853                              10,40,240,19, &last_seq->flag,
854                              0.0, 1.0, 0, 0,
855                              "Translate image before processing.");
856                 
857                 if (last_seq->flag & SEQ_USE_TRANSFORM) {
858                         if (!last_seq->strip->transform) {
859                                 last_seq->strip->transform = 
860                                         MEM_callocN(
861                                                 sizeof(struct StripTransform), 
862                                                 "StripTransform");
863                         }
864                         uiDefButI(block, NUM, 
865                                   B_SEQ_BUT_RELOAD, "X-Ofs", 
866                                   10, 20, 120, 20, 
867                                   &last_seq->strip->transform->xofs, 
868                                   -4096.0, 4096, 0.0, 0.0, "X Offset");
869                         uiDefButI(block, NUM, 
870                                   B_SEQ_BUT_RELOAD, "Y-Ofs", 
871                                   130, 20, 120, 20, 
872                                   &last_seq->strip->transform->yofs, 
873                                   -4096.0, 4096, 0.0, 0.0, "Y Offset");
874                 }
875         }
876
877         uiDefButI(block, NUM, 
878                   B_SEQ_BUT_RELOAD_FILE, "A-Start", 
879                   10, 0, 120, 20, &last_seq->anim_startofs, 
880                   0.0, last_seq->len + last_seq->anim_startofs, 0.0, 0.0, 
881                   "Animation start offset (trim start)");
882         uiDefButI(block, NUM, 
883                   B_SEQ_BUT_RELOAD_FILE, "A-End", 
884                   130, 0, 120, 20, &last_seq->anim_endofs, 
885                   0.0, last_seq->len + last_seq->anim_endofs, 0.0, 0.0, 
886                   "Animation end offset (trim end)");
887
888
889         if (last_seq->type == SEQ_MOVIE) {
890                 uiDefButI(block, NUM, B_SEQ_BUT_RELOAD, "MPEG-Preseek:",
891                           10, -20, 240,19, &last_seq->anim_preseek, 
892                           0.0, 50.0, 100,0,
893                           "On MPEG-seeking preseek this many frames");
894         }
895
896 }
897
898 static void seq_panel_filter_video()
899 {
900         Sequence *last_seq = get_last_seq();
901         uiBlock *block;
902         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
903                            UI_EMBOSS, UI_HELV, curarea->win);
904
905         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
906                       10, 230, 318, 204) == 0) return;
907
908
909         uiBlockBeginAlign(block);
910
911
912         uiDefButBitI(block, TOG, SEQ_MAKE_PREMUL, 
913                      B_SEQ_BUT_RELOAD, "Premul", 
914                      10,110,80,19, &last_seq->flag, 
915                      0.0, 21.0, 100, 0, 
916                      "Converts RGB values to become premultiplied with Alpha");
917
918         uiDefButBitI(block, TOG, SEQ_MAKE_FLOAT, 
919                      B_SEQ_BUT_RELOAD, "Float", 
920                      90,110,80,19, &last_seq->flag, 
921                      0.0, 21.0, 100, 0, 
922                      "Convert input to float data");
923
924         uiDefButBitI(block, TOG, SEQ_FILTERY, 
925                      B_SEQ_BUT_RELOAD_FILE, "De-Inter", 
926                      170,110,80,19, &last_seq->flag, 
927                      0.0, 21.0, 100, 0, 
928                      "For video movies to remove fields");
929
930         uiDefButBitI(block, TOG, SEQ_FLIPX, 
931                      B_SEQ_BUT_RELOAD, "FlipX", 
932                      10,90,80,19, &last_seq->flag, 
933                      0.0, 21.0, 100, 0, 
934                      "Flip on the X axis");
935         uiDefButBitI(block, TOG, SEQ_FLIPY, 
936                      B_SEQ_BUT_RELOAD, "FlipY", 
937                      90,90,80,19, &last_seq->flag, 
938                      0.0, 21.0, 100, 0, 
939                      "Flip on the Y axis");
940
941         uiDefButBitI(block, TOG, SEQ_REVERSE_FRAMES,
942                      B_SEQ_BUT_RELOAD, "Flip Time", 
943                      170,90,80,19, &last_seq->flag, 
944                      0.0, 21.0, 100, 0, 
945                      "Reverse frame order");
946                 
947         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Mul:",
948                   10,70,120,19, &last_seq->mul, 
949                   0.001, 20.0, 0.1, 0, 
950                   "Multiply colors");
951
952         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Strobe:",
953                   130,70,120,19, &last_seq->strobe, 
954                   1.0, 30.0, 100, 0, 
955                   "Only display every nth frame");
956
957         uiDefButBitI(block, TOG, SEQ_USE_COLOR_BALANCE,
958                      B_SEQ_BUT_RELOAD, "Use Color Balance", 
959                      10,50,240,19, &last_seq->flag, 
960                      0.0, 21.0, 100, 0, 
961                      "Activate Color Balance "
962                      "(3-Way color correction) on input");
963
964
965         if (last_seq->flag & SEQ_USE_COLOR_BALANCE) {
966                 if (!last_seq->strip->color_balance) {
967                         int c;
968                         StripColorBalance * cb 
969                                 = last_seq->strip->color_balance 
970                                 = MEM_callocN(
971                                         sizeof(struct StripColorBalance), 
972                                         "StripColorBalance");
973                         for (c = 0; c < 3; c++) {
974                                 cb->lift[c] = 1.0;
975                                 cb->gamma[c] = 1.0;
976                                 cb->gain[c] = 1.0;
977                         }
978                 }
979
980                 uiDefBut(block, LABEL, 0, "Lift",
981                          10,30,80,19, 0, 0, 0, 0, 0, "");
982                 uiDefBut(block, LABEL, 0, "Gamma",
983                          90,30,80,19, 0, 0, 0, 0, 0, "");
984                 uiDefBut(block, LABEL, 0, "Gain",
985                          170,30,80,19, 0, 0, 0, 0, 0, "");
986
987                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Lift",
988                           10,10,80,19, last_seq->strip->color_balance->lift, 
989                           0, 0, 0, 0, "Lift (shadows)");
990
991                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gamma",
992                           90,10,80,19, last_seq->strip->color_balance->gamma, 
993                           0, 0, 0, 0, "Gamma (midtones)");
994
995                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "Gain",
996                           170,10,80,19, last_seq->strip->color_balance->gain, 
997                           0, 0, 0, 0, "Gain (highlights)");
998
999                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_LIFT,
1000                              B_SEQ_BUT_RELOAD, "Inv Lift", 
1001                              10,-10,80,19, 
1002                              &last_seq->strip->color_balance->flag, 
1003                              0.0, 21.0, 100, 0, 
1004                              "Inverse Lift");
1005                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAMMA,
1006                              B_SEQ_BUT_RELOAD, "Inv Gamma", 
1007                              90,-10,80,19, 
1008                              &last_seq->strip->color_balance->flag, 
1009                              0.0, 21.0, 100, 0, 
1010                              "Inverse Gamma");
1011                 uiDefButBitI(block, TOG, SEQ_COLOR_BALANCE_INVERSE_GAIN,
1012                              B_SEQ_BUT_RELOAD, "Inv Gain", 
1013                              170,-10,80,19, 
1014                              &last_seq->strip->color_balance->flag, 
1015                              0.0, 21.0, 100, 0, 
1016                              "Inverse Gain");
1017         }
1018
1019
1020         uiBlockEndAlign(block);
1021
1022 }
1023
1024
1025 static void seq_panel_filter_audio()
1026 {
1027         Sequence *last_seq = get_last_seq();
1028         uiBlock *block;
1029         block = uiNewBlock(&curarea->uiblocks, "seq_panel_filter", 
1030                            UI_EMBOSS, UI_HELV, curarea->win);
1031
1032         if(uiNewPanel(curarea, block, "Filter", "Sequencer", 
1033                       10, 230, 318, 204) == 0) return;
1034
1035         uiBlockBeginAlign(block);
1036         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Gain (dB):", 10,50,150,19, &last_seq->level, -96.0, 6.0, 100, 0, "");
1037         uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Pan:",         10,30,150,19, &last_seq->pan, -1.0, 1.0, 100, 0, "");
1038         uiBlockEndAlign(block);
1039 }
1040
1041 static void seq_panel_effect()
1042 {
1043         Sequence *last_seq = get_last_seq();
1044         uiBlock *block;
1045         block = uiNewBlock(&curarea->uiblocks, "seq_panel_effect", 
1046                            UI_EMBOSS, UI_HELV, curarea->win);
1047
1048         if(uiNewPanel(curarea, block, "Effect", "Sequencer", 
1049                       10, 230, 318, 204) == 0) return;
1050
1051         if(last_seq->type == SEQ_PLUGIN) {
1052                 PluginSeq *pis;
1053                 VarStruct *varstr;
1054                 int a, xco, yco;
1055
1056                 get_sequence_effect(last_seq);/* make sure, plugin is loaded */
1057
1058                 pis= last_seq->plugin;
1059                 if(pis->vars==0) return;
1060
1061                 varstr= pis->varstr;
1062                 if(varstr) {
1063                         for(a=0; a<pis->vars; a++, varstr++) {
1064                                 xco= 150*(a/6)+10;
1065                                 yco= 125 - 20*(a % 6)+1;
1066                                 uiDefBut(block, varstr->type, B_SEQ_BUT_PLUGIN, varstr->name, xco,yco,150,19, &(pis->data[a]), varstr->min, varstr->max, 100, 0, varstr->tip);
1067
1068                         }
1069                 }
1070                 return;
1071         } 
1072
1073         uiBlockBeginAlign(block);
1074
1075         if(last_seq->type==SEQ_WIPE){
1076                 WipeVars *wipe = (WipeVars *)last_seq->effectdata;
1077                 char formatstring[256];
1078                         
1079                 strncpy(formatstring, "Transition Type %t|Single Wipe%x0|Double Wipe %x1|Iris Wipe %x4|Clock Wipe %x5", 255);
1080                 uiDefButS(block, MENU,B_SEQ_BUT_EFFECT, formatstring,   10,65,220,22, &wipe->wipetype, 0, 0, 0, 0, "What type of wipe should be performed");
1081                 uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Blur:",  10,40,220,22, &wipe->edgeWidth,0.0,1.0, 1, 2, "The percent width of the blur edge");
1082                 switch(wipe->wipetype){ /*Skip Types that do not require angle*/
1083                 case DO_IRIS_WIPE:
1084                 case DO_CLOCK_WIPE:
1085                         break;
1086                         
1087                 default:
1088                         uiDefButF(block, NUM,B_SEQ_BUT_EFFECT,"Angle:", 10,15,220,22, &wipe->angle,-90.0,90.0, 1, 2, "The Angle of the Edge");
1089                 }
1090                 uiDefButS(block, TOG,B_SEQ_BUT_EFFECT,"Wipe In",  10,-10,220,22, &wipe->forward,0,0, 0, 0, "Controls Primary Direction of Wipe");                               
1091         } else if(last_seq->type==SEQ_GLOW){
1092                 GlowVars *glow = (GlowVars *)last_seq->effectdata;
1093
1094                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Threshold:",   10,70,150,19, &glow->fMini, 0.0, 1.0, 0, 0, "Trigger Intensity");
1095                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Clamp:",                       10,50,150,19, &glow->fClamp, 0.0, 1.0, 0, 0, "Brightness limit of intensity");
1096                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Boost factor:",        10,30,150,19, &glow->fBoost, 0.0, 10.0, 0, 0, "Brightness multiplier");
1097                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "Blur distance:",       10,10,150,19, &glow->dDist, 0.5, 20.0, 0, 0, "Radius of glow effect");
1098                 uiDefButI(block, NUM, B_NOP, "Quality:", 10,-5,150,19, &glow->dQuality, 1.0, 5.0, 0, 0, "Accuracy of the blur effect");
1099                 uiDefButI(block, TOG, B_NOP, "Only boost", 10,-25,150,19, &glow->bNoComp, 0.0, 0.0, 0, 0, "Show the glow buffer only");
1100         }
1101         else if(last_seq->type==SEQ_TRANSFORM){
1102                 TransformVars *transform = (TransformVars *)last_seq->effectdata;
1103
1104                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale Start:",        10,70,150,19, &transform->ScalexIni, 0.0, 10.0, 0, 0, "X Scale Start");
1105                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "xScale End:",  160,70,150,19, &transform->ScalexFin, 0.0, 10.0, 0, 0, "X Scale End");
1106                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale Start:",        10,50,150,19, &transform->ScaleyIni, 0.0, 10.0, 0, 0, "Y Scale Start");
1107                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "yScale End:",  160,50,150,19, &transform->ScaleyFin, 0.0, 10.0, 0, 0, "Y Scale End");
1108                 
1109                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Percent", 10, 30, 150, 19, &transform->percent, 0.0, 1.0, 0.0, 0.0, "Percent Translate");
1110                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Pixels", 160, 30, 150, 19, &transform->percent, 0.0, 0.0, 0.0, 0.0, "Pixels Translate");
1111                 if(transform->percent==1){
1112                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -500.0, 500.0, 0, 0, "X Position Start");
1113                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -500.0, 500.0, 0, 0, "X Position End");
1114                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -500.0, 500.0, 0, 0, "Y Position Start");
1115                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -500.0, 500.0, 0, 0, "Y Position End");
1116                 } else {
1117                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x Start:",     10,10,150,19, &transform->xIni, -10000.0, 10000.0, 0, 0, "X Position Start");
1118                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "x End:",       160,10,150,19, &transform->xFin, -10000.0, 10000.0, 0, 0, "X Position End");
1119                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y Start:",     10,-10,150,19, &transform->yIni, -10000.0, 10000.0, 0, 0, "Y Position Start");
1120                         uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "y End:",       160,-10,150,19, &transform->yFin, -10000.0, 10000.0, 0, 0, "Y Position End");
1121                         
1122                 }
1123                 
1124                 
1125                 
1126                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot Start:",10,-30,150,19, &transform->rotIni, 0.0, 360.0, 0, 0, "Rotation Start");
1127                 uiDefButF(block, NUM, B_SEQ_BUT_EFFECT, "rot End:",160,-30,150,19, &transform->rotFin, 0.0, 360.0, 0, 0, "Rotation End");
1128                 
1129                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "No Interpolat", 10, -50, 100, 19, &transform->interpolation, 0.0, 0.0, 0.0, 0.0, "No interpolation");
1130                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bilinear", 101, -50, 100, 19, &transform->interpolation, 0.0, 1.0, 0.0, 0.0, "Bilinear interpolation");
1131                 uiDefButI(block, ROW, B_SEQ_BUT_EFFECT, "Bicubic", 202, -50, 100, 19, &transform->interpolation, 0.0, 2.0, 0.0, 0.0, "Bicubic interpolation");
1132         } else if(last_seq->type==SEQ_COLOR) {
1133                 SolidColorVars *colvars = (SolidColorVars *)last_seq->effectdata;
1134                 uiDefButF(block, COL, B_SEQ_BUT_RELOAD, "",10,90,150,19, colvars->col, 0, 0, 0, 0, "");
1135         } else if(last_seq->type==SEQ_SPEED){
1136                 SpeedControlVars *sp = 
1137                         (SpeedControlVars *)last_seq->effectdata;
1138                 
1139                 uiDefButF(block, NUM, B_SEQ_BUT_RELOAD, "Global Speed:",        10,70,150,19, &sp->globalSpeed, 0.0, 100.0, 0, 0, "Global Speed");
1140                 
1141                 uiDefButBitI(block, TOG, SEQ_SPEED_INTEGRATE,
1142                              B_SEQ_BUT_RELOAD, 
1143                              "IPO is velocity",
1144                              10,50,150,19, &sp->flags, 
1145                              0.0, 1.0, 0, 0, 
1146                              "Interpret the IPO value as a "
1147                              "velocity instead of a frame number");
1148
1149                 uiDefButBitI(block, TOG, SEQ_SPEED_BLEND,
1150                              B_SEQ_BUT_RELOAD, 
1151                              "Enable frame blending",
1152                              10,30,150,19, &sp->flags, 
1153                              0.0, 1.0, 0, 0, 
1154                              "Blend two frames into the "
1155                              "target for a smoother result");
1156                 
1157                 uiDefButBitI(block, TOG, SEQ_SPEED_COMPRESS_IPO_Y,
1158                              B_SEQ_BUT_RELOAD, 
1159                              "IPO value runs from [0..1]",
1160                              10,10,150,19, &sp->flags, 
1161                              0.0, 1.0, 0, 0, 
1162                              "Scale IPO value to get the "
1163                              "target frame number.");
1164         }
1165
1166         uiBlockEndAlign(block);
1167 }
1168
1169 static void seq_panel_proxy()
1170 {
1171         Sequence *last_seq = get_last_seq();
1172         uiBlock *block;
1173         block = uiNewBlock(&curarea->uiblocks, "seq_panel_proxy", 
1174                            UI_EMBOSS, UI_HELV, curarea->win);
1175
1176         if(uiNewPanel(curarea, block, "Proxy", "Sequencer", 
1177                       10, 230, 318, 204) == 0) return;
1178
1179         uiBlockBeginAlign(block);
1180
1181         uiDefButBitI(block, TOG, SEQ_USE_PROXY, 
1182                      B_SEQ_BUT_RELOAD, "Use Proxy", 
1183                      10,140,120,19, &last_seq->flag, 
1184                      0.0, 21.0, 100, 0, 
1185                      "Use a preview proxy for this strip");
1186
1187         if (last_seq->flag & SEQ_USE_PROXY) {
1188                 if (!last_seq->strip->proxy) {
1189                         last_seq->strip->proxy = 
1190                                 MEM_callocN(sizeof(struct StripProxy),
1191                                             "StripProxy");
1192                 }
1193
1194                 uiDefButBitI(block, TOG, SEQ_USE_PROXY_CUSTOM_DIR, 
1195                              B_SEQ_BUT_RELOAD, "Custom Dir", 
1196                              130,140,120,19, &last_seq->flag, 
1197                              0.0, 21.0, 100, 0, 
1198                              "Use a custom directory to store data");
1199
1200                 if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) {
1201                         uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_DIR, 
1202                                      ICON_FILESEL, 10, 120, 20, 20, 0, 0, 0, 0, 0, 
1203                                      "Select the directory/name for "
1204                                      "the proxy storage");
1205
1206                         uiDefBut(block, TEX, 
1207                                  B_SEQ_BUT_RELOAD, "Dir: ", 
1208                                  30,120,220,20, last_seq->strip->proxy->dir, 
1209                                  0.0, 160.0, 100, 0, "");
1210                 }
1211         }
1212
1213         if (last_seq->flag & SEQ_USE_PROXY) {
1214                 if (G.scene->r.size == 100) {
1215                         uiDefBut(block, LABEL, 0, 
1216                                  "Full render size selected, ",
1217                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1218                         uiDefBut(block, LABEL, 0, 
1219                                  "so no proxy enabled!",
1220                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1221                 } else if (last_seq->type != SEQ_MOVIE 
1222                            && last_seq->type != SEQ_IMAGE
1223                            && !(last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) {
1224                         uiDefBut(block, LABEL, 0, 
1225                                  "Cannot proxy this strip without ",
1226                                  10,100,240,19, 0, 0, 0, 0, 0, "");
1227                         uiDefBut(block, LABEL, 0, 
1228                                  "custom directory selection!",
1229                                  10,80,240,19, 0, 0, 0, 0, 0, "");
1230
1231                 } else {
1232                         uiDefBut(block, BUT, B_SEQ_BUT_REBUILD_PROXY, 
1233                                  "Rebuild proxy",
1234                                  10,100,240,19, 0, 0, 0, 0, 0, 
1235                                  "Rebuild proxy for the "
1236                                  "currently selected strip.");
1237                 }
1238         }
1239
1240         uiBlockEndAlign(block);
1241 }
1242
1243
1244 void sequencer_panels()
1245 {
1246         Sequence *last_seq = get_last_seq();
1247         int panels = 0;
1248         int type;
1249
1250         if(last_seq == NULL) {
1251                 return;
1252         }
1253         
1254         type = last_seq->type;
1255
1256         panels = SEQ_PANEL_EDITING;
1257
1258         if (type == SEQ_MOVIE || type == SEQ_IMAGE || type == SEQ_SCENE
1259             || type == SEQ_META) {
1260                 panels |= SEQ_PANEL_INPUT | SEQ_PANEL_FILTER | SEQ_PANEL_PROXY;
1261         }
1262
1263         if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1264                 panels |= SEQ_PANEL_FILTER | SEQ_PANEL_INPUT;
1265         }
1266
1267         if (type == SEQ_PLUGIN || type >= SEQ_EFFECT) {
1268                 panels |= SEQ_PANEL_EFFECT | SEQ_PANEL_PROXY;
1269         }
1270
1271         if (panels & SEQ_PANEL_EDITING) {
1272                 seq_panel_editing();
1273         }
1274
1275         if (panels & SEQ_PANEL_INPUT) {
1276                 seq_panel_input();
1277         }
1278
1279         if (panels & SEQ_PANEL_FILTER) {
1280                 if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1281                         seq_panel_filter_audio();
1282                 } else {
1283                         seq_panel_filter_video();
1284                 }
1285         }
1286
1287         if (panels & SEQ_PANEL_EFFECT) {
1288                 seq_panel_effect();
1289         }
1290
1291         if (panels & SEQ_PANEL_PROXY) {
1292                 seq_panel_proxy();
1293         }
1294 }
1295
1296 static void sel_proxy_dir(char *name)
1297 {
1298         Sequence *last_seq = get_last_seq();
1299         strcpy(last_seq->strip->proxy->dir, name);
1300
1301         allqueue(REDRAWBUTSSCENE, 0);
1302
1303         BIF_undo_push("Change proxy directory");
1304 }
1305
1306 void do_sequencer_panels(unsigned short event)
1307 {
1308         Sequence *last_seq = get_last_seq();
1309         ScrArea * sa;
1310
1311         if (!last_seq) {
1312                 return;
1313         }
1314
1315         switch(event) {
1316         case B_SEQ_BUT_PLUGIN:
1317         case B_SEQ_BUT_EFFECT:
1318                 update_changed_seq_and_deps(last_seq, 0, 1);
1319                 break;
1320         case B_SEQ_BUT_RELOAD_FILE:
1321                 reload_sequence_new_file(last_seq);
1322                 break;
1323         case B_SEQ_BUT_REBUILD_PROXY:
1324                 seq_proxy_rebuild(last_seq);
1325                 break;
1326         case B_SEQ_SEL_PROXY_DIR:
1327                 sa= closest_bigger_area();
1328                 areawinset(sa->win);
1329                 activate_fileselect(FILE_SPECIAL, "SELECT PROXY DIR", 
1330                                     last_seq->strip->proxy->dir, 
1331                                     sel_proxy_dir);
1332                 break;
1333         case B_SEQ_BUT_RELOAD:
1334         case B_SEQ_BUT_RELOAD_ALL:
1335                 update_seq_ipo_rect(last_seq);
1336                 update_seq_icu_rects(last_seq);
1337
1338                 free_imbuf_seq();       // frees all
1339
1340                 break;
1341         case B_SEQ_BUT_TRANSFORM:
1342                 calc_sequence(last_seq);
1343                 if (test_overlap_seq(last_seq))
1344                         shuffle_seq(last_seq);
1345                 break;
1346         }
1347
1348         if (event == B_SEQ_BUT_RELOAD_ALL) {
1349                 allqueue(REDRAWALL, 0);
1350         } else {
1351                 allqueue(REDRAWSEQ, 0);
1352                 allqueue(REDRAWBUTSSCENE, 0);
1353         }
1354 }
1355
1356
1357 /* ************************* SCENE *********************** */
1358
1359
1360 static void output_pic(char *name)
1361 {
1362         strcpy(G.scene->r.pic, name);
1363         allqueue(REDRAWBUTSSCENE, 0);
1364         BIF_undo_push("Change output picture directory");
1365 }
1366
1367 static void backbuf_pic(char *name)
1368 {
1369         Image *ima;
1370         
1371         strcpy(G.scene->r.backbuf, name);
1372         allqueue(REDRAWBUTSSCENE, 0);
1373
1374         ima= BKE_add_image_file(name);
1375         if(ima)
1376                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
1377
1378         BIF_undo_push("Change background picture");
1379 }
1380
1381 static void run_playanim(char *file) 
1382 {
1383         extern char bprogname[];        /* usiblender.c */
1384         char str[FILE_MAX*2]; /* FILE_MAX*2 is a bit arbitary, but this should roughly allow for the args + the max-file-length */
1385         int pos[2], size[2];
1386
1387         /* use current settings for defining position of window. it actually should test image size */
1388         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
1389                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
1390 #ifdef WIN32
1391         sprintf(str, "%s -a -s %d -e %d -p %d %d -f %d %g \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, file);
1392 #else
1393         sprintf(str, "\"%s\" -a -s %d -e %d  -p %d %d -f %d %g \"%s\"", bprogname, G.scene->r.sfra, G.scene->r.efra, pos[0], pos[1], G.scene->r.frs_sec, G.scene->r.frs_sec_base, file);
1394 #endif
1395         system(str);
1396 }
1397
1398 void playback_anim(void)
1399 {       
1400         char file[FILE_MAX];
1401
1402         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
1403                 switch (G.scene->r.imtype) {
1404 #ifdef WITH_QUICKTIME
1405                         case R_QUICKTIME:
1406                                 makeqtstring(file);
1407                                 break;
1408 #endif
1409 #ifdef WITH_FFMPEG
1410                 case R_FFMPEG:
1411                         makeffmpegstring(file);
1412                         break;
1413 #endif
1414                 default:
1415                         makeavistring(&G.scene->r, file);
1416                         break;
1417                 }
1418                 if(BLI_exist(file)) {
1419                         run_playanim(file);
1420                 }
1421                 else error("Can't find movie: %s", file);
1422         }
1423         else {
1424                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
1425                 if(BLI_exist(file)) {
1426                         run_playanim(file);
1427                 }
1428                 else error("Can't find image: %s", file);
1429         }
1430 }
1431
1432 #ifdef WITH_FFMPEG
1433 static void set_ffmpeg_preset(int preset);
1434 static int ffmpeg_property_add_string(const char * type, const char * str);
1435 static char ffmpeg_option_to_add[255] = "";
1436 #endif
1437
1438 void do_render_panels(unsigned short event)
1439 {
1440         ScrArea *sa;
1441         ID *id;
1442
1443         switch(event) {
1444
1445         case B_DORENDER:
1446                 BIF_do_render(0);
1447                 break;
1448         case B_RTCHANGED:
1449                 allqueue(REDRAWALL, 0);
1450                 break;
1451         case B_SWITCHRENDER:
1452                 /* new panels added, so... */
1453                 G.buts->re_align= 1;
1454                 allqueue(REDRAWBUTSSCENE, 0);
1455                 break;
1456         case B_PLAYANIM:
1457                 playback_anim();
1458                 break;
1459                 
1460         case B_DOANIM:
1461                 BIF_do_render(1);
1462                 break;
1463         
1464         case B_FS_PIC:
1465                 sa= closest_bigger_area();
1466                 areawinset(sa->win);
1467                 if(G.qual == LR_CTRLKEY)
1468                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1469                 else
1470                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1471                 break;
1472
1473         case B_FS_BACKBUF:
1474                 sa= closest_bigger_area();
1475                 areawinset(sa->win);
1476                 if(G.qual == LR_CTRLKEY)
1477                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1478                 else
1479                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1480                 break;
1481         
1482         case B_PR_PAL:
1483                 G.scene->r.xsch= 720;
1484                 G.scene->r.ysch= 576;
1485                 G.scene->r.xasp= 54;
1486                 G.scene->r.yasp= 51;
1487                 G.scene->r.size= 100;
1488                 G.scene->r.frs_sec= 25;
1489                 G.scene->r.frs_sec_base= 1;
1490                 G.scene->r.mode &= ~R_PANORAMA;
1491                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1492 #ifdef WITH_FFMPEG
1493                 G.scene->r.ffcodecdata.gop_size = 15;
1494 #endif          
1495                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1496                 BIF_undo_push("Set PAL");
1497                 allqueue(REDRAWBUTSSCENE, 0);
1498                 allqueue(REDRAWVIEWCAM, 0);
1499                 break;
1500
1501         case B_FILETYPEMENU:
1502                 allqueue(REDRAWBUTSSCENE, 0);
1503 #ifdef WITH_FFMPEG
1504                 if (G.scene->r.imtype == R_FFMPEG) {
1505                         if (G.scene->r.ffcodecdata.type <= 0 ||
1506                             G.scene->r.ffcodecdata.codec <= 0 ||
1507                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
1508                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
1509                                 G.scene->r.ffcodecdata.codec 
1510                                         = CODEC_ID_MPEG2VIDEO;
1511                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
1512                         }
1513
1514                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
1515                                 G.scene->r.ffcodecdata.audio_codec 
1516                                         = CODEC_ID_MP2;
1517                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
1518                         }
1519                         break;
1520                 }
1521 #endif
1522 #if defined (_WIN32) || defined (__APPLE__)
1523                 // fall through to codec settings if this is the first
1524                 // time R_AVICODEC is selected for this scene.
1525                 if (((G.scene->r.imtype == R_AVICODEC) 
1526                          && (G.scene->r.avicodecdata == NULL)) ||
1527                         ((G.scene->r.imtype == R_QUICKTIME) 
1528                          && (G.scene->r.qtcodecdata == NULL))) {
1529                 } else {
1530                   break;
1531                 }
1532 #endif /*_WIN32 || __APPLE__ */
1533
1534         case B_SELECTCODEC:
1535 #if defined (_WIN32) || defined (__APPLE__)
1536                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
1537 #ifdef WITH_QUICKTIME
1538                         get_qtcodec_settings();
1539 #endif /* WITH_QUICKTIME */
1540                 }
1541 #if defined (_WIN32) && !defined(FREE_WINDOWS)
1542                 else
1543                         get_avicodec_settings();
1544 #endif /* _WIN32 && !FREE_WINDOWS */
1545 #endif /* _WIN32 || __APPLE__ */
1546                 break;
1547
1548         case B_PR_HD:
1549                 G.scene->r.xsch= 1920;
1550                 G.scene->r.ysch= 1080;
1551                 G.scene->r.xasp= 1;
1552                 G.scene->r.yasp= 1;
1553                 G.scene->r.size= 100;
1554                 G.scene->r.mode &= ~R_PANORAMA;
1555                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1556                 
1557                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1558                 BIF_undo_push("Set FULL");
1559                 allqueue(REDRAWBUTSSCENE, 0);
1560                 allqueue(REDRAWVIEWCAM, 0);
1561                 break;
1562         case B_PR_FULL:
1563                 G.scene->r.xsch= 1280;
1564                 G.scene->r.ysch= 1024;
1565                 G.scene->r.xasp= 1;
1566                 G.scene->r.yasp= 1;
1567                 G.scene->r.size= 100;
1568                 G.scene->r.mode &= ~R_PANORAMA;
1569                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1570
1571                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1572                 BIF_undo_push("Set FULL");
1573                 allqueue(REDRAWBUTSSCENE, 0);
1574                 allqueue(REDRAWVIEWCAM, 0);
1575                 break;
1576         case B_PR_PRV:
1577                 G.scene->r.xsch= 640;
1578                 G.scene->r.ysch= 512;
1579                 G.scene->r.xasp= 1;
1580                 G.scene->r.yasp= 1;
1581                 G.scene->r.size= 50;
1582                 G.scene->r.mode &= ~R_PANORAMA;
1583                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1584
1585                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1586                 allqueue(REDRAWVIEWCAM, 0);
1587                 allqueue(REDRAWBUTSSCENE, 0);
1588                 break;
1589         case B_PR_PAL169:
1590                 G.scene->r.xsch= 720;
1591                 G.scene->r.ysch= 576;
1592                 G.scene->r.xasp= 64;
1593                 G.scene->r.yasp= 45;
1594                 G.scene->r.size= 100;
1595                 G.scene->r.frs_sec= 25;
1596                 G.scene->r.frs_sec_base= 1;
1597                 G.scene->r.mode &= ~R_PANORAMA;
1598                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1599 #ifdef WITH_FFMPEG
1600                 G.scene->r.ffcodecdata.gop_size = 15;
1601 #endif          
1602
1603                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1604                 BIF_undo_push("Set PAL 16/9");
1605                 allqueue(REDRAWVIEWCAM, 0);
1606                 allqueue(REDRAWBUTSSCENE, 0);
1607                 break;
1608         case B_PR_PC:
1609                 G.scene->r.xsch= 640;
1610                 G.scene->r.ysch= 480;
1611                 G.scene->r.xasp= 100;
1612                 G.scene->r.yasp= 100;
1613                 G.scene->r.size= 100;
1614                 G.scene->r.mode &= ~R_PANORAMA;
1615                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1616
1617                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
1618                 BIF_undo_push("Set PC");
1619                 allqueue(REDRAWVIEWCAM, 0);
1620                 allqueue(REDRAWBUTSSCENE, 0);
1621                 break;
1622         case B_PR_PRESET:
1623                 G.scene->r.xsch= 720;
1624                 G.scene->r.ysch= 576;
1625                 G.scene->r.xasp= 54;
1626                 G.scene->r.yasp= 51;
1627                 G.scene->r.size= 100;
1628                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS+R_SSS;
1629                 G.scene->r.imtype= R_TARGA;
1630                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1631
1632                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1633                 BIF_undo_push("Set Default");
1634                 allqueue(REDRAWVIEWCAM, 0);
1635                 allqueue(REDRAWBUTSSCENE, 0);
1636                 break;
1637         case B_PR_PANO:
1638                 G.scene->r.xsch= 576;
1639                 G.scene->r.ysch= 176;
1640                 G.scene->r.xasp= 115;
1641                 G.scene->r.yasp= 100;
1642                 G.scene->r.size= 100;
1643                 G.scene->r.mode |= R_PANORAMA;
1644                 G.scene->r.xparts=  16;
1645                 G.scene->r.yparts= 1;
1646
1647                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1648                 BIF_undo_push("Set Panorama");
1649                 allqueue(REDRAWVIEWCAM, 0);
1650                 allqueue(REDRAWBUTSSCENE, 0);
1651                 break;
1652         case B_PR_NTSC:
1653                 G.scene->r.xsch= 720;
1654                 G.scene->r.ysch= 480;
1655                 G.scene->r.xasp= 10;
1656                 G.scene->r.yasp= 11;
1657                 G.scene->r.size= 100;
1658                 G.scene->r.frs_sec= 30;
1659                 G.scene->r.frs_sec_base = 1.001;
1660                 G.scene->r.mode &= ~R_PANORAMA;
1661                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1662 #ifdef WITH_FFMPEG
1663                 G.scene->r.ffcodecdata.gop_size = 18;
1664 #endif          
1665                 
1666                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1667                 BIF_undo_push("Set NTSC");
1668                 allqueue(REDRAWBUTSSCENE, 0);
1669                 allqueue(REDRAWVIEWCAM, 0);
1670                 break;
1671
1672         case B_SETBROWSE:
1673                 id= (ID*) G.scene->set;
1674                 
1675                 if (G.buts->menunr==-2) {
1676                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
1677                 } 
1678                 else if (G.buts->menunr>0) {
1679                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
1680                         
1681                         if (newset==G.scene)
1682                                 error("Can't use the same scene as its own set");
1683                         else if (newset) {
1684                                 G.scene->set= newset;
1685                                 if (scene_check_setscene(G.scene)==0)
1686                                         error("This would create a cycle");
1687
1688                                 allqueue(REDRAWBUTSSCENE, 0);
1689                                 allqueue(REDRAWVIEW3D, 0);
1690                                 BIF_undo_push("Change Set Scene");
1691                         }
1692                 }  
1693                 break;
1694         case B_CLEARSET:
1695                 G.scene->set= NULL;
1696                 allqueue(REDRAWBUTSSCENE, 0);
1697                 allqueue(REDRAWVIEW3D, 0);
1698                 BIF_undo_push("Clear Set Scene");
1699                 
1700                 break;
1701         case B_SET_EDGE:
1702                 allqueue(REDRAWBUTSSCENE, 0);
1703                 break;
1704         case B_SET_ZBLUR:
1705                 G.scene->r.mode &= ~R_EDGE;
1706                 allqueue(REDRAWBUTSSCENE, 0);
1707                 break;
1708         case B_ADD_RENDERLAYER:
1709                 if(G.scene->r.actlay==32767) {
1710                         scene_add_render_layer(G.scene);
1711                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
1712                 }
1713                 allqueue(REDRAWBUTSSCENE, 0);
1714                 allqueue(REDRAWNODE, 0);
1715                 break;
1716         case B_SET_PASS:
1717                 if(G.scene->nodetree) {
1718                         ntreeCompositForceHidden(G.scene->nodetree);
1719                         allqueue(REDRAWNODE, 0);
1720                 }
1721                 allqueue(REDRAWBUTSSCENE, 0);
1722                 allqueue(REDRAWOOPS, 0);
1723 #ifdef WITH_FFMPEG
1724         case B_ADD_FFMPEG_AUDIO_OPTION:
1725                 if (ffmpeg_property_add_string("audio", ffmpeg_option_to_add)){
1726                         *ffmpeg_option_to_add = 0;
1727                 }
1728                 allqueue(REDRAWBUTSSCENE, 0);
1729                 break;
1730         case B_ADD_FFMPEG_VIDEO_OPTION:
1731                 if (ffmpeg_property_add_string("video", ffmpeg_option_to_add)){
1732                         *ffmpeg_option_to_add = 0;
1733                 }
1734                 allqueue(REDRAWBUTSSCENE, 0);
1735                 break;
1736 #endif
1737         }
1738 }
1739
1740 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1741 static uiBlock *edge_render_menu(void *arg_unused)
1742 {
1743         uiBlock *block;
1744         
1745         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
1746                 
1747         /* use this for a fake extra empy space around the buttons */
1748         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
1749         
1750         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
1751                   "Sets edge intensity for Toon shading");
1752
1753         /* color settings for the toon shading */
1754         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
1755         
1756         uiBlockBeginAlign(block);
1757         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
1758                   "Color for edges in toon shading mode.");
1759         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
1760                   "Color for edges in toon shading mode.");
1761         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
1762                   "Color for edges in toon shading mode.");
1763
1764         
1765         uiBlockSetDirection(block, UI_TOP);
1766         
1767         return block;
1768 }
1769
1770
1771 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1772 static uiBlock *framing_render_menu(void *arg_unused)
1773 {
1774         uiBlock *block;
1775         short yco = 190, xco = 0;
1776         int randomcolorindex = 1234;
1777
1778         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
1779
1780         /* use this for a fake extra empy space around the buttons */
1781         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
1782
1783         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
1784         uiBlockBeginAlign(block);
1785         uiDefButC(block, ROW, 0, "Stretch",     xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_SCALE , 0, 0, "Stretch or squeeze the viewport to fill the display window");
1786         uiDefButC(block, ROW, 0, "Expose",      xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_EXTEND, 0, 0, "Show the entire viewport in the display window, viewing more horizontally or vertically");
1787         uiDefButC(block, ROW, 0, "Letterbox",       xco += 70, yco, 68, 19, &G.scene->framing.type, 1.0, SCE_GAMEFRAMING_BARS  , 0, 0, "Show the entire viewport in the display window, using bar horizontally or vertically");
1788         uiBlockEndAlign(block);
1789
1790         yco -= 25;
1791         xco = 40;
1792
1793         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
1794
1795         uiBlockBeginAlign(block);
1796         uiDefButF(block, NUMSLI, 0, "R ", xco,yco,243,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars");
1797         yco -= 20;
1798         uiDefButF(block, NUMSLI, 0, "G ", xco,yco,243,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars");
1799         yco -= 20;
1800         uiDefButF(block, NUMSLI, 0, "B ", xco,yco,243,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars");
1801         uiBlockEndAlign(block);
1802         
1803         xco = 0;
1804         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
1805         uiDefButS(block, TOG, 0, "Fullscreen", xco+70, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display");
1806         uiBlockBeginAlign(block);
1807         uiDefButS(block, NUM, 0, "X:",          xco+40, yco-=27, 100, 19, &G.scene->r.xplay, 10.0, 2000.0, 0, 0, "Displays current X screen/window resolution. Click to change.");
1808         uiDefButS(block, NUM, 0, "Y:",          xco+140, yco, 100, 19, &G.scene->r.yplay,    10.0, 2000.0, 0, 0, "Displays current Y screen/window resolution. Click to change.");
1809         uiDefButS(block, NUM, 0, "Freq:",       xco+40, yco-=21, 100, 19, &G.scene->r.freqplay, 10.0, 2000.0, 0, 0, "Displays clock frequency of fullscreen display. Click to change.");
1810         uiDefButS(block, NUM, 0, "Bits:",       xco+140, yco, 100, 19, &G.scene->r.depth, 8.0, 32.0, 800.0, 0, "Displays bit depth of full screen display. Click to change.");
1811         uiBlockEndAlign(block);
1812
1813         /* stereo settings */
1814         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
1815          * RAS_IRasterizer has definitions:
1816          * RAS_STEREO_NOSTEREO           1
1817          * RAS_STEREO_QUADBUFFERED 2
1818          * RAS_STEREO_ABOVEBELOW         3
1819          * RAS_STEREO_INTERLACED         4       future
1820          * RAS_STEREO_ANAGLYPH          5
1821          * RAS_STEREO_SIDEBYSIDE        6
1822          * RAS_STEREO_VINTERLACE        7
1823          */
1824         uiBlockBeginAlign(block);
1825         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
1826         uiDefButS(block, ROW, 0, "Pageflip", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 2.0, 0, 0, "Enables hardware pageflip stereo method");
1827         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
1828         uiDefButS(block, ROW, 0, "Anaglyph", xco-=180, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method");
1829         uiDefButS(block, ROW, 0, "Side by Side", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 6.0, 0, 0, "Enables side by side left and right images");
1830         uiDefButS(block, ROW, 0, "V Interlace", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display");
1831         
1832         uiBlockEndAlign(block);
1833
1834         uiBlockSetDirection(block, UI_TOP);
1835
1836         return block;
1837 }
1838
1839 #ifdef WITH_FFMPEG
1840
1841 static char* ffmpeg_format_pup(void) 
1842 {
1843         static char string[2048];
1844         char formatstring[2048];
1845 #if 0
1846        int i = 0;
1847        int stroffs = 0;
1848        AVOutputFormat* next = first_oformat;
1849        formatstring = "FFMpeg format: %%t";
1850       sprintf(string, formatstring);
1851        formatstring = "|%s %%x%d";
1852        /* FIXME: This should only be generated once */
1853        while (next != NULL) {
1854                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
1855                        sprintf(string+stroffs, formatstring, next->name, i++);
1856                        stroffs += strlen(string+stroffs);
1857                }
1858                next = next->next;
1859        }
1860        return string;
1861 #endif
1862        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d"
1863 #if 0
1864 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1865               "|%s %%x%d"
1866 #endif
1867               "|%s %%x%d");
1868        sprintf(string, formatstring,
1869                "MPEG-1", FFMPEG_MPEG1,
1870                "MPEG-2", FFMPEG_MPEG2,
1871                "MPEG-4", FFMPEG_MPEG4,
1872                "AVI",    FFMPEG_AVI,
1873                "Quicktime", FFMPEG_MOV,
1874                "DV", FFMPEG_DV,
1875                "H264", FFMPEG_H264,
1876                "XVid", FFMPEG_XVID,
1877 #if 0 
1878 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1879                "OGG", FFMPEG_OGG,
1880 #endif
1881                "FLV", FFMPEG_FLV);
1882        return string;
1883 }
1884
1885 static char* ffmpeg_preset_pup(void) 
1886 {
1887         static char string[2048];
1888         char formatstring[2048];
1889
1890        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1891        sprintf(string, formatstring,
1892                "", FFMPEG_PRESET_NONE,
1893                "DVD", FFMPEG_PRESET_DVD,
1894                "SVCD", FFMPEG_PRESET_SVCD,
1895                "VCD", FFMPEG_PRESET_VCD,
1896                "DV", FFMPEG_PRESET_DV,
1897                "H264", FFMPEG_PRESET_H264);
1898        return string;
1899 }
1900
1901
1902 static char* ffmpeg_codec_pup(void) {
1903        static char string[2048];
1904        char formatstring[2048];
1905        strcpy(formatstring, 
1906               "FFMpeg format: %%t"
1907               "|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d"
1908 #ifdef WITH_OGG
1909               "|%s %%x%d"
1910 #endif
1911               "|%s %%x%d");
1912        sprintf(string, formatstring,
1913                "MPEG1", CODEC_ID_MPEG1VIDEO,
1914                "MPEG2", CODEC_ID_MPEG2VIDEO,
1915                "MPEG4(divx)", CODEC_ID_MPEG4,
1916                "HuffYUV", CODEC_ID_HUFFYUV,
1917                "DV", CODEC_ID_DVVIDEO,
1918                "H264", CODEC_ID_H264,
1919                "XVid", CODEC_ID_XVID,
1920 #ifdef WITH_OGG
1921                "Theora", CODEC_ID_THEORA,
1922 #endif
1923                "FlashVideo1", CODEC_ID_FLV1);
1924        return string;
1925
1926 }
1927
1928 static char* ffmpeg_audio_codec_pup(void) {
1929        static char string[2048];
1930        char formatstring[2048];
1931        strcpy(formatstring, 
1932               "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d"
1933 #ifdef WITH_OGG
1934               "|%s %%x%d"
1935 #endif
1936               "|%s %%x%d");
1937        sprintf(string, formatstring,
1938                "MP2", CODEC_ID_MP2,
1939                "MP3", CODEC_ID_MP3,
1940                "AC3", CODEC_ID_AC3,
1941                "AAC", CODEC_ID_AAC,
1942 #ifdef WITH_OGG
1943                "Vorbis", CODEC_ID_VORBIS,
1944 #endif
1945                "PCM", CODEC_ID_PCM_S16LE);
1946        return string;
1947
1948 }
1949
1950 #endif
1951
1952 static char *imagetype_pup(void)
1953 {
1954         static char string[1024];
1955         char formatstring[1024];
1956         char appendstring[1024];
1957
1958         strcpy(formatstring, "Save image as: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1959
1960 #ifdef __sgi
1961         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1962 #endif
1963
1964         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1965 /*  Commented out until implemented
1966 #ifdef WITH_DDS
1967         strcat(formatstring, "|%s %%x%d");      // add space for DDS
1968 #endif
1969 */
1970         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1971         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1972         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1973         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1974         
1975 #ifdef _WIN32
1976         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1977 #endif
1978
1979 #ifdef WITH_FFMPEG
1980        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1981 #endif
1982        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1983
1984 #ifdef WITH_QUICKTIME
1985         if(G.have_quicktime)
1986                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1987 #endif
1988
1989         if(G.have_quicktime) {
1990                 sprintf(string, formatstring,
1991                         "Frameserver",   R_FRAMESERVER,
1992 #ifdef WITH_FFMPEG
1993                        "FFMpeg",         R_FFMPEG,
1994 #endif
1995                         "AVI Raw",        R_AVIRAW,
1996                         "AVI Jpeg",       R_AVIJPEG,
1997 #ifdef _WIN32
1998                         "AVI Codec",      R_AVICODEC,
1999 #endif
2000 #ifdef WITH_QUICKTIME
2001                         "QuickTime",      R_QUICKTIME,
2002 #endif
2003                         "Targa",          R_TARGA,
2004                         "Targa Raw",      R_RAWTGA,
2005                         "PNG",            R_PNG,
2006 /* commented out until implemented 
2007 #ifdef WITH_DDS
2008                         "DDS",            R_DDS,
2009 #endif
2010 */
2011                         "BMP",            R_BMP,
2012                         "Jpeg",           R_JPEG90,
2013                         "HamX",           R_HAMX,
2014                         "Iris",           R_IRIS,
2015                         "Radiance HDR",   R_RADHDR,
2016                         "Cineon",                 R_CINEON,
2017                         "DPX",                    R_DPX
2018 #ifdef __sgi
2019                         ,"Movie",          R_MOVIE
2020 #endif
2021                 );
2022         } else {
2023                 sprintf(string, formatstring,
2024                         "Frameserver",   R_FRAMESERVER,
2025 #ifdef WITH_FFMPEG
2026                        "FFMpeg",         R_FFMPEG,
2027 #endif
2028                         "AVI Raw",        R_AVIRAW,
2029                         "AVI Jpeg",       R_AVIJPEG,
2030 #ifdef _WIN32
2031                         "AVI Codec",      R_AVICODEC,
2032 #endif
2033                         "Targa",          R_TARGA,
2034                         "Targa Raw",      R_RAWTGA,
2035                         "PNG",            R_PNG,
2036 /*#ifdef WITH_DDS
2037                         "DDS",            R_DDS,
2038 #endif*/
2039                         "BMP",            R_BMP,
2040                         "Jpeg",           R_JPEG90,
2041                         "HamX",           R_HAMX,
2042                         "Iris",           R_IRIS,
2043                         "Radiance HDR",   R_RADHDR,
2044                         "Cineon",                 R_CINEON,
2045                         "DPX",                    R_DPX
2046 #ifdef __sgi
2047                         ,"Movie",          R_MOVIE
2048 #endif
2049                 );
2050         }
2051
2052 #ifdef WITH_OPENEXR
2053         strcpy(formatstring, "|%s %%x%d");
2054         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
2055         strcat(string, appendstring);
2056         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
2057         strcat(string, appendstring);
2058 #endif
2059         
2060         if (G.have_libtiff) {
2061                 strcpy(formatstring, "|%s %%x%d");
2062                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
2063                 strcat(string, appendstring);
2064         }
2065
2066         return (string);
2067 }
2068
2069 #ifdef _WIN32
2070 static char *avicodec_str(void)
2071 {
2072         static char string[1024];
2073
2074         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
2075
2076         return string;
2077 }
2078 #endif
2079
2080 static void render_panel_output(void)
2081 {
2082         ID *id;
2083         int a,b;
2084         uiBlock *block;
2085         char *strp;
2086
2087         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
2088         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
2089         
2090         uiBlockBeginAlign(block);
2091         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for saving animations");
2092         uiDefBut(block, TEX,0,"",                                                       31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save animations, # characters defines the position and length of frame numbers");
2093         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for a Backbuf image");
2094         uiDefBut(block, TEX,0,"",                                                       31, 168, 259, 20,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
2095         uiDefIconButBitS(block, ICONTOG, R_BACKBUF, B_NOP, ICON_CHECKBOX_HLT-1, 290, 168, 20, 20, &G.scene->r.bufflag, 0.0, 0.0, 0, 0, "Enable/Disable use of Backbuf image");
2096         uiBlockEndAlign(block);
2097         
2098         uiDefButBitI(block, TOG, R_EXTENSION, B_NOP, "Extensions", 10, 142, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds filetype extensions to the filename when rendering animations");
2099         
2100         uiBlockBeginAlign(block);
2101         uiDefButBitI(block, TOG, R_TOUCH, B_NOP, "Touch",       170, 142, 50, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Create an empty file before rendering each frame, remove if cancelled (and empty)");
2102         uiDefButBitI(block, TOG, R_NO_OVERWRITE, B_NOP, "No Overwrite", 220, 142, 90, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Skip rendering frames when the file exists (image output only)");
2103         uiBlockEndAlign(block);
2104         
2105         /* SET BUTTON */
2106         uiBlockBeginAlign(block);
2107         id= (ID *)G.scene->set;
2108         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
2109         if(strp[0])
2110                 uiDefButS(block, MENU, B_SETBROWSE, strp,                       10, 114, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
2111         MEM_freeN(strp);
2112
2113         if(G.scene->set) {
2114                 uiSetButLock(1, NULL);
2115                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 114, 100, 20, &(G.scene->set), "Name of the Set");
2116                 uiClearButLock();
2117                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 114, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
2118         } else {
2119                 uiDefBut(block, LABEL, 0, "No Set Scene", 31, 114, 200, 20, 0, 0, 0, 0, 0, "");
2120         }
2121         uiBlockEndAlign(block);
2122
2123         uiBlockBeginAlign(block);
2124         uiDefIconButBitI(block, TOGN, R_FIXED_THREADS, B_REDR, ICON_AUTO,       10, 63, 20, 20, &G.scene->r.mode, 0.0, 0.0, 0, 0, "Automatically set the threads to the number of processors on the system");
2125         if ((G.scene->r.mode & R_FIXED_THREADS)==0) {
2126                 char thread_str[16];
2127                 sprintf(thread_str, " Threads: %d", BLI_system_thread_count());
2128                 uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, "");
2129         } else {
2130                 uiDefButS(block, NUM, B_NOP, "Threads:", 30, 63, 80, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render (takes advantage of multi-core and multi-processor computers)");
2131         }
2132         uiBlockEndAlign(block);
2133         
2134         uiBlockSetCol(block, TH_AUTO);
2135                 
2136         uiBlockBeginAlign(block);
2137         for(b=2; b>=0; b--)
2138                 for(a=0; a<3; a++)
2139                         uiDefButBitS(block, TOG, 1<<(3*b+a), 800,"",    (short)(10+18*a),(short)(10+14*b),16,12, &G.winpos, 0, 0, 0, 0, "Render window placement on screen");
2140         uiBlockEndAlign(block);
2141
2142 #ifdef WITH_OPENEXR
2143         uiBlockBeginAlign(block);
2144         uiDefButBitI(block, TOG, R_EXR_TILE_FILE, B_REDR, "Save Buffers", 72, 31, 120, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Save tiles for all RenderLayers and used SceneNodes to files in the temp directory (saves memory, allows Full Sampling)");
2145         if(G.scene->r.scemode & R_EXR_TILE_FILE)
2146                 uiDefButBitI(block, TOG, R_FULL_SAMPLE, B_REDR, "FullSample",    192, 31, 118, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Saves for every OSA sample the entire RenderLayer results (Higher quality sampling but slower)");
2147         uiBlockEndAlign(block);
2148 #endif
2149         
2150         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
2151                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
2152         
2153         /* Dither control */
2154         uiDefButF(block, NUM,B_DIFF, "Dither:",         10,89,100,19, &G.scene->r.dither_intensity, 0.0, 2.0, 0, 0, "The amount of dithering noise present in the output image (0.0 = no dithering)");
2155         
2156         /* Toon shading buttons */
2157         uiBlockBeginAlign(block);
2158         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   115, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
2159         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 135, 20, "Display Edge settings");
2160         uiBlockEndAlign(block);
2161         
2162         uiBlockBeginAlign(block);
2163         uiDefButBitI(block, TOG, R_NO_TEX, B_NOP, "Disable Tex", 115, 63, 75, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Disables Textures for render");
2164         uiDefButBitI(block, TOG, R_FREE_IMAGE, B_NOP, "Free Tex Images", 210, 63, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Frees all Images used by Textures after each render");
2165         uiBlockEndAlign(block);
2166 }
2167
2168 static void do_bake_func(void *unused_v, void *unused_p)
2169 {
2170         objects_bake_render_ui(0);
2171 }
2172
2173 static void render_panel_bake(void)
2174 {
2175         uiBlock *block;
2176         uiBut *but;
2177         
2178         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
2179         uiNewPanelTabbed("Anim", "Render");
2180         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
2181         
2182         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
2183         uiButSetFunc(but, do_bake_func, NULL, NULL);
2184
2185         uiBlockBeginAlign(block);
2186         uiDefButBitS(block, TOG, R_BAKE_TO_ACTIVE, B_DIFF, "Selected to Active", 10,120,190,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Bake shading on the surface of selected objects to the active object");
2187         uiDefButF(block, NUM, B_DIFF, "Dist:", 10,100,95,20,&G.scene->r.bake_maxdist, 0.0, 1000.0, 1, 0, "Maximum distance from active object to other object (in blender units)");
2188         uiDefButF(block, NUM, B_DIFF, "Bias:", 105,100,95,20,&G.scene->r.bake_biasdist, 0.0, 1000.0, 1, 0, "Bias towards faces further away from the object (in blender units)");
2189         uiBlockEndAlign(block);
2190
2191         if(G.scene->r.bake_mode == RE_BAKE_NORMALS)
2192                 uiDefButS(block, MENU, B_DIFF, "Normal Space %t|Camera %x0|World %x1|Object %x2|Tangent %x3", 
2193                         10,70,190,20, &G.scene->r.bake_normal_space, 0, 0, 0, 0, "Choose normal space for baking");
2194         else if(G.scene->r.bake_mode == RE_BAKE_AO || G.scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
2195                 uiDefButBitS(block, TOG, R_BAKE_NORMALIZE, B_DIFF, "Normalized", 10,70,190,20, &G.scene->r.bake_flag, 0.0, 0, 0, 0,
2196                                 G.scene->r.bake_mode == RE_BAKE_AO ?
2197                                  "Bake ambient occlusion normalized, without taking into acount material settings":
2198                                  "Normalized displacement value to fit the 'Dist' range"
2199                 );
2200         }
2201         
2202         uiDefButS(block, MENU, B_NOP, "Quad Split Order%t|Quad Split Auto%x0|Quad Split A (0,1,2) (0,2,3)%x1|Quad Split B (1,2,3) (1,3,0)%x2", 
2203                 10,10,190,20, &G.scene->r.bake_quad_split, 0, 0, 0, 0, "Method to divide quads (use A or B for external applications that use a fixed order)");
2204         
2205 #if 0   
2206         uiBlockBeginAlign(block);
2207         uiDefButBitS(block, TOG, R_BAKE_OSA, B_DIFF, "OSA",             10,120,190,20, &G.scene->r.bake_flag, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2208         uiDefButS(block, ROW,B_DIFF,"5",                        10,100,50,20,&G.scene->r.bake_osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
2209         uiDefButS(block, ROW,B_DIFF,"8",                        60,100,45,20,&G.scene->r.bake_osa,2.0,8.0, 0, 0, "Sets oversample level to 8");
2210         uiDefButS(block, ROW,B_DIFF,"11",                       105,100,45,20,&G.scene->r.bake_osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
2211         uiDefButS(block, ROW,B_DIFF,"16",                       150,100,50,20,&G.scene->r.bake_osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
2212 #endif  
2213         uiBlockBeginAlign(block);
2214         uiDefButS(block, ROW,B_REDR,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
2215         uiDefButS(block, ROW,B_REDR,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
2216         uiDefButS(block, ROW,B_REDR,"Shadow",                   210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_SHADOW, 0, 0, "");
2217         uiDefButS(block, ROW,B_REDR,"Normals",                  210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
2218         uiDefButS(block, ROW,B_REDR,"Textures",                 210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
2219         uiDefButS(block, ROW,B_REDR,"Displacement",             210,70,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, "");
2220         uiBlockEndAlign(block);
2221         
2222         uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear",         210,40,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking");
2223         
2224         uiDefButS(block, NUM, B_DIFF,"Margin:",                         210,10,120,20,&G.scene->r.bake_filter, 0.0, 32.0, 0, 0, "Amount of pixels to extend the baked result with, as post process filter");
2225 }
2226
2227 static void render_panel_simplify(void)
2228 {
2229         uiBlock *block;
2230         
2231         block= uiNewBlock(&curarea->uiblocks, "render_panel_simplify", UI_EMBOSS, UI_HELV, curarea->win);
2232         uiNewPanelTabbed("Render", "Render");
2233         if(uiNewPanel(curarea, block, "Simplifcation", "Render", 320, 0, 318, 204)==0) return;
2234
2235         uiDefButBitI(block, TOG, R_SIMPLIFY, B_DIFF,"Render Simplification",    10,150,190,20, &G.scene->r.mode, 0, 0, 0, 0, "Enable simplification of scene");
2236
2237         uiBlockBeginAlign(block);
2238         uiDefButI(block, NUM,B_DIFF, "Subsurf:",        10,120,190,20, &G.scene->r.simplify_subsurf, 0.0, 6.0, 0, 0, "Global maximum subsurf level percentage");
2239         uiDefButF(block, NUM,B_DIFF, "Child Particles:",        10,100,190,20, &G.scene->r.simplify_particles, 0.0, 1.0, 0, 0, "Global child particle percentage");
2240         uiBlockEndAlign(block);
2241
2242         uiBlockBeginAlign(block);
2243         uiDefButI(block, NUM,B_DIFF, "Shadow Samples:", 10,70,190,20, &G.scene->r.simplify_shadowsamples, 1.0, 16.0, 0, 0, "Global maximum shadow map samples");
2244         uiDefButF(block, NUM,B_DIFF, "AO and SSS:",     10,50,190,20, &G.scene->r.simplify_aosss, 0.0, 1.0, 0, 0, "Global approximate AO and SSS quality factor");
2245         uiBlockEndAlign(block);
2246 }
2247
2248 static void render_panel_render(void)
2249 {
2250         uiBlock *block;
2251         char str[256];
2252
2253         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
2254         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
2255
2256         uiBlockBeginAlign(block);
2257         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Render the current frame (F12)");
2258 #ifndef DISABLE_YAFRAY
2259         /* yafray: on request, render engine menu is back again, and moved to Render panel */
2260         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
2261                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2262 #else
2263         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
2264                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
2265 #endif /* disable yafray */
2266
2267         uiBlockBeginAlign(block);
2268         if((G.scene->r.scemode & R_FULL_SAMPLE) && (G.scene->r.scemode & R_EXR_TILE_FILE))
2269                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "FSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Saves all samples, then composites, and then merges (for best Anti-aliasing)");
2270         else
2271                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2272         uiDefButS(block, ROW,B_DIFF,"5",                        369,88,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Render 5 samples per pixel for smooth edges (Fast)");
2273         uiDefButS(block, ROW,B_DIFF,"8",                        400,88,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Render 8 samples per pixel for smooth edges (Recommended)");
2274         uiDefButS(block, ROW,B_DIFF,"11",                       431,88,29,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Render 11 samples per pixel for smooth edges (High Quality)");
2275         uiDefButS(block, ROW,B_DIFF,"16",                       462,88,29,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Render 16 samples per pixel for smooth edges (Highest Quality)");
2276         uiBlockEndAlign(block);
2277
2278         uiBlockBeginAlign(block);
2279         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
2280         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
2281         uiBlockEndAlign(block);
2282
2283         uiBlockBeginAlign(block);
2284         uiDefButS(block, NUM,B_DIFF,"Xparts:",          369,46,95,29,&G.scene->r.xparts,1.0, 512.0, 0, 0, "Sets the number of horizontal parts to render image in (For panorama sets number of camera slices)");
2285         uiDefButS(block, NUM,B_DIFF,"Yparts:",          465,46,95,29,&G.scene->r.yparts,1.0, 64.0, 0, 0, "Sets the number of vertical parts to render image in");
2286         uiBlockEndAlign(block);
2287
2288         uiBlockBeginAlign(block);
2289         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
2290         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
2291         uiDefButS(block, ROW,800,"Key",         456,13,35,20,&G.scene->r.alphamode,3.0,2.0, 0, 0, "Alpha and color values remain unchanged");
2292         uiBlockEndAlign(block);
2293
2294         uiDefButS(block, MENU, B_DIFF,"Octree resolution %t|64 %x64|128 %x128|256 %x256|512 %x512",     496,13,64,20,&G.scene->r.ocres,0.0,0.0, 0, 0, "Octree resolution for ray tracing and baking, Use higher values for complex scenes");
2295
2296         uiBlockBeginAlign(block);
2297         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
2298         uiDefButBitI(block, TOG, R_SSS, B_REDR,"SSS",   617,172,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable subsurface scattering map rendering");
2299         uiDefButBitI(block, TOG, R_PANORAMA, B_REDR,"Pano",     649,172,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
2300         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     565,142,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
2301         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",617,142,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
2302         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       649,142,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
2303         uiBlockEndAlign(block);
2304         
2305         uiBlockBeginAlign(block);
2306         uiDefButS(block, ROW,B_DIFF,"100%",                     565,109,122,20,&G.scene->r.size,1.0,100.0, 0, 0, "Set render size to defined size");
2307         uiDefButS(block, ROW,B_DIFF,"75%",                      565,88,40,20,&G.scene->r.size,1.0,75.0, 0, 0, "Set render size to 3/4 of defined size");
2308         uiDefButS(block, ROW,B_DIFF,"50%",                      606,88,40,20,&G.scene->r.size,1.0,50.0, 0, 0, "Set render size to 1/2 of defined size");
2309         uiDefButS(block, ROW,B_DIFF,"25%",                      647,88,40,20,&G.scene->r.size,1.0,25.0, 0, 0, "Set render size to 1/4 of defined size");
2310         uiBlockEndAlign(block);
2311
2312         uiBlockBeginAlign(block);
2313         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
2314         uiDefButBitI(block, TOG, R_ODDFIELD, B_REDR,"Odd",      627,55,39,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Odd field first rendering (Default: Even field)");
2315         uiDefButBitI(block, TOG, R_FIELDSTILL, B_REDR,"X",              668,55,19,20,&G.scene->r.mode, 0, 0, 0, 0, "Disables time difference in field calculations");
2316         
2317         sprintf(str, "Filter%%t|Box %%x%d|Tent %%x%d|Quad %%x%d|Cubic %%x%d|Gauss %%x%d|CatRom %%x%d|Mitch %%x%d", R_FILTER_BOX, R_FILTER_TENT, R_FILTER_QUAD, R_FILTER_CUBIC, R_FILTER_GAUSS, R_FILTER_CATROM, R_FILTER_MITCH);
2318         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
2319         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
2320         
2321         uiDefButBitI(block, TOG, R_BORDER, REDRAWVIEWCAM, "Border",     565,13,122,20, &G.scene->r.mode, 0, 0, 0, 0, "Render a small cut-out of the image (Shift+B to set in the camera view)");
2322         uiBlockEndAlign(block);
2323
2324 }
2325
2326 static void render_panel_anim(void)
2327 {
2328         uiBlock *block;
2329
2330
2331         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2332         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
2333
2334
2335         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Render the animation to disk from start to end frame, (Ctrl+F12)");
2336
2337         uiBlockSetCol(block, TH_BUT_SETTING1);
2338         uiBlockBeginAlign(block);
2339         uiDefButBitI(block, TOG, R_DOSEQ, B_NOP, "Do Sequence",692,114,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Enables sequence output rendering (Default: 3D rendering)");
2340         uiDefButBitI(block, TOG, R_DOCOMP, B_NOP, "Do Composite",692,90,192,20, &G.scene->r.scemode, 0, 0, 0, 0, "Uses compositing nodes for output rendering");
2341         uiBlockEndAlign(block);
2342
2343         uiBlockSetCol(block, TH_AUTO);
2344         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,50,94,33, 0, 0, 0, 0, 0, "Play rendered images/avi animation (Ctrl+F11), (Play Hotkeys: A-Noskip, P-PingPong)");
2345         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,50,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
2346
2347         uiBlockBeginAlign(block);
2348         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,20,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation (inclusive)");
2349         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,20,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation  (inclusive)");
2350         uiDefButI(block, NUM,REDRAWSEQ,"Step:",692,0,192,18, &G.scene->frame_step, 1.0, MAXFRAMEF, 0, 0, "Frame Step");
2351         uiBlockEndAlign(block);
2352 }
2353
2354 #ifdef WITH_FFMPEG
2355
2356 static void ffmpeg_property_del(void *type, void *prop_)
2357 {
2358         struct IDProperty *prop = (struct IDProperty *) prop_;
2359         IDProperty * group;
2360         
2361         if (!G.scene->r.ffcodecdata.properties) {
2362                 return;
2363         }
2364
2365         group = IDP_GetPropertyFromGroup(
2366                 G.scene->r.ffcodecdata.properties, (char*) type);
2367         if (group && prop) {
2368                 IDP_RemFromGroup(group, prop);
2369                 IDP_FreeProperty(prop);
2370                 MEM_freeN(prop);
2371         }
2372         allqueue(REDRAWBUTSSCENE, 0);
2373 }
2374
2375 static IDProperty * ffmpeg_property_add(
2376         char * type, int opt_index, int parent_index)
2377 {
2378         AVCodecContext c;
2379         const AVOption * o;
2380         const AVOption * parent;
2381         IDProperty * group;
2382         IDProperty * prop;
2383         IDPropertyTemplate val;
2384         int idp_type;
2385         char name[256];
2386
2387         avcodec_get_context_defaults(&c);
2388
2389         o = c.av_class->option + opt_index;
2390         parent = c.av_class->option + parent_index;
2391
2392         if (!G.scene->r.ffcodecdata.properties) {
2393                 IDPropertyTemplate val;
2394
2395                 G.scene->r.ffcodecdata.properties 
2396                         = IDP_New(IDP_GROUP, val, "ffmpeg"); 
2397         }
2398
2399         group = IDP_GetPropertyFromGroup(
2400                 G.scene->r.ffcodecdata.properties, (char*) type);
2401         
2402         if (!group) {
2403                 IDPropertyTemplate val;
2404                 
2405                 group = IDP_New(IDP_GROUP, val, (char*) type); 
2406                 IDP_AddToGroup(G.scene->r.ffcodecdata.properties, group);
2407         }
2408
2409         if (parent_index) {
2410                 sprintf(name, "%s:%s", parent->name, o->name);
2411         } else {
2412                 strcpy(name, o->name);
2413         }
2414
2415         fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
2416                 type, parent_index, opt_index, name);
2417
2418         prop = IDP_GetPropertyFromGroup(group, name);
2419         if (prop) {
2420                 return prop;
2421         }
2422
2423         switch (o->type) {
2424         case FF_OPT_TYPE_INT:
2425         case FF_OPT_TYPE_INT64:
2426                 val.i = o->default_val;
2427                 idp_type = IDP_INT;
2428                 break;
2429         case FF_OPT_TYPE_DOUBLE:
2430         case FF_OPT_TYPE_FLOAT:
2431                 val.f = o->default_val;
2432                 idp_type = IDP_FLOAT;
2433                 break;
2434         case FF_OPT_TYPE_STRING:
2435                 val.str = "                                                                               ";
2436                 idp_type = IDP_STRING;
2437                 break;
2438         case FF_OPT_TYPE_CONST:
2439                 val.i = 1;
2440                 idp_type = IDP_INT;
2441                 break;
2442         default:
2443                 return NULL;
2444         }
2445         prop = IDP_New(idp_type, val, name);
2446         IDP_AddToGroup(group, prop);
2447         return prop;
2448 }
2449
2450 /* not all versions of ffmpeg include that, so here we go ... */
2451
2452 static const AVOption *my_av_find_opt(void *v, const char *name, 
2453                                       const char *unit, int mask, int flags){
2454         AVClass *c= *(AVClass**)v; 
2455         const AVOption *o= c->option;
2456
2457         for(;o && o->name; o++){
2458                 if(!strcmp(o->name, name) && 
2459                    (!unit || (o->unit && !strcmp(o->unit, unit))) && 
2460                    (o->flags & mask) == flags )
2461                         return o;
2462         }
2463         return NULL;
2464 }
2465
2466 static int ffmpeg_property_add_string(const char * type, const char * str)
2467 {
2468         AVCodecContext c;
2469         const AVOption * o = 0;
2470         const AVOption * p = 0;
2471         char name_[128];
2472         char * name;
2473         char * param;
2474         IDProperty * prop;
2475         
2476         avcodec_get_context_defaults(&c);
2477
2478         strncpy(name_, str, 128);
2479
2480         name = name_;
2481         while (*name == ' ') name++;
2482
2483         param = strchr(name, ':');
2484
2485         if (!param) {
2486                 param = strchr(name, ' ');
2487         }
2488         if (param) {
2489                 *param++ = 0;
2490                 while (*param == ' ') param++;
2491         }
2492         
2493         o = my_av_find_opt(&c, name, NULL, 0, 0);       
2494         if (!o) {
2495                 return FALSE;
2496         }
2497         if (param && o->type == FF_OPT_TYPE_CONST) {
2498                 return FALSE;
2499         }
2500         if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
2501                 p = my_av_find_opt(&c, param, o->unit, 0, 0);   
2502                 prop = ffmpeg_property_add(
2503                         (char*) type, p - c.av_class->option, 
2504                         o - c.av_class->option);
2505         } else {
2506                 prop = ffmpeg_property_add(
2507                         (char*) type, o - c.av_class->option, 0);
2508         }
2509                 
2510
2511         if (!prop) {
2512                 return FALSE;
2513         }
2514
2515         if (param && !p) {
2516                 switch (prop->type) {
2517                 case IDP_INT:
2518                         IDP_Int(prop) = atoi(param);
2519                         break;
2520                 case IDP_FLOAT:
2521                         IDP_Float(prop) = atof(param);
2522                         break;
2523                 case IDP_STRING:
2524                         strncpy(IDP_String(prop), param, prop->len);
2525                         break;
2526                 }
2527         }
2528         return TRUE;
2529 }
2530
2531 static void ffmpeg_property_add_using_menu(void * type, int opt_indices)
2532 {
2533         int opt_index = opt_indices & 65535;
2534         int parent_index = opt_indices >> 16;
2535
2536         ffmpeg_property_add((char*) type, opt_index, parent_index);
2537
2538         allqueue(REDRAWBUTSSCENE, 0);
2539 }
2540
2541 static uiBlock *ffmpeg_property_add_submenu(AVOption * parent, char * type) 
2542 {
2543         AVCodecContext c;
2544         const AVOption * o;
2545         uiBlock *block;
2546         int yco = 0;
2547         int flags = 0;
2548         int parent_index = 0;
2549
2550         if (strcmp(type, "audio") == 0) {
2551                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2552         } else if (strcmp(type, "video") == 0) {
2553                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2554         } else {
2555                 return NULL;
2556         }
2557
2558         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_submenu",
2559                           UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2560         uiBlockSetButmFunc(block, ffmpeg_property_add_using_menu, type);
2561
2562         avcodec_get_context_defaults(&c);
2563
2564         if (parent) {
2565                 parent_index = (parent - c.av_class->option);
2566         }
2567         
2568         for(o = c.av_class->option; o && o->name; o++){
2569                 if (o->help && 
2570                     (strstr(o->help, "experimental")
2571                      || strstr(o->help, "obsolete")
2572                      || strstr(o->help, "useless")
2573                      || strstr(o->help, "deprecated"))) {
2574                         continue;
2575                 }
2576                 if((o->flags & flags) == flags) {
2577                         if((!parent && !o->unit) 
2578                            || (o->unit && parent 
2579                                && strcmp(o->unit, parent->unit) == 0 
2580                                && o->type == FF_OPT_TYPE_CONST)) {
2581                                 uiDefBut(block, BUTM, B_REDR, 
2582                                          (char*) (o->help && o->help[0] ? 
2583                                                   o->help : o->name),
2584                                          0, yco, 160, 15, 
2585                                          NULL, 0, 0, 1, 
2586                                          (o - c.av_class->option) | 
2587                                          (parent_index << 16),
2588                                          "");
2589                                 yco -= 16;
2590                         }
2591                 }
2592         }
2593         
2594         uiTextBoundsBlock(block, 50);
2595         uiBlockSetDirection(block, UI_RIGHT);
2596
2597         return block;
2598 }
2599
2600 static uiBlock *ffmpeg_property_add_submenu_audio(void* opt)
2601 {
2602         return ffmpeg_property_add_submenu((AVOption*) opt, "audio");
2603 }
2604
2605 static uiBlock *ffmpeg_property_add_submenu_video(void* opt)
2606 {
2607         return ffmpeg_property_add_submenu((AVOption*) opt, "video");
2608 }
2609
2610 static uiBlock *ffmpeg_property_add_menu(void* type_) 
2611 {
2612         char * type = (char*) type_;
2613         AVCodecContext c;
2614         const AVOption * o;
2615         uiBlock *block;
2616         int yco = 0;
2617         int flags = 0;
2618         uiBlockFuncFP add_submenu = NULL;
2619
2620         if (strcmp(type, "audio") == 0) {
2621                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2622                 add_submenu = ffmpeg_property_add_submenu_audio;
2623         } else if (strcmp(type, "video") == 0) {
2624                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2625                 add_submenu = ffmpeg_property_add_submenu_video;
2626         } else {
2627                 return NULL;
2628         }
2629
2630         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_menu",
2631                           UI_EMBOSSP, UI_HELV, curarea->win);
2632
2633         avcodec_get_context_defaults(&c);
2634         
2635         for(o = c.av_class->option; o && o->name; o++){
2636                 if((o->flags & flags) == flags) {
2637                         if (o->type == FF_OPT_TYPE_CONST) {
2638                                 continue;
2639                         }
2640                         if (o->help && 
2641                             (strstr(o->help, "experimental")
2642                              || strstr(o->help, "obsolete")
2643                              || strstr(o->help, "useless")
2644                              || strstr(o->help, "deprecated"))) {
2645                                 continue;
2646                         }
2647
2648                         if (o->unit) {
2649         
2650                                 uiDefIconTextBlockBut(
2651                                         block, 
2652                                         add_submenu, 
2653                                         (void*) o, 
2654                                         ICON_RIGHTARROW_THIN,
2655                                         (char*) (o->help ? 
2656                                                  o->help : o->name), 
2657                                         0, yco, 160, 15, "");
2658                                 yco -= 16;
2659                         } 
2660                 }
2661         }
2662
2663         uiDefIconTextBlockBut(
2664                 block, 
2665                 add_submenu, 
2666                 NULL, 
2667                 ICON_RIGHTARROW_THIN,
2668                 "Value / string options", 
2669                 0, yco, 160, 15, "");
2670         
2671         uiTextBoundsBlock(block, 50);
2672         uiBlockSetDirection(block, UI_DOWN);
2673
2674         return block;
2675 }
2676
2677 static int render_panel_ffmpeg_property_option(
2678         uiBlock *block, int xofs, int yofs, IDProperty * curr,
2679         const char * type)
2680 {
2681         AVCodecContext c;
2682         const AVOption * o;
2683         uiBut *but;
2684         char name[128];
2685         char * param;
2686
2687         strcpy(name, curr->name);
2688         param = strchr(name, ':');
2689
2690         if (param) {
2691                 *param++ = 0;
2692         }
2693
2694         avcodec_get_context_defaults(&c);
2695
2696         o = my_av_find_opt(&c, param ? param : name, NULL, 0, 0);
2697         if (!o) {
2698                 return yofs;
2699         }
2700
2701         switch (curr->type) {
2702         case IDP_STRING:
2703                 uiDefBut(block, TEX, 
2704                          B_REDR, curr->name, 
2705                          xofs,yofs, 200,19, 
2706                          IDP_String(curr), 
2707                          0.0, curr->len - 1, 100, 0, 
2708                          (char*) o->help);
2709                 break;
2710         case IDP_FLOAT:
2711                 uiDefButF(block, NUM, B_REDR, curr->name, 
2712                           xofs, yofs, 200, 19, 
2713                           &IDP_Float(curr), 
2714                           o->min, o->max, 0, 0, (char*) o->help);
2715                 break;
2716         case IDP_INT:
2717                 if (o->type == FF_OPT_TYPE_CONST) {
2718                         uiDefButBitI(block, TOG, 1, B_REDR,
2719                                      curr->name,
2720                                      xofs, yofs, 200, 19, 
2721                                      &IDP_Int(curr), 
2722                                      0, 1, 0,0, (char*) o->help);
2723                 } else {
2724                         uiDefButI(block, NUM, B_REDR, curr->name, 
2725                                   xofs, yofs, 200, 19, 
2726                                   &IDP_Int(curr), 
2727                                   o->min, o->max, 0, 0, (char*) o->help);
2728                 }
2729                 break;
2730         }
2731
2732         but = uiDefIconBut(block, BUT, B_REDR, VICON_X, 
2733                            xofs + 220, yofs, 16, 16, NULL, 
2734                            0.0, 0.0, 0.0, 0.0, "Delete property");
2735
2736         uiButSetFunc(but, ffmpeg_property_del, (void*) type, curr);
2737
2738         yofs -= 25;
2739
2740         return yofs;
2741 }
2742
2743 static int render_panel_ffmpeg_properties(uiBlock *block, const char * type,
2744                                           int xofs, int yofs)
2745 {
2746         short event = B_NOP;
2747
2748         yofs -= 5;
2749         
2750         if (strcmp(type, "audio") == 0) {
2751                 event = B_ADD_FFMPEG_AUDIO_OPTION;
2752         } else if (strcmp(type, "video") == 0) {
2753                 event = B_ADD_FFMPEG_VIDEO_OPTION;
2754         }
2755                 
2756         uiDefBut(block, TEX, event, "", xofs, yofs, 
2757                  170, 19, ffmpeg_option_to_add, 0.0, 255.0, 100, 0, 
2758                  "FFMPEG option to add");
2759
2760         uiDefBut(block, BUT, event, "Add", xofs+170,yofs,
2761                  30, 19, 0, 0, 0, 0, 0, 
2762                  "Add FFMPEG option");
2763
2764         uiDefBlockBut(block, ffmpeg_property_add_menu, (void*) type, 
2765                       "Menu", xofs + 200, yofs, 40, 20, 
2766                       "Add FFMPEG option using menu");
2767         yofs -= 20;
2768
2769         if (G.scene->r.ffcodecdata.properties) {
2770                 IDProperty * prop;
2771                 void * iter;
2772                 IDProperty * curr;
2773
2774                 prop = IDP_GetPropertyFromGroup(
2775                         G.scene->r.ffcodecdata.properties, (char*) type);
2776                 if (prop) {
2777                         iter = IDP_GetGroupIterator(prop);
2778
2779                         while ((curr = IDP_GroupIterNext(iter)) != NULL) {
2780                                 yofs = render_panel_ffmpeg_property_option(
2781                                         block, xofs, yofs, curr, type);
2782                         }
2783                 }
2784         }
2785
2786         uiNewPanelHeight(block, 204-yofs);
2787
2788         return yofs;
2789 }
2790
2791 static void set_ffmpeg_preset(int preset)
2792 {
2793         int isntsc = (G.scene->r.frs_sec != 25);
2794         switch (preset) {
2795         case FFMPEG_PRESET_VCD:
2796                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
2797                 G.scene->r.ffcodecdata.video_bitrate = 1150;
2798                 G.scene->r.xsch = 352;
2799                 G.scene->r.ysch = isntsc ? 240 : 288;
2800                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2801                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
2802                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
2803                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
2804                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2805                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
2806                 break;
2807         case FFMPEG_PRESET_SVCD:
2808                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2809                 G.scene->r.ffcodecdata.video_bitrate = 2040;
2810                 G.scene->r.xsch = 480;
2811                 G.scene->r.ysch = isntsc ? 480 : 576;
2812                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2813                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
2814                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2815                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2816                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2817                 G.scene->r.ffcodecdata.mux_rate = 0;
2818                 
2819                 break;
2820         case FFMPEG_PRESET_DVD:
2821                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2822                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2823                 G.scene->r.xsch = 720;
2824                 G.scene->r.ysch = isntsc ? 480 : 576;
2825                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2826                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2827                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2828                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2829                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2830                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2831                 
2832                 break;
2833         case FFMPEG_PRESET_DV:
2834                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
2835                 G.scene->r.xsch = 720;
2836                 G.scene->r.ysch = isntsc ? 480 : 576;
2837                 break;
2838         case FFMPEG_PRESET_H264:
2839                 G.scene->r.ffcodecdata.type = FFMPEG_AVI;
2840                 G.scene->r.ffcodecdata.codec = CODEC_ID_H264;
2841                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2842                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2843                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2844                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2845                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2846                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2847                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2848
2849                 ffmpeg_property_add_string("video", "coder:vlc");
2850                 ffmpeg_property_add_string("video", "flags:loop");
2851                 ffmpeg_property_add_string("video", "cmp:chroma");
2852                 ffmpeg_property_add_string("video", "partitions:parti4x4");
2853                 ffmpeg_property_add_string("video", "partitions:partp8x8");
2854                 ffmpeg_property_add_string("video", "partitions:partb8x8");
2855                 ffmpeg_property_add_string("video", "me:hex");
2856                 ffmpeg_property_add_string("video", "subq:5");
2857                 ffmpeg_property_add_string("video", "me_range:16");
2858                 ffmpeg_property_add_string("video", "keyint_min:25");
2859                 ffmpeg_property_add_string("video", "sc_threshold:40");
2860                 ffmpeg_property_add_string("video", "i_qfactor:0.71");
2861                 ffmpeg_property_add_string("video", "b_strategy:1");
2862
2863                 break;
2864         }
2865 }
2866
2867 static void render_panel_ffmpeg_video(void)
2868 {
2869         uiBlock *block;
2870         int yofs;
2871         int xcol1;
2872         int xcol2;
2873         
2874         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
2875                                            UI_EMBOSS, UI_HELV, curarea->win);
2876         
2877         uiNewPanelTabbed("Format", "Render");
2878         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
2879                 return;
2880         
2881         if (ffmpeg_preset_sel != 0) {
2882                 set_ffmpeg_preset(ffmpeg_preset_sel);
2883                 ffmpeg_preset_sel = 0;
2884                 allqueue(REDRAWBUTSSCENE, 0);
2885         }
2886         
2887         xcol1 = 872;
2888         xcol2 = 1002;
2889         
2890         yofs = 54;
2891         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
2892                          110, 20, 0, 0, 0, 0, 0, "");
2893         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
2894                          110, 20, 0, 0, 0, 0, 0, "");
2895         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
2896                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
2897                           0,0,0,0, "output file format");
2898         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2899                           xcol1, yofs+44, 110, 20, 
2900                           &G.scene->r.ffcodecdata.video_bitrate, 
2901                           1, 14000, 0, 0, "Video bitrate(kb/s)");
2902         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
2903                   xcol1, yofs+22, 110, 20, 
2904                   &G.scene->r.ffcodecdata.rc_min_rate, 
2905                   0, G.scene->r.ffcodecdata.rc_max_rate, 
2906                   0, 0, "Rate control: min rate(kb/s)");
2907         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
2908                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
2909                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
2910         
2911         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
2912                           xcol1, yofs-22, 110, 20, 
2913                           &G.scene->r.ffcodecdata.mux_rate, 
2914                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
2915         
2916         
2917         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
2918                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
2919                           0,0,0,0, "Output file format preset selection");
2920         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
2921                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
2922                           0, 100, 0, 0, "Distance between key frames");
2923         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
2924                           xcol2, yofs+22, 110, 20,
2925                           &G.scene->r.ffcodecdata.rc_buffer_size, 
2926                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
2927         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
2928                           xcol2, yofs, 110, 20, 
2929                           &G.scene->r.ffcodecdata.mux_packet_size, 
2930                           0, 16384, 0, 0, "Mux packet size (byte)");
2931         
2932         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
2933                                  "Autosplit Output", 
2934                                  xcol2, yofs-22, 110, 20, 
2935                                  &G.scene->r.ffcodecdata.flags, 
2936                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
2937         
2938         
2939         if (ELEM4(G.scene->r.ffcodecdata.type, FFMPEG_AVI, 
2940                   FFMPEG_MOV, FFMPEG_MKV, FFMPEG_OGG)) {
2941                 uiDefBut(block, LABEL, 0, "Codec", 
2942                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
2943                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
2944                                   xcol1, yofs-66, 110, 20, 
2945                                   &G.scene->r.ffcodecdata.codec, 
2946                                   0,0,0,0, "FFMpeg codec to use");
2947         }
2948
2949         render_panel_ffmpeg_properties(block, "video", xcol1, yofs-86);
2950 }
2951
2952 static void render_panel_ffmpeg_audio(void)
2953 {
2954         uiBlock *block;
2955         int yofs;
2956         int xcol;
2957         
2958         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
2959         uiNewPanelTabbed("Format", "Render");
2960         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
2961         
2962         yofs = 54;
2963         xcol = 892;
2964         
2965         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
2966                                  "Multiplex audio", xcol, yofs, 225, 20, 
2967                                  &G.scene->r.ffcodecdata.flags, 
2968                                  0, 1, 0,0, "Interleave audio with the output video");
2969         uiDefBut(block, LABEL, 0, "Codec", 
2970                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
2971         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
2972                           xcol, yofs-44, 225, 20, 
2973                           &G.scene->r.ffcodecdata.audio_codec, 
2974                           0,0,0,0, "FFMpeg codec to use");
2975         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2976                           xcol, yofs-66, 110, 20, 
2977                           &G.scene->r.ffcodecdata.audio_bitrate, 
2978                           32, 384, 0, 0, "Audio bitrate(kb/s)");
2979
2980         render_panel_ffmpeg_properties(block, "audio", xcol, yofs-86);
2981 }
2982 #endif
2983
2984 static void render_panel_stamp(void)
2985 {
2986         uiBlock *block;
2987         int yofs=0, xofs=550;
2988
2989         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
2990         uiNewPanelTabbed ("Format", "Render");
2991         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
2992
2993         if (G.scene->r.scemode & R_STAMP_INFO) {
2994                 uiBlockBeginAlign(block);
2995                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
2996                 uiDefBut(block, TEX, B_NOP, "", xofs+120, yofs, 180, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
2997                 uiBlockEndAlign(block);
2998                 yofs += 30; /* gap */
2999                 
3000                 
3001                 yofs += 80;
3002                 /* Order is important for alligning ... grr */
3003                 uiBlockBeginAlign(block);
3004                 uiDefButBitI(block, TOG, R_STAMP_FILENAME, B_REDR, "Filename", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp blend filename");
3005                 yofs -= 20;
3006                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
3007                 uiDefButBitI(block, TOG, R_STAMP_CAMERA, B_REDR, "Camera", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp camera name");
3008                 yofs -= 20;
3009                 uiDefButBitI(block, TOG, R_STAMP_TIME, B_REDR, "Time", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp time (HH:MM:SS)");
3010                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
3011                 yofs -= 20;
3012                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
3013                 uiDefButBitI(block, TOG, R_STAMP_MARKER, B_REDR, "Marker", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the last marker");
3014                 yofs -= 20;
3015                 uiDefButBitI(block, TOG, R_STAMP_SEQSTRIP, B_REDR, "Sequence Strip", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the forground sequence strip name");
3016                 uiBlockEndAlign(block);
3017                 yofs += 80;
3018                 
3019                 /* draw font selector */
3020                 if (G.scene->r.stamp & R_STAMP_DRAW) {
3021                         uiDefButS(block, MENU, B_REDR, "Stamp Font Size%t|Tiny Text%x1|Small Text%x2|Medium Text%x3|Large Text%x0|Extra Large Text%x4|",
3022                                         xofs+130, yofs, 170, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose stamp text size");
3023                         
3024                         /* draw fg/bg next to the scene */
3025                         yofs -= 25;
3026                         uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+130, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3027                         uiDefBut(block, LABEL, B_NOP, "Background", xofs+215, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3028                         yofs -= 20;
3029                         uiDefButF(block, COL, B_NOP, "", xofs+130, yofs, 80, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
3030                         uiDefButF(block, COL, B_NOP, "", xofs+220, yofs, 80, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
3031                         yofs -= 30;
3032                         uiDefButF(block, NUMSLI, B_NOP, "A ", xofs+130, yofs, 170, 19, &G.scene->r.bg_stamp[3], 0, 1.0, 0, 0, "Alpha for text background");
3033                         yofs += 105;
3034                 } else {
3035                         yofs += 30;
3036                 }
3037                 
3038                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
3039                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+130, yofs, 170, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
3040                 yofs += 20;
3041         }
3042         else {
3043                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
3044                 yofs += 20;
3045                 uiDefBut(block, LABEL, 0, "", xofs, yofs, 300, 19, 0, 0, 0, 0, 0, "");
3046         }
3047 }
3048
3049 static void render_panel_format(void)
3050 {
3051         uiBlock *block;
3052         int yofs;
3053
3054
3055         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
3056         if(uiNewPanel(curarea, block, "Format", "Render",