示例#1
0
        private ReturnValues posterise_5level_custom2(int[] notused)
        {
            // First row = Input
            // Second row = Output
            // e.g. Between 0 and 24, output 0
            //      Between 25 and 49, output 38
            //      Between 50 and 99, output 75
            // etc.
            string a    = @"
0     75     150     200     228     255
   0     113     175     214     255
";
            var    data = ParseString(a);
            var    rv   = new ReturnValues();
            int    pos  = 0;

            for (int i = 0; i < 256; i++)
            {
                if ((pos < data.Length - 1) && // avoid array out-of-bounds
                    (i == data[pos + 1].InValue))    // check next value
                {
                    pos++;
                }
                rv.AssignValue(i, data[pos].OutValue);
            }
            return(rv);
        }
示例#2
0
        //private void linear()
        //{
        //    foreach (var array in new[] { _transformR, _transformG, _transformB })
        //        for (int i = 0; i < 256; i++)
        //            array[i] = i;
        //}

        //private void noise1()
        //{
        //    for (int i = 0; i < 256; i++)
        //        foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //            transform[i] = Clamp(i +
        //                (((i / 2) % 2 == 0) ? (int)slider1.Value : 0 - (int)slider1.Value));
        //}

        //private void noise2()
        //{
        //    Random r = new Random();

        //    for (int i = 0; i < 256; i++)
        //        foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //            transform[i] = Clamp(i + (0 - ((int)slider1.Value / 2)) + r.Next((int)slider1.Value));
        //}

        //private void noise3()
        //{
        //    int step =(int)slider1.Value;
        //    for (int i = 0; i < 256; i++)
        //        foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //            transform[i] = Clamp(i +
        //                (step - (i % step) - (i % step)));
        //}

        //private int Clamp(int val)
        //{
        //    if (val < 0) return 0;
        //    if (val > 255) return 255;
        //    return val;
        //}

        //private void posterise1()
        //{
        //    double posterise_multiplier = 255.0 / (int)slider1.Value;

        //    for (int i = 0; i < 256; i++)
        //        foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //            transform[i] = (int)(Convert.ToInt32(i / posterise_multiplier) * posterise_multiplier);
        //}

        //private void posterise2()
        //{
        //    int posterise_level = (int)slider1.Value;

        //    if (posterise_level <= 1)
        //        throw new Exception("Posterise level 1 or below not allowed");
        //    double multiplier = 255.0 / (posterise_level - 1.0);

        //    foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //    {
        //        for (int i = 0; i < 256; i++)
        //        {
        //            int index = (int)Math.Floor(i * (posterise_level / 256.0));
        //            transform[i] = (int)Math.Round(index * multiplier);
        //        }
        //    }
        //}

        //private void posterise_3level_custom2()
        //{
        //    int threshold1 = (int)slider1.Value;
        //    int threshold2 = (int)slider2.Value;
        //    int threshold3 = (int)slider3.Value;

        //    foreach (var transform in new[] { _transformR, _transformG, _transformB })
        //    {
        //        for (int i = 0; i < 256; i++)
        //        {
        //            if (transform == _transformG)
        //                // 3 bit
        //                transform[i] = i >= threshold2 ? 255
        //                : i >= threshold3 ? 170
        //                : i >= threshold1 ? 85
        //                : 0;
        //            else
        //                // 2 bit
        //                transform[i] = i >= threshold2 ? 255
        //                    : i >= threshold1 ? 128
        //                    : 0;
        //        }
        //    }
        //}


        private ReturnValues posterise_2level_custom(int[] sliderValues)
        {
            int threshold = sliderValues[0];
            var rv        = new ReturnValues();

            for (int i = 0; i < 256; i++)
            {
                rv.AssignValue(i, i >= threshold ? 255 : 0);
            }
            return(rv);
        }
示例#3
0
        private ReturnValues posterise_4level_custom(int[] sliderValues)
        {
            int threshold1 = sliderValues[0];
            int threshold2 = sliderValues[1];
            int threshold3 = sliderValues[2];
            var rv         = new ReturnValues();

            for (int i = 0; i < 256; i++)
            {
                rv.AssignValue(i, i >= threshold3 ? 255
                                : i >= threshold2 ? 170
                                : i >= threshold1 ? 85
                                : 0);
            }
            return(rv);
        }
示例#4
0
        private ReturnValues posterise_nlevels(int nlevels)
        {
            // Number of levels ^ 3 = Number of different colours
            // e.g. 256 ^ 3 = 16,777,216 (24-bit, 8-bit per channel)
            // e.g. 2 ^ 3 = 8 colours (red, yellow, green, cyan, blue, magenta, black, white)

            int[] outvalues = new int[nlevels]; // e.g. [0,127,255]
            float divisor   = nlevels - 1;

            for (int i = 0; i < nlevels; i++)
            {
                outvalues[i] = (int)((255 / divisor) * i);
            }

            int[] thresholds = new int[nlevels - 1]; // e.g. [85,170]
            for (int i = 0; i < (nlevels - 1); i++)
            {
                thresholds[i] = (int)((255 / (float)nlevels) * (i + 1));
            }

            int Lookup(int v) // local function
            {
                for (int t = 0; t < thresholds.Length; t++)
                {
                    if (v < thresholds[t])
                    {
                        return(outvalues[t]);
                    }
                }
                return(outvalues[thresholds.Length]);
            }

            var rv = new ReturnValues();

            for (int i = 0; i < 256; i++)
            {
                rv.AssignValue(i, Lookup(i));
            }
            return(rv);
        }