這是我的代碼來刪除圖像的紅色通道。 有什麼辦法讓它在GPU上?簡單的方法讓GPU做計算
其實我想要的是, 我有一個源位圖數據(指針)和一個目標位圖數據(指針)。 我想對SOURCE BITMAP進行一些計算,並將結果輸出到DESTINATION BITMAP。
此代碼工作得很好,但我負責的高畫質圖像。這就是爲什麼我希望GPU進行計算,但我不想使用CUDA或ATI的SDK。因爲如果我使用CUDA或ATI的SDK,我將需要此圖形卡。這就是爲什麼我需要適用於所有圖形卡的東西。我試圖使用DirectX,但我沒有看到任何類似的計算...
是否有任何庫,使GPU能夠做到這一點?
private unsafe void testX()
{
Bitmap sourceBmp = (Bitmap)System.Drawing.Bitmap.FromFile(@"C:\cc.jpg");
BitmapData sourceBmd = sourceBmp.LockBits(new System.Drawing.Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
IntPtr sourcePtr = sourceBmd.Scan0;
uint* pSource = (uint*)sourcePtr.ToPointer();
Bitmap destinationBmp = new Bitmap(sourceBmp.Width, sourceBmp.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
BitmapData destinationBmd = destinationBmp.LockBits(new System.Drawing.Rectangle(0, 0, sourceBmp.Width, sourceBmp.Height), ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
IntPtr destinationPtr = destinationBmd.Scan0;
uint* pDest = (uint*)destinationPtr.ToPointer();
int _w = sourceBmp.Width;
int _h = sourceBmp.Height;
for (int j = 0; j < _h; j++)
{
for (int i = 0; i < _w; i++)
{
*pDest = (*pSource) & 0xff00ffff;
pDest++;
pSource++;
}
}
sourceBmp.UnlockBits(sourceBmd);
destinationBmp.UnlockBits(destinationBmd);
if (File.Exists(@"C:\deneme2.jpg"))
File.Delete(@"C:\deneme2.jpg");
destinationBmp.Save(@"C:\deneme2.jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
MessageBox.Show("Done!");
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
testX();
}
最後,我試過的東西太多了,例如CUDA,OpenGL的,OpenCL和ATI的SDK,我需要下載的文件至少300MB與theese SDK的工作。所以,我需要的是一個適用於所有顯卡的小尺寸庫或標題。感謝您的幫助和解答。
對不起,我的英語順便說一下。
謝謝。
如果您不想使用CUDA,爲什麼要將此內容發佈到CUDA標籤? GPGPU標籤會更合適。您可以考慮使用OpenCL,它可以幫助您在CUDA和非CUDA卡上運行代碼(一旦寫入)。我正在投票結束這個非問題帖子。下次嘗試使用與您在下面撰寫的帖子相關的標題。 StackOverflow是一個社區。發佈問題,你會得到別人的幫助。如果與您的類似,適當的標題可能有助於其他用戶找到自己問題的解決方案。 – JackOLantern
如果你要求圖書館這樣做,但不想要「CUDA或_something else_」,它會產生一個悖論,因爲「圖書館」是集合「其他」的元素。 –