Comment
Author: Admin | 2025-04-28
I am writing an image processing program with the express purpose to alter large images, the one I'm working with is 8165 pixels by 4915 pixels. I was told to implement gpu processing, so after some research I decided to go with OpenCL. I started implementing the OpenCL C# wrapper OpenCLTemplate. My code takes in a bitmap and uses lockbits to lock its memory location. I then copy the order of each bit into an array, run the array through the openCL kernel, and it inverts each bit in the array. I then run the inverted bits back into the memory location of the image. I split this process into ten chunks so that i can increment a progress bar.My code works perfectly with smaller images, but when I try to run it with my big image I keep getting a MemObjectAllocationFailure when trying to execute the kernel. I don't know why its doing this and i would appreciate any help in figuring out why or how to fix it. using OpenCLTemplate; public static void Invert(Bitmap image, ToolStripProgressBar progressBar) { string openCLInvert = @" __kernel void Filter(__global uchar * Img0, __global float * ImgF) { // Gets information about work-item int x = get_global_id(0); int y = get_global_id(1); // Gets information about work size int width = get_global_size(0); int height = get_global_size(1); int ind = 4 * (x + width * y ); // Inverts image colors ImgF[ind]= 255.0f - (float)Img0[ind]; ImgF[1 + ind]= 255.0f - (float)Img0[1 + ind]; ImgF[2 + ind]= 255.0f - (float)Img0[2 + ind]; // Leave alpha component equal ImgF[ind + 3] = (float)Img0[ind + 3]; }"; //Lock the image in memory and get image lock data var imageData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); CLCalc.InitCL(); for (int i = 0; i
Add Comment