If it's not too much trouble, i'd love to see an example of writing an openCL program to a byte array (which System.Drawing.Bitmap and so on can convert to a bitmap). The program would simply write a flat color (orange?) to the image so you know you're not getting a false positive!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure I understood you correctly. You want to know how to generate an orange (or any color) Bitmap from a byte array using an OpenCL kernel?
If yes here goes:
usingCloo;usingSystem;usingSystem.Drawing;usingSystem.Drawing.Imaging;namespaceClooTesting{publicclassBitmapExample{publicstaticvoidMain(){intimgWidth=320;intimgHeight=240;intchannels=4;// you should beware of the pixel format of the final image. ARGB in our case so there are 4 bytes per pixel.intbufferSize=imgWidth*imgHeight*channels;ComputeContextPropertyListcpl=newComputeContextPropertyList(ComputePlatform.Platforms[1]);ComputeContextcontext=newComputeContext(ComputeDeviceTypes.Default,cpl,null,IntPtr.Zero);ComputeCommandQueuecommands=newComputeCommandQueue(context,context.Devices[0],ComputeCommandQueueFlags.None);ComputeBuffer<byte>clBuffer=newComputeBuffer<byte>(context,ComputeMemoryFlags.WriteOnly,bufferSize);stringclKernel=@"kernelvoidBitmapKernel(globalwrite_onlyuchar4*array){intgid=get_global_id(0);// Even though the Bitmap format will be ARGB this array will be parsed as BGRA. So be careful with that. No, I don't know why it works like this. Ask Microsoft :)array[gid]=(uchar4)(0,0,255,127);// This is full red/half transparent color.}";ComputeProgramprogram=newComputeProgram(context,clKernel);program.Build(null,null,null,IntPtr.Zero);ComputeKernelkernel=program.CreateKernel("BitmapKernel");kernel.SetMemoryArgument(0,clBuffer);commands.Execute(kernel,null,newlong[]{imgWidth*imgHeight},null,null);byte[]array=null;commands.ReadFromBuffer(clBuffer,refarray,true,null);Bitmapbmp;unsafe{fixed(byte*arrayPtr=array)bmp=newBitmap(imgWidth,imgHeight,channels*imgWidth,PixelFormat.Format32bppArgb,(IntPtr)arrayPtr);}bmp.Save("image.png");bmp.Dispose();}}}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
If it's not too much trouble, i'd love to see an example of writing an openCL program to a byte array (which System.Drawing.Bitmap and so on can convert to a bitmap). The program would simply write a flat color (orange?) to the image so you know you're not getting a false positive!
I'm not sure I understood you correctly. You want to know how to generate an orange (or any color) Bitmap from a byte array using an OpenCL kernel?
If yes here goes:
However, there's a better way of getting the data directly into the Bitmap without using a temporary array.