void BrushPreview::generateBoundaries() { Brush* brush = getCurrentBrush(); if (m_brushBoundaries && m_brushGen == brush->gen()) return; bool isFloodfill = m_editor->getCurrentEditorTool()->getPointShape(0)->isFloodFill(); Image* brushImage = brush->image(); int w = (isFloodfill ? 1: brushImage->width()); int h = (isFloodfill ? 1: brushImage->height()); m_brushGen = brush->gen(); m_brushWidth = w; m_brushHeight = h; ImageRef mask; if (isFloodfill) { mask.reset(Image::create(IMAGE_BITMAP, w, w)); mask->putPixel(0, 0, (color_t)1); } else if (brushImage->pixelFormat() != IMAGE_BITMAP) { mask.reset(Image::create(IMAGE_BITMAP, w, h)); LockImageBits<BitmapTraits> bits(mask.get()); auto pos = bits.begin(); for (int v=0; v<h; ++v) { for (int u=0; u<w; ++u) { *pos = get_pixel(brushImage, u, v); ++pos; } } } m_brushBoundaries.reset( new MaskBoundaries( (mask ? mask.get(): brushImage))); }
static void generate_cursor_boundaries(Editor* editor) { tools::Tool* tool = editor->getCurrentEditorTool(); IBrushSettings* brush_settings = NULL; if (tool) brush_settings = UIContext::instance() ->settings() ->getToolSettings(tool) ->getBrush(); if (cursor_bound.seg == NULL || cursor_bound.brush_type != brush_settings->getType() || cursor_bound.brush_size != brush_settings->getSize() || cursor_bound.brush_angle != brush_settings->getAngle()) { cursor_bound.brush_type = brush_settings->getType(); cursor_bound.brush_size = brush_settings->getSize(); cursor_bound.brush_angle = brush_settings->getAngle(); if (cursor_bound.seg != NULL) base_free(cursor_bound.seg); Brush* brush; if (brush_settings) { brush = new Brush(brush_settings->getType(), brush_settings->getSize(), brush_settings->getAngle()); } else brush = new Brush(); cursor_bound.seg = find_mask_boundary(brush->image(), &cursor_bound.nseg, IgnoreBounds, 0, 0, 0, 0); delete brush; } }
void drawWithSpreadType(T_Rasterizer *ras, Bitmap<Pixel> *bitmap, BlendOp *blendOp, const PaintEngineState &state) { const Brush brush = state.brush; const float opacity = state.opacity; if (brush.type() == Malachite::BrushTypeColor) { ColorFiller filler(brush.pixel()); fill(ras, bitmap, blendOp, &filler, opacity); return; } QTransform fillShapeTransform = brush.transform() * state.shapeTransform; if (brush.type() == Malachite::BrushTypeImage) { if (transformIsIntegerTranslating(fillShapeTransform)) { QPoint offset(fillShapeTransform.dx(), fillShapeTransform.dy()); ImageFiller<T_SpreadType> filler(brush.image().constBitmap(), offset); fill(ras, bitmap, blendOp, &filler, opacity); return; } else { drawTransformedImageBrush<T_Rasterizer, T_SpreadType, Bitmap<Pixel> >(ras, bitmap, blendOp, brush.image().constBitmap(), opacity, fillShapeTransform.inverted(), state.imageTransformType); return; } } if (brush.type() == Malachite::BrushTypeSurface) { drawTransformedImageBrush<T_Rasterizer, T_SpreadType, Surface>(ras, bitmap, blendOp, brush.surface(), opacity, fillShapeTransform.inverted(), state.imageTransformType); return; } if (brush.type() == Malachite::BrushTypeLinearGradient) { LinearGradientShape info = brush.linearGradientShape(); if (info.transformable(fillShapeTransform)) { info.transform(fillShapeTransform); fillShapeTransform = QTransform(); } if (fillShapeTransform.isIdentity()) { LinearGradientMethod method(info.start, info.end); GradientGenerator<ColorGradient, LinearGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, LinearGradientMethod, T_SpreadType>, false> filler(&gen); fill(ras, bitmap, blendOp, &filler, opacity); return; } else { LinearGradientMethod method(info.start, info.end); GradientGenerator<ColorGradient, LinearGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, LinearGradientMethod, T_SpreadType>, true> filler(&gen, fillShapeTransform.inverted()); fill(ras, bitmap, blendOp, &filler, opacity); return; } } if (brush.type() == Malachite::BrushTypeRadialGradient) { RadialGradientShape info = brush.radialGradientShape(); if (info.transformable(fillShapeTransform)) { info.transform(fillShapeTransform); fillShapeTransform = QTransform(); } if (info.center == info.focal) { if (fillShapeTransform.isIdentity()) { RadialGradientMethod method(info.center, info.radius); GradientGenerator<ColorGradient, RadialGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, RadialGradientMethod, T_SpreadType>, false> filler(&gen); fill(ras, bitmap, blendOp, &filler, opacity); return; } else { RadialGradientMethod method(info.center, info.radius); GradientGenerator<ColorGradient, RadialGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, RadialGradientMethod, T_SpreadType>, true> filler(&gen, fillShapeTransform.inverted()); fill(ras, bitmap, blendOp, &filler, opacity); return; } } else { if (fillShapeTransform.isIdentity()) { FocalGradientMethod method(info.center, info.radius, info.focal); GradientGenerator<ColorGradient, FocalGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, FocalGradientMethod, T_SpreadType>, false> filler(&gen); fill(ras, bitmap, blendOp, &filler, opacity); return; } else { FocalGradientMethod method(info.center, info.radius, info.focal); GradientGenerator<ColorGradient, FocalGradientMethod, T_SpreadType> gen(brush.gradient(), &method); Filler<GradientGenerator<ColorGradient, FocalGradientMethod, T_SpreadType>, true> filler(&gen, fillShapeTransform.inverted()); fill(ras, bitmap, blendOp, &filler, opacity); return; } } } }