Image Stamping patch by Diego (and peach request)- stamps image info into metadata...
[blender.git] / source / blender / src / buttons_scene.c
1 /**
2  * $Id$ 
3  *
4  * ***** BEGIN GPL/BL DUAL 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. The Blender
10  * Foundation also sells licenses for use in proprietary software under
11  * the Blender License.  See http://www.blender.org/BL/ for information
12  * about this.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
24  * All rights reserved.
25  *
26  * The Original Code is: all of this file.
27  *
28  * Contributor(s): none yet.
29  *
30  * ***** END GPL/BL DUAL LICENSE BLOCK *****
31  */
32
33 #include <time.h>
34 #include <math.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38 #include "MEM_guardedalloc.h"
39 #include "DNA_node_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_scene_types.h"
43 #include "DNA_sound_types.h"
44 #include "DNA_userdef_types.h"
45 #include "DNA_packedFile_types.h"
46
47 #include "BKE_global.h"
48 #include "BKE_main.h"
49 #include "BKE_node.h"
50 #include "BKE_library.h"
51 #include "BKE_scene.h"
52 #include "BKE_sound.h"
53 #include "BKE_packedFile.h"
54 #include "BKE_utildefines.h"
55
56 #include "BLI_blenlib.h"
57
58 #include "BSE_filesel.h"
59
60 #include "BIF_gl.h"
61 #include "BIF_graphics.h"
62 #include "BIF_glutil.h"
63 #include "BIF_interface.h"
64 #include "BIF_imasel.h"
65 #include "BIF_keyval.h"
66 #include "BIF_mainqueue.h"
67 #include "BIF_mywindow.h"
68 #include "BIF_meshtools.h"
69 #include "BIF_resources.h"
70 #include "BIF_renderwin.h"
71 #include "BIF_screen.h"
72 #include "BIF_space.h"
73 #include "BIF_toolbox.h"
74
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
88 #include "BLI_threads.h"
89
90 #include "BIF_editsound.h"
91 #include "BIF_writeimage.h"
92 #include "BIF_writeavicodec.h"
93
94 #include "BSE_seqaudio.h"
95 #include "BSE_headerbuttons.h"
96
97 #include "RE_pipeline.h"
98
99 #include "butspace.h" // own module
100
101 #ifdef WITH_QUICKTIME
102 #include "quicktime_export.h"
103 #endif
104
105 #ifdef WITH_FFMPEG
106
107 #include <ffmpeg/avcodec.h> /* for PIX_FMT_* and CODEC_ID_* */
108 #include <ffmpeg/avformat.h>
109
110 static int ffmpeg_preset_sel = 0;
111
112 extern int is_container(int);
113
114 extern void makeffmpegstring(char* string);
115
116 #endif
117
118 /* here the calls for scene buttons
119    - render
120    - world
121    - anim settings, audio
122 */
123
124 /* prototypes */
125 void playback_anim(void);
126
127 /* ************************ SOUND *************************** */
128 static void load_new_sample(char *str)  /* called from fileselect */
129 {
130         char name[FILE_MAX];
131         bSound *sound;
132         bSample *sample, *newsample;
133
134         sound = G.buts->lockpoin;
135
136         if (sound) {
137                 // save values
138                 sample = sound->sample;
139                 strcpy(name, sound->sample->name);
140
141                 strcpy(sound->name, str);
142                 sound_set_sample(sound, NULL);
143                 sound_initialize_sample(sound);
144
145                 if (sound->sample->type == SAMPLE_INVALID) {
146                         error("Not a valid sample: %s", str);
147
148                         newsample = sound->sample;
149
150                         // restore values
151                         strcpy(sound->name, name);
152                         sound_set_sample(sound, sample);
153
154                         // remove invalid sample
155
156                         sound_free_sample(newsample);
157                         BLI_remlink(samples, newsample);
158                         MEM_freeN(newsample);
159                 }
160         }
161
162         BIF_undo_push("Load new audio file");
163         allqueue(REDRAWBUTSSCENE, 0);
164
165 }
166
167
168 void do_soundbuts(unsigned short event)
169 {
170         char name[FILE_MAX];
171         bSound *sound;
172         bSample *sample;
173         bSound* tempsound;
174         ID *id;
175         
176         sound = G.buts->lockpoin;
177         
178         switch(event) {
179         case B_SOUND_REDRAW:
180                 allqueue(REDRAWBUTSSCENE, 0);
181                 break;
182
183         case B_SOUND_LOAD_SAMPLE:
184                 if (sound) strcpy(name, sound->name);
185                 else strcpy(name, U.sounddir);
186                         
187                 activate_fileselect(FILE_SPECIAL, "SELECT WAV FILE", name, load_new_sample);
188                 break;
189
190         case B_SOUND_PLAY_SAMPLE:
191                 if (sound) {
192                         if (sound->sample->type != SAMPLE_INVALID) {
193                                 sound_play_sound(sound);
194                                 allqueue(REDRAWBUTSSCENE, 0);
195                         }
196                 }
197                 break;
198
199         case B_SOUND_MENU_SAMPLE:
200                 if (G.buts->menunr > 0) {
201                         sample = BLI_findlink(samples, G.buts->menunr - 1);
202                         if (sample && sound) {
203                                 BLI_strncpy(sound->name, sample->name, sizeof(sound->name));
204                                 sound_set_sample(sound, sample);
205                                 do_soundbuts(B_SOUND_REDRAW);
206                         }
207                 }
208                         
209                 break;
210         case B_SOUND_NAME_SAMPLE:
211                 load_new_sample(sound->name);
212                 break;
213         
214         case B_SOUND_UNPACK_SAMPLE:
215                 if(sound && sound->sample) {
216                         sample = sound->sample;
217                         
218                         if (sample->packedfile) {
219                                 if (G.fileflags & G_AUTOPACK) {
220                                         if (okee("Disable AutoPack ?")) {
221                                                 G.fileflags &= ~G_AUTOPACK;
222                                         }
223                                 }
224                                 
225                                 if ((G.fileflags & G_AUTOPACK) == 0) {
226                                         unpackSample(sample, PF_ASK);
227                                 }
228                         } else {
229                                 sound_set_packedfile(sample, newPackedFile(sample->name));
230                         }
231                         allqueue(REDRAWHEADERS, 0);
232                         do_soundbuts(B_SOUND_REDRAW);
233                 }
234                 break;
235
236         case B_SOUND_COPY_SOUND:
237                 if (sound) {
238                         tempsound = sound_make_copy(sound);
239                         sound = tempsound;
240                         id = &sound->id;
241                         G.buts->lockpoin = (bSound*)id;
242                         BIF_undo_push("Copy sound");
243                         do_soundbuts(B_SOUND_REDRAW);
244                 }
245                 break;
246
247         case B_SOUND_RECALC:
248                 waitcursor(1);
249                 sound = G.main->sound.first;
250                 while (sound) {
251                         free(sound->stream);
252                         sound->stream = 0;
253                         audio_makestream(sound);
254                         sound = (bSound *) sound->id.next;
255                 }
256                 waitcursor(0);
257                 allqueue(REDRAWSEQ, 0);
258                 break;
259
260         case B_SOUND_RATECHANGED:
261
262                 allqueue(REDRAWBUTSSCENE, 0);
263                 allqueue(REDRAWSEQ, 0);
264                 break;
265
266         case B_SOUND_MIXDOWN:
267                 audio_mixdown();
268                 break;
269
270         default: 
271                 if (G.f & G_DEBUG) {
272                         printf("do_soundbuts: unhandled event %d\n", event);
273                 }
274         }
275 }
276
277
278 static void sound_panel_listener(void)
279 {
280         uiBlock *block;
281         int xco= 100, yco=100, mixrate;
282         char mixrateinfo[256];
283         
284         block= uiNewBlock(&curarea->uiblocks, "sound_panel_listener", UI_EMBOSS, UI_HELV, curarea->win);
285         if(uiNewPanel(curarea, block, "Listener", "Sound", 320, 0, 318, 204)==0) return;
286
287         mixrate = sound_get_mixrate();
288         sprintf(mixrateinfo, "Game Mixrate: %d Hz", mixrate);
289         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
290
291         yco -= 30;
292         uiDefBut(block, LABEL, 0, "Game listener settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
293
294         yco -= 30;
295         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
296                 xco,yco,195,24,&G.listener->gain, 0.0, 1.0, 1.0, 0, "Sets the maximum volume for the overall sound");
297         
298         yco -= 30;
299         uiDefBut(block, LABEL, 0, "Game Doppler effect settings:",xco,yco,195,20, 0, 0, 0, 0, 0, "");
300
301         yco -= 30;
302         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Doppler: ",
303         xco,yco,195,24,&G.listener->dopplerfactor, 0.0, 10.0, 1.0, 0, "Use this for scaling the doppler effect");
304         
305         yco -=30;
306         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Velocity: ",
307         xco,yco,195,24,&G.listener->dopplervelocity,0.0,10000.0, 1.0,0, "Sets the propagation speed of sound");
308
309         
310 }
311
312 static void sound_panel_sequencer(void)
313 {
314         uiBlock *block;
315         short xco, yco;
316         char mixrateinfo[256];
317         
318         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sequencer", UI_EMBOSS, UI_HELV, curarea->win);
319         if(uiNewPanel(curarea, block, "Sequencer", "Sound", 640, 0, 318, 204)==0) return;
320
321         /* audio sequence engine settings ------------------------------------------------------------------ */
322
323         xco = 1010;
324         yco = 195;
325
326         uiDefBut(block, LABEL, 0, "Audio sequencer settings", xco,yco,295,20, 0, 0, 0, 0, 0, "");
327
328         yco -= 25;
329         sprintf(mixrateinfo, "Mixing/Sync (latency: %d ms)", (int)( (((float)U.mixbufsize)/(float)G.scene->audio.mixrate)*1000.0 ) );
330         uiDefBut(block, LABEL, 0, mixrateinfo, xco,yco,295,20, 0, 0, 0, 0, 0, "");
331
332         yco -= 25;              
333         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");
334         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");
335         uiDefBut(block, BUT, B_SOUND_RECALC, "Recalc",          xco+160,yco,75,20, 0, 0, 0, 0, 0, "Recalculate samples");
336
337         yco -= 25;
338         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");
339         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");
340
341         yco -= 25;
342         uiDefBut(block, LABEL, 0, "Main mix", xco,yco,295,20, 0, 0, 0, 0, 0, "");
343
344         yco -= 25;              
345         uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Main (dB): ",
346                 xco,yco,235,24,&G.scene->audio.main, -24.0, 6.0, 0, 0, "Set the audio master gain/attenuation in dB");
347
348         yco -= 25;
349         uiDefButBitS(block, TOG, AUDIO_MUTE, 0, "Mute", xco,yco,235,24, &G.scene->audio.flag, 0, 0, 0, 0, "Mute audio from sequencer");         
350         
351         yco -= 35;
352         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)");
353         
354 }
355
356 static char *make_sample_menu(void)
357 {
358         int len= BLI_countlist(samples);        /* BKE_sound.h */
359         
360         if(len) {
361                 bSample *sample;
362                 char *str;
363                 int nr, a=0;
364                 
365                 str= MEM_callocN(32*len, "menu");
366                 
367                 for(nr=1, sample= samples->first; sample; sample= sample->id.next, nr++) {
368                         a+= sprintf(str+a, "|%s %%x%d", sample->id.name+2, nr);
369                 }
370                 return str;
371         }
372         return NULL;
373 }
374
375 static void sound_panel_sound(bSound *sound)
376 {
377         static int packdummy=0;
378         ID *id, *idfrom;
379         uiBlock *block;
380         bSample *sample;
381         char *strp, ch[256];
382
383         block= uiNewBlock(&curarea->uiblocks, "sound_panel_sound", UI_EMBOSS, UI_HELV, curarea->win);
384         if(uiNewPanel(curarea, block, "Sound", "Sound", 0, 0, 318, 204)==0) return;
385         
386         uiDefBut(block, LABEL, 0, "Blender Sound block",10,180,195,20, 0, 0, 0, 0, 0, "");
387         
388         // warning: abuse of texnr here! (ton didnt code!)
389         buttons_active_id(&id, &idfrom);
390         std_libbuttons(block, 10, 160, 0, NULL, B_SOUNDBROWSE2, ID_SO, 0, id, idfrom, &(G.buts->texnr), 1, 0, 0, 0, 0);
391
392         if (sound) {
393         
394                 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");
395
396                 uiSetButLock(sound->id.lib!=0, ERROR_LIBDATA_MESSAGE);
397                 sound_initialize_sample(sound);
398                 sample = sound->sample;
399
400                 /* info string */
401                 if (sound->sample && sound->sample->len) {
402                         char *tmp;
403                         if (sound->sample->channels == 1) tmp= "Mono";
404                         else if (sound->sample->channels == 2) tmp= "Stereo";
405                         else tmp= "Unknown";
406                         
407                         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));
408                         uiDefBut(block, LABEL, 0, ch,                   35,140,225,20, 0, 0, 0, 0, 0, "");
409                 }
410                 else {
411                         uiDefBut(block, LABEL, 0, "Sample: No sample info available.",35,140,225,20, 0, 0, 0, 0, 0, "");
412                 }
413
414                 /* sample browse buttons */
415                 uiBlockBeginAlign(block);
416                 strp= make_sample_menu();
417                 if (strp) {
418                         uiDefButS(block, MENU, B_SOUND_MENU_SAMPLE, strp, 10,120,23,20, &(G.buts->menunr), 0, 0, 0, 0, "Select another loaded sample");
419                         MEM_freeN(strp);
420                 }
421                 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");
422                 
423                 if (sound->sample->packedfile) packdummy = 1;
424                 else packdummy = 0;
425                 
426                 uiDefIconButBitI(block, TOG, 1, B_SOUND_UNPACK_SAMPLE, ICON_PACKAGE,
427                         285, 120,25,20, &packdummy, 0, 0, 0, 0,"Pack/Unpack this sample");
428                 
429                 uiBlockBeginAlign(block);
430                 uiDefBut(block, BUT, B_SOUND_LOAD_SAMPLE, "Load sample", 10, 95,150,24, 0, 0, 0, 0, 0, "Load a different sample file");
431
432                 uiDefBut(block, BUT, B_SOUND_PLAY_SAMPLE, "Play",       160, 95, 150, 24, 0, 0.0, 0, 0, 0, "Playback sample using settings below");
433                 
434                 uiBlockBeginAlign(block);
435                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Volume: ",
436                         10,70,150,20, &sound->volume, 0.0, 1.0, 0, 0, "Game engine only: Set the volume of this sound");
437
438                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Pitch: ",
439                         160,70,150,20, &sound->pitch, -12.0, 12.0, 0, 0, "Game engine only: Set the pitch of this sound");
440
441                 /* looping */
442                 uiBlockBeginAlign(block);
443                 uiDefButBitI(block, TOG, SOUND_FLAGS_LOOP, B_SOUND_REDRAW, "Loop",
444                         10, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between looping on/off");
445
446                 if (sound->flags & SOUND_FLAGS_LOOP) {
447                         uiDefButBitI(block, TOG, SOUND_FLAGS_BIDIRECTIONAL_LOOP, B_SOUND_REDRAW, "Ping Pong",
448                                 105, 50, 95, 20, &sound->flags, 0.0, 0.0, 0, 0, "Game engine only: Toggle between A->B and A->B->A looping");
449                         
450                 }
451         
452
453                 /* 3D settings ------------------------------------------------------------------ */
454                 uiBlockBeginAlign(block);
455
456                 if (sound->sample->channels == 1) {
457                         uiDefButBitI(block, TOG, SOUND_FLAGS_3D, B_SOUND_REDRAW, "3D Sound",
458                                 10, 10, 90, 20, &sound->flags, 0, 0, 0, 0, "Game engine only: Turns 3D sound on");
459                         
460                         if (sound->flags & SOUND_FLAGS_3D) {
461                                 uiDefButF(block, NUMSLI, B_SOUND_CHANGED, "Scale: ",
462                                         100,10,210,20, &sound->attenuation, 0.0, 5.0, 1.0, 0, "Game engine only: Sets the surround scaling factor for this sound");
463                                 
464                         }
465                 }
466         }
467 }
468
469
470 /* ************************* SCENE *********************** */
471
472
473 static void output_pic(char *name)
474 {
475         strcpy(G.scene->r.pic, name);
476         allqueue(REDRAWBUTSSCENE, 0);
477         BIF_undo_push("Change output picture directory");
478 }
479
480 static void backbuf_pic(char *name)
481 {
482         Image *ima;
483         
484         strcpy(G.scene->r.backbuf, name);
485         allqueue(REDRAWBUTSSCENE, 0);
486
487         ima= BKE_add_image_file(name);
488         if(ima)
489                 BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
490
491         BIF_undo_push("Change background picture");
492 }
493
494 static void ftype_pic(char *name)
495 {
496         strcpy(G.scene->r.ftype, name);
497         allqueue(REDRAWBUTSSCENE, 0);
498 }
499
500 static void run_playanim(char *file) 
501 {
502         extern char bprogname[];        /* usiblender.c */
503         char str[FILE_MAX];
504         int pos[2], size[2];
505
506         /* use current settings for defining position of window. it actually should test image size */
507         calc_renderwin_rectangle((G.scene->r.xsch*G.scene->r.size)/100, 
508                                                          (G.scene->r.ysch*G.scene->r.size)/100, G.winpos, pos, size);
509 #ifdef WIN32
510         sprintf(str, "%s -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
511 #else
512         sprintf(str, "\"%s\" -a -p %d %d \"%s\"", bprogname, pos[0], pos[1], file);
513 #endif
514         system(str);
515 }
516
517 void playback_anim(void)
518 {       
519         char file[FILE_MAX];
520
521         if(BKE_imtype_is_movie(G.scene->r.imtype)) {
522                 switch (G.scene->r.imtype) {
523 #ifdef WITH_QUICKTIME
524                         case R_QUICKTIME:
525                                 makeqtstring(file);
526                                 break;
527 #endif
528 #ifdef WITH_FFMPEG
529                 case R_FFMPEG:
530                         makeffmpegstring(file);
531                         break;
532 #endif
533                 default:
534                         makeavistring(&G.scene->r, file);
535                         break;
536                 }
537                 if(BLI_exist(file)) {
538                         run_playanim(file);
539                 }
540                 else error("Can't find movie: %s", file);
541         }
542         else {
543                 BKE_makepicstring(file, G.scene->r.pic, G.scene->r.sfra, G.scene->r.imtype);
544                 if(BLI_exist(file)) {
545                         run_playanim(file);
546                 }
547                 else error("Can't find image: %s", file);
548         }
549 }
550
551 #ifdef WITH_FFMPEG
552 static void set_ffmpeg_preset(int preset);
553 #endif
554
555 void do_render_panels(unsigned short event)
556 {
557         ScrArea *sa;
558         ID *id;
559
560         switch(event) {
561
562         case B_DORENDER:
563                 BIF_do_render(0);
564                 break;
565         case B_RTCHANGED:
566                 allqueue(REDRAWALL, 0);
567                 break;
568         case B_SWITCHRENDER:
569                 /* new panels added, so... */
570                 G.buts->re_align= 1;
571                 allqueue(REDRAWBUTSSCENE, 0);
572                 break;
573         case B_PLAYANIM:
574                 playback_anim();
575                 break;
576                 
577         case B_DOANIM:
578                 BIF_do_render(1);
579                 break;
580         
581         case B_FS_PIC:
582                 sa= closest_bigger_area();
583                 areawinset(sa->win);
584                 if(G.qual == LR_CTRLKEY)
585                         activate_imageselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
586                 else
587                         activate_fileselect(FILE_SPECIAL, "SELECT OUTPUT PICTURES", G.scene->r.pic, output_pic);
588                 break;
589
590         case B_FS_BACKBUF:
591                 sa= closest_bigger_area();
592                 areawinset(sa->win);
593                 if(G.qual == LR_CTRLKEY)
594                         activate_imageselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
595                 else
596                         activate_fileselect(FILE_SPECIAL, "SELECT BACKBUF PICTURE", G.scene->r.backbuf, backbuf_pic);
597                 break;
598
599         case B_FS_FTYPE:
600                 sa= closest_bigger_area();
601                 areawinset(sa->win);
602                 if(G.qual == LR_CTRLKEY)
603                         activate_imageselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
604                 else
605                         activate_fileselect(FILE_SPECIAL, "SELECT FTYPE", G.scene->r.ftype, ftype_pic);
606                 break;
607         
608         case B_PR_PAL:
609                 G.scene->r.xsch= 720;
610                 G.scene->r.ysch= 576;
611                 G.scene->r.xasp= 54;
612                 G.scene->r.yasp= 51;
613                 G.scene->r.size= 100;
614                 G.scene->r.frs_sec= 25;
615                 G.scene->r.mode &= ~R_PANORAMA;
616                 G.scene->r.xparts=  G.scene->r.yparts= 4;
617 #ifdef WITH_FFMPEG
618                 G.scene->r.ffcodecdata.gop_size = 15;
619 #endif          
620                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
621                 BIF_undo_push("Set PAL");
622                 allqueue(REDRAWBUTSSCENE, 0);
623                 allqueue(REDRAWVIEWCAM, 0);
624                 break;
625
626         case B_FILETYPEMENU:
627                 allqueue(REDRAWBUTSSCENE, 0);
628 #ifdef WITH_FFMPEG
629                 if (G.scene->r.imtype == R_FFMPEG) {
630                         if (G.scene->r.ffcodecdata.type <= 0 ||
631                             G.scene->r.ffcodecdata.codec <= 0 ||
632                             G.scene->r.ffcodecdata.audio_codec <= 0 ||
633                             G.scene->r.ffcodecdata.video_bitrate <= 1) {
634                                 G.scene->r.ffcodecdata.codec 
635                                         = CODEC_ID_MPEG2VIDEO;
636                                 set_ffmpeg_preset(FFMPEG_PRESET_DVD);
637                         }
638
639                         if (G.scene->r.ffcodecdata.audio_codec <= 0) {
640                                 G.scene->r.ffcodecdata.audio_codec 
641                                         = CODEC_ID_MP2;
642                                 G.scene->r.ffcodecdata.audio_bitrate = 128;
643                         }
644                         break;
645                 }
646 #endif
647 #if defined (_WIN32) || defined (__APPLE__)
648                 // fall through to codec settings if this is the first
649                 // time R_AVICODEC is selected for this scene.
650                 if (((G.scene->r.imtype == R_AVICODEC) 
651                          && (G.scene->r.avicodecdata == NULL)) ||
652                         ((G.scene->r.imtype == R_QUICKTIME) 
653                          && (G.scene->r.qtcodecdata == NULL))) {
654                 } else {
655                   break;
656                 }
657 #endif /*_WIN32 || __APPLE__ */
658
659         case B_SELECTCODEC:
660 #if defined (_WIN32) || defined (__APPLE__)
661                 if ((G.scene->r.imtype == R_QUICKTIME)) { /* || (G.scene->r.qtcodecdata)) */
662 #ifdef WITH_QUICKTIME
663                         get_qtcodec_settings();
664 #endif /* WITH_QUICKTIME */
665                 }
666 #if defined (_WIN32) && !defined(FREE_WINDOWS)
667                 else
668                         get_avicodec_settings();
669 #endif /* _WIN32 && !FREE_WINDOWS */
670 #endif /* _WIN32 || __APPLE__ */
671                 break;
672
673         case B_PR_HD:
674                 G.scene->r.xsch= 1920;
675                 G.scene->r.ysch= 1080;
676                 G.scene->r.xasp= 1;
677                 G.scene->r.yasp= 1;
678                 G.scene->r.size= 100;
679                 G.scene->r.mode &= ~R_PANORAMA;
680                 G.scene->r.xparts=  G.scene->r.yparts= 4;
681                 
682                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
683                 BIF_undo_push("Set FULL");
684                 allqueue(REDRAWBUTSSCENE, 0);
685                 allqueue(REDRAWVIEWCAM, 0);
686                 break;
687         case B_PR_FULL:
688                 G.scene->r.xsch= 1280;
689                 G.scene->r.ysch= 1024;
690                 G.scene->r.xasp= 1;
691                 G.scene->r.yasp= 1;
692                 G.scene->r.size= 100;
693                 G.scene->r.mode &= ~R_PANORAMA;
694                 G.scene->r.xparts=  G.scene->r.yparts= 4;
695
696                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
697                 BIF_undo_push("Set FULL");
698                 allqueue(REDRAWBUTSSCENE, 0);
699                 allqueue(REDRAWVIEWCAM, 0);
700                 break;
701         case B_PR_PRV:
702                 G.scene->r.xsch= 640;
703                 G.scene->r.ysch= 512;
704                 G.scene->r.xasp= 1;
705                 G.scene->r.yasp= 1;
706                 G.scene->r.size= 50;
707                 G.scene->r.mode &= ~R_PANORAMA;
708                 G.scene->r.xparts=  G.scene->r.yparts= 2;
709
710                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
711                 allqueue(REDRAWVIEWCAM, 0);
712                 allqueue(REDRAWBUTSSCENE, 0);
713                 break;
714         case B_PR_PAL169:
715                 G.scene->r.xsch= 720;
716                 G.scene->r.ysch= 576;
717                 G.scene->r.xasp= 64;
718                 G.scene->r.yasp= 45;
719                 G.scene->r.size= 100;
720                 G.scene->r.frs_sec= 25;
721                 G.scene->r.mode &= ~R_PANORAMA;
722                 G.scene->r.xparts=  G.scene->r.yparts= 4;
723 #ifdef WITH_FFMPEG
724                 G.scene->r.ffcodecdata.gop_size = 15;
725 #endif          
726
727                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
728                 BIF_undo_push("Set PAL 16/9");
729                 allqueue(REDRAWVIEWCAM, 0);
730                 allqueue(REDRAWBUTSSCENE, 0);
731                 break;
732         case B_PR_PC:
733                 G.scene->r.xsch= 640;
734                 G.scene->r.ysch= 480;
735                 G.scene->r.xasp= 100;
736                 G.scene->r.yasp= 100;
737                 G.scene->r.size= 100;
738                 G.scene->r.mode &= ~R_PANORAMA;
739                 G.scene->r.xparts=  G.scene->r.yparts= 4;
740
741                 BLI_init_rctf(&G.scene->r.safety, 0.0, 1.0, 0.0, 1.0);
742                 BIF_undo_push("Set PC");
743                 allqueue(REDRAWVIEWCAM, 0);
744                 allqueue(REDRAWBUTSSCENE, 0);
745                 break;
746         case B_PR_PRESET:
747                 G.scene->r.xsch= 720;
748                 G.scene->r.ysch= 576;
749                 G.scene->r.xasp= 54;
750                 G.scene->r.yasp= 51;
751                 G.scene->r.size= 100;
752                 G.scene->r.mode= R_OSA+R_SHADOW+R_FIELDS;
753                 G.scene->r.imtype= R_TARGA;
754                 G.scene->r.xparts=  G.scene->r.yparts= 4;
755
756                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
757                 BIF_undo_push("Set Default");
758                 allqueue(REDRAWVIEWCAM, 0);
759                 allqueue(REDRAWBUTSSCENE, 0);
760                 break;
761         case B_PR_PANO:
762                 G.scene->r.xsch= 576;
763                 G.scene->r.ysch= 176;
764                 G.scene->r.xasp= 115;
765                 G.scene->r.yasp= 100;
766                 G.scene->r.size= 100;
767                 G.scene->r.mode |= R_PANORAMA;
768                 G.scene->r.xparts=  16;
769                 G.scene->r.yparts= 1;
770
771                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
772                 BIF_undo_push("Set Panorama");
773                 allqueue(REDRAWVIEWCAM, 0);
774                 allqueue(REDRAWBUTSSCENE, 0);
775                 break;
776         case B_PR_NTSC:
777                 G.scene->r.xsch= 720;
778                 G.scene->r.ysch= 480;
779                 G.scene->r.xasp= 10;
780                 G.scene->r.yasp= 11;
781                 G.scene->r.size= 100;
782                 G.scene->r.frs_sec= 30;
783                 G.scene->r.mode &= ~R_PANORAMA;
784                 G.scene->r.xparts=  G.scene->r.yparts= 2;
785 #ifdef WITH_FFMPEG
786                 G.scene->r.ffcodecdata.gop_size = 18;
787 #endif          
788                 
789                 BLI_init_rctf(&G.scene->r.safety, 0.1, 0.9, 0.1, 0.9);
790                 BIF_undo_push("Set NTSC");
791                 allqueue(REDRAWBUTSSCENE, 0);
792                 allqueue(REDRAWVIEWCAM, 0);
793                 break;
794
795         case B_SETBROWSE:
796                 id= (ID*) G.scene->set;
797                 
798                 if (G.buts->menunr==-2) {
799                          activate_databrowse(id, ID_SCE, 0, B_SETBROWSE, &G.buts->menunr, do_render_panels);
800                 } 
801                 else if (G.buts->menunr>0) {
802                         Scene *newset= (Scene*) BLI_findlink(&G.main->scene, G.buts->menunr-1);
803                         
804                         if (newset==G.scene)
805                                 error("Can't use the same scene as its own set");
806                         else if (newset) {
807                                 G.scene->set= newset;
808                                 if (scene_check_setscene(G.scene)==0)
809                                         error("This would create a cycle");
810
811                                 allqueue(REDRAWBUTSSCENE, 0);
812                                 allqueue(REDRAWVIEW3D, 0);
813                                 BIF_undo_push("Change Set Scene");
814                         }
815                 }  
816                 break;
817         case B_CLEARSET:
818                 G.scene->set= NULL;
819                 allqueue(REDRAWBUTSSCENE, 0);
820                 allqueue(REDRAWVIEW3D, 0);
821                 BIF_undo_push("Clear Set Scene");
822                 
823                 break;
824         case B_SET_EDGE:
825                 allqueue(REDRAWBUTSSCENE, 0);
826                 break;
827         case B_SET_ZBLUR:
828                 G.scene->r.mode &= ~R_EDGE;
829                 allqueue(REDRAWBUTSSCENE, 0);
830                 break;
831         case B_ADD_RENDERLAYER:
832                 if(G.scene->r.actlay==32767) {
833                         scene_add_render_layer(G.scene);
834                         G.scene->r.actlay= BLI_countlist(&G.scene->r.layers) - 1;
835                 }
836                 allqueue(REDRAWBUTSSCENE, 0);
837                 allqueue(REDRAWNODE, 0);
838                 break;
839         case B_SET_PASS:
840                 if(G.scene->nodetree) {
841                         ntreeCompositForceHidden(G.scene->nodetree);
842                         allqueue(REDRAWNODE, 0);
843                 }
844                 allqueue(REDRAWBUTSSCENE, 0);
845                 allqueue(REDRAWOOPS, 0);
846         }
847 }
848
849 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
850 static uiBlock *edge_render_menu(void *arg_unused)
851 {
852         uiBlock *block;
853         
854         block= uiNewBlock(&curarea->uiblocks, "edge render", UI_EMBOSS, UI_HELV, curarea->win);
855                 
856         /* use this for a fake extra empy space around the buttons */
857         uiDefBut(block, LABEL, 0, "",  0, 0, 220, 115, NULL,  0, 0, 0, 0, "");
858         
859         uiDefButS(block, NUM, 0,"Eint:",        45,75,175,19,  &G.scene->r.edgeint, 0.0, 255.0, 0, 0,
860                   "Sets edge intensity for Toon shading");
861
862         /* color settings for the toon shading */
863         uiDefButF(block, COL, 0, "",            10, 10,30,60,  &(G.scene->r.edgeR), 0, 0, 0, B_EDGECOLSLI, "");
864         
865         uiBlockBeginAlign(block);
866         uiDefButF(block, NUMSLI, 0, "R ",   45, 50, 175,19,   &G.scene->r.edgeR, 0.0, 1.0, B_EDGECOLSLI, 0,
867                   "Color for edges in toon shading mode.");
868         uiDefButF(block, NUMSLI, 0, "G ",       45, 30, 175,19,  &G.scene->r.edgeG, 0.0, 1.0, B_EDGECOLSLI, 0,
869                   "Color for edges in toon shading mode.");
870         uiDefButF(block, NUMSLI, 0, "B ",       45, 10, 175,19,  &G.scene->r.edgeB, 0.0, 1.0, B_EDGECOLSLI, 0,
871                   "Color for edges in toon shading mode.");
872
873         
874         uiBlockSetDirection(block, UI_TOP);
875         
876         return block;
877 }
878
879
880 /* NOTE: this is a block-menu, needs 0 events, otherwise the menu closes */
881 static uiBlock *framing_render_menu(void *arg_unused)
882 {
883         uiBlock *block;
884         short yco = 190, xco = 0;
885         int randomcolorindex = 1234;
886
887         block= uiNewBlock(&curarea->uiblocks, "framing_options", UI_EMBOSS, UI_HELV, curarea->win);
888
889         /* use this for a fake extra empy space around the buttons */
890         uiDefBut(block, LABEL, 0, "",                   -5, -10, 295, 224, NULL, 0, 0, 0, 0, "");
891
892         uiDefBut(block, LABEL, 0, "Framing:", xco, yco, 68,19, 0, 0, 0, 0, 0, "");
893         uiBlockBeginAlign(block);
894         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");
895         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");
896         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");
897         uiBlockEndAlign(block);
898
899         yco -= 25;
900         xco = 40;
901
902         uiDefButF(block, COL, 0, "",                0, yco - 58 + 18, 33, 58, &G.scene->framing.col[0], 0, 0, 0, randomcolorindex, "");
903
904         uiBlockBeginAlign(block);
905         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");
906         yco -= 20;
907         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");
908         yco -= 20;
909         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");
910         uiBlockEndAlign(block);
911         
912         xco = 0;
913         uiDefBut(block, LABEL, 0, "Fullscreen:",                xco, yco-=30, 100, 19, 0, 0.0, 0.0, 0, 0, "");
914         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");
915         uiBlockBeginAlign(block);
916         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.");
917         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.");
918         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.");
919         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.");
920         uiBlockEndAlign(block);
921
922         /* stereo settings */
923         /* can't use any definition from the game engine here so hardcode it. Change it here when it changes there!
924          * RAS_IRasterizer has definitions:
925          * RAS_STEREO_NOSTEREO           1
926          * RAS_STEREO_QUADBUFFERED 2
927          * RAS_STEREO_ABOVEBELOW         3
928          * RAS_STEREO_INTERLACED         4       future
929          * RAS_STEREO_ANAGLYPH          5
930          * RAS_STEREO_SIDEBYSIDE        6
931          * RAS_STEREO_VINTERLACE        7
932          */
933         uiBlockBeginAlign(block);
934         uiDefButS(block, ROW, 0, "No Stereo", xco, yco-=30, 88, 19, &(G.scene->r.stereomode), 7.0, 1.0, 0, 0, "Disables stereo");
935         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");
936         uiDefButS(block, ROW, 0, "Syncdouble", xco+=90, yco, 88, 19, &(G.scene->r.stereomode), 7.0, 3.0, 0, 0, "Enables syncdoubling stereo method");
937         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");
938         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");
939         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");
940         
941         uiBlockEndAlign(block);
942
943         uiBlockSetDirection(block, UI_TOP);
944
945         return block;
946 }
947
948 #ifdef WITH_FFMPEG
949
950 static char* ffmpeg_format_pup(void) 
951 {
952         static char string[2048];
953         char formatstring[2048];
954 #if 0
955        int i = 0;
956        int stroffs = 0;
957        AVOutputFormat* next = first_oformat;
958        formatstring = "FFMpeg format: %%t";
959       sprintf(string, formatstring);
960        formatstring = "|%s %%x%d";
961        /* FIXME: This should only be generated once */
962        while (next != NULL) {
963                if (next->video_codec != CODEC_ID_NONE && !(next->flags & AVFMT_NOFILE)) {
964                        sprintf(string+stroffs, formatstring, next->name, i++);
965                        stroffs += strlen(string+stroffs);
966                }
967                next = next->next;
968        }
969        return string;
970 #endif
971        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");
972        sprintf(string, formatstring,
973                "MPEG-1", FFMPEG_MPEG1,
974                "MPEG-2", FFMPEG_MPEG2,
975                "MPEG-4", FFMPEG_MPEG4,
976                "AVI",    FFMPEG_AVI,
977                "Quicktime", FFMPEG_MOV,
978                "DV", FFMPEG_DV,
979                "H264", FFMPEG_H264,
980                "XVid", FFMPEG_XVID);
981        return string;
982 }
983
984 static char* ffmpeg_preset_pup(void) 
985 {
986         static char string[2048];
987         char formatstring[2048];
988
989        strcpy(formatstring, "FFMpeg preset: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
990        sprintf(string, formatstring,
991                "", FFMPEG_PRESET_NONE,
992                "DVD", FFMPEG_PRESET_DVD,
993                "SVCD", FFMPEG_PRESET_SVCD,
994                "VCD", FFMPEG_PRESET_VCD,
995                "DV", FFMPEG_PRESET_DV);
996        return string;
997 }
998
999
1000 static char* ffmpeg_codec_pup(void) {
1001        static char string[2048];
1002        char formatstring[2048];
1003        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");
1004        sprintf(string, formatstring,
1005                "MPEG1", CODEC_ID_MPEG1VIDEO,
1006                "MPEG2", CODEC_ID_MPEG2VIDEO,
1007                "MPEG4(divx)", CODEC_ID_MPEG4,
1008                "HuffYUV", CODEC_ID_HUFFYUV,
1009                "DV", CODEC_ID_DVVIDEO,
1010                "H264", CODEC_ID_H264,
1011                "XVid", CODEC_ID_XVID);
1012        return string;
1013
1014 }
1015
1016 static char* ffmpeg_audio_codec_pup(void) {
1017        static char string[2048];
1018        char formatstring[2048];
1019        strcpy(formatstring, "FFMpeg format: %%t|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d|%s %%x%d");
1020        sprintf(string, formatstring,
1021                "MP2", CODEC_ID_MP2,
1022                "MP3", CODEC_ID_MP3,
1023                "AC3", CODEC_ID_AC3,
1024                "AAC", CODEC_ID_AAC,
1025                "PCM", CODEC_ID_PCM_S16LE);
1026        return string;
1027
1028 }
1029
1030 #endif
1031
1032 static char *imagetype_pup(void)
1033 {
1034         static char string[1024];
1035         char formatstring[1024];
1036         char appendstring[1024];
1037
1038         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");
1039
1040 #ifdef __sgi
1041         strcat(formatstring, "|%s %%x%d");      // add space for Movie
1042 #endif
1043
1044         strcat(formatstring, "|%s %%x%d");      // add space for PNG
1045 /*  Commented out until implemented
1046 #ifdef WITH_DDS
1047         strcat(formatstring, "|%s %%x%d");      // add space for DDS
1048 #endif
1049 */
1050         strcat(formatstring, "|%s %%x%d");      // add space for BMP
1051         strcat(formatstring, "|%s %%x%d");      // add space for Radiance HDR
1052         strcat(formatstring, "|%s %%x%d");      // add space for Cineon
1053         strcat(formatstring, "|%s %%x%d");      // add space for DPX
1054         
1055 #ifdef _WIN32
1056         strcat(formatstring, "|%s %%x%d");      // add space for AVI Codec
1057 #endif
1058
1059 #ifdef WITH_FFMPEG
1060        strcat(formatstring, "|%s %%x%d"); // Add space for ffmpeg
1061 #endif
1062        strcat(formatstring, "|%s %%x%d"); // Add space for frameserver
1063
1064 #ifdef WITH_QUICKTIME
1065         if(G.have_quicktime)
1066                 strcat(formatstring, "|%s %%x%d");      // add space for Quicktime
1067 #endif
1068
1069         if(G.have_quicktime) {
1070                 sprintf(string, formatstring,
1071                         "Frameserver",   R_FRAMESERVER,
1072 #ifdef WITH_FFMPEG
1073                        "FFMpeg",         R_FFMPEG,
1074 #endif
1075                         "AVI Raw",        R_AVIRAW,
1076                         "AVI Jpeg",       R_AVIJPEG,
1077 #ifdef _WIN32
1078                         "AVI Codec",      R_AVICODEC,
1079 #endif
1080 #ifdef WITH_QUICKTIME
1081                         "QuickTime",      R_QUICKTIME,
1082 #endif
1083                         "Targa",          R_TARGA,
1084                         "Targa Raw",      R_RAWTGA,
1085                         "PNG",            R_PNG,
1086 /* commented out until implemented 
1087 #ifdef WITH_DDS
1088                         "DDS",            R_DDS,
1089 #endif
1090 */
1091                         "BMP",            R_BMP,
1092                         "Jpeg",           R_JPEG90,
1093                         "HamX",           R_HAMX,
1094                         "Iris",           R_IRIS,
1095                         "Radiance HDR",   R_RADHDR,
1096                         "Cineon",                 R_CINEON,
1097                         "DPX",                    R_DPX
1098 #ifdef __sgi
1099                         ,"Movie",          R_MOVIE
1100 #endif
1101                 );
1102         } else {
1103                 sprintf(string, formatstring,
1104                         "Frameserver",   R_FRAMESERVER,
1105 #ifdef WITH_FFMPEG
1106                        "FFMpeg",         R_FFMPEG,
1107 #endif
1108                         "AVI Raw",        R_AVIRAW,
1109                         "AVI Jpeg",       R_AVIJPEG,
1110 #ifdef _WIN32
1111                         "AVI Codec",      R_AVICODEC,
1112 #endif
1113                         "Targa",          R_TARGA,
1114                         "Targa Raw",      R_RAWTGA,
1115                         "PNG",            R_PNG,
1116 #ifdef WITH_DDS
1117                         "DDS",            R_DDS,
1118 #endif
1119                         "BMP",            R_BMP,
1120                         "Jpeg",           R_JPEG90,
1121                         "HamX",           R_HAMX,
1122                         "Iris",           R_IRIS,
1123                         "Radiance HDR",   R_RADHDR,
1124                         "Cineon",                 R_CINEON,
1125                         "DPX",                    R_DPX
1126 #ifdef __sgi
1127                         ,"Movie",          R_MOVIE
1128 #endif
1129                 );
1130         }
1131
1132 #ifdef WITH_OPENEXR
1133         strcpy(formatstring, "|%s %%x%d");
1134         sprintf(appendstring, formatstring, "OpenEXR", R_OPENEXR);
1135         strcat(string, appendstring);
1136         sprintf(appendstring, formatstring, "MultiLayer", R_MULTILAYER);
1137         strcat(string, appendstring);
1138 #endif
1139         
1140         if (G.have_libtiff) {
1141                 strcpy(formatstring, "|%s %%x%d");
1142                 sprintf(appendstring, formatstring, "TIFF", R_TIFF);
1143                 strcat(string, appendstring);
1144         }
1145
1146         return (string);
1147 }
1148
1149 #ifdef _WIN32
1150 static char *avicodec_str(void)
1151 {
1152         static char string[1024];
1153
1154         sprintf(string, "Codec: %s", G.scene->r.avicodecdata->avicodecname);
1155
1156         return string;
1157 }
1158 #endif
1159
1160 static void render_panel_output(void)
1161 {
1162         ID *id;
1163         int a,b;
1164         uiBlock *block;
1165         char *strp;
1166
1167
1168         block= uiNewBlock(&curarea->uiblocks, "render_panel_output", UI_EMBOSS, UI_HELV, curarea->win);
1169         if(uiNewPanel(curarea, block, "Output", "Render", 0, 0, 318, 204)==0) return;
1170         
1171         uiBlockBeginAlign(block);
1172         uiDefIconBut(block, BUT, B_FS_PIC, ICON_FILESEL,        10, 190, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Pics dir/name");
1173         uiDefBut(block, TEX,0,"",                                                       31, 190, 279, 20,G.scene->r.pic, 0.0,79.0, 0, 0, "Directory/name to save rendered Pics to");
1174         uiDefIconBut(block, BUT,B_FS_BACKBUF, ICON_FILESEL, 10, 168, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Backbuf image");
1175         uiDefBut(block, TEX,0,"",                                                       31, 168, 279, 20,G.scene->r.backbuf, 0.0,79.0, 0, 0, "Image to use as background for rendering");
1176         uiDefIconBut(block, BUT,B_FS_FTYPE, ICON_FILESEL,       10, 146, 20, 20, 0, 0, 0, 0, 0, "Open Fileselect to get Ftype image");
1177         uiDefBut(block, TEX,0,"",                                                       31, 146, 279, 20,G.scene->r.ftype,0.0,79.0, 0, 0, "Image to use with FTYPE Image type");
1178         uiBlockEndAlign(block);
1179         
1180         
1181         /* SET BUTTON */
1182         uiBlockBeginAlign(block);
1183         id= (ID *)G.scene->set;
1184         IDnames_to_pupstring(&strp, NULL, NULL, &(G.main->scene), id, &(G.buts->menunr));
1185         if(strp[0])
1186                 uiDefButS(block, MENU, B_SETBROWSE, strp, 10, 120, 20, 20, &(G.buts->menunr), 0, 0, 0, 0, "Scene to link as a Set");
1187         MEM_freeN(strp);
1188
1189         if(G.scene->set) {
1190                 uiSetButLock(1, NULL);
1191                 uiDefIDPoinBut(block, test_scenepoin_but, ID_SCE, B_NOP, "",    31, 120, 100, 20, &(G.scene->set), "Name of the Set");
1192                 uiClearButLock();
1193                 uiDefIconBut(block, BUT, B_CLEARSET, ICON_X,            132, 120, 20, 20, 0, 0, 0, 0, 0, "Remove Set link");
1194         }
1195         uiBlockEndAlign(block);
1196
1197         uiBlockSetCol(block, TH_BUT_SETTING1);
1198         uiDefButBitS(block, TOG, R_BACKBUF, B_NOP,"Backbuf",    10, 94, 80, 20, &G.scene->r.bufflag, 0, 0, 0, 0, "Enable/Disable use of Backbuf image");        
1199         uiDefButS(block, NUM, B_NOP, "Threads:",                                10, 68, 100, 20, &G.scene->r.threads, 1, BLENDER_MAX_THREADS, 0, 0, "Amount of threads for render");    
1200         uiBlockSetCol(block, TH_AUTO);
1201                 
1202         uiBlockBeginAlign(block);
1203         for(b=2; b>=0; b--)
1204                 for(a=0; a<3; a++)
1205                         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");
1206         uiBlockEndAlign(block);
1207
1208         uiDefButBitS(block, TOG, R_EXR_TILE_FILE, B_NOP, "Save Buffers", 72, 31, 120, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Save the tiles for all RenderLayers and used SceneNodes to files, to save memory");
1209         
1210         uiDefButS(block, MENU, B_REDR, "Render Display %t|Render Window %x1|Image Editor %x0|Full Screen %x2",  
1211                                         72, 10, 120, 19, &G.displaymode, 0.0, (float)R_DISPLAYWIN, 0, 0, "Sets render output display");
1212
1213         uiDefButBitS(block, TOG, R_EXTENSION, B_NOP, "Extensions", 205, 10, 105, 19, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Adds extensions to the output when rendering animations");
1214
1215         /* Dither control */
1216         uiDefButF(block, NUM,B_DIFF, "Dither:",         205,31,105,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)");
1217         
1218         /* Toon shading buttons */
1219         uiBlockBeginAlign(block);
1220         uiDefButBitI(block, TOG, R_EDGE, B_NOP,"Edge",   100, 94, 70, 20, &G.scene->r.mode, 0, 0, 0, 0, "Enable Toon Edge-enhance");
1221         uiDefBlockBut(block, edge_render_menu, NULL, "Edge Settings", 170, 94, 140, 20, "Display Edge settings");
1222         uiBlockEndAlign(block);
1223         
1224         uiBlockBeginAlign(block);
1225         uiDefButBitS(block, TOG, R_NO_TEX, B_NOP, "Disable Tex", 115, 68, 70, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Disables Textures for render");
1226         uiDefButBitS(block, TOG, R_FREE_IMAGE, B_NOP, "Free Tex Images", 205, 68, 100, 20, &G.scene->r.scemode, 0.0, 0.0, 0, 0, "Frees all Images used by Textures after each render");
1227         uiBlockEndAlign(block);
1228 }
1229
1230 static void do_bake_func(void *unused_v, void *unused_p)
1231 {
1232         objects_bake_render(0);
1233 }
1234
1235 static void render_panel_bake(void)
1236 {
1237         uiBlock *block;
1238         uiBut *but;
1239         
1240         block= uiNewBlock(&curarea->uiblocks, "render_panel_bake", UI_EMBOSS, UI_HELV, curarea->win);
1241         uiNewPanelTabbed("Anim", "Render");
1242         if(uiNewPanel(curarea, block, "Bake", "Render", 320, 0, 318, 204)==0) return;
1243         
1244         but= uiDefBut(block, BUT, B_NOP, "BAKE",        10, 150, 190,40, 0, 0, 0, 0, 0, "Start the bake render for selected Objects");
1245         uiButSetFunc(but, do_bake_func, NULL, NULL);
1246 #if 0   
1247         uiBlockBeginAlign(block);
1248         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)");
1249         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");
1250         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");
1251         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");
1252         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");
1253 #endif  
1254         uiBlockBeginAlign(block);
1255         uiDefButS(block, ROW,B_DIFF,"Full Render",              210,170,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_ALL, 0, 0, "");
1256         uiDefButS(block, ROW,B_DIFF,"Ambient Occlusion",210,150,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_AO, 0, 0, "");
1257         uiDefButS(block, ROW,B_DIFF,"Normals",          210,130,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_NORMALS, 0, 0, "");
1258         uiDefButS(block, ROW,B_DIFF,"Textures",         210,110,120,20,&G.scene->r.bake_mode, 1.0, RE_BAKE_TEXTURE, 0, 0, "");
1259         uiBlockEndAlign(block);
1260         
1261         uiDefButBitS(block, TOG, R_BAKE_CLEAR, B_DIFF, "Clear",         210,80,120,20,&G.scene->r.bake_flag, 0.0, 0, 0, 0, "Clear Images before baking");
1262         
1263         uiDefButS(block, NUM, B_DIFF,"Margin:",                         210,50,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");
1264 }
1265
1266 static void render_panel_render(void)
1267 {
1268         uiBlock *block;
1269         char str[256];
1270
1271         block= uiNewBlock(&curarea->uiblocks, "render_panel_render", UI_EMBOSS, UI_HELV, curarea->win);
1272         if(uiNewPanel(curarea, block, "Render", "Render", 320, 0, 318, 204)==0) return;
1273
1274         uiBlockBeginAlign(block);
1275         uiDefBut(block, BUT,B_DORENDER,"RENDER",        369, 164, 191,37, 0, 0, 0, 0, 0, "Start the rendering");
1276 #ifndef DISABLE_YAFRAY
1277         /* yafray: on request, render engine menu is back again, and moved to Render panel */
1278         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0|YafRay %x1", 
1279                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1280 #else
1281         uiDefButS(block, MENU, B_SWITCHRENDER, "Rendering Engine %t|Blender Internal %x0", 
1282                                                                                                 369, 142, 191, 20, &G.scene->r.renderer, 0, 0, 0, 0, "Choose rendering engine");        
1283 #endif /* disable yafray */
1284
1285         uiBlockBeginAlign(block);
1286         uiDefButBitI(block, TOG, R_OSA, B_DIFF, "OSA",  369,109,122,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Oversampling (Anti-aliasing)");
1287         uiDefButS(block, ROW,B_DIFF,"5",                        369,88,29,20,&G.scene->r.osa,2.0,5.0, 0, 0, "Sets oversample level to 5");
1288         uiDefButS(block, ROW,B_DIFF,"8",                        400,88,29,20,&G.scene->r.osa,2.0,8.0, 0, 0, "Sets oversample level to 8 (Recommended)");
1289         uiDefButS(block, ROW,B_DIFF,"11",                       431,88,29,20,&G.scene->r.osa,2.0,11.0, 0, 0, "Sets oversample level to 11");
1290         uiDefButS(block, ROW,B_DIFF,"16",                       462,88,29,20,&G.scene->r.osa,2.0,16.0, 0, 0, "Sets oversample level to 16");
1291         uiBlockEndAlign(block);
1292
1293         uiBlockBeginAlign(block);
1294         uiDefButBitI(block, TOG, R_MBLUR, B_REDR, "MBLUR",      496,109,64,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables Motion Blur calculation");
1295         uiDefButF(block, NUM,B_DIFF,"Bf:",                      496,88,64,20,&G.scene->r.blurfac, 0.01, 5.0, 10, 2, "Sets motion blur factor");
1296         uiBlockEndAlign(block);
1297
1298         uiBlockBeginAlign(block);
1299         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)");
1300         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");
1301         uiBlockEndAlign(block);
1302
1303         uiBlockBeginAlign(block);
1304         uiDefButS(block, ROW,800,"Sky",         369,13,35,20,&G.scene->r.alphamode,3.0,0.0, 0, 0, "Fill background with sky");
1305         uiDefButS(block, ROW,800,"Premul",      405,13,50,20,&G.scene->r.alphamode,3.0,1.0, 0, 0, "Multiply alpha in advance");
1306         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");
1307         uiBlockEndAlign(block);
1308
1309         if(G.scene->r.mode & R_RAYTRACE)
1310                 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");
1311
1312         uiBlockBeginAlign(block);
1313         uiDefButBitI(block, TOG, R_SHADOW, B_REDR,"Shadow",     565,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable shadow calculation");
1314         uiDefButBitI(block, TOG, R_ENVMAP, B_REDR,"EnvMap",     627,172,60,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable environment map rendering");
1315         uiDefButBitI(block, TOG, R_PANORAMA, B_REDR,"Pano",     565,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable panorama rendering (output width is multiplied by Xparts)");
1316         uiDefButBitI(block, TOG, R_RAYTRACE, B_REDR,"Ray",606,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable ray tracing");
1317         uiDefButBitI(block, TOG, R_RADIO, B_REDR,"Radio",       647,142,40,29, &G.scene->r.mode, 0, 0, 0, 0, "Enable radiosity rendering");
1318         uiBlockEndAlign(block);
1319         
1320         uiBlockBeginAlign(block);
1321         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");
1322         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");
1323         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");
1324         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");
1325         uiBlockEndAlign(block);
1326
1327         uiBlockBeginAlign(block);
1328         uiDefButBitI(block, TOG, R_FIELDS, B_REDR,"Fields",  565,55,60,20,&G.scene->r.mode, 0, 0, 0, 0, "Enables field rendering");
1329         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)");
1330         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");
1331         
1332         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);
1333         uiDefButS(block, MENU, B_DIFF,str,              565,34,60,20, &G.scene->r.filtertype, 0, 0, 0, 0, "Set sampling filter for antialiasing");
1334         uiDefButF(block, NUM,B_DIFF,"",                 627,34,60,20,&G.scene->r.gauss,0.5, 1.5, 10, 2, "Sets the filter size");
1335         
1336         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");
1337         uiBlockEndAlign(block);
1338
1339 }
1340
1341 static void render_panel_anim(void)
1342 {
1343         uiBlock *block;
1344
1345
1346         block= uiNewBlock(&curarea->uiblocks, "render_panel_anim", UI_EMBOSS, UI_HELV, curarea->win);
1347         if(uiNewPanel(curarea, block, "Anim", "Render", 640, 0, 318, 204)==0) return;
1348
1349
1350         uiDefBut(block, BUT,B_DOANIM,"ANIM",            692,142,192,47, 0, 0, 0, 0, 0, "Start rendering a sequence");
1351
1352         uiBlockSetCol(block, TH_BUT_SETTING1);
1353         uiBlockBeginAlign(block);
1354         uiDefButBitS(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)");
1355         uiDefButBitS(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");
1356         uiBlockEndAlign(block);
1357
1358         uiBlockSetCol(block, TH_AUTO);
1359         uiDefBut(block, BUT,B_PLAYANIM, "PLAY",692,40,94,33, 0, 0, 0, 0, 0, "Play animation of rendered images/avi (searches Pics: field)");
1360         uiDefButS(block, NUM, B_RTCHANGED, "rt:",789,40,95,33, &G.rt, -1000.0, 1000.0, 0, 0, "General testing/debug button");
1361
1362         uiBlockBeginAlign(block);
1363         uiDefButI(block, NUM,REDRAWSEQ,"Sta:",692,10,94,24, &G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "The start frame of the animation");
1364         uiDefButI(block, NUM,REDRAWSEQ,"End:",789,10,95,24, &G.scene->r.efra,SFRA,MAXFRAMEF, 0, 0, "The end  frame of the animation");
1365         uiBlockEndAlign(block);
1366 }
1367
1368 #ifdef WITH_FFMPEG
1369 static void set_ffmpeg_preset(int preset)
1370 {
1371         int isntsc = (G.scene->r.frs_sec != 25);
1372         switch (preset) {
1373         case FFMPEG_PRESET_VCD:
1374                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG1;
1375                 G.scene->r.ffcodecdata.video_bitrate = 1150;
1376                 G.scene->r.xsch = 352;
1377                 G.scene->r.ysch = isntsc ? 240 : 288;
1378                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1379                 G.scene->r.ffcodecdata.rc_max_rate = 1150;
1380                 G.scene->r.ffcodecdata.rc_min_rate = 1150;
1381                 G.scene->r.ffcodecdata.rc_buffer_size = 40*8;
1382                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1383                 G.scene->r.ffcodecdata.mux_rate = 2352 * 75 * 8;
1384                 break;
1385         case FFMPEG_PRESET_SVCD:
1386                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1387                 G.scene->r.ffcodecdata.video_bitrate = 2040;
1388                 G.scene->r.xsch = 480;
1389                 G.scene->r.ysch = isntsc ? 480 : 576;
1390                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1391                 G.scene->r.ffcodecdata.rc_max_rate = 2516;
1392                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1393                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1394                 G.scene->r.ffcodecdata.mux_packet_size = 2324;
1395                 G.scene->r.ffcodecdata.mux_rate = 0;
1396                 
1397                 break;
1398         case FFMPEG_PRESET_DVD:
1399                 G.scene->r.ffcodecdata.type = FFMPEG_MPEG2;
1400                 G.scene->r.ffcodecdata.video_bitrate = 6000;
1401                 G.scene->r.xsch = 720;
1402                 G.scene->r.ysch = isntsc ? 480 : 576;
1403                 G.scene->r.ffcodecdata.gop_size = isntsc ? 18 : 15;
1404                 G.scene->r.ffcodecdata.rc_max_rate = 9000;
1405                 G.scene->r.ffcodecdata.rc_min_rate = 0;
1406                 G.scene->r.ffcodecdata.rc_buffer_size = 224*8;
1407                 G.scene->r.ffcodecdata.mux_packet_size = 2048;
1408                 G.scene->r.ffcodecdata.mux_rate = 10080000;
1409                 
1410                 break;
1411         case FFMPEG_PRESET_DV:
1412                 G.scene->r.ffcodecdata.type = FFMPEG_DV;
1413                 G.scene->r.xsch = 720;
1414                 G.scene->r.ysch = isntsc ? 480 : 576;
1415                 break;
1416         }
1417 }
1418
1419 static void render_panel_ffmpeg_video(void)
1420 {
1421         uiBlock *block;
1422         int yofs;
1423         int xcol1;
1424         int xcol2;
1425         
1426         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_video", 
1427                                            UI_EMBOSS, UI_HELV, curarea->win);
1428         
1429         uiNewPanelTabbed("Format", "Render");
1430         if (uiNewPanel(curarea, block, "Video", "Render", 960, 0, 318, 204)== 0) 
1431                 return;
1432         
1433         if (ffmpeg_preset_sel != 0) {
1434                 set_ffmpeg_preset(ffmpeg_preset_sel);
1435                 ffmpeg_preset_sel = 0;
1436                 allqueue(REDRAWBUTSSCENE, 0);
1437         }
1438         
1439         xcol1 = 872;
1440         xcol2 = 1002;
1441         
1442         yofs = 54;
1443         uiDefBut(block, LABEL, B_DIFF, "Format", xcol1, yofs+88, 
1444                          110, 20, 0, 0, 0, 0, 0, "");
1445         uiDefBut(block, LABEL, B_DIFF, "Preset", xcol2, yofs+88, 
1446                          110, 20, 0, 0, 0, 0, 0, "");
1447         uiDefButI(block, MENU, B_DIFF, ffmpeg_format_pup(), 
1448                           xcol1, yofs+66, 110, 20, &G.scene->r.ffcodecdata.type, 
1449                           0,0,0,0, "output file format");
1450         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1451                           xcol1, yofs+44, 110, 20, 
1452                           &G.scene->r.ffcodecdata.video_bitrate, 
1453                           1, 14000, 0, 0, "Video bitrate(kb/s)");
1454         uiDefButI(block, NUM, B_DIFF, "Min Rate", 
1455                           xcol1, yofs+22, 110, 20, &G.scene->r.ffcodecdata.rc_min_rate, 
1456                           0, 14000, 0, 0, "Rate control: min rate(kb/s)");
1457         uiDefButI(block, NUM, B_DIFF, "Max Rate", 
1458                           xcol1, yofs, 110, 20, &G.scene->r.ffcodecdata.rc_max_rate, 
1459                           1, 14000, 0, 0, "Rate control: max rate(kb/s)");
1460         
1461         uiDefButI(block, NUM, B_DIFF, "Mux Rate", 
1462                           xcol1, yofs-22, 110, 20, 
1463                           &G.scene->r.ffcodecdata.mux_rate, 
1464                           0, 100000000, 0, 0, "Mux rate (bits/s(!))");
1465         
1466         
1467         uiDefButI(block, MENU, B_REDR, ffmpeg_preset_pup(), 
1468                           xcol2, yofs+66, 110, 20, &ffmpeg_preset_sel, 
1469                           0,0,0,0, "Output file format preset selection");
1470         uiDefButI(block, NUM, B_DIFF, "GOP Size", 
1471                           xcol2, yofs+44, 110, 20, &G.scene->r.ffcodecdata.gop_size, 
1472                           0, 100, 0, 0, "Distance between key frames");
1473         uiDefButI(block, NUM, B_DIFF, "Buffersize", 
1474                           xcol2, yofs+22, 110, 20,
1475                           &G.scene->r.ffcodecdata.rc_buffer_size, 
1476                           0, 2000, 0, 0, "Rate control: buffer size (kb)");
1477         uiDefButI(block, NUM, B_DIFF, "Mux PSize", 
1478                           xcol2, yofs, 110, 20, 
1479                           &G.scene->r.ffcodecdata.mux_packet_size, 
1480                           0, 16384, 0, 0, "Mux packet size (byte)");
1481         
1482         uiDefButBitI(block, TOG, FFMPEG_AUTOSPLIT_OUTPUT, B_NOP,
1483                                  "Autosplit Output", 
1484                                  xcol2, yofs-22, 110, 20, 
1485                                  &G.scene->r.ffcodecdata.flags, 
1486                                  0, 1, 0,0, "Autosplit output at 2GB boundary.");
1487         
1488         
1489         if (ELEM(G.scene->r.ffcodecdata.type, FFMPEG_AVI, FFMPEG_MOV)) {
1490                 uiDefBut(block, LABEL, 0, "Codec", 
1491                                 xcol1, yofs-44, 110, 20, 0, 0, 0, 0, 0, "");
1492                 uiDefButI(block, MENU,B_REDR, ffmpeg_codec_pup(), 
1493                                   xcol1, yofs-66, 110, 20, 
1494                                   &G.scene->r.ffcodecdata.codec, 
1495                                   0,0,0,0, "FFMpeg codec to use");
1496         }
1497 }
1498
1499 static void render_panel_ffmpeg_audio(void)
1500 {
1501         uiBlock *block;
1502         int yofs;
1503         int xcol;
1504         
1505         block = uiNewBlock(&curarea->uiblocks, "render_panel_ffmpeg_audio", UI_EMBOSS, UI_HELV, curarea->win);
1506         uiNewPanelTabbed("Format", "Render");
1507         if (uiNewPanel(curarea, block, "Audio", "Render", 960, 0, 318, 204) == 0) return;
1508         
1509         yofs = 54;
1510         xcol = 892;
1511         
1512         uiDefButBitI(block, TOG, FFMPEG_MULTIPLEX_AUDIO, B_NOP,
1513                                  "Multiplex audio", xcol, yofs, 225, 20, 
1514                                  &G.scene->r.ffcodecdata.flags, 
1515                                  0, 1, 0,0, "Interleave audio with the output video");
1516         uiDefBut(block, LABEL, 0, "Codec", 
1517                          xcol, yofs-22, 225, 20, 0, 0, 0, 0, 0, "");
1518         uiDefButI(block, MENU,B_NOP, ffmpeg_audio_codec_pup(), 
1519                           xcol, yofs-44, 225, 20, 
1520                           &G.scene->r.ffcodecdata.audio_codec, 
1521                           0,0,0,0, "FFMpeg codec to use");
1522         uiDefButI(block, NUM, B_DIFF, "Bitrate", 
1523                           xcol, yofs-66, 110, 20, 
1524                           &G.scene->r.ffcodecdata.audio_bitrate, 
1525                           32, 384, 0, 0, "Audio bitrate(kb/s)");
1526 }
1527 #endif
1528
1529 static void render_panel_stamp(void)
1530 {
1531         uiBlock *block;
1532         int yofs, xofs;
1533
1534
1535         block= uiNewBlock (&curarea->uiblocks, "render_panel_stamp", UI_EMBOSS, UI_HELV, curarea->win);
1536         uiNewPanelTabbed ("Format", "Render");
1537         if(uiNewPanel (curarea, block, "Stamp", "Render", 960, 0, 318, 204)==0) return;
1538
1539         if (G.scene->r.scemode & R_STAMP_INFO) {
1540                 yofs = 0;
1541                 xofs = 550;uiBlockBeginAlign(block);
1542                 
1543                 uiBlockBeginAlign(block);
1544                 uiDefButBitI(block, TOG, R_STAMP_NOTE, B_REDR, "Note", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp user data");
1545                 uiDefBut(block, TEX, B_NOP, "", xofs+100, yofs, 200, 19, &G.scene->r.stamp_udata, 0.0, 128.0, 100, 0, "User Note");
1546                 uiBlockEndAlign(block);
1547                 yofs += 30; /* gap */
1548                 
1549                 
1550                 yofs += 100;
1551                 // Order is important for alligning ... grr
1552                 uiBlockBeginAlign(block);
1553                 uiDefButBitI(block, TOG, R_STAMP_SCENE, B_REDR, "Scene", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp scene name");
1554                 yofs -= 20;
1555                 uiDefButBitI(block, TOG, R_STAMP_CAMERA, B_REDR, "Camera", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp camera name");
1556                 yofs -= 20;
1557                 uiDefButBitI(block, TOG, R_STAMP_DATE, B_REDR, "Date", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp date");
1558                 yofs -= 20;
1559                 uiDefButBitI(block, TOG, R_STAMP_TIME, B_REDR, "Time", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp time (HH:MM:SS)");
1560                 yofs -= 20;
1561                 uiDefButBitI(block, TOG, R_STAMP_FRAME, B_REDR, "Frame", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp frame number");
1562                 yofs -= 20;
1563                 uiDefButBitI(block, TOG, R_STAMP_MARKER, B_REDR, "Marker", xofs, yofs, 100, 19, &G.scene->r.stamp, 0, 0, 0, 0, "Stamp the last marker");
1564                 uiBlockEndAlign(block);
1565                 yofs += 100;
1566                 
1567                 /* draw font selector */
1568                 if (G.scene->r.stamp & R_STAMP_DRAW) {
1569                         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|",
1570                                         xofs+110, yofs, 190, 19, &G.scene->r.stamp_font_id, 0, 0, 0, 0, "Choose rendering engine");
1571                         
1572                         /* draw fg/bg next to the scene */
1573                         yofs -= 25;
1574                         uiDefBut(block, LABEL, 0, "Text Color", xofs+110, yofs, 80, 19, 0, 0, 0, 0, 0, "");
1575                         uiDefBut(block, LABEL, 0, "Background", xofs+205, yofs, 80, 19, 0, 0, 0, 0, 0, "");
1576                         yofs -= 20;
1577                         uiDefButF(block, COL, B_NOP, "", xofs+110, yofs, 90, 19, G.scene->r.fg_stamp, 0, 0, 0, 0, "Foreground text color");
1578                         uiDefButF(block, COL, B_NOP, "", xofs+210, yofs, 90, 19, G.scene->r.bg_stamp, 0, 0, 0, 0, "Background color");
1579                         yofs += 75;
1580                 } else {
1581                         yofs += 30;
1582                 }
1583                 
1584                 uiDefButBitS(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, yofs, 100, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Disable stamp info in images metadata");
1585                 uiDefButBitI(block, TOG, R_STAMP_DRAW, B_REDR, "Draw Stamp", xofs+110, yofs, 190, 20, &G.scene->r.stamp, 0, 0, 0, 0, "Draw the stamp info into each frame");
1586                 yofs += 20;
1587         }
1588         else {
1589                 uiDefButBitS(block, TOG, R_STAMP_INFO, B_REDR, "Enable Stamp", xofs, 142, 100, 20, &G.scene->r.scemode, 0, 0, 0, 0, "Enable stamp info to image metadata");
1590                 yofs += 20;
1591                 uiDefBut(block, LABEL, 0, "", xofs, yofs, 300, 19, 0, 0, 0, 0, 0, "");
1592         }
1593 }
1594
1595 static void render_panel_format(void)
1596 {
1597         uiBlock *block;
1598         int yofs;
1599
1600
1601         block= uiNewBlock(&curarea->uiblocks, "render_panel_format", UI_EMBOSS, UI_HELV, curarea->win);
1602         if(uiNewPanel(curarea, block, "Format", "Render", 960, 0, 318, 204)==0) return;
1603         uiDefBlockBut(block, framing_render_menu, NULL, 
1604                                   "Game framing settings", 
1605                                   892, 169, 227, 20, "Display game framing settings");
1606         /* uiDefIconTextBlockBut(block, framing_render_menu, NULL, 
1607                                                    ICON_BLOCKBUT_CORNER, 
1608                                                    "Game framing settings", 
1609                                                    892, 169, 227, 20, 
1610                                                    "Display game framing settings"); */
1611
1612         uiBlockBeginAlign(block);
1613         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeX:",    892 ,136,112,27, &G.scene->r.xsch, 4.0, 10000.0, 0, 0, "The image width in pixels");
1614         uiDefButS(block, NUM,REDRAWVIEWCAM,"SizeY:",    1007,136,112,27, &G.scene->r.ysch, 4.0,10000.0, 0, 0, "The image height in scanlines");
1615         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspX:",     892 ,114,112,20, &G.scene->r.xasp, 1.0,200.0, 0, 0, "The horizontal aspect ratio");
1616         uiDefButS(block, NUM,REDRAWVIEWCAM,"AspY:",     1007,114,112,20, &G.scene->r.yasp, 1.0,200.0, 0, 0, "The vertical aspect ratio");
1617         uiBlockEndAlign(block);
1618
1619         yofs = 54;
1620
1621 #ifdef __sgi
1622         yofs = 76;
1623         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");
1624         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");
1625 #endif
1626
1627         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");
1628         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");
1629
1630         yofs -= 22;
1631
1632         if(G.scene->r.quality==0) G.scene->r.quality= 90;
1633
1634 #ifdef WITH_QUICKTIME
1635         if (G.scene->r.imtype == R_AVICODEC || G.scene->r.imtype == R_QUICKTIME) {
1636 #else /* WITH_QUICKTIME */
1637         if (0) {
1638 #endif
1639                 if(G.scene->r.imtype == R_QUICKTIME) {
1640 #ifdef WITH_QUICKTIME
1641 #if defined (_WIN32) || defined (__APPLE__)
1642                         //glColor3f(0.65, 0.65, 0.7);
1643                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1644                         if(G.scene->r.qtcodecdata == NULL)
1645                                 uiDefBut(block, LABEL, 0, "Codec: not set",  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1646                         else
1647                                 uiDefBut(block, LABEL, 0, G.scene->r.qtcodecdata->qtcodecname,  892,yofs+44,225,20, 0, 0, 0, 0, 0, "");
1648                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for Quicktime");
1649 #endif
1650 #endif /* WITH_QUICKTIME */
1651                 } else {
1652 #ifdef _WIN32
1653                         //glColor3f(0.65, 0.65, 0.7);
1654                         //glRecti(892,yofs+46,892+225,yofs+45+20);
1655                         if(G.scene->r.avicodecdata == NULL)
1656                                 uiDefBut(block, LABEL, 0, "Codec: not set.",  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1657                         else
1658                                 uiDefBut(block, LABEL, 0, avicodec_str(),  892,yofs+43,225,20, 0, 0, 0, 0, 0, "");
1659 #endif
1660                         uiDefBut(block, BUT,B_SELECTCODEC, "Set codec",  892,yofs,112,20, 0, 0, 0, 0, 0, "Set codec settings for AVI");
1661                 }
1662 #ifdef WITH_OPENEXR
1663         } 
1664         else if (ELEM(G.scene->r.imtype, R_OPENEXR, R_MULTILAYER)) {
1665                 if (G.scene->r.quality > 5) G.scene->r.quality = 2;
1666                 
1667                 if(G.scene->r.imtype==R_OPENEXR) {
1668                         uiBlockBeginAlign(block);
1669                         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");
1670                         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)");
1671                         uiBlockEndAlign(block);
1672                         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");
1673                 }               
1674                 uiDefButS(block, MENU,B_NOP, "Codec %t|None %x0|Pxr24 (lossy) %x1|ZIP (lossless) %x2|PIZ (lossless) %x3|RLE (lossless) %x4",  
1675                                                                                                                         892,yofs,112,20, &G.scene->r.quality, 0, 0, 0, 0, "Set codec settings for OpenEXR");
1676                 
1677 #endif
1678         } else {
1679                 if(G.scene->r.quality < 5) G.scene->r.quality = 90;     /* restore from openexr */
1680                 
1681                 uiDefButS(block, NUM,B_DIFF, "Quality:",           892,yofs,112,20, &G.scene->r.quality, 10.0, 100.0, 0, 0, "Quality setting for JPEG images, AVI Jpeg and SGI movies");
1682         }
1683         uiDefButS(block, NUM,B_FRAMEMAP,"Frs/sec:",   1006,yofs,113,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
1684
1685
1686         uiBlockBeginAlign(block);
1687         uiDefButS(block, ROW,B_DIFF,"BW",                       892, 10,74,19, &G.scene->r.planes, 5.0,(float)R_PLANESBW, 0, 0, "Images are saved with BW (grayscale) data");
1688         uiDefButS(block, ROW,B_DIFF,"RGB",                  968, 10,74,19, &G.scene->r.planes, 5.0,(float)R_PLANES24, 0, 0, "Images are saved with RGB (color) data");
1689         uiDefButS(block, ROW,B_DIFF,"RGBA",                1044, 10,75,19, &G.scene->r.planes, 5.0,(float)R_PLANES32, 0, 0, "Images are saved with RGB and Alpha data (if supported)");
1690
1691         uiBlockBeginAlign(block);
1692         uiDefBut(block, BUT,B_PR_PAL, "PAL",            1146,170,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x576, Aspect ratio - 54x51, 25 fps");
1693         uiDefBut(block, BUT,B_PR_NTSC, "NTSC",          1146,150,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x480, Aspect ratio - 10x11, 30 fps");
1694         uiDefBut(block, BUT,B_PR_PRESET, "Default",     1146,130,100,18, 0, 0, 0, 0, 0, "Same as PAL, with render settings (OSA, Shadows, Fields)");
1695         uiDefBut(block, BUT,B_PR_PRV, "Preview",        1146,110,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x512, Render size 50%");
1696         uiDefBut(block, BUT,B_PR_PC, "PC",                      1146,90,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 640x480, Aspect ratio - 100x100");
1697         uiDefBut(block, BUT,B_PR_PAL169, "PAL 16:9",1146,70,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 720x576, Aspect ratio - 64x45");
1698         uiDefBut(block, BUT,B_PR_PANO, "PANO",          1146,50,100,18, 0, 0, 0, 0, 0, "Standard panorama settings");
1699         uiDefBut(block, BUT,B_PR_FULL, "FULL",          1146,30,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1280x1024, Aspect ratio - 1x1");
1700         uiDefBut(block, BUT,B_PR_HD, "HD",              1146,10,100,18, 0, 0, 0, 0, 0, "Size preset: Image size - 1920x1080, Aspect ratio - 1x1");
1701         uiBlockEndAlign(block);
1702 }
1703
1704 #ifndef DISABLE_YAFRAY /* disable yafray stuff */
1705 /* yafray: global illumination options panel */
1706 static void render_panel_yafrayGI()
1707 {
1708         uiBlock *block;
1709
1710         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGI", UI_EMBOSS, UI_HELV, curarea->win);
1711         uiNewPanelTabbed("Render", "Render");
1712         if(uiNewPanel(curarea, block, "YafRay GI", "Render", 320, 0, 318, 204)==0) return;
1713
1714         // label to force a boundbox for buttons not to be centered
1715         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1716
1717         uiDefBut(block, LABEL, 0, "Method", 5,175,70,20, 0, 1.0, 0, 0, 0, "");
1718         uiDefButS(block, MENU, B_REDR, "GiMethod %t|None %x0|SkyDome %x1|Full %x2", 70,175,89,20, &G.scene->r.GImethod, 0, 0, 0, 0, "Global Illumination Method");
1719
1720         uiDefBut(block, LABEL, 0, "Quality", 5,150,70,20, 0, 1.0, 0, 0, 0, "");
1721         uiDefButS(block, MENU, B_REDR, "GiQuality %t|None %x0|Low %x1|Medium %x2 |High %x3|Higher %x4|Best %x5|Use Blender AO settings %x6", 70,150,89,20, &G.scene->r.GIquality, 0, 0, 0, 0, "Global Illumination Quality");
1722
1723         if (G.scene->r.GImethod>0) {
1724                 uiDefButF(block, NUM, B_DIFF, "EmitPwr:", 5,35,154,20, &G.scene->r.GIpower, 0.01, 100.0, 10, 0, "arealight, material emit and background intensity scaling, 1 is normal");
1725                 if (G.scene->r.GImethod==2) uiDefButF(block, NUM, B_DIFF, "GI Pwr:", 5,10,154,20, &G.scene->r.GIindirpower, 0.01, 100.0, 10, 0, "GI indirect lighting intensity scaling, 1 is normal");
1726         }
1727
1728         if (G.scene->r.GImethod>0)
1729         {
1730                 if (G.scene->r.GIdepth==0) G.scene->r.GIdepth=2;
1731
1732                 if (G.scene->r.GImethod==2) {
1733                         uiDefButI(block, NUM, B_DIFF, "Depth:", 180,175,110,20, &G.scene->r.GIdepth, 1.0, 100.0, 10, 10, "Number of bounces of the indirect light");
1734                         uiDefButI(block, NUM, B_DIFF, "CDepth:", 180,150,110,20, &G.scene->r.GIcausdepth, 1.0, 100.0, 10, 10, "Number of bounces inside objects (for caustics)");
1735                         uiDefButBitS(block, TOG, 1,  B_REDR, "Photons",210,125,100,20, &G.scene->r.GIphotons, 0, 0, 0, 0, "Use global photons to help in GI");
1736                 }
1737
1738                 uiDefButBitS(block, TOG, 1, B_REDR, "Cache",6,125,95,20, &G.scene->r.GIcache, 0, 0, 0, 0, "Cache occlusion/irradiance samples (faster)");
1739                 if (G.scene->r.GIcache) 
1740                 {
1741                         uiDefButBitS(block,TOG, 1, B_REDR, "NoBump",108,125,95,20, &G.scene->r.YF_nobump, 0, 0, 0, 0, "Don't use bumpnormals for cache (faster, but no bumpmapping in total indirectly lit areas)");
1742                         uiDefBut(block, LABEL, 0, "Cache parameters:", 5,105,130,20, 0, 1.0, 0, 0, 0, "");
1743                         if (G.scene->r.GIshadowquality==0.0) G.scene->r.GIshadowquality=0.9;
1744                         uiDefButF(block, NUM, B_DIFF,"ShadQu:", 5,85,154,20,    &(G.scene->r.GIshadowquality), 0.01, 1.0 ,1,0, "Sets the shadow quality, keep it under 0.95 :-) ");
1745                         if (G.scene->r.GIpixelspersample==0) G.scene->r.GIpixelspersample=10;
1746                         uiDefButI(block, NUM, B_DIFF, "Prec:",  5,60,75,20, &G.scene->r.GIpixelspersample, 1, 50, 10, 10, "Maximum number of pixels without samples, the lower the better and slower");
1747                         if (G.scene->r.GIrefinement==0) G.scene->r.GIrefinement=1.0;
1748                         uiDefButF(block, NUM, B_DIFF, "Ref:", 84,60,75,20, &G.scene->r.GIrefinement, 0.001, 1.0, 1, 0, "Threshold to refine shadows EXPERIMENTAL. 1 = no refinement");
1749                 }
1750
1751                 if (G.scene->r.GImethod==2) {
1752                         if (G.scene->r.GIphotons)
1753                         {
1754                                 uiDefBut(block, LABEL, 0, "Photon parameters:", 170,105,130,20, 0, 1.0, 0, 0, 0, "");
1755                                 if(G.scene->r.GIphotoncount==0) G.scene->r.GIphotoncount=100000;
1756                                 uiDefButI(block, NUM, B_DIFF, "Count:", 170,85,140,20, &G.scene->r.GIphotoncount, 
1757                                                 0, 10000000, 10, 10, "Number of photons to shoot");
1758                                 if(G.scene->r.GIphotonradius==0.0) G.scene->r.GIphotonradius=1.0;
1759                                 uiDefButF(block, NUMSLI, B_DIFF,"Radius:", 170,60,140,20,       &(G.scene->r.GIphotonradius), 
1760                                                 0.00001, 100.0 ,0,0, "Radius to search for photons to mix (blur)");
1761                                 if(G.scene->r.GImixphotons==0) G.scene->r.GImixphotons=100;
1762                                 uiDefButI(block, NUM, B_DIFF, "MixCount:", 170,35,140,20, &G.scene->r.GImixphotons, 
1763                                                 0, 1000, 10, 10, "Number of photons to mix");
1764                                 uiDefButBitS(block, TOG, 1, B_REDR, "Tune Photons",170,10,140,20, &G.scene->r.GIdirect, 
1765                                                 0, 0, 0, 0, "Show the photonmap directly in the render for tuning");
1766                         }
1767                 }
1768
1769         }
1770 }
1771
1772 /* yafray: global  options panel */
1773 static void render_panel_yafrayGlobal()
1774 {
1775         uiBlock *block;
1776
1777         block= uiNewBlock(&curarea->uiblocks, "render_panel_yafrayGlobal", UI_EMBOSS, UI_HELV, curarea->win);
1778         uiNewPanelTabbed("Render", "Render");
1779         if(uiNewPanel(curarea, block, "YafRay", "Render", 320, 0, 318, 204)==0) return;
1780
1781         // label to force a boundbox for buttons not to be centered
1782         uiDefBut(block, LABEL, 0, " ", 305,180,10,10, 0, 0, 0, 0, 0, "");
1783
1784         uiDefButBitS(block, TOGN, 1, B_REDR, "xml", 5,180,75,20, &G.scene->r.YFexportxml,
1785                                         0, 0, 0, 0, "Export to an xml file and call yafray instead of plugin");
1786
1787         uiDefButF(block, NUMSLI, B_DIFF,"Bi ", 5,35,150,20,     &(G.scene->r.YF_raybias), 
1788                                 0.0, 10.0 ,0,0, "Shadow ray bias to avoid self shadowing");
1789         uiDefButI(block, NUM, B_DIFF, "Raydepth ", 5,60,150,20,
1790                                 &G.scene->r.YF_raydepth, 1.0, 80.0, 10, 10, "Maximum render ray depth from the camera");
1791         uiDefButF(block, NUMSLI, B_DIFF, "Gam ", 5,10,150,20, &G.scene->r.YF_gamma, 0.001, 5.0, 0, 0, "Gamma correction, 1 is off");
1792         uiDefButF(block, NUMSLI, B_DIFF, "Exp ", 160,10,150,20,&G.scene->r.YF_exposure, 0.0, 10.0, 0, 0, "Exposure adjustment, 0 is off");
1793         
1794         uiDefButI(block, NUM, B_DIFF, "Processors:", 160,60,150,20, &G.scene->r.YF_numprocs, 1.0, 8.0, 10, 10, "Number of processors to use");
1795
1796         /*AA Settings*/
1797         uiDefButBitS(block, TOGN, 1, B_REDR, "Auto AA", 5,140,150,20, &G.scene->r.YF_AA, 
1798                                         0, 0, 0, 0, "Set AA using OSA and GI quality, disable for manual control");
1799         uiDefButBitS(block, TOGN, 1, B_DIFF, "Clamp RGB", 160,140,150,20, &G.scene->r.YF_clamprgb, 1.0, 8.0, 10, 10, "For AA on fast high contrast changes. Not advisable for Bokeh! Dulls lens shape detail.");
1800         if(G.scene->r.YF_AA){
1801                 uiDefButI(block, NUM, B_DIFF, "AA Passes ", 5,115,150,20, &G.scene->r.YF_AApasses, 0, 64, 10, 10, "Number of AA passes (0 is no AA)");
1802                 uiDefButI(block, NUM, B_DIFF, "AA Samples ", 160,115,150,20, &G.scene->r.YF_AAsamples, 0, 2048, 10, 10, "Number of samples per pass");
1803                 uiDefButF(block, NUMSLI, B_DIFF, "Psz ", 5,90,150,20, &G.scene->r.YF_AApixelsize, 1.0, 2.0, 0, 0, "AA pixel filter size");
1804                 uiDefButF(block, NUMSLI, B_DIFF, "Thr ", 160,90,150,20, &G.scene->r.YF_AAthreshold, 0.000001, 1.0, 0, 0, "AA threshold");
1805         }
1806 }
1807 #endif /* disable yafray stuff */
1808
1809 static void layer_copy_func(void *lay_v, void *lay_p)
1810 {
1811         unsigned int *lay= lay_p;
1812         int laybit= (int)lay_v;
1813
1814         if(G.qual & LR_SHIFTKEY) {
1815                 if(*lay==0) *lay= 1<<laybit;
1816         }
1817         else
1818                 *lay= 1<<laybit;
1819         
1820         copy_view3d_lock(REDRAW);
1821         allqueue(REDRAWBUTSSCENE, 0);
1822 }
1823
1824 static void delete_scene_layer_func(void *srl_v, void *act_i)
1825 {
1826         if(BLI_countlist(&G.scene->r.layers)>1) {
1827                 long act= (long)act_i;
1828                 
1829                 BLI_remlink(&G.scene->r.layers, srl_v);
1830                 MEM_freeN(srl_v);
1831                 G.scene->r.actlay= 0;
1832                 
1833                 if(G.scene->nodetree) {
1834                         bNode *node;
1835                         for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1836                                 if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1837                                         if(node->custom1==act)
1838                                                 node->custom1= 0;
1839                                         else if(node->custom1>act)
1840                                                 node->custom1--;
1841                                 }
1842                         }
1843                 }
1844                 allqueue(REDRAWBUTSSCENE, 0);
1845                 allqueue(REDRAWNODE, 0);
1846         }
1847 }
1848
1849 static void rename_scene_layer_func(void *srl_v, void *unused_v)
1850 {
1851         if(G.scene->nodetree) {
1852                 SceneRenderLayer *srl= srl_v;
1853                 bNode *node;
1854                 for(node= G.scene->nodetree->nodes.first; node; node= node->next) {
1855                         if(node->type==CMP_NODE_R_LAYERS && node->id==NULL) {
1856                                 if(node->custom1==G.scene->r.actlay)
1857                                         BLI_strncpy(node->name, srl->name, NODE_MAXSTR);
1858                         }
1859                 }
1860         }
1861         allqueue(REDRAWBUTSSCENE, 0);
1862         allqueue(REDRAWOOPS, 0);
1863         allqueue(REDRAWNODE, 0);
1864 }
1865
1866 static char *scene_layer_menu(void)
1867 {
1868         SceneRenderLayer *srl;
1869         int len= 32 + 32*BLI_countlist(&G.scene->r.layers);
1870         short a, nr;
1871         char *str= MEM_callocN(len, "menu layers");
1872         
1873         strcpy(str, "ADD NEW %x32767");
1874         a= strlen(str);
1875         for(nr=0, srl= G.scene->r.layers.first; srl; srl= srl->next, nr++) {
1876                 if(srl->layflag & SCE_LAY_DISABLE)
1877                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_BLANK1, nr);
1878                 else 
1879                         a+= sprintf(str+a, "|%s %%i%d %%x%d", srl->name, ICON_CHECKBOX_HLT, nr);
1880         }
1881         
1882         return str;
1883 }
1884
1885 static void draw_3d_layer_buttons(uiBlock *block, unsigned int *poin, short xco, short yco, short dx, short dy)
1886 {
1887         uiBut *bt;
1888         long a;
1889         
1890         uiBlockBeginAlign(block);
1891         for(a=0; a<5; a++) {
1892                 bt= uiDefButBitI(block, TOG, 1<<a, B_NOP, "",   (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1893                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1894         }
1895         for(a=0; a<5; a++) {
1896                 bt=uiDefButBitI(block, TOG, 1<<(a+10), B_NOP, "",       (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1897                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1898         }
1899         
1900         xco+= 7;
1901         uiBlockBeginAlign(block);
1902         for(a=5; a<10; a++) {
1903                 bt=uiDefButBitI(block, TOG, 1<<a, B_NOP, "",    (short)(xco+a*(dx/2)), yco+dy/2, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1904                 uiButSetFunc(bt, layer_copy_func, (void *)a, poin);
1905         }
1906         for(a=5; a<10; a++) {
1907                 bt=uiDefButBitI(block, TOG, 1<<(a+10), B_NOP, "",       (short)(xco+a*(dx/2)), yco, (short)(dx/2), (short)(dy/2), (int *)poin, 0, 0, 0, 0, "");
1908                 uiButSetFunc(bt, layer_copy_func, (void *)(a+10), poin);
1909         }
1910         
1911         uiBlockEndAlign(block);
1912 }
1913
1914 static void render_panel_layers(void)
1915 {
1916         uiBlock *block;
1917         uiBut *bt;
1918         SceneRenderLayer *srl= BLI_findlink(&G.scene->r.layers, G.scene->r.actlay);
1919         char *strp;
1920         
1921         if(srl==NULL) {
1922                 G.scene->r.actlay= 0;
1923                 srl= G.scene->r.layers.first;
1924         }
1925         
1926         block= uiNewBlock(&curarea->uiblocks, "render_panel_layers", UI_EMBOSS, UI_HELV, curarea->win);
1927         uiNewPanelTabbed("Output", "Render");
1928         if(uiNewPanel(curarea, block, "Render Layers", "Render", 320, 0, 318, 204)==0) return;
1929         
1930         /* first, as reminder, the scene layers */
1931         uiDefBut(block, LABEL, 0, "Scene:",                             10,170,100,20, NULL, 0, 0, 0, 0, "");
1932         draw_3d_layer_buttons(block, &G.scene->lay,             130, 170, 35, 30);
1933         
1934         /* layer disable, menu, name, delete button */
1935         uiBlockBeginAlign(block);
1936         uiDefIconButBitI(block, ICONTOGN, SCE_LAY_DISABLE, B_REDR, ICON_CHECKBOX_HLT-1, 10, 145, 20, 20, &srl->layflag, 0.0, 0.0, 0, 0, "Disable or enable this RenderLayer");
1937         strp= scene_layer_menu();
1938         uiDefButS(block, MENU, B_ADD_RENDERLAYER, strp, 30,145,23,20, &(G.scene->r.actlay), 0, 0, 0, 0, "Choose Active Render Layer");
1939         MEM_freeN(strp);
1940         
1941         /* name max 20, exr format limit... */
1942         bt= uiDefBut(block, TEX, REDRAWNODE, "",  53,145,172,20, srl->name, 0.0, 20.0, 0, 0, "");
1943         uiButSetFunc(bt, rename_scene_layer_func, srl, NULL);
1944         
1945         uiDefButBitS(block, TOG, R_SINGLE_LAYER, B_NOP, "Single",       230,145,60,20, &G.scene->r.scemode, 0, 0, 0, 0, "Only render this layer");      
1946         bt=uiDefIconBut(block, BUT, B_NOP, ICON_X,      285, 145, 25, 20, 0, 0, 0, 0, 0, "Deletes current Render Layer");
1947         uiButSetFunc(bt, delete_scene_layer_func, srl, (void *)(long)G.scene->r.actlay);
1948         uiBlockEndAlign(block);
1949
1950         /* RenderLayer visible-layers */
1951         uiDefBut(block, LABEL, 0, "Layer:",                     10,110,100,20, NULL, 0, 0, 0, 0, "");
1952         draw_3d_layer_buttons(block, &srl->lay,         130,110, 35, 30);
1953         
1954         uiBlockBeginAlign(block);
1955         uiDefButBitI(block, TOG, SCE_LAY_ALL_Z, B_NOP,"AllZ",   10, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Fill in Z values for all not-rendered faces, for masking"); 
1956         uiBlockBeginAlign(block);
1957         uiDefButBitI(block, TOG, SCE_LAY_SOLID, B_NOP,"Solid",  50, 85, 60, 20, &srl->layflag, 0, 0, 0, 0, "Render Solid faces in this Layer"); 
1958         uiDefButBitI(block, TOG, SCE_LAY_HALO, B_NOP,"Halo",    110, 85, 55, 20, &srl->layflag, 0, 0, 0, 0, "Render Halos in this Layer (on top of Solid)");    
1959         uiDefButBitI(block, TOG, SCE_LAY_ZTRA, B_NOP,"Ztra",    165, 85, 55, 20, &srl->layflag, 0, 0, 0, 0, "Render Z-Transparent faces in this Layer (On top of Solid and Halos)");    
1960         uiDefButBitI(block, TOG, SCE_LAY_SKY, B_NOP,"Sky",              220, 85, 40, 20, &srl->layflag, 0, 0, 0, 0, "Render Sky or backbuffer in this Layer");  
1961         uiDefButBitI(block, TOG, SCE_LAY_EDGE, B_NOP,"Edge",    260, 85, 50, 20, &srl->layflag, 0, 0, 0, 0, "Render Edge-enhance in this Layer (only works for Solid faces)");  
1962         
1963         uiDefIDPoinBut(block, test_grouppoin_but, ID_GR, B_SET_PASS, "Light:",  10, 65, 150, 20, &(srl->light_override), "Name of Group to use as Lamps instead");
1964         uiDefIDPoinBut(block, test_matpoin_but, ID_MA, B_SET_PASS, "Mat:",      160, 65, 150, 20, &(srl->mat_override), "Name of Material to use as Materials instead");
1965         uiBlockEndAlign(block);
1966
1967         uiBlockBeginAlign(block);
1968         uiDefButBitI(block, TOG, SCE_PASS_COMBINED, B_SET_PASS,"Combined",      10, 30, 80, 20, &srl->passflag, 0, 0, 0, 0, "Deliver full combined RGBA buffer");       
1969         uiDefButBitI(block, TOG, SCE_PASS_Z, B_SET_PASS,"Z",                    90, 30, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Z values pass");   
1970         uiDefButBitI(block, TOG, SCE_PASS_VECTOR, B_SET_PASS,"Vec",             120, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Speed Vector pass");      
1971         uiDefButBitI(block, TOG, SCE_PASS_NORMAL, B_SET_PASS,"Nor",             160, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Normal pass");    
1972         uiDefButBitI(block, TOG, SCE_PASS_UV, B_SET_PASS,"UV",                  200, 30, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Texture UV pass");        
1973         uiDefButBitI(block, TOG, SCE_PASS_INDEXOB, B_SET_PASS,"IndexOb",240, 30, 70, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Object Index pass");      
1974         
1975         uiDefButBitI(block, TOG, SCE_PASS_RGBA, B_SET_PASS,"Col",                               10, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver shade-less Color pass");   
1976         uiDefButBitI(block, TOG, SCE_PASS_DIFFUSE, B_SET_PASS,"Diff",                   45, 10, 35, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Diffuse pass");    
1977         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SPEC, B_SET_PASS,"Spec",              80, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Specular pass");   
1978         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_SHADOW, B_SET_PASS,"Shad",    120, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Shadow pass");    
1979         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_AO, B_SET_PASS,"AO",                  160, 10, 30, 20, &srl->passflag, 0, 0, 0, 0, "Deliver AO pass");        
1980         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_REFLECT, B_SET_PASS,"Refl",   190, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Raytraced Reflection pass");      
1981         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_REFRACT, B_SET_PASS,"Refr",   230, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Raytraced Refraction pass");      
1982         uiDefButBitI(block, BUT_TOGDUAL, SCE_PASS_RADIO, B_SET_PASS,"Rad",              270, 10, 40, 20, &srl->passflag, 0, 0, 0, 0, "Deliver Radiosity pass"); 
1983 }       
1984
1985 void render_panels()
1986 {
1987
1988         render_panel_output();
1989         render_panel_layers();
1990         render_panel_render();
1991         render_panel_anim();
1992         render_panel_bake();
1993
1994         render_panel_format();
1995         render_panel_stamp();
1996 #ifdef WITH_FFMPEG
1997        if (G.scene->r.imtype == R_FFMPEG) {
1998                    render_panel_ffmpeg_video();
1999                render_panel_ffmpeg_audio();
2000        }
2001 #endif
2002
2003 #ifndef DISABLE_YAFRAY
2004         /* yafray: GI & Global panel, only available when yafray enabled for rendering */
2005         if (G.scene->r.renderer==R_YAFRAY) {
2006                 if (G.scene->r.YF_gamma==0.0) G.scene->r.YF_gamma=1.0;
2007                 if (G.scene->r.YF_raybias==0.0) G.scene->r.YF_raybias=0.001;
2008                 if (G.scene->r.YF_raydepth==0) G.scene->r.YF_raydepth=5;
2009                 if (G.scene->r.YF_AApixelsize==0.0) G.scene->r.YF_AApixelsize=1.5;
2010                 if (G.scene->r.YF_AAthreshold==0.0) G.scene->r.YF_AAthreshold=0.05;
2011                 if (G.scene->r.GIpower==0.0) G.scene->r.GIpower=1.0;
2012                 if (G.scene->r.GIindirpower==0.0) G.scene->r.GIindirpower=1.0;
2013                 render_panel_yafrayGlobal();
2014                 render_panel_yafrayGI();
2015         }
2016 #endif
2017
2018 }
2019
2020 /* --------------------------------------------- */
2021
2022 void anim_panels()
2023 {
2024         uiBlock *block;
2025
2026         block= uiNewBlock(&curarea->uiblocks, "anim_panel", UI_EMBOSS, UI_HELV, curarea->win);
2027         if(uiNewPanel(curarea, block, "Anim", "Anim", 0, 0, 318, 204)==0) return;
2028
2029         uiBlockBeginAlign(block);
2030         uiDefButI(block, NUM,B_FRAMEMAP,"Map Old:",     10,160,150,20,&G.scene->r.framapto,1.0,900.0, 0, 0, "Specify old mapping value in frames");
2031         uiDefButI(block, NUM,B_FRAMEMAP,"Map New:",     160,160,150,20,&G.scene->r.images,1.0,900.0, 0, 0, "Specify how many frames the Map Old will last");
2032
2033         uiBlockBeginAlign(block);
2034         uiDefButS(block, NUM,B_FRAMEMAP,"Frs/sec:",  10,130,150,20, &G.scene->r.frs_sec, 1.0, 120.0, 100.0, 0, "Frames per second");
2035         uiDefButBitS(block, TOG, AUDIO_SYNC, B_SOUND_CHANGED, "Sync",160,130,150,20, &G.scene->audio.flag, 0, 0, 0, 0, "Use sample clock for syncing animation to audio");
2036         
2037         uiBlockBeginAlign(block);
2038         uiDefButI(block, NUM,REDRAWALL,"Sta:",  10,100,150,20,&G.scene->r.sfra,1.0,MAXFRAMEF, 0, 0, "Specify the start frame of the animation");
2039         uiDefButI(block, NUM,REDRAWALL,"End:",  160,100,150,20,&G.scene->r.efra,1.0,MAXFRAMEF, 0, 0, "Specify the end frame of the animation");
2040
2041         uiBlockBeginAlign(block);
2042         uiDefButS(block, NUM, REDRAWTIME, "Steps:",10, 70, 150, 20,&(G.scene->jumpframe), 1, 100, 1, 100, "Set spacing between frames changes with up and down arrow keys");
2043
2044
2045 }
2046
2047 /* --------------------------------------------- */
2048
2049 void sound_panels()
2050 {
2051         bSound *sound;
2052
2053         /* paranoia check */
2054         sound = G.buts->lockpoin;
2055         if(sound && GS(sound->id.name)!=ID_SO) {
2056                 sound= NULL;
2057                 G.buts->lockpoin= NULL;
2058         }
2059         
2060         sound_panel_sound(sound);
2061         sound_panel_listener();
2062         sound_panel_sequencer();
2063 }
2064
2065
2066