Exemplo n.º 1
0
        // B G B G
        // G R G R
        // B G B G
        // G R G R
        static void ProcessBottomLine(ColorMap <ushort> map, ColorMap <Vector3> res, float maxValue)
        {
            var pix  = res.GetRow(res.Height - 1);
            var raw0 = map.GetRow(res.Height - 1);
            var rawU = map.GetRow(res.Height - 2);

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

            pix.SetAndMoveNext(
                (raw0.GetRel(1) << 1),
                (raw0.Value << 1),
                (rawU.GetRel(0) << 1),
                maxValue);
            raw0.MoveNext();
            rawU.MoveNext();

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

                pix.SetAndMoveNext(
                    ((raw0.Value + raw0.GetRel(+2))),
                    (raw0.GetRel(+1) << 1),
                    (rawU.GetRel(+1) << 1),
                    maxValue);
                raw0.MoveNext(2);
                rawU.MoveNext(2);
            }

            // Bottom right pixel
            pix.SetAndMoveNext(
                (raw0.GetRel(-1) << 1),
                ((rawU.GetRel(-1) + raw0.GetRel(-2))),
                (rawU.GetRel(-2) << 1),
                maxValue);
        }
Exemplo n.º 2
0
 private static void ApplyCurveInplace(ColorMap <ushort> map, ushort[][] curve)
 {
     Parallel.For(0, map.Height, y =>
     {
         var pix = map.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             pix.SetAndMoveNext(curve[0][pix.R], curve[1][pix.G], curve[2][pix.B]);
         }
     });
 }
Exemplo n.º 3
0
        static void ProcessTopLine(ColorMap <ushort> map, ColorMap <Vector3> res, float maxValue)
        {
            var pix  = res.GetRow(0);
            var raw0 = map.GetRow(0);
            var rawD = map.GetRow(1);

            // Top Left pixel

            pix.SetAndMoveNext(
                (rawD.GetRel(1) << 1),
                ((raw0.GetRel(1) + rawD.GetRel(0))),
                (raw0.Value << 1),
                maxValue);
            raw0.MoveNext();
            rawD.MoveNext();

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

                pix.SetAndMoveNext(
                    ((rawD.GetRel(0) + rawD.GetRel(+2))),
                    ((raw0.Value + raw0.GetRel(+2) + (rawD.GetRel(+1) << 1)) >> 1),
                    (raw0.GetRel(+1) << 1),
                    maxValue);
                raw0.MoveNext(2);
                rawD.MoveNext(2);
            }

            // Top right pixel
            pix.SetAndMoveNext(
                (rawD.GetRel(-1) << 1),
                (raw0.GetRel(-1) << 1),
                (raw0.GetRel(-2) << 1),
                maxValue);
        }
Exemplo n.º 4
0
 private static void ApplySingleFilterInplace(ColorMap <float> map, ColorToColorFilter <float, float> filter)
 {
     Parallel.For(0, map.Height, y =>
     {
         var pix = map.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             filter.ProcessColor(pix, pix);
             pix.MoveNext();
         }
     });
 }
Exemplo n.º 5
0
 private static ColorMapFloat ApplyCurve(ColorMap<ushort> map, float[][] curve)
 {
     var result = new ColorMapFloat(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[0][input.R], curve[1][input.G], curve[2][input.B]);
             input.MoveNext();
         }
     });
     return result;
 }
Exemplo n.º 6
0
        private static RGB8Map ApplyCurve(ColorMap <ushort> map, byte[][] curve)
        {
            var result = new RGB8Map(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[0][input.R], curve[1][input.G], curve[2][input.B]);
                    input.MoveNext();
                }
            });
            return(result);
        }
Exemplo n.º 7
0
        private static RGB8Map ConvertToRGB(ColorMap <float> map, ColorToColorFilter <float, byte> filter)
        {
            var result = new RGB8Map(map.Width, map.Height);

            Parallel.For(0, map.Height, y =>
            {
                var input  = map.GetRow(y);
                var output = result.GetRow(y);
                for (var x = 0; x < map.Width; x++)
                {
                    filter.ProcessColor(input, output);
                    input.MoveNext();
                    output.MoveNext();
                }
            });
            return(result);
        }
Exemplo n.º 8
0
        static void ProcessMiddleRows(ColorMap <ushort> map, ColorMap <Vector3> res, float maxValue)
        {
            // Middle Rows
            Parallel.For(0, (res.Height - 2) / 2, yy =>
            {
                var y = yy * 2 + 1;
                ProcessMiddleOddRows(map.GetRow(y), map.GetRow(y - 1), map.GetRow(y + 1), res.Width, res.GetRow(y), maxValue);

                y++;

                ProcessMiddleEvenRows(map.GetRow(y), map.GetRow(y - 1), map.GetRow(y + 1), res.Width, res.GetRow(y), maxValue);
            });
        }
Exemplo n.º 9
0
 private static RGB8Map ConvertToRGB(ColorMap<float> map, ColorToColorFilter<float, byte> filter)
 {
     var result = new RGB8Map(map.Width, map.Height);
     Parallel.For(0, map.Height, y =>
     {
         var input = map.GetRow(y);
         var output = result.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             filter.ProcessColor(input, output);
             input.MoveNext();
             output.MoveNext();
         }
     });
     return result;
 }
Exemplo n.º 10
0
 private static void ApplySingleFilterInplace(ColorMap<float> map, ColorToColorFilter<float, float> filter)
 {
     Parallel.For(0, map.Height, y =>
     {
         var pix = map.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             filter.ProcessColor(pix, pix);
             pix.MoveNext();
         }
     });
 }
Exemplo n.º 11
0
 private static void ApplyCurveInplace(ColorMap<ushort> map, ushort[][] curve)
 {
     Parallel.For(0, map.Height, y =>
     {
         var pix = map.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             pix.SetAndMoveNext(curve[0][pix.R], curve[1][pix.G], curve[2][pix.B]);
         }
     });
 }
Exemplo n.º 12
0
        public ColorMap <ushort> DecodeMap(Stream stream, Exif _exif)
        {
            var exif = (PanasonicExif)_exif;

            stream.Seek(exif.RawOffset, SeekOrigin.Begin);
            int row, col, i, j, sh = 0;

            int[] pred = new int[2], nonz = new int[2];

            var resultHeight = exif.ImageHeight;
            var resultWidth  = exif.CropRight;
            var map          = new ColorMap <ushort>(resultWidth, resultHeight, 12);
            int value;
            var bits = new PanasonicBitStream(stream);

            for (row = 0; row < exif.ImageHeight; row++)
            {
                var line = map.GetRow(row);
                for (col = 0; col < exif.ImageWidth; col++)
                {
                    unchecked
                    {
                        i = col % 14;
                        if (i == 0)
                        {
                            pred[0] = pred[1] = nonz[0] = nonz[1] = 0;
                        }
                        if (i % 3 == 2)
                        {
                            sh = 4 >> (3 - bits.Read(2));
                        }
                        if (nonz[i & 1] != 0)
                        {
                            j = bits.Read(8);
                            if (j != 0)
                            {
                                pred[i & 1] -= 0x80 << sh;
                                if (pred[i & 1] < 0 || sh == 4)
                                {
                                    pred[i & 1] &= ~(-1 << sh);
                                }
                                pred[i & 1] += j << sh;
                            }
                        }
                        else
                        {
                            nonz[i & 1] = bits.Read(8);
                            if (nonz[i & 1] != 0 || i > 11)
                            {
                                pred[i & 1] = nonz[i & 1] << 4 | bits.Read(4);
                            }
                        }
                        if (col >= resultWidth)
                        {
                            continue;
                        }

                        value = pred[col & 1];

                        if (value > 4098)
                        {
                            throw new Exception("Decoding error");
                        }

                        line.SetAndMoveNext((ushort)Math.Min(4095, value));
                    }
                }
            }
            return(map);
        }