本文整理汇总了C#中ManagedCuda.NPP.NPPImage_8uC3.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# NPPImage_8uC3.Dispose方法的具体用法?C# NPPImage_8uC3.Dispose怎么用?C# NPPImage_8uC3.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ManagedCuda.NPP.NPPImage_8uC3
的用法示例。
在下文中一共展示了NPPImage_8uC3.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaveJpeg
//.........这里部分代码省略.........
nMCUBlocksH = Math.Max(nMCUBlocksH, oFrameHeader.aSamplingFactors[i] & 0x0f);
}
for (int i = 0; i < oFrameHeader.nComponents; ++i)
{
NppiSize oBlocks = new NppiSize();
NppiSize oBlocksPerMCU = new NppiSize(oFrameHeader.aSamplingFactors[i] & 0x0f, oFrameHeader.aSamplingFactors[i] >> 4);
oBlocks.width = (int)Math.Ceiling((oFrameHeader.nWidth + 7) / 8 *
(float)(oBlocksPerMCU.width) / nMCUBlocksH);
oBlocks.width = DivUp(oBlocks.width, oBlocksPerMCU.width) * oBlocksPerMCU.width;
oBlocks.height = (int)Math.Ceiling((oFrameHeader.nHeight + 7) / 8 *
(float)(oBlocksPerMCU.height) / nMCUBlocksV);
oBlocks.height = DivUp(oBlocks.height, oBlocksPerMCU.height) * oBlocksPerMCU.height;
// Allocate Memory
apdDCT[i] = new NPPImage_16sC1(oBlocks.width * 64, oBlocks.height);
}
/***************************
*
* Output
*
***************************/
// Forward DCT
for (int i = 0; i < 3; ++i)
{
compression.DCTQuantFwd8x8LS(apDstImage[i], apdDCT[i], aDstSize[i], pdQuantizationTables[oFrameHeader.aQuantizationTableSelector[i]]);
}
// Huffman Encoding
CudaDeviceVariable<byte> pdScan = new CudaDeviceVariable<byte>(BUFFER_SIZE);
int nScanLength = 0;
int nTempSize = JPEGCompression.EncodeHuffmanGetSize(aDstSize[0], 3);
CudaDeviceVariable<byte> pJpegEncoderTemp = new CudaDeviceVariable<byte>(nTempSize);
NppiEncodeHuffmanSpec[] apHuffmanDCTableEnc = new NppiEncodeHuffmanSpec[3];
NppiEncodeHuffmanSpec[] apHuffmanACTableEnc = new NppiEncodeHuffmanSpec[3];
for (int i = 0; i < 3; ++i)
{
apHuffmanDCTableEnc[i] = JPEGCompression.EncodeHuffmanSpecInitAlloc(aHuffmanTables[(oScanHeader.aHuffmanTablesSelector[i] >> 4)].aCodes, NppiHuffmanTableType.nppiDCTable);
apHuffmanACTableEnc[i] = JPEGCompression.EncodeHuffmanSpecInitAlloc(aHuffmanTables[(oScanHeader.aHuffmanTablesSelector[i] & 0x0f) + 2].aCodes, NppiHuffmanTableType.nppiACTable);
}
JPEGCompression.EncodeHuffmanScan(apdDCT, 0, oScanHeader.nSs, oScanHeader.nSe, oScanHeader.nA >> 4, oScanHeader.nA & 0x0f, pdScan, ref nScanLength, apHuffmanDCTableEnc, apHuffmanACTableEnc, aDstSize, pJpegEncoderTemp);
for (int i = 0; i < 3; ++i)
{
JPEGCompression.EncodeHuffmanSpecFree(apHuffmanDCTableEnc[i]);
JPEGCompression.EncodeHuffmanSpecFree(apHuffmanACTableEnc[i]);
}
// Write JPEG to byte array, as in original sample code
byte[] pDstOutput = new byte[BUFFER_SIZE];
int pos = 0;
oFrameHeader.nWidth = (ushort)oDstImageSize.width;
oFrameHeader.nHeight = (ushort)oDstImageSize.height;
writeMarker(0x0D8, pDstOutput, ref pos);
writeJFIFTag(pDstOutput, ref pos);
writeQuantizationTable(aQuantizationTables[0], pDstOutput, ref pos);
writeQuantizationTable(aQuantizationTables[1], pDstOutput, ref pos);
writeFrameHeader(oFrameHeader, pDstOutput, ref pos);
writeHuffmanTable(aHuffmanTables[0], pDstOutput, ref pos);
writeHuffmanTable(aHuffmanTables[1], pDstOutput, ref pos);
writeHuffmanTable(aHuffmanTables[2], pDstOutput, ref pos);
writeHuffmanTable(aHuffmanTables[3], pDstOutput, ref pos);
writeScanHeader(oScanHeader, pDstOutput, ref pos);
pdScan.CopyToHost(pDstOutput, 0, pos, nScanLength);
pos += nScanLength;
writeMarker(0x0D9, pDstOutput, ref pos);
FileStream fs = new FileStream(aFilename, FileMode.Create, FileAccess.Write);
fs.Write(pDstOutput, 0, pos);
fs.Close();
//cleanup:
fs.Dispose();
pJpegEncoderTemp.Dispose();
pdScan.Dispose();
apdDCT[2].Dispose();
apdDCT[1].Dispose();
apdDCT[0].Dispose();
pdQuantizationTables[1].Dispose();
pdQuantizationTables[0].Dispose();
srcCr.Dispose();
srcCb.Dispose();
srcY.Dispose();
src.Dispose();
compression.Dispose();
}
示例2: 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();
}
示例3: LoadJpeg
const int BUFFER_SIZE = 4 << 23; //32 MegaBytes
#endregion Fields
#region Methods
public static Bitmap LoadJpeg(string aFilename)
{
JPEGCompression compression = new JPEGCompression();
byte[] pJpegData = File.ReadAllBytes(aFilename);
int nInputLength = pJpegData.Length;
// Check if this is a valid JPEG file
int nPos = 0;
int nMarker = nextMarker(pJpegData, ref nPos, nInputLength);
if (nMarker != 0x0D8)
{
throw new ArgumentException(aFilename + " is not a JPEG file.");
}
nMarker = nextMarker(pJpegData, ref nPos, nInputLength);
// Parsing and Huffman Decoding (on host)
FrameHeader oFrameHeader = new FrameHeader();
oFrameHeader.aComponentIdentifier = new byte[3];
oFrameHeader.aSamplingFactors = new byte[3];
oFrameHeader.aQuantizationTableSelector = new byte[3];
QuantizationTable[] aQuantizationTables = new QuantizationTable[4];
aQuantizationTables[0] = new QuantizationTable();
aQuantizationTables[1] = new QuantizationTable();
aQuantizationTables[2] = new QuantizationTable();
aQuantizationTables[3] = new QuantizationTable();
CudaDeviceVariable<byte>[] pdQuantizationTables = new CudaDeviceVariable<byte>[4];
pdQuantizationTables[0] = new CudaDeviceVariable<byte>(64);
pdQuantizationTables[1] = new CudaDeviceVariable<byte>(64);
pdQuantizationTables[2] = new CudaDeviceVariable<byte>(64);
pdQuantizationTables[3] = new CudaDeviceVariable<byte>(64);
HuffmanTable[] aHuffmanTables = new HuffmanTable[4];
aHuffmanTables[0] = new HuffmanTable();
aHuffmanTables[1] = new HuffmanTable();
aHuffmanTables[2] = new HuffmanTable();
aHuffmanTables[3] = new HuffmanTable();
ScanHeader oScanHeader = new ScanHeader();
oScanHeader.aComponentSelector = new byte[3];
oScanHeader.aHuffmanTablesSelector = new byte[3];
int nMCUBlocksH = 0;
int nMCUBlocksV = 0;
int nRestartInterval = -1;
NppiSize[] aSrcSize = new NppiSize[3];
short[][] aphDCT = new short[3][];
NPPImage_16sC1[] apdDCT = new NPPImage_16sC1[3];
int[] aDCTStep = new int[3];
NPPImage_8uC1[] apSrcImage = new NPPImage_8uC1[3];
int[] aSrcImageStep = new int[3];
NPPImage_8uC1[] apDstImage = new NPPImage_8uC1[3];
int[] aDstImageStep = new int[3];
NppiSize[] aDstSize = new NppiSize[3];
//Same read routine as in NPP JPEG sample from Nvidia
while (nMarker != -1)
{
if (nMarker == 0x0D8)
{
// Embeded Thumbnail, skip it
int nNextMarker = nextMarker(pJpegData, ref nPos, nInputLength);
while (nNextMarker != -1 && nNextMarker != 0x0D9)
{
nNextMarker = nextMarker(pJpegData, ref nPos, nInputLength);
}
}
if (nMarker == 0x0DD)
{
readRestartInterval(pJpegData, ref nPos, ref nRestartInterval);
}
if ((nMarker == 0x0C0) | (nMarker == 0x0C2))
{
//Assert Baseline for this Sample
//Note: NPP does support progressive jpegs for both encode and decode
if (nMarker != 0x0C0)
{
pdQuantizationTables[0].Dispose();
pdQuantizationTables[1].Dispose();
pdQuantizationTables[2].Dispose();
pdQuantizationTables[3].Dispose();
//.........这里部分代码省略.........