Click here to Skip to main content
15,886,963 members
Home / Discussions / C#
   

C#

 
AnswerRe: Retrieve array items to use in NUnit Test Pin
Luc Pattyn22-Sep-10 15:44
sitebuilderLuc Pattyn22-Sep-10 15:44 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 15:48
mtn*rain22-Sep-10 15:48 
GeneralRe: Retrieve array items to use in NUnit Test Pin
Luc Pattyn22-Sep-10 15:59
sitebuilderLuc Pattyn22-Sep-10 15:59 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 16:02
mtn*rain22-Sep-10 16:02 
AnswerRe: Retrieve array items to use in NUnit Test Pin
AspDotNetDev22-Sep-10 16:07
protectorAspDotNetDev22-Sep-10 16:07 
GeneralRe: Retrieve array items to use in NUnit Test Pin
mtn*rain22-Sep-10 16:12
mtn*rain22-Sep-10 16:12 
GeneralRe: Retrieve array items to use in NUnit Test Pin
Paul Michalik22-Sep-10 20:47
Paul Michalik22-Sep-10 20:47 
Question3 way byte merge Pin
jkohler22-Sep-10 4:01
jkohler22-Sep-10 4:01 
Hi all,

I'm working with a machine vision package which uses a proprietary internal image format. Their package will convert to many common formats (jpg/bmp/png/etc) but this conversion is only done to disk and I want to do an in-memory conversion because the to-disk conversion is just plain too slow (>200ms).

Their format for 8bit color images is 3 separate planes (R,G&B) which easily combine into a 24bpp BitMap like this:

private static unsafe void CopyColorPlanes( BitmapData bmp, IntPtr _b, IntPtr _g, IntPtr _r )
{
    byte* imgPtr = (byte*)bmp.Scan0;

    //
    // single tasked version - one row at a time.....

    int h = bmp.Height;
    int w = bmp.Width;
    int s = bmp.Stride;
    byte* b = (byte*)_b;
    byte* g = (byte*)_g;
    byte* r = (byte*)_r;

    for ( int row = 0; row < h; row++ ) {
        for ( int col = 0; col < w; col++ ) {
            *imgPtr++ = *b++;
            *imgPtr++ = *g++;
            *imgPtr++ = *r++;
        }
        imgPtr += ( ( s / 3 ) - w ) * 3;  // ensures we're starting the row properly aligned
    }
}

This works well and is "reasonably" fast - a 1600x1200 color image conversion takes roughly 42ms on a 1.8MHz VIA C7 (the target system).

Two questions:
1) Does anyone see anything in the above method that could be tweaked (staying within "pure" C#) to make it faster? (I've already tried partitioning the source planes into halves and quarters to make them fit better in the CPU cache and while this has a small impact it's not significant and interestingly, doing columns in the outer loop runs about 10% faster on an AMD DualCore 4200 - go figger).

2) Is there some native Windows API that will do this job?

I know I probably end up crafting this in assembly but I view that as a last resort... and deadlines loom...
Subvert The Dominant Paradigm

AnswerRe: 3 way byte merge Pin
OriginalGriff22-Sep-10 4:19
mveOriginalGriff22-Sep-10 4:19 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 4:28
jkohler22-Sep-10 4:28 
AnswerRe: 3 way byte merge Pin
Ennis Ray Lynch, Jr.22-Sep-10 5:07
Ennis Ray Lynch, Jr.22-Sep-10 5:07 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 5:15
jkohler22-Sep-10 5:15 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 5:40
harold aptroot22-Sep-10 5:40 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 6:00
jkohler22-Sep-10 6:00 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 6:11
harold aptroot22-Sep-10 6:11 
AnswerRe: 3 way byte merge Pin
Chris Trelawny-Ross22-Sep-10 9:19
Chris Trelawny-Ross22-Sep-10 9:19 
GeneralRe: 3 way byte merge Pin
jkohler22-Sep-10 9:35
jkohler22-Sep-10 9:35 
GeneralRe: 3 way byte merge Pin
Michael B. Hansen23-Sep-10 2:27
Michael B. Hansen23-Sep-10 2:27 
GeneralRe: 3 way byte merge Pin
ely_bob23-Sep-10 8:25
professionalely_bob23-Sep-10 8:25 
GeneralRe: 3 way byte merge Pin
JonHarrison23-Sep-10 2:27
professionalJonHarrison23-Sep-10 2:27 
GeneralRe: 3 way byte merge Pin
jkohler23-Sep-10 3:24
jkohler23-Sep-10 3:24 
GeneralRe: 3 way byte merge Pin
JonHarrison23-Sep-10 3:34
professionalJonHarrison23-Sep-10 3:34 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 9:51
harold aptroot22-Sep-10 9:51 
GeneralRe: 3 way byte merge Pin
Chris Trelawny-Ross22-Sep-10 11:04
Chris Trelawny-Ross22-Sep-10 11:04 
GeneralRe: 3 way byte merge Pin
harold aptroot22-Sep-10 11:42
harold aptroot22-Sep-10 11:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.