本文整理汇总了C#中ManagedCuda.NPP.NPPImage_8uC3.CopyToHost方法的典型用法代码示例。如果您正苦于以下问题:C# NPPImage_8uC3.CopyToHost方法的具体用法?C# NPPImage_8uC3.CopyToHost怎么用?C# NPPImage_8uC3.CopyToHost使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ManagedCuda.NPP.NPPImage_8uC3
的用法示例。
在下文中一共展示了NPPImage_8uC3.CopyToHost方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: btn_Resize_Click
private void btn_Resize_Click(object sender, EventArgs e)
{
if ((Bitmap)pic_Image.Image == null) return;
Bitmap bmp = (Bitmap)pic_Image.Image;
int w = bmp.Width;
int h = bmp.Height;
if ((w <= 16 || h <= 16) && trk_Size.Value < 100)
{
MessageBox.Show("Image is too small for resizing.");
return;
}
int newW = (int)(trk_Size.Value / 100.0f * w);
int newH = (int)(trk_Size.Value / 100.0f * h);
if (newW % 16 != 0)
{
newW = newW - (newW % 16);
}
if (newW < 16) newW = 16;
if (newH % 16 != 0)
{
newH = newH - (newH % 16);
}
if (newH < 16) newH = 16;
double ratioW = newW / (double)w;
double ratioH = newH / (double)h;
if (ratioW == 1 && ratioH == 1)
return;
if (bmp.PixelFormat != System.Drawing.Imaging.PixelFormat.Format24bppRgb)
{
MessageBox.Show("Only three channel color images are supported!");
return;
}
NPPImage_8uC3 imgIn = new NPPImage_8uC3(w, h);
NPPImage_8uC3 imgOut = new NPPImage_8uC3(newW, newH);
InterpolationMode interpol = InterpolationMode.SuperSampling;
if (ratioH >= 1 || ratioW >= 1)
interpol = InterpolationMode.Lanczos;
imgIn.CopyToDevice(bmp);
imgIn.ResizeSqrPixel(imgOut, ratioW, ratioH, 0, 0, interpol);
Bitmap bmpRes = new Bitmap(newW, newH, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
imgOut.CopyToHost(bmpRes);
pic_Image.Image = bmpRes;
imgIn.Dispose();
imgOut.Dispose();
}
示例2: LoadJpeg
//.........这里部分代码省略.........
NppiDecodeHuffmanSpec[] apHuffmanDCTableDec = new NppiDecodeHuffmanSpec[3];
NppiDecodeHuffmanSpec[] apHuffmanACTableDec = new NppiDecodeHuffmanSpec[3];
for (int i = 0; i < 3; ++i)
{
apHuffmanDCTableDec[i] = JPEGCompression.DecodeHuffmanSpecInitAllocHost(aHuffmanTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, NppiHuffmanTableType.nppiDCTable);
apHuffmanACTableDec[i] = JPEGCompression.DecodeHuffmanSpecInitAllocHost(aHuffmanTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f) + 2].aCodes, NppiHuffmanTableType.nppiACTable);
}
byte[] img = new byte[nAfterNextMarkerPos - nPos - 2];
Buffer.BlockCopy(pJpegData, nPos, img, 0, nAfterNextMarkerPos - nPos - 2);
JPEGCompression.DecodeHuffmanScanHost(img, nRestartInterval, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, aphDCT[0], aphDCT[1], aphDCT[2], aDCTStep, apHuffmanDCTableDec, apHuffmanACTableDec, aSrcSize);
for (int i = 0; i < 3; ++i)
{
JPEGCompression.DecodeHuffmanSpecFreeHost(apHuffmanDCTableDec[i]);
JPEGCompression.DecodeHuffmanSpecFreeHost(apHuffmanACTableDec[i]);
}
}
nMarker = nextMarker(pJpegData, ref nPos, nInputLength);
}
// Copy DCT coefficients and Quantization Tables from host to device
for (int i = 0; i < 4; ++i)
{
pdQuantizationTables[i].CopyToDevice(aQuantizationTables[i].aTable);
}
for (int i = 0; i < 3; ++i)
{
apdDCT[i].CopyToDevice(aphDCT[i], aDCTStep[i]);
}
// Inverse DCT
for (int i = 0; i < 3; ++i)
{
compression.DCTQuantInv8x8LS(apdDCT[i], apSrcImage[i], aSrcSize[i], pdQuantizationTables[oFrameHeader.aQuantizationTableSelector[i]]);
}
//Alloc final image
NPPImage_8uC3 res = new NPPImage_8uC3(apSrcImage[0].Width, apSrcImage[0].Height);
//Copy Y color plane to first channel
apSrcImage[0].Copy(res, 0);
//Cb anc Cr channel might be smaller
if ((oFrameHeader.aSamplingFactors[0] & 0x0f) == 1 && oFrameHeader.aSamplingFactors[0] >> 4 == 1)
{
//Color planes are of same size as Y channel
apSrcImage[1].Copy(res, 1);
apSrcImage[2].Copy(res, 2);
}
else
{
//rescale color planes to full size
double scaleX = oFrameHeader.aSamplingFactors[0] & 0x0f;
double scaleY = oFrameHeader.aSamplingFactors[0] >> 4;
apSrcImage[1].ResizeSqrPixel(apSrcImage[0], scaleX, scaleY, 0, 0, InterpolationMode.Lanczos);
apSrcImage[0].Copy(res, 1);
apSrcImage[2].ResizeSqrPixel(apSrcImage[0], scaleX, scaleY, 0, 0, InterpolationMode.Lanczos);
apSrcImage[0].Copy(res, 2);
}
//System.Drawing.Bitmap is ordered BGR not RGB
//The NPP routine YCbCR to BGR needs clampled input values, following the YCbCr standard.
//But JPEG uses unclamped values ranging all from [0..255], thus use our own color matrix:
float[,] YCbCrToBgr = new float[3, 4]
{{1.0f, 1.772f, 0.0f, -226.816f },
{1.0f, -0.34414f, -0.71414f, 135.45984f},
{1.0f, 0.0f, 1.402f, -179.456f }};
//Convert from YCbCr to BGR
res.ColorTwist(YCbCrToBgr);
Bitmap bmp = new Bitmap(apSrcImage[0].Width, apSrcImage[0].Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
res.CopyToHost(bmp);
//Cleanup:
res.Dispose();
apSrcImage[2].Dispose();
apSrcImage[1].Dispose();
apSrcImage[0].Dispose();
apdDCT[2].Dispose();
apdDCT[1].Dispose();
apdDCT[0].Dispose();
pdQuantizationTables[0].Dispose();
pdQuantizationTables[1].Dispose();
pdQuantizationTables[2].Dispose();
pdQuantizationTables[3].Dispose();
compression.Dispose();
return bmp;
}