Soft Paint Bucket Fill: Colour Equality

后端 未结 2 1254
自闭症患者
自闭症患者 2021-01-07 09:34

I\'m making a small app where children can fill preset illustrations with colours. I\'ve succesfully implemented an MS-paint style paint bucket using the flood fill argorith

相关标签:
2条回答
  • 2021-01-07 10:13

    Made something that works:

                    c = b.getPixel(xx,yy);
                    if (c == to) continue;
                    if (c != from) d = 
                        Math.pow(f1 - (c & 0xFF), 2) +
                        Math.pow(f2 - (c >> 8 & 0xFF), 2) +
                        Math.pow(f3 - (c >> 16 & 0xFF), 2)
                    if (c == from || d < tres) {
    
    0 讨论(0)
  • 2021-01-07 10:24

    well, i guess the most natural approach is to calculate the difference between to colors. to achieve a sensible value, one should calculate the difference per channel. haven't tested it, but the following should work:

    const perChanThreshold:uint = 5;
    const overallThreshold:uint = perChanThreshold * perChanThreshold * 3;
    function match(source:uint, target:uint):Boolean {
        var diff:uint = 0, chanDiff:uint;
        for (var i:int = 0; i < 3; i++) {
            chanDiff = (source >> (i * 8)) & 0xFF;
            diff += chanDiff * chanDiff;
        }
        return diff <= overallThreshold;
    }
    
    0 讨论(0)
提交回复
热议问题