示例#1
0
        public ColorMap <ushort> Process(RawMap <ushort> map)
        {
            var res = new ColorMapUshort(map.Width / 2, map.Height / 2, map.MaxBits);
            var c   = new ushort[4];
            var pix = res.GetPixel();

            for (var y = 0; y < res.Height; y++)
            {
                var raw = map.GetRow(y * 2);
                for (var x = 0; x < res.Width; x++)
                {
                    c[0] = raw.Value;
                    c[1] = raw.GetRel(+1, +0);
                    c[2] = raw.GetRel(0, +1);
                    c[3] = raw.GetRel(+1, +1);

                    pix[0] = c[3];
                    pix[1] = c[1];
                    pix[2] = c[0];
                    pix.MoveNext();
                    raw.MoveNext();
                    raw.MoveNext();
                }
            }
            return(res);
        }
示例#2
0
        private static ColorMapFloat ApplyIndependentColorToFloatFilters(ColorMapUshort map,
                                                                         ICollection <IndependentComponentColorToColorFilter <float, float> > indColorFilters)
        {
            if (indColorFilters.Count == 0)
            {
                return(map.ConvertToFloat());
            }

            var maxValue = map.MaxValue;
            var curvef   = ConvertToCurveF(indColorFilters, maxValue);

            return(ApplyCurve(map, curvef));
        }
示例#3
0
        private static VectorMap ApplyIndependentColorToVectorFilters(ColorMapUshort map,
                                                                      ICollection <IndependentComponentVectorToVectorFilter> indColorFilters)
        {
            if (indColorFilters.Count == 0)
            {
                return(map.ConvertToVector());
            }

            var maxValue = map.MaxValue;
            var curvef   = ConvertToCurveV(indColorFilters, maxValue);

            return(ApplyCurve(map, curvef));
        }
示例#4
0
        private static void ProcessMiddleRows(RawBGGRMap <ushort> file, ColorMapUshort res)
        {
            // Middle Rows
            Parallel.For(0, (res.Height - 2) / 2, yy =>
            {
                var y = yy * 2 + 1;
                ProcessMiddleOddRows(file.GetRow(y), res.Width, res.GetRow(y));

                y++;

                ProcessMiddleEvenRows(file.GetRow(y), res.Width, res.GetRow(y));
            });
        }
示例#5
0
        private static void ApplyIndependentColorFiltersInplace(ColorMapUshort map,
                                                                ICollection <IndependentComponentColorToColorFilter <float, float> > indColorFilters)
        {
            if (indColorFilters.Count == 0)
            {
                return;
            }

            var maxValue = map.MaxValue;
            var curvef   = ConvertToCurveF(indColorFilters, maxValue);
            var curve    = ConvertToUshortCurve(curvef);

            ApplyCurveInplace(map, curve);
        }
示例#6
0
 private static VectorMap ApplyCurve(ColorMapUshort map, Vector3[] curve)
 {
     var result = new VectorMap(map.Width, map.Height);
     Parallel.For(0, result.Height, y =>
     {
         var input = map.GetRow(y);
         var output = result.GetRow(y);
         for (var x = 0; x < result.Width; x++)
         {
             output.SetAndMoveNext(curve[input.R].X, curve[input.G].Y, curve[input.B].Z);
             input.MoveNext();
         }
     });
     return result;
 }
示例#7
0
 private static ColorMapUshort ApplyCurve(ColorMapUshort map, ushort[][] curve)
 {
     var result = new ColorMapUshort(map.Width, map.Height, map.MaxBits);
     Parallel.For(0, result.Height, y =>
     {
         var input = map.GetRow(y);
         var output = result.GetRow(y);
         for (var x = 0; x < result.Width; x++)
         {
             output.SetAndMoveNext(curve[0][input.R], curve[1][input.G], curve[2][input.B]);
             input.MoveNext();
         }
     });
     return result;
 }
示例#8
0
        // B G B G
        // G R G R
        // B G B G
        // G R G R
        public ColorMap <ushort> Process(RawBGGRMap <ushort> file)
        {
            if (file.Width % 2 != 0 || file.Height % 2 != 0)
            {
                throw new ArgumentException("Width and Height should be even");
            }
            var res = new ColorMapUshort(file.Width, file.Height, file.MaxBits + 1);

            ProcessTopLine(file, res);

            ProcessMiddleRows(file, res);

            ProcessBottomLine(file, res);

            return(res);
        }
示例#9
0
        private static VectorMap ApplyCurve(ColorMapUshort map, Vector3[] curve)
        {
            var result = new VectorMap(map.Width, map.Height);

            Parallel.For(0, result.Height, y =>
            {
                var input  = map.GetRow(y);
                var output = result.GetRow(y);
                for (var x = 0; x < result.Width; x++)
                {
                    output.SetAndMoveNext(curve[input.R].X, curve[input.G].Y, curve[input.B].Z);
                    input.MoveNext();
                }
            });
            return(result);
        }
示例#10
0
        private static ColorMapUshort ApplyCurve(ColorMapUshort map, ushort[][] curve)
        {
            var result = new ColorMapUshort(map.Width, map.Height, map.MaxBits);

            Parallel.For(0, result.Height, y =>
            {
                var input  = map.GetRow(y);
                var output = result.GetRow(y);
                for (var x = 0; x < result.Width; x++)
                {
                    output.SetAndMoveNext(curve[0][input.R], curve[1][input.G], curve[2][input.B]);
                    input.MoveNext();
                }
            });
            return(result);
        }
示例#11
0
        private static RGB8Map ApplyIndependentVectorFiltersWithRGB(ColorMapUshort map,
                                                                    ICollection <IndependentComponentVectorToVectorFilter> indColorFilters,
                                                                    IndependentComponentVectorToColorFilter <byte> colorFilter)
        {
            if (!indColorFilters.Any())
            {
                throw new NotSupportedException("Is not supported without filters");
            }

            var maxValue = map.MaxValue;
            var curve    = new[] { new byte[maxValue + 1], new byte[maxValue + 1], new byte[maxValue + 1] };
            var curvef   = ConvertToCurveV(indColorFilters, maxValue);

            Parallel.For(0, maxValue + 1, i => colorFilter.ProcessColorInCurve(i, curvef, curve));

            indColorFilters.Clear();
            return(ApplyCurve(map, curve));
        }
示例#12
0
        // B G B G
        // G R G R
        // B G B G
        // G R G R
        private static void ProcessBottomLine(RawBGGRMap <ushort> map, ColorMapUshort res)
        {
            var pix = res.GetPixel();
            var raw = map.GetRow(res.Height - 1);

            // Bottom Left pixel
            var lastY = res.Height - 1;

            pix.SetAndMoveNext(
                (ushort)(raw.GetRel(1, 0) << 1),
                (ushort)(raw.Value << 1),
                (ushort)(raw.GetRel(0, -1) << 1));
            raw.MoveNext();

            // Bottom row
            for (var x = 1; x < res.Width - 1; x += 2)
            {
                pix.SetAndMoveNext(
                    (ushort)(raw.Value << 1),
                    (ushort)((raw.GetRel(-1, 0) + raw.GetRel(+1, 0) + raw.GetRel(0, -1) << 1) >> 1),
                    (ushort)((raw.GetRel(-1, 0) + raw.GetRel(+1, 0))));

                pix.SetAndMoveNext(
                    (ushort)((raw.Value + raw.GetRel(+2, 0))),
                    (ushort)(raw.GetRel(+1, 0) << 1),
                    (ushort)(raw.GetRel(+1, 0 - 1) << 1));

                raw.MoveNext();
                raw.MoveNext();
            }

            // Bottom right pixel
            pix.SetAndMoveNext(
                (ushort)(raw.GetRel(-1, 0) << 1),
                (ushort)((raw.GetRel(-1, -1) + raw.GetRel(-2, 0))),
                (ushort)(raw.GetRel(-2, -1) << 1));
            raw.MoveNext();
        }
示例#13
0
        private static void ProcessTopLine(RawBGGRMap <ushort> map, ColorMapUshort res)
        {
            var pix = res.GetPixel();
            var raw = map.GetRow(0);

            // Top Left pixel

            pix.SetAndMoveNext(
                (ushort)(raw.GetRel(1, 1) << 1),
                (ushort)((raw.GetRel(1, 0) + raw.GetRel(0, 1))),
                (ushort)(raw.Value << 1));
            raw.MoveNext();

            // Top row
            for (var x = 1; x < res.Width - 1; x += 2)
            {
                pix.SetAndMoveNext(
                    (ushort)(raw.GetRel(0, 1) << 1),
                    (ushort)(raw.Value << 1),
                    (ushort)((raw.GetRel(-1, 0) + raw.GetRel(+1, 0))));

                pix.SetAndMoveNext(
                    (ushort)((raw.GetRel(0, 1) + raw.GetRel(+2, 1))),
                    (ushort)((raw.Value + raw.GetRel(+2, 0) + (raw.GetRel(+1, 1) << 1)) >> 1),
                    (ushort)(raw.GetRel(+1, 0) << 1));
                raw.MoveNext();
                raw.MoveNext();
            }

            // Top right pixel
            pix.SetAndMoveNext(
                (ushort)(raw.GetRel(res.Width - 1, 1) << 1),
                (ushort)(raw.GetRel(res.Width - 1, 0) << 1),
                (ushort)(raw.GetRel(res.Width - 2, 0) << 1));
            raw.MoveNext();
        }
示例#14
0
        private static VectorMap ApplyIndependentColorToVectorFilters(ColorMapUshort map,
            ICollection<IndependentComponentVectorToVectorFilter> indColorFilters)
        {
            if (indColorFilters.Count == 0) return map.ConvertToVector();

            var maxValue = map.MaxValue;
            var curvef = ConvertToCurveV(indColorFilters, maxValue);

            return ApplyCurve(map, curvef);
        }
示例#15
0
        //{
        //    {ColorComponent.G, ColorComponent.B},
        //    {ColorComponent.R,ColorComponent.G}
        //};


        public ColorMap <ushort> Process(RawMap <ushort> map)
        {
            var res  = new ColorMapUshort(map.Width, map.Height, map.MaxBits + 2);
            var pix  = res.GetPixel();
            var file = map.GetPixel();

            for (var x = 0; x < res.Width; x++)
            {
                pix.MoveNext();
                file.MoveNext();
            }
            for (var y = 1; y < res.Height - 1; y++)
            {
                pix.MoveNext();
                file.MoveNext();
                for (var x = 1; x < res.Width - 1; x++)
                {
                    var component = _componentsMap[(y + 0) % 2, (x + 0) % 2];
                    var invertRb  = ((x % 2) ^ (y % 2)) == 0;
                    switch (component)
                    {
                    case ColorComponent.R:
                        pix[0] = (ushort)(file.Value << 2);
                        pix[1] =
                            (ushort)
                            ((file.GetRel(-1, 0) + file.GetRel(+1, 0) + file.GetRel(0, -1) + file.GetRel(0, +1)));
                        pix[2] =
                            (ushort)
                            ((file.GetRel(-1, -1) + file.GetRel(+1, -1) + file.GetRel(-1, +1) +
                              file.GetRel(+1, +1)));
                        break;

                    case ColorComponent.G:
                        pix[(invertRb) ? 2 : 0] = (ushort)((file.GetRel(-1, 0) + file.GetRel(+1, 0)) << 1);
                        pix[1] = (ushort)(file.Value << 2);
                        pix[(invertRb) ? 0 : 2] = (ushort)((file.GetRel(0, -1) + file.GetRel(0, +1)) << 1);
                        break;

                    case ColorComponent.B:
                        pix[0] =
                            (ushort)
                            ((file.GetRel(-1, -1) + file.GetRel(+1, -1) + file.GetRel(-1, +1) +
                              file.GetRel(+1, +1)));
                        pix[1] =
                            (ushort)
                            ((file.GetRel(-1, 0) + file.GetRel(+1, 0) + file.GetRel(0, -1) + file.GetRel(0, +1)));
                        pix[2] = (ushort)(file.Value << 2);
                        break;
                    }
                    pix.MoveNext();
                    file.MoveNext();
                }
                pix.MoveNext();
                file.MoveNext();
            }
            for (var x = 0; x < res.Width; x++)
            {
                pix.MoveNext();
                file.MoveNext();
            }
            return(res);
        }
示例#16
0
        private static ColorMapUshort ApplyIndependentColorToUshortFilters(ColorMapUshort map,
            ICollection<IndependentComponentColorToColorFilter<float, float>> indColorFilters)
        {
            if (indColorFilters.Count == 0) return map;

            var maxValue = map.MaxValue;
            var curvef = ConvertToCurveF(indColorFilters, maxValue);
            var curve = ConvertToUshortCurve(curvef);

            return ApplyCurve(map, curve);
        }
示例#17
0
        private static RGB8Map ApplyIndependentVectorFiltersWithRGB(ColorMapUshort map,
            ICollection<IndependentComponentVectorToVectorFilter> indColorFilters,
            IndependentComponentVectorToColorFilter<byte> colorFilter)
        {
            if (!indColorFilters.Any()) throw new NotSupportedException("Is not supported without filters");

            var maxValue = map.MaxValue;
            var curve = new[] { new byte[maxValue + 1], new byte[maxValue + 1], new byte[maxValue + 1] };
            var curvef = ConvertToCurveV(indColorFilters, maxValue);

            Parallel.For(0, maxValue + 1, i => colorFilter.ProcessColorInCurve(i, curvef, curve));

            indColorFilters.Clear();
            return ApplyCurve(map, curve);
        }