void ImageBrush::UpdateComposite(const PaintContext& pc, const Image& img, const Point& dst_offset, const Point& src_offset) { return UpdatePixels(Drawing::Shaders::BlitAlphaPoint(), pc, img, dst_offset, src_offset); }
void MeanGridSeg::Run(time::Progress * prog) { prog->Push(); // Prep storage... prog->Report(0,104); ds::Array2D<nat32> a(image.Size(0),image.Size(1)); ds::Array2D<nat32> b(image.Size(0),image.Size(1)); ds::Array2D<nat32> * current = &a; ds::Array2D<nat32> * old = &b; nat32 gridWidth = ((image.Size(0)-1)/dim)+1; nat32 gridHeight = ((image.Size(1)-1)/dim)+1; ds::Array<Mean> mean(gridWidth*gridHeight); // Create the initial state... prog->Report(1,104); for (nat32 y=0;y<current->Height();y++) { for (nat32 x=0;x<current->Width();x++) { nat32 gx = x/dim; nat32 gy = y/dim; current->Get(x,y) = gy*gridWidth + gx; } } // Iterate till convergance, or we run out of iterations to converge with... prog->Report(2,104); nat32 maxChanges = 1; for (nat32 iter=0;iter<maxIters;iter++) { CalcMeans(*current,mean); nat32 changes = UpdatePixels(*current,*old,mean); maxChanges = math::Max(maxChanges,changes); math::Swap(current,old); if (changes==0) break; nat32 comp = nat32(100.0*math::Ln(1.0+changes)/math::Ln(1.0+maxChanges)); prog->Report(102-comp,104); } CalcMeans(*current,mean); // Needed for if changes!=0 in the last run. // Remove segments which have been emptied... prog->Report(102,104); ds::Array<nat32> map(mean.Size()); segments = 0; for (nat32 i=0;i<mean.Size();i++) { map[i] = segments; if (mean[i].samples!=0) segments += 1; } // Store the final data... prog->Report(103,104); out.Resize(image.Size(0),image.Size(1)); for (nat32 y=0;y<out.Height();y++) { for (nat32 x=0;x<out.Width();x++) { out.Get(x,y) = map[current->Get(x,y)]; } } prog->Pop(); }