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