Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
P

philpalk

@philpalk
About
Posts
1
Topics
0
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • 3 way byte merge
    P philpalk

    I've faced the exact same issue a little while ago (targeting a different processor though). IIRC the big surprise for me was that I gained a significant performance increase by swapping from the for loop you have to the while loop below (must be friendlier to the C# optimizer). Something else you might try is to manually unroll your loop to do 4 pixels at a time in the inner loop and read your source image channels 32-bits at a time. This is definitely something where you'd benefit from dropping down to native code if the performance of this step is that critical (and if p/invoke proves to be significant you can implement it using a mixed mode assembly). Usually with machine vision though converting to a packed byte format is only done as a last step for displaying/storing the results, processing is usually done in planar formats (which I really wouldn't call 'proprietary' either btw) for better performance.

    private static unsafe void PlanarToPackedByteRgb32(
    int width, int height,
    IntPtr rSrc, IntPtr gSrc, IntPtr bSrc,
    IntPtr dest, int stride)
    {
    var rSrcPtr = (byte*)rSrc.ToPointer();
    var gSrcPtr = (byte*)gSrc.ToPointer();
    var bSrcPtr = (byte*)bSrc.ToPointer();
    var destPtr = (byte*)dest.ToPointer();
    var destEndPtr = destPtr + stride * height;
    var rowStep = 4 * width;

    while (destPtr != destEndPtr)
    {
        var it = (uint\*)destPtr;
        var end = (uint\*)(destPtr + rowStep);
        destPtr += stride;
    
        while (it != end)
        {
            \*it++ =
                ((uint)(\*rSrcPtr++) << 16) |
                ((uint)(\*gSrcPtr++) << 8) |
                ((uint)(\*bSrcPtr++) << 0);
        }
    }
    

    }

    C# csharp c++ graphics json performance
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups