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