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