svn merge ^/trunk/blender -r49947:49952
authorCampbell Barton <ideasman42@gmail.com>
Fri, 17 Aug 2012 13:04:23 +0000 (13:04 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 17 Aug 2012 13:04:23 +0000 (13:04 +0000)
source/blender/compositor/operations/COM_BokehImageOperation.h
source/blender/editors/space_image/image_ops.c
source/blender/editors/space_node/node_view.c
source/blender/editors/space_view3d/drawobject.c

index fe86e162eb236edb2d449cf75d15565d80d6a7b8..44c4c0cfe2773b306a0fd2733e2815c57d590bcd 100644 (file)
 #define _COM_BokehImageOperation_h
 #include "COM_NodeOperation.h"
 
-
+/**
+ * @brief The BokehImageOperation class is an operation that creates an image useful to mimic the internals
+ *of a camera.
+ *
+ * features:
+ *  - number of flaps
+ *  - angle offset of the flaps
+ *  - rounding of the flaps (also used to make a circular lens)
+ *  - simulate catadioptric
+ *  - simulate lensshift
+ *
+ * Per pixel the algorithm determines the edge of the bokeh on the same line as the center of the image and the pixel
+ * is evaluating.
+ *
+ * The edge is detected by finding the closest point on the direct line between the two nearest flap-corners.
+ * this edge is interpolated with a full circle. 
+ * Result of this edge detection is stored as the distance between the center of the image and the edge.
+ *
+ * catadioptric lenses are simulated to interpolate between the center of the image and the distance of the edge.
+ * We now have three distances:
+ *  - distance between the center of the image and the pixel to be evaluated
+ *  - distance between the center of the image and the outer-edge
+ *  - distance between the center of the image and the inner-edge
+ *
+ * With a simple compare it can be detected if the evaluated pixel is between the outer and inner edge.
+ */
 class BokehImageOperation : public NodeOperation {
 private:
+       /**
+        * @brief Settings of the bokeh image
+        */
        NodeBokehImage *m_data;
 
+       /**
+        * @brief precalced center of the image
+        */
        float m_center[2];
+       
+       /**
+        * @brief 1.0-rounding
+        */
        float m_inverseRounding;
+       
+       /**
+        * @brief distance of a full circle lens
+        */
        float m_circularDistance;
+       
+       /**
+        * @brief radius when the first flap starts
+        */
        float m_flapRad;
+       
+       /**
+        * @brief radians of a single flap
+        */
        float m_flapRadAdd;
        
+       /**
+        * @brief should the m_data field by deleted when this operation is finished
+        */
        bool m_deleteData;
 
+       /**
+        * @brief detemine the coordinate of a flap cornder
+        *
+        * @param r result in bokehimage space are stored [x,y]
+        * @param flapNumber the flap number to calculate
+        * @param distance the lens distance is used to simulate lens shifts
+        */
        void detemineStartPointOfFlap(float r[2], int flapNumber, float distance);
+       
+       /**
+        * @brief Determine if a coordinate is inside the bokeh image
+        *
+        * @param distance the distance that will be used. This parameter is modified a bit to mimic lens shifts
+        * @param x the x coordinate of the pixel to evaluate
+        * @param y the y coordinate of the pixel to evaluate
+        * @return float range 0..1 0 is completely outside
+        */
        float isInsideBokeh(float distance, float x, float y);
 public:
        BokehImageOperation();
 
        /**
-        * the inner loop of this program
+        * @brief the inner loop of this program
         */
        void executePixel(float output[4], float x, float y, PixelSampler sampler);
        
        /**
-        * Initialize the execution
+        * @brief Initialize the execution
         */
        void initExecution();
        
        /**
-        * Deinitialize the execution
+        * @brief Deinitialize the execution
         */
        void deinitExecution();
        
+       /**
+        * @brief determine the resolution of this operation. currently fixed at [COM_BLUR_BOKEH_PIXELS, COM_BLUR_BOKEH_PIXELS]
+        * @param resolution
+        * @param preferredResolution
+        */
        void determineResolution(unsigned int resolution[2], unsigned int preferredResolution[2]);
 
+       /**
+        * @brief set the node data
+        * @param data
+        */
        void setData(NodeBokehImage *data) { this->m_data = data; }
+       
+       /**
+        * @brief deleteDataOnFinish
+        *
+        * There are cases that the compositor uses this operation on its own (see defocus node)
+        * the deleteDataOnFinish must only be called when the data has been created by the compositor.
+        *It should not be called when the data has been created by the node-editor/user.
+        */
        void deleteDataOnFinish() { this->m_deleteData = true; }
 };
 #endif
index 0fb2892cf7edf21698994e925f6f1bc08296ca96..439299ddcda0d5968f0488e5dea72818028b8209 100644 (file)
@@ -2027,7 +2027,7 @@ int ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], floa
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
 
-                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
                                linearrgb_to_srgb_v3_v3(r_col, fp);
                        }
                        else {
@@ -2037,9 +2037,7 @@ int ED_space_image_color_sample(SpaceImage *sima, ARegion *ar, int mval[2], floa
                }
                else if (ibuf->rect) {
                        cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
-                       r_col[0] = cp[0] / 255.0f;
-                       r_col[1] = cp[1] / 255.0f;
-                       r_col[2] = cp[2] / 255.0f;
+                       rgb_uchar_to_float(r_col, cp);
                        ret = TRUE;
                }
        }
index e0cbbd697d74e4306cadd7787e21da264f1962a5..27b57885b2bceda7259c009f4eed1f547f5bf169 100644 (file)
@@ -375,7 +375,7 @@ int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float
 
        if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
                float *fp;
-               char *cp;
+               unsigned char *cp;
                int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
 
                CLAMP(x, 0, ibuf->x - 1);
@@ -383,8 +383,8 @@ int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float
 
                if (ibuf->rect_float) {
                        fp = (ibuf->rect_float + (ibuf->channels) * (y * ibuf->x + x));
-
-                       if (ibuf->profile == IB_PROFILE_LINEAR_RGB) {
+                       /* IB_PROFILE_NONE is default but infact its linear */
+                       if (ELEM(ibuf->profile, IB_PROFILE_LINEAR_RGB, IB_PROFILE_NONE)) {
                                linearrgb_to_srgb_v3_v3(r_col, fp);
                        }
                        else {
@@ -393,10 +393,8 @@ int ED_space_node_color_sample(SpaceNode *snode, ARegion *ar, int mval[2], float
                        ret = TRUE;
                }
                else if (ibuf->rect) {
-                       cp = (char *)(ibuf->rect + y * ibuf->x + x);
-                       r_col[0] = cp[0] / 255.0f;
-                       r_col[1] = cp[1] / 255.0f;
-                       r_col[2] = cp[2] / 255.0f;
+                       cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
+                       rgb_uchar_to_float(r_col, cp);
                        ret = TRUE;
                }
        }
@@ -439,7 +437,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
 
        if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
                float *fp;
-               char *cp;
+               unsigned char *cp;
                int x = (int)(fx * ibuf->x), y = (int)(fy * ibuf->y);
 
                CLAMP(x, 0, ibuf->x - 1);
@@ -451,7 +449,7 @@ static void sample_apply(bContext *C, wmOperator *op, wmEvent *event)
                info->channels = ibuf->channels;
 
                if (ibuf->rect) {
-                       cp = (char *)(ibuf->rect + y * ibuf->x + x);
+                       cp = (unsigned char *)(ibuf->rect + y * ibuf->x + x);
 
                        info->col[0] = cp[0];
                        info->col[1] = cp[1];
index d9a57cadb2c83eee8167092d226846eb26d5f12f..a1a7bda480015029df5035a7cdc8e50d94d5b50c 100644 (file)
@@ -195,10 +195,9 @@ static void draw_empty_cone(float size);
 
 static void ob_wire_color_blend_theme_id(const unsigned char ob_wire_col[4], const int theme_id, float fac)
 {
-       float col_bg[3], col[3];
-       float col_wire[3] = {ob_wire_col[0] / 255.0f,
-                            ob_wire_col[1] / 255.0f,
-                            ob_wire_col[2] / 255.0f};
+       float col_wire[3], col_bg[3], col[3];
+
+       rgb_uchar_to_float(col_wire, ob_wire_col);
 
        UI_GetThemeColor3fv(theme_id, col_bg);
        interp_v3_v3v3(col, col_bg, col_wire, fac);
@@ -1573,17 +1572,18 @@ static void draw_bundle_sphere(void)
 
 static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D *v3d,
                                                 MovieClip *clip, MovieTrackingObject *tracking_object,
-                                                const short dflag, int *global_track_index, int draw_selected)
+                                                const short dflag, const unsigned char ob_wire_col[4],
+                                                int *global_track_index, int draw_selected)
 {
        MovieTracking *tracking = &clip->tracking;
        MovieTrackingTrack *track;
        float mat[4][4], imat[4][4];
-       unsigned char col[4], scol[4];
+       unsigned char col_unsel[4], col_sel[4];
        int tracknr = *global_track_index;
        ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
 
-       UI_GetThemeColor4ubv(TH_TEXT, col);
-       UI_GetThemeColor4ubv(TH_SELECT, scol);
+       UI_GetThemeColor4ubv(TH_TEXT, col_unsel);
+       UI_GetThemeColor4ubv(TH_SELECT, col_sel);
 
        BKE_tracking_get_camera_object_matrix(scene, base->object, mat);
 
@@ -1626,13 +1626,13 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                if (v3d->drawtype == OB_WIRE) {
                        glDisable(GL_LIGHTING);
 
-                       if (selected) {
-                               if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                               else UI_ThemeColor(TH_SELECT);
-                       }
-                       else {
-                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                               else UI_ThemeColor(TH_WIRE);
+                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                               if (selected && (track->flag & TRACK_CUSTOMCOLOR) == 0) {
+                                       glColor3ubv(ob_wire_col);
+                               }
+                               else {
+                                       glColor3fv(track->color);
+                               }
                        }
 
                        drawaxes(0.05f, v3d->bundle_drawtype);
@@ -1643,8 +1643,9 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                        if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
                                /* selection outline */
                                if (selected) {
-                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                                       else UI_ThemeColor(TH_SELECT);
+                                       if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                               glColor3ubv(ob_wire_col);
+                                       }
 
                                        glLineWidth(2.f);
                                        glDisable(GL_LIGHTING);
@@ -1657,21 +1658,24 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
                                        glLineWidth(1.f);
                                }
 
-                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                               else UI_ThemeColor(TH_BUNDLE_SOLID);
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                       else UI_ThemeColor(TH_BUNDLE_SOLID);
+                               }
 
                                draw_bundle_sphere();
                        }
                        else {
                                glDisable(GL_LIGHTING);
 
-                               if (selected) {
-                                       if (base == BASACT) UI_ThemeColor(TH_ACTIVE);
-                                       else UI_ThemeColor(TH_SELECT);
-                               }
-                               else {
-                                       if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
-                                       else UI_ThemeColor(TH_WIRE);
+                               if ((dflag & DRAW_CONSTCOLOR) == 0) {
+                                       if (selected) {
+                                               glColor3ubv(ob_wire_col);
+                                       }
+                                       else {
+                                               if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
+                                               else UI_ThemeColor(TH_WIRE);
+                                       }
                                }
 
                                drawaxes(0.05f, v3d->bundle_drawtype);
@@ -1684,13 +1688,9 @@ static void draw_viewport_object_reconstruction(Scene *scene, Base *base, View3D
 
                if ((dflag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
                        float pos[3];
-                       unsigned char tcol[4];
-
-                       if (selected) memcpy(tcol, scol, sizeof(tcol));
-                       else memcpy(tcol, col, sizeof(tcol));
 
                        mul_v3_m4v3(pos, mat, track->bundle_pos);
-                       view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, tcol);
+                       view3d_cached_text_draw_add(pos, track->name, 10, V3D_CACHE_TEXT_GLOBALSPACE, selected ? col_sel : col_unsel);
                }
 
                tracknr++;
@@ -1748,7 +1748,7 @@ static void draw_viewport_reconstruction(Scene *scene, Base *base, View3D *v3d,
        tracking_object = tracking->objects.first;
        while (tracking_object) {
                draw_viewport_object_reconstruction(scene, base, v3d, clip, tracking_object,
-                                                   dflag, &global_track_index, draw_selected);
+                                                   dflag, ob_wire_col, &global_track_index, draw_selected);
 
                tracking_object = tracking_object->next;
        }