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