Writing Pixel Values to an Array

@illusive: Homework done :sunglasses::

    using Cvb;
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Threading.Tasks;

    namespace ArrayTestThatActuallyWritesToAList
    {
      class Program
      {
        static void Main(string[] args)
        {
          Image.IMG image;
          Image.CreateGenericImage(1, 4000, 200, false, out image);
          List<int> values = new List<int>();
          Stopwatch executionWatch = new Stopwatch();
          executionWatch.Start();
          CopyPixelsWithValue(image, values);
          executionWatch.Stop();
          Image.ReleaseObj(image);
          Console.WriteLine(executionWatch.ElapsedMilliseconds.ToString());
          Console.Read();
        }

        static unsafe void CopyPixelsWithValue(Image.IMG source, List<int> values)
        {
          int width = Image.ImageWidth(source);
          int height = Image.ImageHeight(source);
          IntPtr sourceBase;
          int sourceYInc;
          int sourceXInc;

          Cvb.Utilities.GetLinearAccess(source, 0, out sourceBase, out sourceXInc, out sourceYInc);

          Parallel.For(0, height, y =>
          {
            byte* pSrcLine = (byte*)sourceBase + y * sourceYInc;

            for (int x = 0; x < width; x++)
            {
              var srcVal = *(pSrcLine + x * sourceXInc);
              values.Add(srcVal);
            }
          });
        }
      }
    }

Didn’t feel very satisfying however :no_mouth:

@mave This should be pretty much copy-pasteable right now :wink:

Cheers
Chris

1 Like