2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19 * All rights reserved.
21 * Contributor(s): Blender Foundation, 2002-2009
23 * ***** END GPL LICENSE BLOCK *****
26 /** \file blender/editors/space_image/image_buttons.c
35 #include "DNA_meshdata_types.h"
36 #include "DNA_object_types.h"
37 #include "DNA_node_types.h"
38 #include "DNA_scene_types.h"
40 #include "MEM_guardedalloc.h"
42 #include "BLI_blenlib.h"
44 #include "BLI_editVert.h"
46 #include "BLI_utildefines.h"
48 #include "BKE_colortools.h"
49 #include "BKE_context.h"
50 #include "BKE_customdata.h"
51 #include "BKE_image.h"
54 #include "BKE_screen.h"
56 #include "RE_pipeline.h"
58 #include "IMB_imbuf.h"
59 #include "IMB_imbuf_types.h"
61 #include "ED_gpencil.h"
63 #include "ED_screen.h"
65 #include "RNA_access.h"
70 #include "UI_interface.h"
71 #include "UI_resources.h"
73 #include "image_intern.h"
76 #define B_IMAGECHANGED 2
79 #define B_SIMAGETILE 6
81 #define B_FACESEL_PAINT_TEST 11
82 #define B_SIMA_RECORD 12
83 #define B_SIMA_PLAY 13
85 #define B_SIMANOTHING 16
86 #define B_SIMABRUSHCHANGE 17
87 #define B_SIMABRUSHBROWSE 18
88 #define B_SIMABRUSHLOCAL 19
89 #define B_SIMABRUSHDELETE 20
91 #define B_SIMABTEXBROWSE 22
92 #define B_SIMABTEXDELETE 23
94 #define B_SIMACLONEBROWSE 25
95 #define B_SIMACLONEDELETE 26
99 static void image_info(Scene *scene, ImageUser *iuser, Image *ima, ImBuf *ibuf, char *str)
105 if(ima==NULL) return;
108 ofs+= sprintf(str, "Can't Load Image");
111 if(ima->source==IMA_SRC_MOVIE) {
112 ofs+= sprintf(str, "Movie");
114 ofs+= sprintf(str+ofs, "%d frs", IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN));
117 ofs+= sprintf(str, "Image");
119 ofs+= sprintf(str+ofs, ": size %d x %d,", ibuf->x, ibuf->y);
121 if(ibuf->rect_float) {
122 if(ibuf->channels!=4) {
123 ofs+= sprintf(str+ofs, "%d float channel(s)", ibuf->channels);
125 else if(ibuf->planes == R_IMF_PLANES_RGBA)
126 ofs+= sprintf(str+ofs, " RGBA float");
128 ofs+= sprintf(str+ofs, " RGB float");
131 if(ibuf->planes == R_IMF_PLANES_RGBA)
132 ofs+= sprintf(str+ofs, " RGBA byte");
134 ofs+= sprintf(str+ofs, " RGB byte");
136 if(ibuf->zbuf || ibuf->zbuf_float)
137 ofs+= sprintf(str+ofs, " + Z");
139 if(ima->source==IMA_SRC_SEQUENCE) {
140 char *file= BLI_last_slash(ibuf->name);
141 if(file==NULL) file= ibuf->name;
143 ofs+= sprintf(str+ofs, ", %s", file);
147 /* the frame number, even if we cant */
148 if(ima->source==IMA_SRC_SEQUENCE) {
149 /* don't use iuser->framenr directly because it may not be updated if auto-refresh is off */
150 const int framenr= BKE_image_user_get_frame(iuser, CFRA, 0);
151 ofs+= sprintf(str+ofs, ", Frame: %d", framenr);
157 /* gets active viewer user */
158 struct ImageUser *ntree_get_active_iuser(bNodeTree *ntree)
163 for(node= ntree->nodes.first; node; node= node->next)
164 if( ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER))
165 if(node->flag & NODE_DO_OUTPUT)
166 return node->storage;
171 /* ************ panel stuff ************* */
173 /* is used for both read and write... */
175 static int image_panel_poll(const bContext *C, PanelType *UNUSED(pt))
177 SpaceImage *sima= CTX_wm_space_image(C);
182 ibuf= ED_space_image_acquire_buffer(sima, &lock);
183 result= ibuf && ibuf->rect_float;
184 ED_space_image_release_buffer(sima, lock);
189 static void image_panel_curves(const bContext *C, Panel *pa)
191 bScreen *sc= CTX_wm_screen(C);
192 SpaceImage *sima= CTX_wm_space_image(C);
198 ibuf= ED_space_image_acquire_buffer(sima, &lock);
201 if(sima->cumap==NULL)
202 sima->cumap= curvemapping_add(4, 0.0f, 0.0f, 1.0f, 1.0f);
204 /* curvemap black/white levels only works for RGBA */
205 levels= (ibuf->channels==4);
207 RNA_pointer_create(&sc->id, &RNA_SpaceImageEditor, sima, &simaptr);
208 uiTemplateCurveMapping(pa->layout, &simaptr, "curve", 'c', levels, 0);
211 ED_space_image_release_buffer(sima, lock);
215 /* 0: disable preview
216 otherwise refresh preview
218 XXX if you put this back, also check XXX in image_main_area_draw() */
220 void image_preview_event(int event)
225 G.scene->r.scemode &= ~R_COMP_CROP;
229 if(image_preview_active(curarea, NULL, NULL)) {
230 G.scene->r.scemode |= R_COMP_CROP;
234 G.scene->r.scemode &= ~R_COMP_CROP;
237 if(exec && G.scene->nodetree) {
238 /* should work when no node editor in screen..., so we execute right away */
240 ntreeCompositTagGenerators(G.scene->nodetree);
243 G.scene->nodetree->timecursor= set_timecursor;
244 G.scene->nodetree->test_break= blender_test_break;
248 ntreeCompositExecTree(G.scene->nodetree, &G.scene->r, 1); /* 1 is do_previews */
250 G.scene->nodetree->timecursor= NULL;
251 G.scene->nodetree->test_break= NULL;
253 scrarea_do_windraw(curarea);
256 WM_event_add_notifier(C, NC_IMAGE, ima_v);
261 /* nothing drawn here, we use it to store values */
262 static void preview_cb(struct ScrArea *sa, struct uiBlock *block)
264 SpaceImage *sima= sa->spacedata.first;
266 rcti *disprect= &G.scene->r.disprect;
267 int winx= (G.scene->r.size*G.scene->r.xsch)/100;
268 int winy= (G.scene->r.size*G.scene->r.ysch)/100;
271 if(G.scene->r.mode & R_BORDER) {
272 winx*= (G.scene->r.border.xmax - G.scene->r.border.xmin);
273 winy*= (G.scene->r.border.ymax - G.scene->r.border.ymin);
276 /* while dragging we need to update the rects, otherwise it doesn't end with correct one */
278 BLI_init_rctf(&dispf, 15.0f, (block->maxx - block->minx)-15.0f, 15.0f, (block->maxy - block->miny)-15.0f);
279 ui_graphics_to_window_rct(sa->win, &dispf, disprect);
281 /* correction for gla draw */
282 BLI_translate_rcti(disprect, -curarea->winrct.xmin, -curarea->winrct.ymin);
284 calc_image_view(sima, 'p');
285 // printf("winrct %d %d %d %d\n", disprect->xmin, disprect->ymin,disprect->xmax, disprect->ymax);
286 /* map to image space coordinates */
287 mval[0]= disprect->xmin; mval[1]= disprect->ymin;
288 areamouseco_to_ipoco(v2d, mval, &dispf.xmin, &dispf.ymin);
289 mval[0]= disprect->xmax; mval[1]= disprect->ymax;
290 areamouseco_to_ipoco(v2d, mval, &dispf.xmax, &dispf.ymax);
292 /* map to render coordinates */
293 disprect->xmin= dispf.xmin;
294 disprect->xmax= dispf.xmax;
295 disprect->ymin= dispf.ymin;
296 disprect->ymax= dispf.ymax;
298 CLAMP(disprect->xmin, 0, winx);
299 CLAMP(disprect->xmax, 0, winx);
300 CLAMP(disprect->ymin, 0, winy);
301 CLAMP(disprect->ymax, 0, winy);
302 // printf("drawrct %d %d %d %d\n", disprect->xmin, disprect->ymin,disprect->xmax, disprect->ymax);
306 static int is_preview_allowed(ScrArea *cur)
308 SpaceImage *sima= cur->spacedata.first;
311 /* check if another areawindow has preview set */
312 for(sa=G.curscreen->areabase.first; sa; sa= sa->next) {
313 if(sa!=cur && sa->spacetype==SPACE_IMAGE) {
314 if(image_preview_active(sa, NULL, NULL))
318 /* check image type */
319 if(sima->image==NULL || sima->image->type!=IMA_TYPE_COMPOSITE)
326 static void image_panel_preview(ScrArea *sa, short cntrl) // IMAGE_HANDLER_PREVIEW
329 SpaceImage *sima= sa->spacedata.first;
332 if(is_preview_allowed(sa)==0) {
333 rem_blockhandler(sa, IMAGE_HANDLER_PREVIEW);
334 G.scene->r.scemode &= ~R_COMP_CROP; /* quite weak */
338 block= uiBeginBlock(C, ar, __func__, UI_EMBOSS);
339 uiPanelControl(UI_PNL_SOLID | UI_PNL_CLOSE | UI_PNL_SCALE | cntrl);
340 uiSetPanelHandler(IMAGE_HANDLER_PREVIEW); // for close and esc
342 ofsx= -150+(sa->winx/2)/sima->blockscale;
343 ofsy= -100+(sa->winy/2)/sima->blockscale;
344 if(uiNewPanel(C, ar, block, "Preview", "Image", ofsx, ofsy, 300, 200)==0) return;
346 uiBlockSetDrawExtraFunc(block, preview_cb);
352 /* ********************* callbacks for standard image buttons *************** */
354 static char *slot_menu(void)
359 str= MEM_callocN(IMA_MAX_RENDER_SLOT*32, "menu slots");
361 strcpy(str, "Slot %t");
364 for(slot=0; slot<IMA_MAX_RENDER_SLOT; slot++)
365 a += sprintf(str+a, "|Slot %d %%x%d", slot+1, slot);
370 /* TODO, curlay should be removed? */
371 static char *layer_menu(RenderResult *rr, short *UNUSED(curlay))
374 int len= 64 + 32*BLI_countlist(&rr->layers);
376 char *str= MEM_callocN(len, "menu layers");
378 strcpy(str, "Layer %t");
383 a+= sprintf(str+a, "|Composite %%x0");
386 else if(rr->rect32) {
387 a+= sprintf(str+a, "|Sequence %%x0");
390 for(rl= rr->layers.first; rl; rl= rl->next, nr++) {
391 a+= sprintf(str+a, "|%s %%x%d", rl->name, nr);
394 /* no curlay clip here, on render (redraws) the amount of layers can be 1 fir single-layer render */
399 /* rl==NULL means composite result */
400 static char *pass_menu(RenderLayer *rl, short *curpass)
403 int len= 64 + 32*(rl?BLI_countlist(&rl->passes):1);
405 char *str= MEM_callocN(len, "menu layers");
407 strcpy(str, "Pass %t");
410 /* rendered results don't have a Combined pass */
411 if(rl==NULL || rl->rectf) {
412 a+= sprintf(str+a, "|Combined %%x0");
417 for(rpass= rl->passes.first; rpass; rpass= rpass->next, nr++)
418 a+= sprintf(str+a, "|%s %%x%d", rpass->name, nr);
426 static void set_frames_cb(bContext *C, void *ima_v, void *iuser_v)
428 Scene *scene= CTX_data_scene(C);
430 ImageUser *iuser= iuser_v;
433 iuser->frames = IMB_anim_get_duration(ima->anim, IMB_TC_RECORD_RUN);
434 BKE_image_user_calc_frame(iuser, scene->r.cfra, 0);
438 /* 5 layer button callbacks... */
439 static void image_multi_cb(bContext *C, void *rr_v, void *iuser_v)
441 ImageUser *iuser= iuser_v;
443 BKE_image_multilayer_index(rr_v, iuser);
444 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
446 static void image_multi_inclay_cb(bContext *C, void *rr_v, void *iuser_v)
448 RenderResult *rr= rr_v;
449 ImageUser *iuser= iuser_v;
450 int tot= BLI_countlist(&rr->layers);
452 if(rr->rectf || rr->rect32)
453 tot++; /* fake compo/sequencer layer */
455 if(iuser->layer<tot-1) {
457 BKE_image_multilayer_index(rr, iuser);
458 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
461 static void image_multi_declay_cb(bContext *C, void *rr_v, void *iuser_v)
463 ImageUser *iuser= iuser_v;
467 BKE_image_multilayer_index(rr_v, iuser);
468 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
471 static void image_multi_incpass_cb(bContext *C, void *rr_v, void *iuser_v)
473 RenderResult *rr= rr_v;
474 ImageUser *iuser= iuser_v;
475 RenderLayer *rl= BLI_findlink(&rr->layers, iuser->layer);
478 int tot= BLI_countlist(&rl->passes);
480 if(rr->rectf || rr->rect32)
481 tot++; /* fake compo/sequencer layer */
483 if(iuser->pass<tot-1) {
485 BKE_image_multilayer_index(rr, iuser);
486 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
490 static void image_multi_decpass_cb(bContext *C, void *rr_v, void *iuser_v)
492 ImageUser *iuser= iuser_v;
496 BKE_image_multilayer_index(rr_v, iuser);
497 WM_event_add_notifier(C, NC_IMAGE|ND_DRAW, NULL);
502 static void image_freecache_cb(bContext *C, void *ima_v, void *unused)
504 Scene *scene= CTX_data_scene(C);
505 BKE_image_free_anim_ibufs(ima_v, scene->r.cfra);
506 WM_event_add_notifier(C, NC_IMAGE, ima_v);
511 static void image_user_change(bContext *C, void *iuser_v, void *unused)
513 Scene *scene= CTX_data_scene(C);
514 BKE_image_user_calc_imanr(iuser_v, scene->r.cfra, 0);
518 static void uiblock_layer_pass_buttons(uiLayout *layout, RenderResult *rr, ImageUser *iuser, int w, short *render_slot)
520 uiBlock *block= uiLayoutGetBlock(layout);
522 RenderLayer *rl= NULL;
523 int wmenu1, wmenu2, wmenu3, layer;
526 uiLayoutRow(layout, 1);
528 /* layer menu is 1/3 larger than pass */
536 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu1, UI_UNIT_Y, render_slot, 0,0,0,0, "Select Slot");
537 uiButSetFunc(but, image_multi_cb, rr, iuser);
542 strp= layer_menu(rr, &iuser->layer);
543 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu2, UI_UNIT_Y, &iuser->layer, 0,0,0,0, "Select Layer");
544 uiButSetFunc(but, image_multi_cb, rr, iuser);
547 layer = iuser->layer;
548 if(rr->rectf || rr->rect32)
549 layer--; /* fake compo/sequencer layer */
551 rl= BLI_findlink(&rr->layers, layer); /* return NULL is meant to be */
552 strp= pass_menu(rl, &iuser->pass);
553 but= uiDefButS(block, MENU, 0, strp, 0, 0, wmenu3, UI_UNIT_Y, &iuser->pass, 0,0,0,0, "Select Pass");
554 uiButSetFunc(but, image_multi_cb, rr, iuser);
559 static void uiblock_layer_pass_arrow_buttons(uiLayout *layout, RenderResult *rr, ImageUser *iuser, short *render_slot)
561 uiBlock *block= uiLayoutGetBlock(layout);
564 const float dpi_fac= UI_DPI_FAC;
566 row= uiLayoutRow(layout, 1);
568 if(rr==NULL || iuser==NULL)
570 if(rr->layers.first==NULL) {
571 uiItemL(row, "No Layers in Render Result", ICON_NONE);
575 /* decrease, increase arrows */
576 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_LEFT, 0,0,17,20, NULL, 0, 0, 0, 0, "Previous Layer");
577 uiButSetFunc(but, image_multi_declay_cb, rr, iuser);
578 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_RIGHT, 0,0,18,20, NULL, 0, 0, 0, 0, "Next Layer");
579 uiButSetFunc(but, image_multi_inclay_cb, rr, iuser);
581 uiblock_layer_pass_buttons(row, rr, iuser, 230 * dpi_fac, render_slot);
583 /* decrease, increase arrows */
584 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_LEFT, 0,0,17,20, NULL, 0, 0, 0, 0, "Previous Pass");
585 uiButSetFunc(but, image_multi_decpass_cb, rr, iuser);
586 but= uiDefIconBut(block, BUT, 0, ICON_TRIA_RIGHT, 0,0,18,20, NULL, 0, 0, 0, 0, "Next Pass");
587 uiButSetFunc(but, image_multi_incpass_cb, rr, iuser);
589 uiBlockEndAlign(block);
593 // static int packdummy=0;
595 typedef struct RNAUpdateCb {
601 static void rna_update_cb(bContext *C, void *arg_cb, void *UNUSED(arg))
603 RNAUpdateCb *cb= (RNAUpdateCb*)arg_cb;
605 /* ideally this would be done by RNA itself, but there we have
606 no image user available, so we just update this flag here */
609 /* we call update here on the pointer property, this way the
610 owner of the image pointer can still define it's own update
612 RNA_property_update(C, &cb->ptr, cb->prop);
615 void uiTemplateImage(uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, PointerRNA *userptr, int compact)
623 Scene *scene= CTX_data_scene(C);
624 uiLayout *row, *split, *col;
633 prop= RNA_struct_find_property(ptr, propname);
635 printf("%s: property not found: %s.%s\n",
636 __func__, RNA_struct_identifier(ptr->type), propname);
640 if(RNA_property_type(prop) != PROP_POINTER) {
641 printf("%s: expected pointer property for %s.%s\n",
642 __func__, RNA_struct_identifier(ptr->type), propname);
646 block= uiLayoutGetBlock(layout);
648 imaptr= RNA_property_pointer_get(ptr, prop);
650 iuser= userptr->data;
652 cb= MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
657 uiLayoutSetContextPointer(layout, "edit_image", &imaptr);
660 uiTemplateID(layout, C, ptr, propname, "IMAGE_OT_new", "IMAGE_OT_open", NULL);
663 uiBlockSetNFunc(block, rna_update_cb, MEM_dupallocN(cb), NULL);
665 if(ima->source == IMA_SRC_VIEWER) {
666 ibuf= BKE_image_acquire_ibuf(ima, iuser, &lock);
667 image_info(scene, iuser, ima, ibuf, str);
668 BKE_image_release_ibuf(ima, lock);
670 uiItemL(layout, ima->id.name+2, ICON_NONE);
671 uiItemL(layout, str, ICON_NONE);
673 if(ima->type==IMA_TYPE_COMPOSITE) {
674 // XXX not working yet
676 iuser= ntree_get_active_iuser(scene->nodetree);
678 uiBlockBeginAlign(block);
679 uiDefIconTextBut(block, BUT, B_SIMA_RECORD, ICON_REC, "Record", 10,120,100,20, 0, 0, 0, 0, 0, "");
680 uiDefIconTextBut(block, BUT, B_SIMA_PLAY, ICON_PLAY, "Play", 110,120,100,20, 0, 0, 0, 0, 0, "");
681 but= uiDefBut(block, BUT, B_NOP, "Free Cache", 210,120,100,20, 0, 0, 0, 0, 0, "");
682 uiButSetFunc(but, image_freecache_cb, ima, NULL);
685 BLI_snprintf(str, sizeof(str), "(%d) Frames:", iuser->framenr);
686 else strcpy(str, "Frames:");
687 uiBlockBeginAlign(block);
688 uiDefButI(block, NUM, imagechanged, str, 10, 90,150, 20, &iuser->frames, 0.0, MAXFRAMEF, 0, 0, "Number of images of a movie to use");
689 uiDefButI(block, NUM, imagechanged, "StartFr:", 160,90,150,20, &iuser->sfra, 1.0, MAXFRAMEF, 0, 0, "Global starting frame of the movie");
693 else if(ima->type==IMA_TYPE_R_RESULT) {
694 /* browse layer/passes */
695 Render *re= RE_GetRender(scene->id.name);
696 RenderResult *rr= RE_AcquireResultRead(re);
697 uiblock_layer_pass_arrow_buttons(layout, rr, iuser, &ima->render_slot);
698 RE_ReleaseResult(re);
702 uiItemR(layout, &imaptr, "source", 0, NULL, ICON_NONE);
704 if(ima->source != IMA_SRC_GENERATED) {
705 row= uiLayoutRow(layout, 1);
707 uiItemO(row, "", ICON_PACKAGE, "image.unpack");
709 uiItemO(row, "", ICON_UGLYPACKAGE, "image.pack");
711 row= uiLayoutRow(row, 0);
712 uiLayoutSetEnabled(row, ima->packedfile==NULL);
713 uiItemR(row, &imaptr, "filepath", 0, "", ICON_NONE);
714 uiItemO(row, "", ICON_FILE_REFRESH, "image.reload");
717 // XXX what was this for?
719 /* check for re-render, only buttons */
720 if(imagechanged==B_IMAGECHANGED) {
721 if(iuser->flag & IMA_ANIM_REFRESHED) {
722 iuser->flag &= ~IMA_ANIM_REFRESHED;
723 WM_event_add_notifier(C, NC_IMAGE, ima);
729 if(ima->type==IMA_TYPE_MULTILAYER && ima->rr) {
730 uiblock_layer_pass_arrow_buttons(layout, ima->rr, iuser, NULL);
732 else if(ima->source != IMA_SRC_GENERATED) {
734 ibuf= BKE_image_acquire_ibuf(ima, iuser, &lock);
735 image_info(scene, iuser, ima, ibuf, str);
736 BKE_image_release_ibuf(ima, lock);
737 uiItemL(layout, str, ICON_NONE);
741 if(ima->source != IMA_SRC_GENERATED) {
742 if(compact == 0) { /* background image view doesnt need these */
745 split= uiLayoutSplit(layout, 0, 0);
747 col= uiLayoutColumn(split, 0);
748 uiItemR(col, &imaptr, "use_fields", 0, NULL, ICON_NONE);
749 row= uiLayoutRow(col, 0);
750 uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
751 uiItemR(row, &imaptr, "field_order", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
753 row= uiLayoutRow(layout, 0);
754 uiItemR(row, &imaptr, "use_premultiply", 0, NULL, ICON_NONE);
755 uiItemR(row, &imaptr, "use_color_unpremultiply", 0, NULL, ICON_NONE);
759 if(ELEM(ima->source, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) {
762 split= uiLayoutSplit(layout, 0, 0);
764 col= uiLayoutColumn(split, 0);
766 BLI_snprintf(str, sizeof(str), "(%d) Frames", iuser->framenr);
767 uiItemR(col, userptr, "frame_duration", 0, str, ICON_NONE);
769 block= uiLayoutGetBlock(col);
770 but= uiDefBut(block, BUT, 0, "Match Movie Length", 0, 0, UI_UNIT_X*2, UI_UNIT_Y, NULL, 0, 0, 0, 0, "Set the number of frames to match the movie or sequence");
771 uiButSetFunc(but, set_frames_cb, ima, iuser);
774 uiItemR(col, userptr, "frame_start", 0, "Start", ICON_NONE);
775 uiItemR(col, userptr, "frame_offset", 0, NULL, ICON_NONE);
777 col= uiLayoutColumn(split, 0);
778 row= uiLayoutRow(col, 0);
779 uiLayoutSetActive(row, RNA_boolean_get(&imaptr, "use_fields"));
780 uiItemR(row, userptr, "fields_per_frame", 0, "Fields", ICON_NONE);
781 uiItemR(col, userptr, "use_auto_refresh", 0, NULL, ICON_NONE);
782 uiItemR(col, userptr, "use_cyclic", 0, NULL, ICON_NONE);
784 else if(ima->source==IMA_SRC_GENERATED) {
785 split= uiLayoutSplit(layout, 0, 0);
787 col= uiLayoutColumn(split, 1);
788 uiItemR(col, &imaptr, "generated_width", 0, "X", ICON_NONE);
789 uiItemR(col, &imaptr, "generated_height", 0, "Y", ICON_NONE);
790 uiItemR(col, &imaptr, "use_generated_float", 0, NULL, ICON_NONE);
792 uiItemR(split, &imaptr, "generated_type", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
797 uiBlockSetNFunc(block, NULL, NULL, NULL);
803 void uiTemplateImageSettings(uiLayout *layout, PointerRNA *imfptr)
805 ImageFormatData *imf= imfptr->data;
806 ID *id= imfptr->id.data;
807 const int depth_ok= BKE_imtype_valid_depths(imf->imtype);
808 /* some settings depend on this being a scene thats rendered */
809 const short is_render_out= (id && GS(id->name) == ID_SCE);
811 uiLayout *col, *row, *split, *sub;
813 col= uiLayoutColumn(layout, 0);
815 split= uiLayoutSplit(col, 0.5f, 0);
817 uiItemR(split, imfptr, "file_format", 0, "", ICON_NONE);
818 sub= uiLayoutRow(split, 0);
819 uiItemR(sub, imfptr, "color_mode", UI_ITEM_R_EXPAND, "Color", ICON_NONE);
821 /* only display depth setting if multiple depths can be used */
828 R_IMF_CHAN_DEPTH_32)) == 0)
830 row= uiLayoutRow(col, 0);
831 uiItemR(row, imfptr, "color_depth", UI_ITEM_R_EXPAND, NULL, ICON_NONE);
834 if (BKE_imtype_supports_quality(imf->imtype)) {
835 uiItemR(col, imfptr, "quality", 0, NULL, ICON_NONE);
838 if (BKE_imtype_supports_compress(imf->imtype)) {
839 uiItemR(col, imfptr, "compression", 0, NULL, ICON_NONE);
842 if (ELEM(imf->imtype, R_IMF_IMTYPE_OPENEXR, R_IMF_IMTYPE_MULTILAYER)) {
843 uiItemR(col, imfptr, "exr_codec", 0, NULL, ICON_NONE);
846 row= uiLayoutRow(col, 0);
847 if (BKE_imtype_supports_zbuf(imf->imtype)) {
848 uiItemR(row, imfptr, "use_zbuffer", 0, NULL, ICON_NONE);
851 if (is_render_out && (imf->imtype == R_IMF_IMTYPE_OPENEXR)) {
852 uiItemR(row, imfptr, "use_preview", 0, NULL, ICON_NONE);
855 if (imf->imtype == R_IMF_IMTYPE_JP2) {
856 row= uiLayoutRow(col, 0);
857 uiItemR(row, imfptr, "use_jpeg2k_cinema_preset", 0, NULL, ICON_NONE);
858 uiItemR(row, imfptr, "use_jpeg2k_cinema_48", 0, NULL, ICON_NONE);
860 uiItemR(col, imfptr, "use_jpeg2k_ycc", 0, NULL, ICON_NONE);
863 if (imf->imtype == R_IMF_IMTYPE_CINEON) {
865 uiItemL(col, "Hard coded Non-Linear, Gamma:1.0", ICON_NONE);
867 uiItemR(col, imfptr, "use_cineon_log", 0, NULL, ICON_NONE);
868 uiItemR(col, imfptr, "cineon_black", 0, NULL, ICON_NONE);
869 uiItemR(col, imfptr, "cineon_white", 0, NULL, ICON_NONE);
870 uiItemR(col, imfptr, "cineon_gamma", 0, NULL, ICON_NONE);
875 void uiTemplateImageLayers(uiLayout *layout, bContext *C, Image *ima, ImageUser *iuser)
877 Scene *scene= CTX_data_scene(C);
880 /* render layers and passes */
882 const float dpi_fac= UI_DPI_FAC;
883 rr= BKE_image_acquire_renderresult(scene, ima);
884 uiblock_layer_pass_buttons(layout, rr, iuser, 160 * dpi_fac, (ima->type==IMA_TYPE_R_RESULT)? &ima->render_slot: NULL);
885 BKE_image_release_renderresult(scene, ima);
889 void image_buttons_register(ARegionType *art)
893 pt= MEM_callocN(sizeof(PanelType), "spacetype image panel curves");
894 strcpy(pt->idname, "IMAGE_PT_curves");
895 strcpy(pt->label, "Curves");
896 pt->draw= image_panel_curves;
897 pt->poll= image_panel_poll;
898 pt->flag |= PNL_DEFAULT_CLOSED;
899 BLI_addtail(&art->paneltypes, pt);
901 pt= MEM_callocN(sizeof(PanelType), "spacetype image panel gpencil");
902 strcpy(pt->idname, "IMAGE_PT_gpencil");
903 strcpy(pt->label, "Grease Pencil");
904 pt->draw= gpencil_panel_standard;
905 BLI_addtail(&art->paneltypes, pt);
908 static int image_properties(bContext *C, wmOperator *UNUSED(op))
910 ScrArea *sa= CTX_wm_area(C);
911 ARegion *ar= image_has_buttons_region(sa);
914 ED_region_toggle_hidden(C, ar);
916 return OPERATOR_FINISHED;
919 void IMAGE_OT_properties(wmOperatorType *ot)
921 ot->name= "Properties";
922 ot->idname= "IMAGE_OT_properties";
923 ot->description= "Toggle display properties panel";
925 ot->exec= image_properties;
926 ot->poll= ED_operator_image_active;
932 static int image_scopes(bContext *C, wmOperator *UNUSED(op))
934 ScrArea *sa= CTX_wm_area(C);
935 ARegion *ar= image_has_scope_region(sa);
938 ED_region_toggle_hidden(C, ar);
940 return OPERATOR_FINISHED;
943 void IMAGE_OT_scopes(wmOperatorType *ot)
946 ot->idname= "IMAGE_OT_scopes";
947 ot->description= "Toggle display scopes panel";
949 ot->exec= image_scopes;
950 ot->poll= ED_operator_image_active;