Logo Search packages:      
Sourcecode: inkscape version File versions

int objects_query_blur ( GSList *  objects,
SPStyle style_res 
)

Write to style_res the average blurring of a list of objects.

Definition at line 1195 of file desktop-style.cpp.

References SPObject::children, SPStyle::filter, SPStyle::filter_gaussianBlur_deviation, SPStyle::getFilter(), SPObject::next, SPIFilter::set, and SPILength::value.

Referenced by sp_desktop_query_style_from_list().

{
   if (g_slist_length(objects) == 0) {
        /* No objects, set empty */
        return QUERY_STYLE_NOTHING;
    }

    float blur_sum = 0;
    float blur_prev = -1;
    bool same_blur = true;
    guint blur_items = 0;
    guint items = 0;
    
    for (GSList const *i = objects; i != NULL; i = i->next) {
        SPObject *obj = SP_OBJECT (i->data);
        SPStyle *style = SP_OBJECT_STYLE (obj);
        if (!style) continue;
        if (!SP_IS_ITEM(obj)) continue;

        NR::Matrix i2d = sp_item_i2d_affine (SP_ITEM(obj));

        items ++;

        //if object has a filter
        if (style->filter.set && style->getFilter()) {
            //cycle through filter primitives
            SPObject *primitive_obj = style->getFilter()->children;
            while (primitive_obj) {
                if (SP_IS_FILTER_PRIMITIVE(primitive_obj)) {
                    SPFilterPrimitive *primitive = SP_FILTER_PRIMITIVE(primitive_obj);
                    
                    //if primitive is gaussianblur
                    if(SP_IS_GAUSSIANBLUR(primitive)) {
                        SPGaussianBlur * spblur = SP_GAUSSIANBLUR(primitive);
                        float num = spblur->stdDeviation.getNumber();
                        blur_sum += num * NR::expansion(i2d);
                        if (blur_prev != -1 && fabs (num - blur_prev) > 1e-2) // rather low tolerance because difference in blur radii is much harder to notice than e.g. difference in sizes
                            same_blur = false;
                        blur_prev = num;
                        //TODO: deal with opt number, for the moment it's not necessary to the ui.
                        blur_items ++;
                    }
                }
                primitive_obj = primitive_obj->next;
            }
        }
    }

    if (items > 0) {
        if (blur_items > 0)
            blur_sum /= blur_items;
        style_res->filter_gaussianBlur_deviation.value = blur_sum;
    }

    if (items == 0) {
        return QUERY_STYLE_NOTHING;
    } else if (items == 1) {
        return QUERY_STYLE_SINGLE;
    } else {
        if (same_blur)
            return QUERY_STYLE_MULTIPLE_SAME;
        else
            return QUERY_STYLE_MULTIPLE_AVERAGED;
    }
}


Generated by  Doxygen 1.6.0   Back to index