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