== Sequencer ==
[blender.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                       0, 0, 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                       320, 0, 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                       640, 0, 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                       640, 0, 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                       320, 0, 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                       960, 0, 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,80,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                              90,140,80,19, &last_seq->flag, 
1191                              0.0, 21.0, 100, 0, 
1192                              "Use a custom directory to store data");
1193
1194                 uiDefButBitI(block, TOG, SEQ_USE_PROXY_CUSTOM_FILE, 
1195                              B_SEQ_BUT_RELOAD, "Custom File", 
1196                              170,140,80,19, &last_seq->flag, 
1197                              0.0, 21.0, 100, 0, 
1198                              "Use a custom file to load data from");
1199
1200                 if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR) {
1201                         uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_DIR, 
1202                                      ICON_FILESEL, 10, 120, 20, 20, 0, 0, 0, 0, 0, 
1203                                      "Select the directory/name for "
1204                                      "the proxy storage");
1205
1206                         uiDefBut(block, TEX, 
1207                                  B_SEQ_BUT_RELOAD, "Dir: ", 
1208                                  30,120,220,20, last_seq->strip->proxy->dir, 
1209                                  0.0, (float)sizeof(last_seq->strip->proxy->dir)-1, 100, 0, "");
1210                 }
1211                 if (last_seq->flag & SEQ_USE_PROXY_CUSTOM_FILE) {
1212                         uiDefIconBut(block, BUT, B_SEQ_SEL_PROXY_FILE, 
1213                                      ICON_FILESEL, 10, 100, 20, 20, 0, 0, 0, 
1214                                      0, 0, 
1215                                      "Select the custom proxy file "
1216                                      "(used for all preview resolutions!)");
1217
1218                         uiDefBut(block, TEX, 
1219                                  B_SEQ_BUT_RELOAD, "File: ", 
1220                                  30,100,220,20, last_seq->strip->proxy->file, 
1221                                  0.0, (float)sizeof(last_seq->strip->proxy->file)-1, 100, 0, "");
1222                 }
1223         }
1224
1225         if (last_seq->flag & SEQ_USE_PROXY) {
1226                 if (G.scene->r.size == 100) {
1227                         uiDefBut(block, LABEL, 0, 
1228                                  "Full render size selected, ",
1229                                  10,60,240,19, 0, 0, 0, 0, 0, "");
1230                         uiDefBut(block, LABEL, 0, 
1231                                  "so no proxy enabled!",
1232                                  10,40,240,19, 0, 0, 0, 0, 0, "");
1233                 } else if (last_seq->type != SEQ_MOVIE 
1234                            && last_seq->type != SEQ_IMAGE
1235                            && !(last_seq->flag & SEQ_USE_PROXY_CUSTOM_DIR)) {
1236                         uiDefBut(block, LABEL, 0, 
1237                                  "Cannot proxy this strip without ",
1238                                  10,60,240,19, 0, 0, 0, 0, 0, "");
1239                         uiDefBut(block, LABEL, 0, 
1240                                  "custom directory selection!",
1241                                  10,40,240,19, 0, 0, 0, 0, 0, "");
1242                 } else if (!(last_seq->flag & SEQ_USE_PROXY_CUSTOM_FILE)) {
1243                         uiDefBut(block, BUT, B_SEQ_BUT_REBUILD_PROXY, 
1244                                  "Rebuild proxy",
1245                                  10,60,240,19, 0, 0, 0, 0, 0, 
1246                                  "Rebuild proxy for the "
1247                                  "currently selected strip.");
1248                 }
1249         }
1250
1251         uiBlockEndAlign(block);
1252 }
1253
1254
1255 void sequencer_panels()
1256 {
1257         Sequence *last_seq = get_last_seq();
1258         int panels = 0;
1259         int type;
1260
1261         if(last_seq == NULL) {
1262                 return;
1263         }
1264         
1265         type = last_seq->type;
1266
1267         panels = SEQ_PANEL_EDITING;
1268
1269         if (type == SEQ_MOVIE || type == SEQ_IMAGE || type == SEQ_SCENE
1270             || type == SEQ_META) {
1271                 panels |= SEQ_PANEL_INPUT | SEQ_PANEL_FILTER | SEQ_PANEL_PROXY;
1272         }
1273
1274         if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1275                 panels |= SEQ_PANEL_FILTER | SEQ_PANEL_INPUT;
1276         }
1277
1278         if (type == SEQ_PLUGIN || type >= SEQ_EFFECT) {
1279                 panels |= SEQ_PANEL_EFFECT | SEQ_PANEL_FILTER| SEQ_PANEL_PROXY;
1280         }
1281
1282         if (panels & SEQ_PANEL_EDITING) {
1283                 seq_panel_editing();
1284         }
1285
1286         if (panels & SEQ_PANEL_INPUT) {
1287                 seq_panel_input();
1288         }
1289
1290         if (panels & SEQ_PANEL_FILTER) {
1291                 if (type == SEQ_RAM_SOUND || type == SEQ_HD_SOUND) {
1292                         seq_panel_filter_audio();
1293                 } else {
1294                         seq_panel_filter_video();
1295                 }
1296         }
1297
1298         if (panels & SEQ_PANEL_EFFECT) {
1299                 seq_panel_effect();
1300         }
1301
1302         if (panels & SEQ_PANEL_PROXY) {
1303                 seq_panel_proxy();
1304         }
1305 }
1306
1307 static void sel_proxy_dir(char *name)
1308 {
1309         Sequence *last_seq = get_last_seq();
1310         BLI_strncpy(last_seq->strip->proxy->dir, name, sizeof(last_seq->strip->proxy->dir));
1311
1312         allqueue(REDRAWBUTSSCENE, 0);
1313
1314         BIF_undo_push("Change custom proxy directory");
1315 }
1316
1317 static void sel_proxy_file(char *name)
1318 {
1319         Sequence *last_seq = get_last_seq();
1320
1321         BLI_split_dirfile_basic(name, last_seq->strip->proxy->dir,
1322                                 last_seq->strip->proxy->file);
1323
1324         allqueue(REDRAWBUTSSCENE, 0);
1325
1326         BIF_undo_push("Change custom proxy file");
1327 }
1328
1329 void do_sequencer_panels(unsigned short event)
1330 {
1331         Sequence *last_seq = get_last_seq();
1332         ScrArea * sa;
1333
1334         if (!last_seq) {
1335                 return;
1336         }
1337
1338         switch(event) {
1339         case B_SEQ_BUT_PLUGIN:
1340         case B_SEQ_BUT_EFFECT:
1341                 update_changed_seq_and_deps(last_seq, 0, 1);
1342                 break;
1343         case B_SEQ_BUT_RELOAD_FILE:
1344                 reload_sequence_new_file(last_seq);
1345                 break;
1346         case B_SEQ_BUT_REBUILD_PROXY:
1347                 seq_proxy_rebuild(last_seq);
1348                 break;
1349         case B_SEQ_SEL_PROXY_DIR:
1350                 sa= closest_bigger_area();
1351                 areawinset(sa->win);
1352                 activate_fileselect(FILE_SPECIAL, "SELECT PROXY DIR", 
1353                                     last_seq->strip->proxy->dir, 
1354                                     sel_proxy_dir);
1355                 break;
1356         case B_SEQ_SEL_PROXY_FILE:
1357                 sa= closest_bigger_area();
1358                 areawinset(sa->win);
1359                 activate_fileselect(FILE_SPECIAL, "SELECT PROXY FILE", 
1360                                     last_seq->strip->proxy->dir, 
1361                                     sel_proxy_file);
1362                 break;
1363         case B_SEQ_BUT_RELOAD:
1364         case B_SEQ_BUT_RELOAD_ALL:
1365                 update_seq_ipo_rect(last_seq);
1366                 update_seq_icu_rects(last_seq);
1367
1368                 free_imbuf_seq();       // frees all
1369
1370                 break;
1371         case B_SEQ_BUT_TRANSFORM:
1372                 calc_sequence(last_seq);
1373                 if (test_overlap_seq(last_seq))
1374                         shuffle_seq(last_seq);
1375                 break;
1376         }
1377
1378         if (event == B_SEQ_BUT_RELOAD_ALL) {
1379                 allqueue(REDRAWALL, 0);
1380         } else {
1381                 allqueue(REDRAWSEQ, 0);
1382                 allqueue(REDRAWBUTSSCENE, 0);
1383         }
1384 }
1385
1386
1387 /* ************************* SCENE *********************** */
1388
1389
1390 static void output_pic(char *name)
1391 {
1392         strcpy(G.scene->r.pic, name);
1393         allqueue(REDRAWBUTSSCENE, 0);
1394         BIF_undo_push("Change output picture directory");
1395 }
1396
1397 static void backbuf_pic(char *name)
1398 {
1399         Image *ima;
1400         
1401         strcpy(G.scene->r.backbuf, name);
1402         allqueue(REDRAWBUTSSCENE, 0);
1403
1404         ima= BKE_add_image_file(name);
1405         if(ima)
1406                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
1407
1408         BIF_undo_push("Change background picture");
1409 }
1410
1411 static void run_playanim(char *file) 
1412 {
1413         extern char bprogname[];        /* usiblender.c */
1414         char str[FILE_MAX*2]; /* FILE_MAX*2 is a bit arbitary, but this should roughly allow for the args + the max-file-length */
1415         int pos[2], size[2];
1416
1417         /* use current settings for defining position of window. it actually should test image size */
1418         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
1419                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
1420 #ifdef WIN32
1421         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);
1422 #else
1423         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);
1424 #endif
1425         system(str);
1426 }
1427
1428 void playback_anim(void)
1429 {       
1430         char file[FILE_MAX];
1431
1432         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
1433                 switch (G.scene->r.imtype) {
1434 #ifdef WITH_QUICKTIME
1435                         case R_QUICKTIME:
1436                                 makeqtstring(file);
1437                                 break;
1438 #endif
1439 #ifdef WITH_FFMPEG
1440                 case R_FFMPEG:
1441                         makeffmpegstring(file);
1442                         break;
1443 #endif
1444                 default:
1445                         makeavistring(&G.scene->r, file);
1446                         break;
1447                 }
1448                 if(BLI_exist(file)) {
1449                         run_playanim(file);
1450                 }
1451                 else error("Can't find movie: %s", file);
1452         }
1453         else {
1454                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
1455                 if(BLI_exist(file)) {
1456                         run_playanim(file);
1457                 }
1458                 else error("Can't find image: %s", file);
1459         }
1460 }
1461
1462 #ifdef WITH_FFMPEG
1463 static void set_ffmpeg_preset(int preset);
1464 static int ffmpeg_property_add_string(const char * type, const char * str);
1465 static char ffmpeg_option_to_add[255] = "";
1466 #endif
1467
1468 void do_render_panels(unsigned short event)
1469 {
1470         ScrArea *sa;
1471         ID *id;
1472
1473         switch(event) {
1474
1475         case B_DORENDER:
1476                 BIF_do_render(0);
1477                 break;
1478         case B_RTCHANGED:
1479                 allqueue(REDRAWALL, 0);
1480                 break;
1481         case B_SWITCHRENDER:
1482                 /* new panels added, so... */
1483                 G.buts->re_align= 1;
1484                 allqueue(REDRAWBUTSSCENE, 0);
1485                 break;
1486         case B_PLAYANIM:
1487                 playback_anim();
1488                 break;
1489                 
1490         case B_DOANIM:
1491                 BIF_do_render(1);
1492                 break;
1493         
1494         case B_FS_PIC:
1495                 sa= closest_bigger_area();
1496                 areawinset(sa->win);
1497                 if(G.qual == LR_CTRLKEY)
1498                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1499                 else
1500                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
1501                 break;
1502
1503         case B_FS_BACKBUF:
1504                 sa= closest_bigger_area();
1505                 areawinset(sa->win);
1506                 if(G.qual == LR_CTRLKEY)
1507                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1508                 else
1509                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
1510                 break;
1511         
1512         case B_PR_PAL:
1513                 G.scene->r.xsch= 720;
1514                 G.scene->r.ysch= 576;
1515                 G.scene->r.xasp= 54;
1516                 G.scene->r.yasp= 51;
1517                 G.scene->r.size= 100;
1518                 G.scene->r.frs_sec= 25;
1519                 G.scene->r.frs_sec_base= 1;
1520                 G.scene->r.mode &= ~R_PANORAMA;
1521                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1522 #ifdef WITH_FFMPEG
1523                 G.scene->r.ffcodecdata.gop_size = 15;
1524 #endif          
1525                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1526                 BIF_undo_push("Set PAL");
1527                 allqueue(REDRAWBUTSSCENE, 0);
1528                 allqueue(REDRAWVIEWCAM, 0);
1529                 break;
1530
1531         case B_FILETYPEMENU:
1532                 allqueue(REDRAWBUTSSCENE, 0);
1533 #ifdef WITH_FFMPEG
1534                 if (G.scene->r.imtype == R_FFMPEG) {
1535                         if (G.scene->r.ffcodecdata.type <= 0 ||
1536                             G.scene->r.ffcodecdata.codec <= 0 ||
1537                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
1538                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
1539                                 G.scene->r.ffcodecdata.codec 
1540                                         = CODEC_ID_MPEG2VIDEO;
1541                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
1542                         }
1543
1544                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
1545                                 G.scene->r.ffcodecdata.audio_codec 
1546                                         = CODEC_ID_MP2;
1547                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
1548                         }
1549                         break;
1550                 }
1551 #endif
1552 #if defined (_WIN32) || defined (__APPLE__)
1553                 // fall through to codec settings if this is the first
1554                 // time R_AVICODEC is selected for this scene.
1555                 if (((G.scene->r.imtype == R_AVICODEC) 
1556                          && (G.scene->r.avicodecdata == NULL)) ||
1557                         ((G.scene->r.imtype == R_QUICKTIME) 
1558                          && (G.scene->r.qtcodecdata == NULL))) {
1559                 } else {
1560                   break;
1561                 }
1562 #endif /*_WIN32 || __APPLE__ */
1563
1564         case B_SELECTCODEC:
1565 #if defined (_WIN32) || defined (__APPLE__)
1566                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
1567 #ifdef WITH_QUICKTIME
1568                         get_qtcodec_settings();
1569 #endif /* WITH_QUICKTIME */
1570                 }
1571 #if defined (_WIN32) && !defined(FREE_WINDOWS)
1572                 else
1573                         get_avicodec_settings();
1574 #endif /* _WIN32 && !FREE_WINDOWS */
1575 #endif /* _WIN32 || __APPLE__ */
1576                 break;
1577
1578         case B_PR_HD:
1579                 G.scene->r.xsch= 1920;
1580                 G.scene->r.ysch= 1080;
1581                 G.scene->r.xasp= 1;
1582                 G.scene->r.yasp= 1;
1583                 G.scene->r.size= 100;
1584                 G.scene->r.mode &= ~R_PANORAMA;
1585                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1586                 
1587                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1588                 BIF_undo_push("Set FULL");
1589                 allqueue(REDRAWBUTSSCENE, 0);
1590                 allqueue(REDRAWVIEWCAM, 0);
1591                 break;
1592         case B_PR_FULL:
1593                 G.scene->r.xsch= 1280;
1594                 G.scene->r.ysch= 1024;
1595                 G.scene->r.xasp= 1;
1596                 G.scene->r.yasp= 1;
1597                 G.scene->r.size= 100;
1598                 G.scene->r.mode &= ~R_PANORAMA;
1599                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1600
1601                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1602                 BIF_undo_push("Set FULL");
1603                 allqueue(REDRAWBUTSSCENE, 0);
1604                 allqueue(REDRAWVIEWCAM, 0);
1605                 break;
1606         case B_PR_PRV:
1607                 G.scene->r.xsch= 640;
1608                 G.scene->r.ysch= 512;
1609                 G.scene->r.xasp= 1;
1610                 G.scene->r.yasp= 1;
1611                 G.scene->r.size= 50;
1612                 G.scene->r.mode &= ~R_PANORAMA;
1613                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1614
1615                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1616                 allqueue(REDRAWVIEWCAM, 0);
1617                 allqueue(REDRAWBUTSSCENE, 0);
1618                 break;
1619         case B_PR_PAL169:
1620                 G.scene->r.xsch= 720;
1621                 G.scene->r.ysch= 576;
1622                 G.scene->r.xasp= 64;
1623                 G.scene->r.yasp= 45;
1624                 G.scene->r.size= 100;
1625                 G.scene->r.frs_sec= 25;
1626                 G.scene->r.frs_sec_base= 1;
1627                 G.scene->r.mode &= ~R_PANORAMA;
1628                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1629 #ifdef WITH_FFMPEG
1630                 G.scene->r.ffcodecdata.gop_size = 15;
1631 #endif          
1632
1633                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1634                 BIF_undo_push("Set PAL 16/9");
1635                 allqueue(REDRAWVIEWCAM, 0);
1636                 allqueue(REDRAWBUTSSCENE, 0);
1637                 break;
1638         case B_PR_PC:
1639                 G.scene->r.xsch= 640;
1640                 G.scene->r.ysch= 480;
1641                 G.scene->r.xasp= 100;
1642                 G.scene->r.yasp= 100;
1643                 G.scene->r.size= 100;
1644                 G.scene->r.mode &= ~R_PANORAMA;
1645                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1646
1647                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
1648                 BIF_undo_push("Set PC");
1649                 allqueue(REDRAWVIEWCAM, 0);
1650                 allqueue(REDRAWBUTSSCENE, 0);
1651                 break;
1652         case B_PR_PRESET:
1653                 G.scene->r.xsch= 720;
1654                 G.scene->r.ysch= 576;
1655                 G.scene->r.xasp= 54;
1656                 G.scene->r.yasp= 51;
1657                 G.scene->r.size= 100;
1658                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS+R_SSS;
1659                 G.scene->r.imtype= R_TARGA;
1660                 G.scene->r.xparts=  G.scene->r.yparts= 4;
1661
1662                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1663                 BIF_undo_push("Set Default");
1664                 allqueue(REDRAWVIEWCAM, 0);
1665                 allqueue(REDRAWBUTSSCENE, 0);
1666                 break;
1667         case B_PR_PANO:
1668                 G.scene->r.xsch= 576;
1669                 G.scene->r.ysch= 176;
1670                 G.scene->r.xasp= 115;
1671                 G.scene->r.yasp= 100;
1672                 G.scene->r.size= 100;
1673                 G.scene->r.mode |= R_PANORAMA;
1674                 G.scene->r.xparts=  16;
1675                 G.scene->r.yparts= 1;
1676
1677                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1678                 BIF_undo_push("Set Panorama");
1679                 allqueue(REDRAWVIEWCAM, 0);
1680                 allqueue(REDRAWBUTSSCENE, 0);
1681                 break;
1682         case B_PR_NTSC:
1683                 G.scene->r.xsch= 720;
1684                 G.scene->r.ysch= 480;
1685                 G.scene->r.xasp= 10;
1686                 G.scene->r.yasp= 11;
1687                 G.scene->r.size= 100;
1688                 G.scene->r.frs_sec= 30;
1689                 G.scene->r.frs_sec_base = 1.001;
1690                 G.scene->r.mode &= ~R_PANORAMA;
1691                 G.scene->r.xparts=  G.scene->r.yparts= 2;
1692 #ifdef WITH_FFMPEG
1693                 G.scene->r.ffcodecdata.gop_size = 18;
1694 #endif          
1695                 
1696                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
1697                 BIF_undo_push("Set NTSC");
1698                 allqueue(REDRAWBUTSSCENE, 0);
1699                 allqueue(REDRAWVIEWCAM, 0);
1700                 break;
1701
1702         case B_SETBROWSE:
1703                 id= (ID*) G.scene->set;
1704                 
1705                 if (G.buts->menunr==-2) {
1706                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
1707                 } 
1708                 else if (G.buts->menunr>0) {
1709                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
1710                         
1711                         if (newset==G.scene)
1712                                 error("Can't use the same scene as its own set");
1713                         else if (newset) {
1714                                 G.scene->set= newset;
1715                                 if (scene_check_setscene(G.scene)==0)
1716                                         error("This would create a cycle");
1717
1718                                 allqueue(REDRAWBUTSSCENE, 0);
1719                                 allqueue(REDRAWVIEW3D, 0);
1720                                 BIF_undo_push("Change Set Scene");
1721                         }
1722                 }  
1723                 break;
1724         case B_CLEARSET:
1725                 G.scene->set= NULL;
1726                 allqueue(REDRAWBUTSSCENE, 0);
1727                 allqueue(REDRAWVIEW3D, 0);
1728                 BIF_undo_push("Clear Set Scene");
1729                 
1730                 break;
1731         case B_SET_EDGE:
1732                 allqueue(REDRAWBUTSSCENE, 0);
1733                 break;
1734         case B_SET_ZBLUR:
1735                 G.scene->r.mode &= ~R_EDGE;
1736                 allqueue(REDRAWBUTSSCENE, 0);
1737                 break;
1738         case B_ADD_RENDERLAYER:
1739                 if(G.scene->r.actlay==32767) {
1740                         scene_add_render_layer(G.scene);
1741                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
1742                 }
1743                 allqueue(REDRAWBUTSSCENE, 0);
1744                 allqueue(REDRAWNODE, 0);
1745                 break;
1746         case B_SET_PASS:
1747                 if(G.scene->nodetree) {
1748                         ntreeCompositForceHidden(G.scene->nodetree);
1749                         allqueue(REDRAWNODE, 0);
1750                 }
1751                 allqueue(REDRAWBUTSSCENE, 0);
1752                 allqueue(REDRAWOOPS, 0);
1753 #ifdef WITH_FFMPEG
1754         case B_ADD_FFMPEG_AUDIO_OPTION:
1755                 if (ffmpeg_property_add_string("audio", ffmpeg_option_to_add)){
1756                         *ffmpeg_option_to_add = 0;
1757                 }
1758                 allqueue(REDRAWBUTSSCENE, 0);
1759                 break;
1760         case B_ADD_FFMPEG_VIDEO_OPTION:
1761                 if (ffmpeg_property_add_string("video", ffmpeg_option_to_add)){
1762                         *ffmpeg_option_to_add = 0;
1763                 }
1764                 allqueue(REDRAWBUTSSCENE, 0);
1765                 break;
1766 #endif
1767         }
1768 }
1769
1770 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1771 static uiBlock *edge_render_menu(void *arg_unused)
1772 {
1773         uiBlock *block;
1774         
1775         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
1776                 
1777         /* use this for a fake extra empy space around the buttons */
1778         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
1779         
1780         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
1781                   "Sets edge intensity for Toon shading");
1782
1783         /* color settings for the toon shading */
1784         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
1785         
1786         uiBlockBeginAlign(block);
1787         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
1788                   "Color for edges in toon shading mode.");
1789         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
1790                   "Color for edges in toon shading mode.");
1791         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
1792                   "Color for edges in toon shading mode.");
1793
1794         
1795         uiBlockSetDirection(block, UI_TOP);
1796         
1797         return block;
1798 }
1799
1800
1801 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
1802 static uiBlock *framing_render_menu(void *arg_unused)
1803 {
1804         uiBlock *block;
1805         short yco = 267, xco = 0;
1806         int randomcolorindex = 1234;
1807
1808         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
1809
1810         /* use this for a fake extra empy space around the buttons */
1811         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 305, NULL, 0, 0, 0, 0, "");
1812
1813         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
1814         uiBlockBeginAlign(block);
1815         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");
1816         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");
1817         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");
1818         uiBlockEndAlign(block);
1819
1820         yco -= 25;
1821         xco = 40;
1822
1823         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
1824
1825         uiBlockBeginAlign(block);
1826         uiDefButF(block, NUMSLI, 0, "R ", xco,yco,240,18, &G.scene->framing.col[0], 0.0, 1.0, randomcolorindex, 0, "Set the red component of the bars");
1827         yco -= 20;
1828         uiDefButF(block, NUMSLI, 0, "G ", xco,yco,240,18, &G.scene->framing.col[1], 0.0, 1.0, randomcolorindex, 0, "Set the green component of the bars");
1829         yco -= 20;
1830         uiDefButF(block, NUMSLI, 0, "B ", xco,yco,240,18, &G.scene->framing.col[2], 0.0, 1.0, randomcolorindex, 0, "Set the blue component of the bars");
1831         uiBlockEndAlign(block);
1832         
1833         xco = 0;
1834         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
1835         uiDefButS(block, TOG, 0, "Fullscreen", xco+74, yco, 68, 19, &G.scene->r.fullscreen, 0.0, 0.0, 0, 0, "Starts player in a new fullscreen display");
1836         xco = 3;
1837         uiBlockBeginAlign(block);
1838         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.");
1839         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.");
1840         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.");
1841         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.");
1842         uiBlockEndAlign(block);
1843
1844         /* stereo settings */
1845         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
1846          * RAS_IRasterizer has definitions:
1847          * RAS_STEREO_NOSTEREO           1
1848          * RAS_STEREO_QUADBUFFERED 2
1849          * RAS_STEREO_ABOVEBELOW         3
1850          * RAS_STEREO_INTERLACED         4       future
1851          * RAS_STEREO_ANAGLYPH          5
1852          * RAS_STEREO_SIDEBYSIDE        6
1853          * RAS_STEREO_VINTERLACE        7
1854          * RAS_STEREO_DOME              8
1855          */
1856
1857         xco = 8;
1858         uiBlockBeginAlign(block);
1859         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
1860         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");
1861         uiDefButS(block, ROW, 0, "Syncdouble", xco+180, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
1862         uiDefButS(block, ROW, 0, "Anaglyph", xco, yco-=21, 88, 19, &(G.scene->r.stereomode), 7.0, 5.0, 0, 0, "Enables anaglyph (Red-Blue) stereo method");
1863         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");
1864         uiDefButS(block, ROW, 0, "V Interlace", xco+180, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 7.0, 0, 0, "Enables interlaced vertical strips for autostereo display");
1865         
1866         uiBlockEndAlign(block);
1867
1868         xco = 8;
1869         uiBlockBeginAlign(block);
1870         uiDefButS(block, ROW, 0, "Dome",        xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 8.0, 0, 0, "Enables dome camera");
1871         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 to 3");
1872         uiDefButS(block, NUM, 0, "Mode:",       xco+180, yco, 88, 19, &G.scene->r.domemode, 1.0, 5.0, 0, 0, "1 fulldome, 2 front-truncated, 3 rear-truncated, 4 environment map, 5 spherical panoramic");
1873
1874         uiDefButS(block, NUM, 0, "Tilt:",       xco, yco-=21, 88, 19, &G.scene->r.dometilt, -180.0, 180.0, 0, 0, "Dome tilt - camera rotation in horizontal axis");
1875         uiDefButS(block, NUM, 0, "Tes:",        xco+90, yco, 88, 19, &G.scene->r.domeres, 0.0, 8.0, 0, 0, "Tesselation level - check the generated mesh in wireframe mode");
1876         uiDefButF(block, NUM, 0, "Res:",        xco+180, yco, 88, 19, &G.scene->r.domeresbuf, 0.1, 1.0, 0, 0, "Buffer Resolution - decrease it to increase speed");
1877
1878         uiDefIDPoinBut(block, test_scriptpoin_but, ID_SCRIPT, 1, "Warp Data: ", xco,yco-=21,268, 19, &G.scene->r.dometext, "Custom Warp Mesh data file");
1879         uiBlockEndAlign(block);
1880
1881         uiBlockSetDirection(block, UI_TOP);
1882
1883         return block;
1884 }
1885
1886 #ifdef WITH_FFMPEG
1887
1888 static char* ffmpeg_format_pup(void) 
1889 {
1890         static char string[2048];
1891         char formatstring[2048];
1892 #if 0
1893        int i = 0;
1894        int stroffs = 0;
1895        AVOutputFormat* next = first_oformat;
1896        formatstring = "FFMpeg format: %%t";
1897       sprintf(string, formatstring);
1898        formatstring = "|%s %%x%d";
1899        /* FIXME: This should only be generated once */
1900        while (next != NULL) {
1901                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
1902                        sprintf(string+stroffs, formatstring, next->name, i++);
1903                        stroffs += strlen(string+stroffs);
1904                }
1905                next = next->next;
1906        }
1907        return string;
1908 #endif
1909        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"
1910 #if 0
1911 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1912               "|%s %%x%d"
1913 #endif
1914               "|%s %%x%d");
1915        sprintf(string, formatstring,
1916                "MPEG-1", FFMPEG_MPEG1,
1917                "MPEG-2", FFMPEG_MPEG2,
1918                "MPEG-4", FFMPEG_MPEG4,
1919                "AVI",    FFMPEG_AVI,
1920                "Quicktime", FFMPEG_MOV,
1921                "DV", FFMPEG_DV,
1922                "H264", FFMPEG_H264,
1923                "XVid", FFMPEG_XVID,
1924 #if 0 
1925 /* ifdef WITH_OGG, disabled, since broken within ffmpeg bundled with blender */
1926                "OGG", FFMPEG_OGG,
1927 #endif
1928                "FLV", FFMPEG_FLV);
1929        return string;
1930 }
1931
1932 static char* ffmpeg_preset_pup(void) 
1933 {
1934         static char string[2048];
1935         char formatstring[2048];
1936
1937        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1938        sprintf(string, formatstring,
1939                "", FFMPEG_PRESET_NONE,
1940                "DVD", FFMPEG_PRESET_DVD,
1941                "SVCD", FFMPEG_PRESET_SVCD,
1942                "VCD", FFMPEG_PRESET_VCD,
1943                "DV", FFMPEG_PRESET_DV,
1944                "H264", FFMPEG_PRESET_H264);
1945        return string;
1946 }
1947
1948
1949 static char* ffmpeg_codec_pup(void) {
1950        static char string[2048];
1951        char formatstring[2048];
1952        strcpy(formatstring, 
1953               "FFMpeg format: %%t"
1954               "|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d"
1955 #ifdef WITH_OGG
1956               "|%s %%x%d"
1957 #endif
1958               "|%s %%x%d");
1959        sprintf(string, formatstring,
1960                "MPEG1", CODEC_ID_MPEG1VIDEO,
1961                "MPEG2", CODEC_ID_MPEG2VIDEO,
1962                "MPEG4(divx)", CODEC_ID_MPEG4,
1963                "HuffYUV", CODEC_ID_HUFFYUV,
1964                "DV", CODEC_ID_DVVIDEO,
1965                "H264", CODEC_ID_H264,
1966                "XVid", CODEC_ID_XVID,
1967 #ifdef WITH_OGG
1968                "Theora", CODEC_ID_THEORA,
1969 #endif
1970                "FlashVideo1", CODEC_ID_FLV1);
1971        return string;
1972
1973 }
1974
1975 static char* ffmpeg_audio_codec_pup(void) {
1976        static char string[2048];
1977        char formatstring[2048];
1978        strcpy(formatstring, 
1979               "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d"
1980 #ifdef WITH_OGG
1981               "|%s %%x%d"
1982 #endif
1983               "|%s %%x%d");
1984        sprintf(string, formatstring,
1985                "MP2", CODEC_ID_MP2,
1986                "MP3", CODEC_ID_MP3,
1987                "AC3", CODEC_ID_AC3,
1988                "AAC", CODEC_ID_AAC,
1989 #ifdef WITH_OGG
1990                "Vorbis", CODEC_ID_VORBIS,
1991 #endif
1992                "PCM", CODEC_ID_PCM_S16LE);
1993        return string;
1994
1995 }
1996
1997 #endif
1998
1999 static char *imagetype_pup(void)
2000 {
2001         static char string[1024];
2002         char formatstring[1024];
2003         char appendstring[1024];
2004
2005         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");
2006 #ifdef __sgi
2007         strcat(formatstring, "|%s %%x%d");      // add space for Movie
2008 #endif
2009
2010         strcat(formatstring, "|%s %%x%d");      // add space for PNG
2011 /*  Commented out until implemented
2012 #ifdef WITH_DDS
2013         strcat(formatstring, "|%s %%x%d");      // add space for DDS
2014 #endif
2015 */
2016 #ifdef WITH_OPENJPEG
2017         strcat(formatstring, "|%s %%x%d");      // add space for JP2
2018 #endif
2019         
2020         strcat(formatstring, "|%s %%x%d");      // add space for BMP
2021         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
2022         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
2023         strcat(formatstring, "|%s %%x%d");      // add space for DPX
2024         
2025 #ifdef _WIN32
2026         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
2027 #endif
2028
2029 #ifdef WITH_FFMPEG
2030        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
2031 #endif
2032        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
2033
2034 #ifdef WITH_QUICKTIME
2035         if(G.have_quicktime)
2036                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
2037 #endif
2038
2039         if(G.have_quicktime) {
2040                 sprintf(string, formatstring,
2041                         "Frameserver",   R_FRAMESERVER,
2042 #ifdef WITH_FFMPEG
2043                        "FFMpeg",         R_FFMPEG,
2044 #endif
2045                         "AVI Raw",        R_AVIRAW,
2046                         "AVI Jpeg",       R_AVIJPEG,
2047 #ifdef _WIN32
2048                         "AVI Codec",      R_AVICODEC,
2049 #endif
2050 #ifdef WITH_QUICKTIME
2051                         "QuickTime",      R_QUICKTIME,
2052 #endif
2053                         "Targa",          R_TARGA,
2054                         "Targa Raw",      R_RAWTGA,
2055                         "PNG",            R_PNG,
2056 /* commented out until implemented 
2057 #ifdef WITH_DDS
2058                         "DDS",            R_DDS,
2059 #endif
2060 */
2061 #ifdef WITH_OPENJPEG
2062                         "Jpeg 2000",   R_JP2,
2063 #endif
2064                         "BMP",            R_BMP,
2065                         "Jpeg",           R_JPEG90,
2066                         "HamX",           R_HAMX,
2067                         "Iris",           R_IRIS,
2068                         "Radiance HDR",   R_RADHDR,
2069                         "Cineon",                 R_CINEON,
2070                         "DPX",                    R_DPX
2071
2072 #ifdef __sgi
2073                         ,"Movie",          R_MOVIE
2074 #endif
2075                 );
2076         } else {
2077                 sprintf(string, formatstring,
2078                         "Frameserver",   R_FRAMESERVER,
2079 #ifdef WITH_FFMPEG
2080                        "FFMpeg",         R_FFMPEG,
2081 #endif
2082                         "AVI Raw",        R_AVIRAW,
2083                         "AVI Jpeg",       R_AVIJPEG,
2084 #ifdef _WIN32
2085                         "AVI Codec",      R_AVICODEC,
2086 #endif
2087                         "Targa",          R_TARGA,
2088                         "Targa Raw",      R_RAWTGA,
2089                         "PNG",            R_PNG,
2090 /*#ifdef WITH_DDS
2091                         "DDS",            R_DDS,
2092 #endif*/
2093 #ifdef WITH_OPENJPEG
2094                         "Jpeg 2000",   R_JP2,
2095 #endif
2096                         "BMP",            R_BMP,
2097                         "Jpeg",           R_JPEG90,
2098                         "HamX",           R_HAMX,
2099                         "Iris",           R_IRIS,
2100                         "Radiance HDR",   R_RADHDR,
2101                         "Cineon",                 R_CINEON,
2102                         "DPX",                    R_DPX
2103
2104
2105 #ifdef __sgi
2106                         ,"Movie",          R_MOVIE
2107 #endif
2108                 );
2109         }
2110
2111 #ifdef WITH_OPENEXR
2112         strcpy(formatstring, "|%s %%x%d");
2113         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
2114         strcat(string, appendstring);
2115         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
2116         strcat(string, appendstring);
2117 #endif
2118         
2119         if (G.have_libtiff) {
2120                 strcpy(formatstring, "|%s %%x%d");
2121                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
2122                 strcat(string, appendstring);
2123         }
2124
2125         return (string);
2126 }
2127
2128 #ifdef _WIN32
2129 static char *avicodec_str(void)
2130 {
2131         static char string[1024];
2132
2133         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
2134
2135         return string;
2136 }
2137 #endif
2138
2139 static void render_panel_output(void)
2140 {
2141         ID *id;
2142         int a,b;
2143         uiBlock *block;
2144         char *strp;
2145
2146         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
2147         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
2148         
2149         uiBlockBeginAlign(block);
2150         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Select the directory/name for saving animations");
2151         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");
2152         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");
2153         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");
2154         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");
2155         uiBlockEndAlign(block);
2156         
2157         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");
2158         
2159         uiBlockBeginAlign(block);
2160         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)");
2161         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)");
2162         uiBlockEndAlign(block);
2163         
2164         /* SET BUTTON */
2165         uiBlockBeginAlign(block);
2166         id= (ID *)G.scene->set;
2167         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
2168         if(strp[0])
2169                 uiDefButS(block, MENU, B_SETBROWSE, strp,                       10, 114, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
2170         MEM_freeN(strp);
2171
2172         if(G.scene->set) {
2173                 uiSetButLock(1, NULL);
2174                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 114, 100, 20, &(G.scene->set), "Name of the Set");
2175                 uiClearButLock();
2176                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 114, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
2177         } else {
2178                 uiDefBut(block, LABEL, 0, "No Set Scene", 31, 114, 200, 20, 0, 0, 0, 0, 0, "");
2179         }
2180         uiBlockEndAlign(block);
2181
2182         uiBlockBeginAlign(block);
2183         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");
2184         if ((G.scene->r.mode & R_FIXED_THREADS)==0) {
2185                 char thread_str[16];
2186                 sprintf(thread_str, " Threads: %d", BLI_system_thread_count());
2187                 uiDefBut(block, LABEL, 0, thread_str, 30, 63,80,20, 0, 0, 0, 0, 0, "");
2188         } else {
2189                 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)");
2190         }
2191         uiBlockEndAlign(block);
2192         
2193         uiBlockSetCol(block, TH_AUTO);
2194                 
2195         uiBlockBeginAlign(block);
2196         for(b=2; b>=0; b--)
2197                 for(a=0; a<3; a++)
2198                         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");
2199         uiBlockEndAlign(block);
2200
2201 #ifdef WITH_OPENEXR
2202         uiBlockBeginAlign(block);
2203         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)");
2204         if(G.scene->r.scemode & R_EXR_TILE_FILE)
2205                 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)");
2206         uiBlockEndAlign(block);
2207 #endif
2208         
2209         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
2210                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
2211         
2212         /* Dither control */
2213         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)");
2214         
2215         /* Toon shading buttons */
2216         uiBlockBeginAlign(block);
2217         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   115, 89, 60, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
2218         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 175, 89, 135, 20, "Display Edge settings");
2219         uiBlockEndAlign(block);
2220         
2221         uiBlockBeginAlign(block);
2222         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");
2223         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");
2224         uiBlockEndAlign(block);
2225 }
2226
2227 static void do_bake_func(void *unused_v, void *unused_p)
2228 {
2229         objects_bake_render_ui(0);
2230 }
2231
2232 static void render_panel_bake(void)
2233 {
2234         uiBlock *block;
2235         uiBut *but;
2236         
2237         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
2238         uiNewPanelTabbed("Anim", "Render");
2239         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
2240         
2241         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
2242         uiButSetFunc(but, do_bake_func, NULL, NULL);
2243
2244         uiBlockBeginAlign(block);
2245         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");
2246         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)");
2247         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)");
2248         uiBlockEndAlign(block);
2249
2250         if(G.scene->r.bake_mode == RE_BAKE_NORMALS)
2251                 uiDefButS(block, MENU, B_DIFF, "Normal Space %t|Camera %x0|World %x1|Object %x2|Tangent %x3", 
2252                         10,70,190,20, &G.scene->r.bake_normal_space, 0, 0, 0, 0, "Choose normal space for baking");
2253         else if(G.scene->r.bake_mode == RE_BAKE_AO || G.scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
2254                 uiDefButBitS(block, TOG, R_BAKE_NORMALIZE, B_DIFF, "Normalized", 10,70,190,20, &G.scene->r.bake_flag, 0.0, 0, 0, 0,
2255                                 G.scene->r.bake_mode == RE_BAKE_AO ?
2256                                  "Bake ambient occlusion normalized, without taking into acount material settings":
2257                                  "Normalized displacement value to fit the 'Dist' range"
2258                 );
2259         }
2260         
2261         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", 
2262                 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)");
2263         
2264 #if 0   
2265         uiBlockBeginAlign(block);
2266         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)");
2267         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");
2268         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");
2269         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");
2270         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");
2271 #endif  
2272         uiBlockBeginAlign(block);
2273         uiDefButS(block, ROW,B_REDR,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
2274         uiDefButS(block, ROW,B_REDR,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
2275         uiDefButS(block, ROW,B_REDR,"Shadow",                   210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_SHADOW, 0, 0, "");
2276         uiDefButS(block, ROW,B_REDR,"Normals",                  210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
2277         uiDefButS(block, ROW,B_REDR,"Textures",                 210,90,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
2278         uiDefButS(block, ROW,B_REDR,"Displacement",             210,70,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_DISPLACEMENT, 0, 0, "");
2279         uiBlockEndAlign(block);
2280         
2281         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");
2282         
2283         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");
2284 }
2285
2286 static void render_panel_simplify(void)
2287 {
2288         uiBlock *block;
2289         
2290         block= uiNewBlock(&curarea->uiblocks, "render_panel_simplify", UI_EMBOSS, UI_HELV, curarea->win);
2291         uiNewPanelTabbed("Render", "Render");
2292         if(uiNewPanel(curarea, block, "Simplifcation", "Render", 320, 0, 318, 204)==0) return;
2293
2294         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");
2295
2296         uiBlockBeginAlign(block);
2297         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");
2298         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");
2299         uiBlockEndAlign(block);
2300
2301         uiBlockBeginAlign(block);
2302         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");
2303         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");
2304         uiBlockEndAlign(block);
2305 }
2306
2307 static void render_panel_render(void)
2308 {
2309         uiBlock *block;
2310         char str[256];
2311
2312         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
2313         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
2314
2315         uiBlockBeginAlign(block);
2316         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 142, 191,59, 0, 0, 0, 0, 0, "Render the current frame (F12)");
2317
2318         uiBlockBeginAlign(block);
2319         if((G.scene->r.scemode & R_FULL_SAMPLE) && (G.scene->r.scemode & R_EXR_TILE_FILE))
2320                 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)");
2321         else
2322                 uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
2323         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)");
2324         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)");
2325         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)");
2326         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)");
2327         uiBlockEndAlign(block);
2328
2329         uiBlockBeginAlign(block);
2330         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
2331         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
2332         uiBlockEndAlign(block);
2333
2334         uiBlockBeginAlign(block);
2335         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)");
2336         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");
2337         uiBlockEndAlign(block);
2338
2339         uiBlockBeginAlign(block);
2340         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
2341         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
2342         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");
2343         uiBlockEndAlign(block);
2344
2345         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");
2346
2347         uiBlockBeginAlign(block);
2348         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
2349         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");
2350         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)");
2351         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     565,142,52,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
2352         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",617,142,32,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
2353         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       649,142,38,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
2354         uiBlockEndAlign(block);
2355         
2356         uiBlockBeginAlign(block);
2357         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");
2358         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");
2359         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");
2360         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");
2361         uiBlockEndAlign(block);
2362
2363         uiBlockBeginAlign(block);
2364         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
2365         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)");
2366         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");
2367         
2368         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);
2369         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
2370         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
2371         
2372         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)");
2373         uiBlockEndAlign(block);
2374
2375 }
2376
2377 static void render_panel_anim(void)
2378 {
2379         uiBlock *block;
2380
2381
2382         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
2383         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
2384
2385
2386         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)");
2387
2388         uiBlockSetCol(block, TH_BUT_SETTING1);
2389         uiBlockBeginAlign(block);
2390         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)");
2391         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");
2392         uiBlockEndAlign(block);
2393
2394         uiBlockSetCol(block, TH_AUTO);
2395         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)");
2396         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,50,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
2397
2398         uiBlockBeginAlign(block);
2399         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)");
2400         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,20,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation  (inclusive)");
2401         uiDefButI(block, NUM,REDRAWSEQ,"Step:",692,0,192,18, &G.scene->frame_step, 1.0, MAXFRAMEF, 0, 0, "Frame Step");
2402         uiBlockEndAlign(block);
2403 }
2404
2405 #ifdef WITH_FFMPEG
2406
2407 static void ffmpeg_property_del(void *type, void *prop_)
2408 {
2409         struct IDProperty *prop = (struct IDProperty *) prop_;
2410         IDProperty * group;
2411         
2412         if (!G.scene->r.ffcodecdata.properties) {
2413                 return;
2414         }
2415
2416         group = IDP_GetPropertyFromGroup(
2417                 G.scene->r.ffcodecdata.properties, (char*) type);
2418         if (group && prop) {
2419                 IDP_RemFromGroup(group, prop);
2420                 IDP_FreeProperty(prop);
2421                 MEM_freeN(prop);
2422         }
2423         allqueue(REDRAWBUTSSCENE, 0);
2424 }
2425
2426 static IDProperty * ffmpeg_property_add(
2427         char * type, int opt_index, int parent_index)
2428 {
2429         AVCodecContext c;
2430         const AVOption * o;
2431         const AVOption * parent;
2432         IDProperty * group;
2433         IDProperty * prop;
2434         IDPropertyTemplate val;
2435         int idp_type;
2436         char name[256];
2437
2438         avcodec_get_context_defaults(&c);
2439
2440         o = c.av_class->option + opt_index;
2441         parent = c.av_class->option + parent_index;
2442
2443         if (!G.scene->r.ffcodecdata.properties) {
2444                 IDPropertyTemplate val;
2445
2446                 G.scene->r.ffcodecdata.properties 
2447                         = IDP_New(IDP_GROUP, val, "ffmpeg"); 
2448         }
2449
2450         group = IDP_GetPropertyFromGroup(
2451                 G.scene->r.ffcodecdata.properties, (char*) type);
2452         
2453         if (!group) {
2454                 IDPropertyTemplate val;
2455                 
2456                 group = IDP_New(IDP_GROUP, val, (char*) type); 
2457                 IDP_AddToGroup(G.scene->r.ffcodecdata.properties, group);
2458         }
2459
2460         if (parent_index) {
2461                 sprintf(name, "%s:%s", parent->name, o->name);
2462         } else {
2463                 strcpy(name, o->name);
2464         }
2465
2466         fprintf(stderr, "ffmpeg_property_add: %s %d %d %s\n",
2467                 type, parent_index, opt_index, name);
2468
2469         prop = IDP_GetPropertyFromGroup(group, name);
2470         if (prop) {
2471                 return prop;
2472         }
2473
2474         switch (o->type) {
2475         case FF_OPT_TYPE_INT:
2476         case FF_OPT_TYPE_INT64:
2477                 val.i = o->default_val;
2478                 idp_type = IDP_INT;
2479                 break;
2480         case FF_OPT_TYPE_DOUBLE:
2481         case FF_OPT_TYPE_FLOAT:
2482                 val.f = o->default_val;
2483                 idp_type = IDP_FLOAT;
2484                 break;
2485         case FF_OPT_TYPE_STRING:
2486                 val.str = "                                                                               ";
2487                 idp_type = IDP_STRING;
2488                 break;
2489         case FF_OPT_TYPE_CONST:
2490                 val.i = 1;
2491                 idp_type = IDP_INT;
2492                 break;
2493         default:
2494                 return NULL;
2495         }
2496         prop = IDP_New(idp_type, val, name);
2497         IDP_AddToGroup(group, prop);
2498         return prop;
2499 }
2500
2501 /* not all versions of ffmpeg include that, so here we go ... */
2502
2503 static const AVOption *my_av_find_opt(void *v, const char *name, 
2504                                       const char *unit, int mask, int flags){
2505         AVClass *c= *(AVClass**)v; 
2506         const AVOption *o= c->option;
2507
2508         for(;o && o->name; o++){
2509                 if(!strcmp(o->name, name) && 
2510                    (!unit || (o->unit && !strcmp(o->unit, unit))) && 
2511                    (o->flags & mask) == flags )
2512                         return o;
2513         }
2514         return NULL;
2515 }
2516
2517 static int ffmpeg_property_add_string(const char * type, const char * str)
2518 {
2519         AVCodecContext c;
2520         const AVOption * o = 0;
2521         const AVOption * p = 0;
2522         char name_[128];
2523         char * name;
2524         char * param;
2525         IDProperty * prop;
2526         
2527         avcodec_get_context_defaults(&c);
2528
2529         strncpy(name_, str, 128);
2530
2531         name = name_;
2532         while (*name == ' ') name++;
2533
2534         param = strchr(name, ':');
2535
2536         if (!param) {
2537                 param = strchr(name, ' ');
2538         }
2539         if (param) {
2540                 *param++ = 0;
2541                 while (*param == ' ') param++;
2542         }
2543         
2544         o = my_av_find_opt(&c, name, NULL, 0, 0);       
2545         if (!o) {
2546                 return FALSE;
2547         }
2548         if (param && o->type == FF_OPT_TYPE_CONST) {
2549                 return FALSE;
2550         }
2551         if (param && o->type != FF_OPT_TYPE_CONST && o->unit) {
2552                 p = my_av_find_opt(&c, param, o->unit, 0, 0);   
2553                 prop = ffmpeg_property_add(
2554                         (char*) type, p - c.av_class->option, 
2555                         o - c.av_class->option);
2556         } else {
2557                 prop = ffmpeg_property_add(
2558                         (char*) type, o - c.av_class->option, 0);
2559         }
2560                 
2561
2562         if (!prop) {
2563                 return FALSE;
2564         }
2565
2566         if (param && !p) {
2567                 switch (prop->type) {
2568                 case IDP_INT:
2569                         IDP_Int(prop) = atoi(param);
2570                         break;
2571                 case IDP_FLOAT:
2572                         IDP_Float(prop) = atof(param);
2573                         break;
2574                 case IDP_STRING:
2575                         strncpy(IDP_String(prop), param, prop->len);
2576                         break;
2577                 }
2578         }
2579         return TRUE;
2580 }
2581
2582 static void ffmpeg_property_add_using_menu(void * type, int opt_indices)
2583 {
2584         int opt_index = opt_indices & 65535;
2585         int parent_index = opt_indices >> 16;
2586
2587         ffmpeg_property_add((char*) type, opt_index, parent_index);
2588
2589         allqueue(REDRAWBUTSSCENE, 0);
2590 }
2591
2592 static uiBlock *ffmpeg_property_add_submenu(AVOption * parent, char * type) 
2593 {
2594         AVCodecContext c;
2595         const AVOption * o;
2596         uiBlock *block;
2597         int yco = 0;
2598         int flags = 0;
2599         int parent_index = 0;
2600
2601         if (strcmp(type, "audio") == 0) {
2602                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2603         } else if (strcmp(type, "video") == 0) {
2604                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2605         } else {
2606                 return NULL;
2607         }
2608
2609         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_submenu",
2610                           UI_EMBOSSP, UI_HELV, G.curscreen->mainwin);
2611         uiBlockSetButmFunc(block, ffmpeg_property_add_using_menu, type);
2612
2613         avcodec_get_context_defaults(&c);
2614
2615         if (parent) {
2616                 parent_index = (parent - c.av_class->option);
2617         }
2618         
2619         for(o = c.av_class->option; o && o->name; o++){
2620                 if (o->help && 
2621                     (strstr(o->help, "experimental")
2622                      || strstr(o->help, "obsolete")
2623                      || strstr(o->help, "useless")
2624                      || strstr(o->help, "deprecated"))) {
2625                         continue;
2626                 }
2627                 if((o->flags & flags) == flags) {
2628                         if((!parent && !o->unit) 
2629                            || (o->unit && parent 
2630                                && strcmp(o->unit, parent->unit) == 0 
2631                                && o->type == FF_OPT_TYPE_CONST)) {
2632                                 uiDefBut(block, BUTM, B_REDR, 
2633                                          (char*) (o->help && o->help[0] ? 
2634                                                   o->help : o->name),
2635                                          0, yco, 160, 15, 
2636                                          NULL, 0, 0, 1, 
2637                                          (o - c.av_class->option) | 
2638                                          (parent_index << 16),
2639                                          "");
2640                                 yco -= 16;
2641                         }
2642                 }
2643         }
2644         
2645         uiTextBoundsBlock(block, 50);
2646         uiBlockSetDirection(block, UI_RIGHT);
2647
2648         return block;
2649 }
2650
2651 static uiBlock *ffmpeg_property_add_submenu_audio(void* opt)
2652 {
2653         return ffmpeg_property_add_submenu((AVOption*) opt, "audio");
2654 }
2655
2656 static uiBlock *ffmpeg_property_add_submenu_video(void* opt)
2657 {
2658         return ffmpeg_property_add_submenu((AVOption*) opt, "video");
2659 }
2660
2661 static uiBlock *ffmpeg_property_add_menu(void* type_) 
2662 {
2663         char * type = (char*) type_;
2664         AVCodecContext c;
2665         const AVOption * o;
2666         uiBlock *block;
2667         int yco = 0;
2668         int flags = 0;
2669         uiBlockFuncFP add_submenu = NULL;
2670
2671         if (strcmp(type, "audio") == 0) {
2672                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM;
2673                 add_submenu = ffmpeg_property_add_submenu_audio;
2674         } else if (strcmp(type, "video") == 0) {
2675                 flags = AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM;
2676                 add_submenu = ffmpeg_property_add_submenu_video;
2677         } else {
2678                 return NULL;
2679         }
2680
2681         block= uiNewBlock(&curarea->uiblocks, "ffmpeg_property_add_menu",
2682                           UI_EMBOSSP, UI_HELV, curarea->win);
2683
2684         avcodec_get_context_defaults(&c);
2685         
2686         for(o = c.av_class->option; o && o->name; o++){
2687                 if((o->flags & flags) == flags) {
2688                         if (o->type == FF_OPT_TYPE_CONST) {
2689                                 continue;
2690                         }
2691                         if (o->help && 
2692                             (strstr(o->help, "experimental")
2693                              || strstr(o->help, "obsolete")
2694                              || strstr(o->help, "useless")
2695                              || strstr(o->help, "deprecated"))) {
2696                                 continue;
2697                         }
2698
2699                         if (o->unit) {
2700         
2701                                 uiDefIconTextBlockBut(
2702                                         block, 
2703                                         add_submenu, 
2704                                         (void*) o, 
2705                                         ICON_RIGHTARROW_THIN,
2706                                         (char*) (o->help ? 
2707                                                  o->help : o->name), 
2708                                         0, yco, 160, 15, "");
2709                                 yco -= 16;
2710                         } 
2711                 }
2712         }
2713
2714         uiDefIconTextBlockBut(
2715                 block, 
2716                 add_submenu, 
2717                 NULL, 
2718                 ICON_RIGHTARROW_THIN,
2719                 "Value / string options", 
2720                 0, yco, 160, 15, "");
2721         
2722         uiTextBoundsBlock(block, 50);
2723         uiBlockSetDirection(block, UI_DOWN);
2724
2725         return block;
2726 }
2727
2728 static int render_panel_ffmpeg_property_option(
2729         uiBlock *block, int xofs, int yofs, IDProperty * curr,
2730         const char * type)
2731 {
2732         AVCodecContext c;
2733         const AVOption * o;
2734         uiBut *but;
2735         char name[128];
2736         char * param;
2737
2738         strcpy(name, curr->name);
2739         param = strchr(name, ':');
2740
2741         if (param) {
2742                 *param++ = 0;
2743         }
2744
2745         avcodec_get_context_defaults(&c);
2746
2747         o = my_av_find_opt(&c, param ? param : name, NULL, 0, 0);
2748         if (!o) {
2749                 return yofs;
2750         }
2751
2752         switch (curr->type) {
2753         case IDP_STRING:
2754                 uiDefBut(block, TEX, 
2755                          B_REDR, curr->name, 
2756                          xofs,yofs, 200,19, 
2757                          IDP_String(curr), 
2758                          0.0, curr->len - 1, 100, 0, 
2759                          (char*) o->help);
2760                 break;
2761         case IDP_FLOAT:
2762                 uiDefButF(block, NUM, B_REDR, curr->name, 
2763                           xofs, yofs, 200, 19, 
2764                           &IDP_Float(curr), 
2765                           o->min, o->max, 0, 0, (char*) o->help);
2766                 break;
2767         case IDP_INT:
2768                 if (o->type == FF_OPT_TYPE_CONST) {
2769                         uiDefButBitI(block, TOG, 1, B_REDR,
2770                                      curr->name,
2771                                      xofs, yofs, 200, 19, 
2772                                      &IDP_Int(curr), 
2773                                      0, 1, 0,0, (char*) o->help);
2774                 } else {
2775                         uiDefButI(block, NUM, B_REDR, curr->name, 
2776                                   xofs, yofs, 200, 19, 
2777                                   &IDP_Int(curr), 
2778                                   o->min, o->max, 0, 0, (char*) o->help);
2779                 }
2780                 break;
2781         }
2782
2783         but = uiDefIconBut(block, BUT, B_REDR, VICON_X, 
2784                            xofs + 220, yofs, 16, 16, NULL, 
2785                            0.0, 0.0, 0.0, 0.0, "Delete property");
2786
2787         uiButSetFunc(but, ffmpeg_property_del, (void*) type, curr);
2788
2789         yofs -= 25;
2790
2791         return yofs;
2792 }
2793
2794 static int render_panel_ffmpeg_properties(uiBlock *block, const char * type,
2795                                           int xofs, int yofs)
2796 {
2797         short event = B_NOP;
2798
2799         yofs -= 5;
2800         
2801         if (strcmp(type, "audio") == 0) {
2802                 event = B_ADD_FFMPEG_AUDIO_OPTION;
2803         } else if (strcmp(type, "video") == 0) {
2804                 event = B_ADD_FFMPEG_VIDEO_OPTION;
2805         }
2806                 
2807         uiDefBut(block, TEX, event, "", xofs, yofs, 
2808                  170, 19, ffmpeg_option_to_add, 0.0, 255.0, 100, 0, 
2809                  "FFMPEG option to add");
2810
2811         uiDefBut(block, BUT, event, "Add", xofs+170,yofs,
2812                  30, 19, 0, 0, 0, 0, 0, 
2813                  "Add FFMPEG option");
2814
2815         uiDefBlockBut(block, ffmpeg_property_add_menu, (void*) type, 
2816                       "Menu", xofs + 200, yofs, 40, 20, 
2817                       "Add FFMPEG option using menu");
2818         yofs -= 20;
2819
2820         if (G.scene->r.ffcodecdata.properties) {
2821                 IDProperty * prop;
2822                 void * iter;
2823                 IDProperty * curr;
2824
2825                 prop = IDP_GetPropertyFromGroup(
2826                         G.scene->r.ffcodecdata.properties, (char*) type);
2827                 if (prop) {
2828                         iter = IDP_GetGroupIterator(prop);
2829
2830                         while ((curr = IDP_GroupIterNext(iter)) != NULL) {
2831                                 yofs = render_panel_ffmpeg_property_option(
2832                                         block, xofs, yofs, curr, type);
2833                         }
2834                 }
2835         }
2836
2837         uiNewPanelHeight(block, 204-yofs);
2838
2839         return yofs;
2840 }
2841
2842 static void set_ffmpeg_preset(int preset)
2843 {
2844         int isntsc = (G.scene->r.frs_sec != 25);
2845         switch (preset) {
2846         case FFMPEG_PRESET_VCD:
2847                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
2848                 G.scene->r.ffcodecdata.video_bitrate = 1150;
2849                 G.scene->r.xsch = 352;
2850                 G.scene->r.ysch = isntsc ? 240 : 288;
2851                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2852                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
2853                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
2854                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
2855                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2856                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
2857                 break;
2858         case FFMPEG_PRESET_SVCD:
2859                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2860                 G.scene->r.ffcodecdata.video_bitrate = 2040;
2861                 G.scene->r.xsch = 480;
2862                 G.scene->r.ysch = isntsc ? 480 : 576;
2863                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2864                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
2865                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2866                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2867                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
2868                 G.scene->r.ffcodecdata.mux_rate = 0;
2869                 
2870                 break;
2871         case FFMPEG_PRESET_DVD:
2872                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
2873                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2874                 G.scene->r.xsch = 720;
2875                 G.scene->r.ysch = isntsc ? 480 : 576;
2876                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2877                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2878                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2879                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2880                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2881                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2882                 
2883                 break;
2884         case FFMPEG_PRESET_DV:
2885                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
2886                 G.scene->r.xsch = 720;
2887                 G.scene->r.ysch = isntsc ? 480 : 576;
2888                 break;
2889         case FFMPEG_PRESET_H264:
2890                 G.scene->r.ffcodecdata.type = FFMPEG_AVI;
2891                 G.scene->r.ffcodecdata.codec = CODEC_ID_H264;
2892                 G.scene->r.ffcodecdata.video_bitrate = 6000;
2893                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
2894                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
2895                 G.scene->r.ffcodecdata.rc_min_rate = 0;
2896                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
2897                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
2898                 G.scene->r.ffcodecdata.mux_rate = 10080000;
2899
2900                 ffmpeg_property_add_string("video", "coder:vlc");
2901                 ffmpeg_property_add_string("video", "flags:loop");
2902                 ffmpeg_property_add_string("video", "cmp:chroma");
2903                 ffmpeg_property_add_string("video", "partitions:parti4x4");
2904                 ffmpeg_property_add_string("video", "partitions:partp8x8");
2905                 ffmpeg_property_add_string("video", "partitions:partb8x8");
2906                 ffmpeg_property_add_string("video", "me:hex");
2907                 ffmpeg_property_add_string("video", "subq:5");
2908                 ffmpeg_property_add_string("video", "me_range:16");
2909                 ffmpeg_property_add_string("video", "keyint_min:25");
2910                 ffmpeg_property_add_string("video", "sc_threshold:40");
2911                 ffmpeg_property_add_string("video", "i_qfactor:0.71");
2912                 ffmpeg_property_add_string("video", "b_strategy:1");
2913
2914                 break;
2915         }
2916 }
2917
2918 static void render_panel_ffmpeg_video(void)
2919 {
2920         uiBlock *block;
2921         int yofs;
2922         int xcol1;
2923         int xcol2;
2924         
2925         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
2926                                            UI_EMBOSS, UI_HELV, curarea->win);
2927         
2928         uiNewPanelTabbed("Format", "Render");
2929         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
2930                 return;
2931         
2932         if (ffmpeg_preset_sel != 0) {
2933                 set_ffmpeg_preset(ffmpeg_preset_sel);
2934                 ffmpeg_preset_sel = 0;
2935                 allqueue(REDRAWBUTSSCENE, 0);
2936         }
2937         
2938         xcol1 = 872;
2939         xcol2 = 1002;
2940         
2941         yofs = 54;
2942         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
2943                          110, 20, 0, 0, 0, 0, 0, "");
2944         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
2945                          110, 20, 0, 0, 0, 0, 0, "");
2946         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
2947                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
2948                           0,0,0,0, "output file format");
2949         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
2950                           xcol1, yofs+44, 110, 20, 
2951                           &G.scene->r.ffcodecdata.video_bitrate, 
2952                           1, 14000, 0, 0, "Video bitrate(kb/s)");
2953         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
2954                   xcol1, yofs+22, 110, 20, 
2955                   &G.scene->r.ffcodecdata.rc_min_rate, 
2956                   0, G.scene->r.ffcodecdata.rc_max_rate, 
2957                   0, 0, "Rate control: min rate(kb/s)");
2958         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
2959                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
2960                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
2961         
2962         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
2963                           xcol1, yofs-22, 110, 20, 
2964                           &G.scene->r.ffcodecdata.mux_rate, 
2965                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
2966         
2967         
2968         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
2969                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
2970                           0,0,0,0, "Output file format preset selection");
2971         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
2972                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
2973                           0, 100, 0, 0, "Distance between key frames");
2974         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
2975                           xcol2, yofs+22, 110, 20,
2976                           &G.scene->r.ffcodecdata.rc_buffer_size, 
2977                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
2978         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
2979                           xcol2, yofs, 110, 20, 
2980                           &G.scene->r.ffcodecdata.mux_packet_size, 
2981                           0, 16384, 0, 0, "Mux packet size (byte)");
2982         
2983         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
2984                                  "Autosplit Output", 
2985                                  xcol2, yofs-22, 110, 20, 
2986                                  &G.scene->r.ffcodecdata.flags, 
2987                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
2988         
2989         
2990         if (ELEM4(G.scene->r.ffcodecdata.type, FFMPEG_AVI, 
2991                   FFMPEG_MOV, FFMPEG_MKV, FFMPEG_OGG)) {
2992                 uiDefBut(block, LABEL, 0, "Codec", 
2993                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
2994                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
2995                                   xcol1, yofs-66, 110, 20, 
2996                                   &G.scene->r.ffcodecdata.codec, 
2997                                   0,0,0,0, "FFMpeg codec to use");
2998         }
2999
3000         render_panel_ffmpeg_properties(block, "video", xcol1, yofs-86);
3001 }
3002
3003 static void render_panel_ffmpeg_audio(void)
3004 {
3005         uiBlock *block;
3006         int yofs;
3007         int xcol;
3008         
3009         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
3010         uiNewPanelTabbed("Format", "Render");
3011         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
3012         
3013         yofs = 54;
3014         xcol = 892;
3015         
3016         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
3017                                  "Multiplex audio", xcol, yofs, 225, 20, 
3018                                  &G.scene->r.ffcodecdata.flags, 
3019                                  0, 1, 0,0, "Interleave audio with the output video");
3020         uiDefBut(block, LABEL, 0, "Codec", 
3021                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
3022         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
3023                           xcol, yofs-44, 225, 20, 
3024                           &G.scene->r.ffcodecdata.audio_codec, 
3025                           0,0,0,0, "FFMpeg codec to use");
3026         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
3027                           xcol, yofs-66, 110, 20, 
3028                           &G.scene->r.ffcodecdata.audio_bitrate, 
3029                           32, 384, 0, 0, "Audio bitrate(kb/s)");
3030
3031         render_panel_ffmpeg_properties(block, "audio", xcol, yofs-86);
3032 }
3033 #endif
3034
3035 static void render_panel_stamp(void)
3036 {
3037         uiBlock *block;
3038         int yofs=0, xofs=550;
3039
3040         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
3041         uiNewPanelTabbed ("Format", "Render");
3042         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
3043
3044         if (G.scene->r.scemode & R_STAMP_INFO) {
3045                 uiBlockBeginAlign(block);
3046                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
3047                 uiDefBut(block, TEX, B_NOP, "", xofs+120, yofs, 180, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
3048                 uiBlockEndAlign(block);
3049                 yofs += 30; /* gap */
3050                 
3051                 
3052                 yofs += 80;
3053                 /* Order is important for alligning ... grr */
3054                 uiBlockBeginAlign(block);
3055                 uiDefButBitI(block, TOG, R_STAMP_FILENAME, B_REDR, "Filename", xofs, yofs, 120, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp blend filename");
3056                 yofs -= 20;
3057                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
3058                 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");
3059                 yofs -= 20;
3060                 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)");
3061                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs+60, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
3062                 yofs -= 20;
3063                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 60, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
3064                 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");
3065                 yofs -= 20;
3066                 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");
3067                 uiBlockEndAlign(block);
3068                 yofs += 80;
3069                 
3070                 /* draw font selector */
3071                 if (G.scene->r.stamp & R_STAMP_DRAW) {
3072                         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|",
3073                                         xofs+130, yofs, 170, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose stamp text size");
3074                         
3075                         /* draw fg/bg next to the scene */
3076                         yofs -= 25;
3077                         uiDefBut(block, LABEL, B_NOP, "Text Color", xofs+130, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3078                         uiDefBut(block, LABEL, B_NOP, "Background", xofs+215, yofs, 70, 19, 0, 0, 0, 0, 0, "");
3079                         yofs -= 20;
3080                         uiDefButF(block, COL, B_NOP, "", xofs+130, yofs, 80, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
3081                         uiDefButF(block, COL, B_NOP, "", xofs+220, yofs, 80, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
3082                         yofs -= 30;
3083                         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");
3084                         yofs += 105;
3085                 } else {
3086                         yofs += 30;
3087                 }
3088                 
3089                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
3090                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+130, yofs, 170, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
3091                 yofs += 20;
3092         }
3093         else {
3094                 uiDefButBitI(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 120, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
3095                 yofs += 20;
3096                 uiDefBut(block, LABEL, 0, "", xofs, yofs, 300, 19, 0, 0, 0, 0, 0, "");
3097         }
3098 }
3099
3100 static void render_panel_format(void)
3101 {
3102         uiBlock *block;
3103         int yofs;
3104
3105
3106         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
3107         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
3108         uiDefBlockBut(block, framing_render_menu, NULL, 
3109                                   "Game framing settings", 
3110                                   892, 169, 227, 20, "Display game framing settings");
3111         /* uiDefIconTextBlockBut(block, framing_render_menu, NULL, 
3112                                                    ICON_BLOCKBUT_CORNER, 
3113                                                    "Game framing settings", 
3114                                                    892, 169, 227, 20, 
3115                                                    "Display game framing settings"); */
3116
3117         uiBlockBeginAlign(block);
3118         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
3119         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
3120         
3121         uiDefButF(block, NUM, REDRAWVIEWCAM, "AspX:",
3122                                 892 ,114,112,20,
3123                                 &G.scene->r.xasp,
3124               &