/// <summary> /// Forward DCT, quantization and level shift part of the JPEG encoding. /// Input is expected in 8x8 macro blocks and output is expected to be in 64x1 /// macro blocks. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image</param> /// <param name="QuantFwdTable">Forward quantization tables for JPEG encoding created using QuantInvTableInit()</param> /// <param name="oSizeRoi">Roi size (in macro blocks?).</param> public static void DCTQuantFwd8x8LS(NPPImage_8uC1 src, NPPImage_16sC1 dst, CudaDeviceVariable<ushort> QuantFwdTable, NppiSize oSizeRoi) { NppStatus status; status = NPPNativeMethods.NPPi.ImageCompression.nppiDCTQuantFwd8x8LS_JPEG_8u16s_C1R(src.DevicePointer, src.Pitch, dst.DevicePointer, dst.Pitch, QuantFwdTable.DevicePointer, oSizeRoi); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTQuantFwd8x8LS_JPEG_8u16s_C1R", status)); NPPException.CheckNppStatus(status, null); }
public void nppsSet_32s_test() { int length = 1024; int value = 75; IntPtr ptr = Npps.nppsMalloc_32s(length); int[] result = new int[length]; GCHandle gcHandle = GCHandle.Alloc(result, GCHandleType.Pinned); IntPtr h_result = Marshal.UnsafeAddrOfPinnedArrayElement(result, 0); UInt64 size = Convert.ToUInt64(sizeof(int) * result.Length); NppStatus status = Npps.nppsSet_32s(value, ptr, length); if (status != NppStatus.NPP_SUCCESS) { Assert.Fail(String.Format("Fail {0}", status.ToString())); } cudaError cudaStatus = CudaRuntimeApi.cudaMemcpy(h_result, ptr, size, cudaMemcpyKind.DeviceToHost); if (cudaStatus != cudaError.cudaSuccess) { Assert.Fail(String.Format("Fail {0}", cudaStatus.ToString())); } for (int i = 0; i < result.Length; i++) { Assert.AreEqual(value, result[i]); } gcHandle.Free(); Npps.nppsFree(ptr); }
/// <summary> /// Initializes DCT state structure and allocates additional resources /// </summary> public JPEGCompression() { _state = new NppiDCTState(); status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTInitAlloc(ref _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTInitAlloc", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// image warp perspective batch. /// </summary> /// <param name="oSmallestSrcSize">Size in pixels of the entire smallest source image width and height, may be from different images.</param> /// <param name="oSrcRectROI">Region of interest in the source images (may overlap source image size width and height).</param> /// <param name="oDstRectROI">Region of interest in the destination images (may overlap destination image size width and height).</param> /// <param name="eInterpolation">The type of eInterpolation to perform resampling. Currently limited to NPPI_INTER_NN, NPPI_INTER_LINEAR, NPPI_INTER_CUBIC, or NPPI_INTER_SUPER. </param> /// <param name="pBatchList">Device memory pointer to nBatchSize list of NppiWarpAffineBatchCXR structures.</param> public static void WarpPerspectiveBatch(NppiSize oSmallestSrcSize, NppiRect oSrcRectROI, NppiRect oDstRectROI, InterpolationMode eInterpolation, CudaDeviceVariable <NppiWarpAffineBatchCXR> pBatchList) { NppStatus status = NPPNativeMethods.NPPi.GeometricTransforms.nppiWarpPerspectiveBatch_16f_C3R(oSmallestSrcSize, oSrcRectROI, oDstRectROI, eInterpolation, pBatchList.DevicePointer, pBatchList.Size); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiWarpPerspectiveBatch_16f_C3R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// color twist batch /// An input color twist matrix with floating-point coefficient values is applied /// within the ROI for each image in batch. Color twist matrix can vary per image. The same ROI is applied to each image. /// </summary> /// <param name="nMin">Minimum clamp value.</param> /// <param name="nMax">Maximum saturation and clamp value.</param> /// <param name="oSizeROI"></param> /// <param name="pBatchList">Device memory pointer to nBatchSize list of NppiColorTwistBatchCXR structures.</param> public static void ColorTwistBatchI(float nMin, float nMax, NppiSize oSizeROI, CudaDeviceVariable <NppiColorTwistBatchCXR> pBatchList) { NppStatus status = NPPNativeMethods.NPPi.ColorTwistBatch.nppiColorTwistBatch32f_16f_C3IR(nMin, nMax, oSizeROI, pBatchList.DevicePointer, pBatchList.Size); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiColorTwistBatch32f_16f_C3IR", status)); NPPException.CheckNppStatus(status, pBatchList); }
/// <summary> /// label markers image generation with per image destination ROI. /// </summary> /// <param name="pSrcBatchList">source_batch_images_pointer device memory pointer to the list of device memory source image descriptors, oSize element is ignored.</param> /// <param name="pDstBatchList">destination_batch_images_pointer device memory pointer to the list of device memory destination image descriptors, oSize element is ignored.</param> /// <param name="oMaxSizeROI">maximum ROI width and height of ALL images in the batch.</param> /// <param name="eNorm">Type of pixel connectivity test to use, nppiNormInf will use 8 way connectivity and nppiNormL1 will use 4 way connectivity. </param> public static void LabelMarkersUFBatch_Advanced(CudaDeviceVariable <NppiImageDescriptor> pSrcBatchList, CudaDeviceVariable <NppiImageDescriptor> pDstBatchList, NppiSize oMaxSizeROI, NppiNorm eNorm) { NppStatus status = NPPNativeMethods.NPPi.LabelMarkers.nppiLabelMarkersUFBatch_32u_C1R_Advanced(pSrcBatchList.DevicePointer, pDstBatchList.DevicePointer, pSrcBatchList.Size, oMaxSizeROI, eNorm); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiLabelMarkersUFBatch_32u_C1R_Advanced", status)); NPPException.CheckNppStatus(status, pSrcBatchList); }
/// <summary> /// Inverse DCT, de-quantization and level shift part of the JPEG decoding. /// Input is expected in 64x1 macro blocks and output is expected to be in 8x8 /// macro blocks. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image</param> /// <param name="QuantInvTable">Inverse quantization tables for JPEG decoding created using QuantInvTableInit()</param> /// <param name="oSizeRoi">Roi size (in macro blocks?).</param> public static void DCTQuantInv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, CudaDeviceVariable <ushort> QuantInvTable, NppiSize oSizeRoi) { NppStatus status; status = NPPNativeMethods.NPPi.ImageCompression.nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R(src.DevicePointer, src.Pitch, dst.DevicePointer, dst.Pitch, QuantInvTable.DevicePointer, oSizeRoi); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Initializes a quantization table for DCTQuantInv8x8LS().<para/> /// The DCTQuantFwd8x8LS() method uses a quantization table /// in a 16-bit format allowing for faster processing. In addition it converts the /// data order from zigzag layout to original row-order layout. Typically raw /// quantization tables are stored in zigzag format.<para/> /// This method is a host method. It consumes and produces host data. I.e. the pointers /// passed to this function must be host pointers. The resulting table needs to be /// transferred to device memory in order to be used with DCTQuantFwd8x8LS() /// function. /// </summary> /// <param name="QuantRawTable">Raw quantization table.</param> /// <param name="QuantInvRawTable">Inverse quantization table.</param> public static void QuantInvTableInit(byte[] QuantRawTable, ushort[] QuantInvRawTable) { NppStatus status; status = NPPNativeMethods.NPPi.ImageCompression.nppiQuantInvTableInit_JPEG_8u16u(QuantRawTable, QuantInvRawTable); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiQuantInvTableInit_JPEG_8u16u", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Creates a Huffman table in a format that is suitable for the encoder. /// </summary> /// <param name="pRawHuffmanTable">Huffman table formated as specified in the JPEG standard.</param> /// <param name="eTableType">Enum specifying type of table (nppiDCTable or nppiACTable).</param> /// <param name="pHuffmanSpec">Pointer to the Huffman table for the decoder</param> /// <returns>Huffman table for the encoder</returns> public static void EncodeHuffmanSpecInit(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType, NppiEncodeHuffmanSpec pHuffmanSpec) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecInit_JPEG(pRawHuffmanTable, eTableType, pHuffmanSpec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecInit_JPEG", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// image resize batch for variable ROI. /// </summary> /// <param name="nMaxWidth">Size in pixels of the entire smallest source image width and height, may be from different images.</param> /// <param name="nMaxHeight">Region of interest in the source images (may overlap source image size width and height).</param> /// <param name="pBatchSrc">Size in pixels of the entire smallest destination image width and height, may be from different images.</param> /// <param name="pBatchDst">Region of interest in the destination images (may overlap destination image size width and height).</param> /// <param name="nBatchSize">Device memory pointer to nBatchSize list of NppiResizeBatchCXR structures.</param> /// <param name="pBatchROI">Device pointer to NppiResizeBatchROI_Advanced list of per-image variable ROIs.User needs to initialize this structure and copy it to device.</param> /// <param name="eInterpolation">The type of eInterpolation to perform resampling.</param> public static void ResizeBatchAdvanced(int nMaxWidth, int nMaxHeight, CudaDeviceVariable<NppiImageDescriptor> pBatchSrc, CudaDeviceVariable<NppiImageDescriptor> pBatchDst, CudaDeviceVariable<NppiResizeBatchROI_Advanced> pBatchROI, uint nBatchSize, InterpolationMode eInterpolation) { NppStatus status = NPPNativeMethods.NPPi.GeometricTransforms.nppiResizeBatch_16f_C1R_Advanced(nMaxWidth, nMaxHeight, pBatchSrc.DevicePointer, pBatchDst.DevicePointer, pBatchROI.DevicePointer, pBatchDst.Size, eInterpolation); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiResizeBatch_16f_C1R_Advanced", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Apply quality factor to raw 8-bit quantization table.<para/> /// This is effectively and in-place method that modifies a given raw /// quantization table based on a quality factor.<para/> /// Note that this method is a host method and that the pointer to the /// raw quantization table is a host pointer. /// </summary> /// <param name="QuantRawTable">Raw quantization table.</param> /// <param name="nQualityFactor">Quality factor for the table. Range is [1:100].</param> public static void QuantFwdRawTableInit(byte[] QuantRawTable, int nQualityFactor) { NppStatus status; status = NPPNativeMethods.NPPi.ImageCompression.nppiQuantFwdRawTableInit_JPEG_8u(QuantRawTable, nQualityFactor); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiQuantFwdRawTableInit_JPEG_8u", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Frees the memory allocated by nppiEncodeHuffmanSpecInitAlloc_JPEG. /// </summary> /// <param name="pHuffmanSpec">Pointer to the Huffman table for the encoder</param> public static void EncodeHuffmanSpecFree(NppiEncodeHuffmanSpec pHuffmanSpec) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecFree_JPEG(pHuffmanSpec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecFree_JPEG", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Huffman Decoding of the JPEG decoding on the host.<para/> /// Input is expected in byte stuffed huffman encoded JPEG scan and output is expected to be 64x1 macro blocks. /// </summary> /// <param name="pSrc">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDst">Destination image pointer</param> /// <param name="nDstStep">destination image line step.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> public static void DecodeHuffmanScanHost(byte[] pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, short[] pDst, int nDstStep, NppiDecodeHuffmanSpec pHuffmanTableDC, NppiDecodeHuffmanSpec pHuffmanTableAC, NppiSize oSizeROI) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiDecodeHuffmanScanHost_JPEG_8u16s_P1R(pSrc, pSrc.Length, restartInterval, Ss, Se, Ah, Al, pDst, nDstStep, pHuffmanTableDC, pHuffmanTableAC, oSizeROI); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDecodeHuffmanScanHost_JPEG_8u16s_P1R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Huffman Encoding of the JPEG Encoding.<para/> /// Input is expected to be 64x1 macro blocks and output is expected as byte stuffed huffman encoded JPEG scan. /// </summary> /// <param name="pSrc">Source image.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDst">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="nLength">Byte length of the huffman encoded JPEG scan.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> /// <param name="buffer">Scratch buffer</param> public static void EncodeHuffmanScan(NPPImage_16sC1 pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, CudaDeviceVariable <byte> pDst, ref int nLength, NppiEncodeHuffmanSpec pHuffmanTableDC, NppiEncodeHuffmanSpec pHuffmanTableAC, NppiSize oSizeROI, CudaDeviceVariable <byte> buffer) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanScan_JPEG_8u16s_P1R(pSrc.DevicePointer, pSrc.Pitch, restartInterval, Ss, Se, Ah, Al, pDst.DevicePointer, ref nLength, pHuffmanTableDC, pHuffmanTableAC, oSizeROI, buffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanScan_JPEG_8u16s_P1R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Graphcut of a flow network (32bit floating point edge capacities). The /// function computes the minimal cut (graphcut) of a 2D regular 4-connected /// graph. <para/> /// The inputs are the capacities of the horizontal (in transposed form), /// vertical and terminal (source and sink) edges. The capacities to source and /// sink /// are stored as capacity differences in the terminals array /// ( terminals(x) = source(x) - sink(x) ). The implementation assumes that the /// edge capacities /// for boundary edges that would connect to nodes outside the specified domain /// are set to 0 (for example left(0,*) == 0). If this is not fulfilled the /// computed labeling may be wrong!<para/> /// The computed binary labeling is encoded as unsigned 8bit values (0 and >0). /// </summary> /// <param name="Terminals">Pointer to differences of terminal edge capacities</param> /// <param name="LeftTransposed">Pointer to transposed left edge capacities</param> /// <param name="RightTransposed">Pointer to transposed right edge capacities</param> /// <param name="Top">Pointer to top edge capacities (top(*,0) must be 0)</param> /// <param name="Bottom">Pointer to bottom edge capacities (bottom(*,height-1)</param> /// <param name="Label">Pointer to destination label image </param> /// <returns></returns> public void GraphCut(NPPImage_32fC1 Terminals, NPPImage_32fC1 LeftTransposed, NPPImage_32fC1 RightTransposed, NPPImage_32fC1 Top, NPPImage_32fC1 Bottom, NPPImage_8uC1 Label) { status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut_32f8u(Terminals.DevicePointer, LeftTransposed.DevicePointer, RightTransposed.DevicePointer, Top.DevicePointer, Bottom.DevicePointer, Terminals.Pitch, LeftTransposed.Pitch, _size, Label.DevicePointer, Label.Pitch, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut_32f8u", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// Graphcut of a flow network (32bit floating point edge capacities). The /// function computes the minimal cut (graphcut) of a 2D regular 4-connected /// graph. <para/> /// The inputs are the capacities of the horizontal (in transposed form), /// vertical and terminal (source and sink) edges. The capacities to source and /// sink /// are stored as capacity differences in the terminals array /// ( terminals(x) = source(x) - sink(x) ). The implementation assumes that the /// edge capacities /// for boundary edges that would connect to nodes outside the specified domain /// are set to 0 (for example left(0,*) == 0). If this is not fulfilled the /// computed labeling may be wrong!<para/> /// The computed binary labeling is encoded as unsigned 8bit values (0 and >0). /// </summary> /// <param name="Terminals">Pointer to differences of terminal edge capacities</param> /// <param name="LeftTransposed">Pointer to transposed left edge capacities</param> /// <param name="RightTransposed">Pointer to transposed right edge capacities</param> /// <param name="Top">Pointer to top edge capacities (top(*,0) must be 0)</param> /// <param name="Bottom">Pointer to bottom edge capacities (bottom(*,height-1)</param> /// <param name="Label">Pointer to destination label image </param> /// <returns></returns> public void GraphCut(CudaPitchedDeviceVariable <float> Terminals, CudaPitchedDeviceVariable <float> LeftTransposed, CudaPitchedDeviceVariable <float> RightTransposed, CudaPitchedDeviceVariable <float> Top, CudaPitchedDeviceVariable <float> Bottom, CudaPitchedDeviceVariable <byte> Label) { status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut_32f8u(Terminals.DevicePointer, LeftTransposed.DevicePointer, RightTransposed.DevicePointer, Top.DevicePointer, Bottom.DevicePointer, Terminals.Pitch, LeftTransposed.Pitch, _size, Label.DevicePointer, Label.Pitch, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut_32f8u", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// Initializes a job that has to be called at the beginning of decoding. /// </summary> public NppiJpegDecodeJob JobCreateMemzero() { NppiJpegDecodeJob ret = new NppiJpegDecodeJob(); status = NPPNativeMethods.NPPi.CompressionDCT.nppiJpegDecodeJobCreateMemzero(ref ret); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiJpegDecodeJobCreateMemzero", status)); NPPException.CheckNppStatus(status, this); return(ret); }
/// <summary> /// Calculates sizes of additional buffers used by the job. /// </summary> /// <param name="pJob">has to point to properly initialized job</param> public SizeT JobMemorySize(NppiJpegDecodeJob pJob) { SizeT ret = new SizeT(); status = NPPNativeMethods.NPPi.CompressionDCT.nppiJpegDecodeJobMemorySize(ref pJob, ref ret); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiJpegDecodeJobMemorySize", status)); NPPException.CheckNppStatus(status, this); return(ret); }
/// <summary> /// Returns the length of the NppiEncodeHuffmanSpec structure. /// </summary> /// <returns>length of the NppiEncodeHuffmanSpec structure.</returns> public static int EncodeHuffmanSpecGetBufSize() { NppStatus status; int res = 0; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecGetBufSize_JPEG(ref res); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecGetBufSize_JPEG", status)); NPPException.CheckNppStatus(status, null); return(res); }
/// <summary> /// Calculates the size of the temporary buffer for huffman encoding. /// </summary> /// <param name="oSize">Image Dimension</param> /// <param name="nChannels">Number of channels</param> /// <returns>the size of the temporary buffer</returns> public static int EncodeHuffmanGetSize(NppiSize oSize, int nChannels) { int size = 0; NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanGetSize(oSize, nChannels, ref size); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanGetSize", status)); NPPException.CheckNppStatus(status, null); return(size); }
/// <summary> /// Allocates memory and creates a Huffman table in a format that is suitable for the encoder. /// </summary> /// <param name="pRawHuffmanTable">Huffman table formated as specified in the JPEG standard.</param> /// <param name="eTableType">Enum specifying type of table (nppiDCTable or nppiACTable).</param> /// <returns>Huffman table for the encoder.</returns> public static NppiEncodeHuffmanSpec EncodeHuffmanSpecInitAlloc(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType) { NppiEncodeHuffmanSpec spec = new NppiEncodeHuffmanSpec(); NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecInitAlloc_JPEG(pRawHuffmanTable, eTableType, ref spec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecInitAlloc_JPEG", status)); NPPException.CheckNppStatus(status, null); return(spec); }
/// <summary> /// For IDisposable /// </summary> /// <param name="fDisposing"></param> protected virtual void Dispose(bool fDisposing) { if (fDisposing && !disposed) { //Ignore if failing status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTFree(_state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTFree", status)); disposed = true; } if (!fDisposing && !disposed) Debug.WriteLine(String.Format("NPP not-disposed warning: {0}", this.GetType())); }
/// <summary> /// /// </summary> /// <param name="size">Graph size</param> public GraphCut4(NppiSize size) { _size = size; int bufferSize = 0; status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcutGetSize(_size, ref bufferSize); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcutGetSize", status)); NPPException.CheckNppStatus(status, this); _buffer = new CudaDeviceVariable<byte>(bufferSize); _state = new NppiGraphcutState(); status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcutInitAlloc(_size, ref _state, _buffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcutInitAlloc", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// For IDisposable /// </summary> /// <param name="fDisposing"></param> protected virtual void Dispose(bool fDisposing) { if (fDisposing && !disposed) { //Ignore if failing status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTFree(_state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTFree", status)); disposed = true; } if (!fDisposing && !disposed) { Debug.WriteLine(String.Format("NPP not-disposed warning: {0}", this.GetType())); } }
/// <summary> /// /// </summary> /// <param name="size">Graph size</param> public GraphCut8f(NppiSize size) { _size = size; int bufferSize = 0; status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut8GetSize(_size, ref bufferSize); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut8GetSize", status)); NPPException.CheckNppStatus(status, this); _buffer = new CudaDeviceVariable <byte>(bufferSize); _state = new NppiGraphcutState(); status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut8InitAlloc(_size, ref _state, _buffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut8InitAlloc", status)); NPPException.CheckNppStatus(status, this); }
internal static void CheckNppStatus(NppStatus status, bool throwWarnings, object sender) { if (status == NppStatus.NoError) { return; } if ((int)status < 0) { throw new NPPException(status); } if (throwWarnings) { throw new NPPWarning(status); } else { NPPWarningHandler.GetInstance().NotifyNPPWarning(sender, status, GetErrorMessageFromNppStatus(status)); } }
/// <summary> /// Huffman Decoding of the JPEG decoding on the host.<para/> /// Input is expected in byte stuffed huffman encoded JPEG scan and output is expected to be 64x1 macro blocks. /// </summary> /// <param name="pSrc">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDstY">Destination first image channel</param> /// <param name="pDstCb">Destination second image channel</param> /// <param name="pDstCr">Destination third image channel</param> /// <param name="nDstStep">destination image line step.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> public static void DecodeHuffmanScanHost(byte[] pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, short[] pDstY, short[] pDstCb, short[] pDstCr, int[] nDstStep, NppiDecodeHuffmanSpec[] pHuffmanTableDC, NppiDecodeHuffmanSpec[] pHuffmanTableAC, NppiSize[] oSizeROI) { NppStatus status; GCHandle[] handles = new GCHandle[3]; try { handles[0] = GCHandle.Alloc(pDstY, GCHandleType.Pinned); handles[1] = GCHandle.Alloc(pDstCb, GCHandleType.Pinned); handles[2] = GCHandle.Alloc(pDstCr, GCHandleType.Pinned); IntPtr[] temp = new IntPtr[] { handles[0].AddrOfPinnedObject(), handles[1].AddrOfPinnedObject(), handles[2].AddrOfPinnedObject() }; status = NPPNativeMethods.NPPi.CompressionDCT.nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pSrc, pSrc.Length, restartInterval, Ss, Se, Ah, Al, temp, nDstStep, pHuffmanTableDC, pHuffmanTableAC, oSizeROI); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R", status)); } finally { handles[0].Free(); handles[1].Free(); handles[2].Free(); } NPPException.CheckNppStatus(status, null); }
internal static void CheckNppStatus(NppStatus status, object sender) { CheckNppStatus(status, false, sender); }
/// <summary> /// /// </summary> /// <param name="error"></param> /// <param name="message"></param> /// <param name="exception"></param> public NPPException(NppStatus error, string message, Exception exception) : base(message, exception) { this._nppError = error; }
/// <summary> /// /// </summary> /// <param name="error"></param> public NPPException(NppStatus error) : base(GetErrorMessageFromNppStatus(error)) { this._nppError = error; }
/// <summary> /// Allocates memory and creates a Huffman table in a format that is suitable for the encoder. /// </summary> /// <param name="pRawHuffmanTable">Huffman table formated as specified in the JPEG standard.</param> /// <param name="eTableType">Enum specifying type of table (nppiDCTable or nppiACTable).</param> /// <returns>Huffman table for the encoder.</returns> public static NppiEncodeHuffmanSpec EncodeHuffmanSpecInitAllocHost_JPEG(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType) { NppiEncodeHuffmanSpec spec = new NppiEncodeHuffmanSpec(); NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecInitAlloc_JPEG(pRawHuffmanTable, eTableType, ref spec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecInitAlloc_JPEG", status)); NPPException.CheckNppStatus(status, null); return spec; }
internal static string GetErrorMessageFromNppStatus(NppStatus error) { string message = string.Empty; switch (error) { case NppStatus.NotSupportedModeError: break; case NppStatus.InvalidHostPointerError: break; case NppStatus.InvalidDevicePointerError: break; case NppStatus.LUTPaletteBitsizeError: break; case NppStatus.ZCModeNotSupportedError: message = "ZeroCrossing mode not supported."; break; case NppStatus.NotSufficientComputeCapability: break; case NppStatus.TextureBindError: break; case NppStatus.WrongIntersectionRoiError: break; case NppStatus.HaarClassifierPixelMatchError: break; case NppStatus.MemfreeError: break; case NppStatus.MemsetError: break; case NppStatus.MemcpyError: break; case NppStatus.AlignmentError: break; case NppStatus.CudaKernelExecutionError: break; case NppStatus.RoundModeNotSupportedError: message = "Unsupported round mode."; break; case NppStatus.QualityIndexError: message = "Image pixels are constant for quality index."; break; case NppStatus.ResizeNoOperationError: message = "One of the output image dimensions is less than 1 pixel."; break; case NppStatus.OverflowError: message = "Number overflows the upper or lower limit of the data type."; break; case NppStatus.NotEvenStepError: message = "Step value is not pixel multiple."; break; case NppStatus.HistogramNumberOfLevelsError: message = "Number of levels for histogram is less than 2."; break; case NppStatus.LutMumberOfLevelsError: message = "Number of levels for LUT is less than 2."; break; case NppStatus.ChannelOrderError: message = "Wrong order of the destination channels."; break; case NppStatus.ZeroMaskValueError: message = "All values of the mask are zero."; break; case NppStatus.QuadrangleError: message = "The quadrangle is nonconvex or degenerates into triangle, line or point."; break; case NppStatus.RectangleError: message = "Size of the rectangle region is less than or equal to 1."; break; case NppStatus.CoefficientError: message = "Unallowable values of the transformation coefficients."; break; case NppStatus.NumberOfChannelsError: message = "Bad or unsupported number of channels."; break; case NppStatus.ChannelOfInterestError: message = "Channel of interest is not 1, 2, or 3."; break; case NppStatus.DivisorError: message = "Divisor is equal to zero."; break; case NppStatus.CorruptedDataError: message = "Processed data is corrupted."; break; case NppStatus.ChannelError: message = "Illegal channel index."; break; case NppStatus.StrideError: message = "Stride is less than the row length."; break; case NppStatus.AnchorError: message = "Anchor point is outside mask."; break; case NppStatus.MaskSizeError: message = "Lower bound is larger than upper bound."; break; case NppStatus.ResizeFactorError: break; case NppStatus.InterpolationError: break; case NppStatus.MirrorFlipError: break; case NppStatus.Moment00ZeroErro: break; case NppStatus.ThresholdNegativeLevelError: break; case NppStatus.ThresholdError: break; case NppStatus.ContextMatchError: break; case NppStatus.FFTFlagError: break; case NppStatus.FFTOrderError: break; case NppStatus.StepError: message = "Step is less or equal zero."; break; case NppStatus.ScaleRangeError: break; case NppStatus.DataTypeError: break; case NppStatus.OutOfRangeError: break; case NppStatus.DivideByZeroError: break; case NppStatus.MemoryAllocationError: break; case NppStatus.NullPointerError: break; case NppStatus.RangeError: break; case NppStatus.SizeError: break; case NppStatus.BadArgumentError: break; case NppStatus.NoMemoryError: break; case NppStatus.NotImplementedError: break; case NppStatus.Error: break; case NppStatus.ErrorReserved: break; case NppStatus.NoError: message = "Successful operation."; break; //case NppStatus.Success: // break; case NppStatus.NoOperationWarning: message = "Indicates that no operation was performed."; break; case NppStatus.DivideByZeroWarning: message = "Divisor is zero however does not terminate the execution."; break; case NppStatus.AffineQuadIncorrectWarning: message = "Indicates that the quadrangle passed to one of affine warping functions doesn't have necessary properties. First 3 vertices are used, the fourth vertex discarded."; break; case NppStatus.WrongIntersectionRoiWarning: message = "The given ROI has no interestion with either the source or destination ROI. Thus no operation was performed."; break; case NppStatus.WrongIntersectionQuadWarning: message = "The given quadrangle has no intersection with either the source or destination ROI. Thus no operation was performed."; break; case NppStatus.DoubleSizeWarning: message = "Image size isn't multiple of two. Indicates that in case of 422/411/420 sampling the ROI width/height was modified for proper processing."; break; case NppStatus.MisalignedDstRoiWarning: message = "Speed reduction due to uncoalesced memory accesses warning."; break; default: break; } return error.ToString() + ": " + message; }
/// <summary> /// Calculates the size of the temporary buffer for huffman encoding. /// </summary> /// <param name="oSize">Image Dimension</param> /// <param name="nChannels">Number of channels</param> /// <returns>the size of the temporary buffer</returns> public static int EncodeHuffmanGetSize(NppiSize oSize, int nChannels) { int size = 0; NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanGetSize(oSize, nChannels, ref size); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanGetSize", status)); NPPException.CheckNppStatus(status, null); return size; }
/// <summary> /// Initializes a job that has to be called at the end of decoding, /// in order to convert temporary representation of DCT coefficients /// to the final one. /// </summary> /// <param name="pJob">pJob.pFrame should point to valid frame description. /// pJob.pScan will be overwritten.</param> public void DecodeJobCreateFinalize(ref NppiJpegDecodeJob pJob) { status = NPPNativeMethods.NPPi.CompressionDCT.nppiJpegDecodeJobCreateFinalize(ref pJob); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiJpegDecodeJobCreateFinalize", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// /// </summary> /// <param name="status"></param> /// <param name="message"></param> public NPPWarningEventArgs(NppStatus status, string message) { _status = status; _message = message; }
internal void NotifyNPPWarning(object sender, NppStatus status, string message) { NPPWarningEventArgs e = new NPPWarningEventArgs(status, message); RaiseOnNPPWarning(sender, e); }
/// <summary> /// Huffman Encoding of the JPEG Encoding.<para/> /// Input is expected to be 64x1 macro blocks and output is expected as byte stuffed huffman encoded JPEG scan. /// </summary> /// <param name="pSrc">Source image.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDst">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="nLength">Byte length of the huffman encoded JPEG scan.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> /// <param name="buffer">Scratch buffer</param> public static void EncodeHuffmanScan(NPPImage_16sC1[] pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, CudaDeviceVariable<byte> pDst, ref int nLength, NppiEncodeHuffmanSpec[] pHuffmanTableDC, NppiEncodeHuffmanSpec[] pHuffmanTableAC, NppiSize[] oSizeROI, CudaDeviceVariable<byte> buffer) { NppStatus status; CUdeviceptr[] srcs = new CUdeviceptr[] { pSrc[0].DevicePointer, pSrc[1].DevicePointer, pSrc[2].DevicePointer }; int[] steps = new int[] { pSrc[0].Pitch, pSrc[1].Pitch, pSrc[2].Pitch }; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanScan_JPEG_8u16s_P3R(srcs, steps, restartInterval, Ss, Se, Ah, Al, pDst.DevicePointer, ref nLength, pHuffmanTableDC, pHuffmanTableAC, oSizeROI, buffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanScan_JPEG_8u16s_P3R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Frees the memory allocated by nppiEncodeHuffmanSpecInitAlloc_JPEG. /// </summary> /// <param name="pHuffmanSpec">Pointer to the Huffman table for the encoder</param> public static void EncodeHuffmanSpecFree_JPEG(NppiEncodeHuffmanSpec pHuffmanSpec) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecFree_JPEG(pHuffmanSpec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecFree_JPEG", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Inverse DCT, de-quantization and level shift part of the JPEG decoding. /// Input is expected in 64x1 macro blocks and output is expected to be in 8x8 /// macro blocks. The new version of the primitive takes the ROI in image pixel size and /// works with DCT coefficients that are in zig-zag order. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image</param> /// <param name="QuantInvTable">Quantization Table in zig-zag order.</param> /// <param name="oSizeRoi">Roi size (in pixels).</param> public void DCTQuantInv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, NppiSize oSizeRoi, CudaDeviceVariable<byte> QuantInvTable) { status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW(src.DevicePointer, src.Pitch, dst.DevicePointer, dst.Pitch, QuantInvTable.DevicePointer, oSizeRoi, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTQuantInv8x8LS_JPEG_16s8u_C1R_NEW", status)); NPPException.CheckNppStatus(status, null); }
internal static void CheckNppStatus(NppStatus status, bool throwWarnings, object sender) { if (status == NppStatus.NoError) return; if ((int)status < 0) throw new NPPException(status); if (throwWarnings) throw new NPPWarning(status); else NPPWarningHandler.GetInstance().NotifyNPPWarning(sender, status, GetErrorMessageFromNppStatus(status)); }
/// <summary> /// Creates a Huffman table in a format that is suitable for the encoder. /// </summary> /// <param name="pRawHuffmanTable">Huffman table formated as specified in the JPEG standard.</param> /// <param name="eTableType">Enum specifying type of table (nppiDCTable or nppiACTable).</param> /// <param name="pHuffmanSpec">Pointer to the Huffman table for the decoder</param> /// <returns>Huffman table for the encoder</returns> public static void EncodeHuffmanSpecInit_JPEG(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType, NppiEncodeHuffmanSpec pHuffmanSpec) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecInit_JPEG(pRawHuffmanTable, eTableType, pHuffmanSpec); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecInit_JPEG", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Inverse DCT, de-quantization and level shift part of the JPEG decoding, 16-bit short integer. /// Input is expected in 64x1 macro blocks and output is expected to be in 8x8 /// macro blocks. The new version of the primitive takes the ROI in image pixel size and /// works with DCT coefficients that are in zig-zag order. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image</param> /// <param name="pQuantizationTable">Quantization Table in zig-zag order.</param> /// <param name="oSizeRoi">Roi size (in pixels).</param> public void DCTQuant16Inv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, NppiSize oSizeRoi, CudaDeviceVariable <ushort> pQuantizationTable) { status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTQuant16Inv8x8LS_JPEG_16s8u_C1R_NEW(src.DevicePointer, src.Pitch, dst.DevicePointer, dst.Pitch, pQuantizationTable.DevicePointer, oSizeRoi, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTQuant16Inv8x8LS_JPEG_16s8u_C1R_NEW", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// Huffman Decoding of the JPEG decoding on the host.<para/> /// Input is expected in byte stuffed huffman encoded JPEG scan and output is expected to be 64x1 macro blocks. /// </summary> /// <param name="pSrc">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDst">Destination image pointer</param> /// <param name="nDstStep">destination image line step.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> public static void DecodeHuffmanScanHost(byte[] pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, IntPtr[] pDst, int[] nDstStep, NppiDecodeHuffmanSpec[] pHuffmanTableDC, NppiDecodeHuffmanSpec[] pHuffmanTableAC, NppiSize[] oSizeROI) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R(pSrc, pSrc.Length, restartInterval, Ss, Se, Ah, Al, pDst, nDstStep, pHuffmanTableDC, pHuffmanTableAC, oSizeROI); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDecodeHuffmanScanHost_JPEG_8u16s_P3R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Graphcut of a flow network (32bit floating point edge capacities). The /// function computes the minimal cut (graphcut) of a 2D regular 8-connected /// graph. <para/> /// The inputs are the capacities of the horizontal (in transposed form), /// vertical and terminal (source and sink) edges. The capacities to source and /// sink /// are stored as capacity differences in the terminals array /// ( terminals(x) = source(x) - sink(x) ). The implementation assumes that the /// edge capacities /// for boundary edges that would connect to nodes outside the specified domain /// are set to 0 (for example left(0,*) == 0). If this is not fulfilled the /// computed labeling may be wrong!<para/> /// The computed binary labeling is encoded as unsigned 8bit values (0 and >0). /// </summary> /// <param name="Terminals">Pointer to differences of terminal edge capacities</param> /// <param name="LeftTransposed">Pointer to transposed left edge capacities</param> /// <param name="RightTransposed">Pointer to transposed right edge capacities</param> /// <param name="Top">Pointer to top edge capacities (top(*,0) must be 0)</param> /// <param name="TopLeft">Pointer to top left edge capacities (topleft(*,0) </param> /// <param name="TopRight">Pointer to top right edge capacities (topright(*,0)</param> /// <param name="Bottom">Pointer to bottom edge capacities (bottom(*,height-1)</param> /// <param name="BottomLeft">Pointer to bottom left edge capacities </param> /// <param name="BottomRight">Pointer to bottom right edge capacities </param> /// <param name="Label">Pointer to destination label image </param> /// <returns></returns> public void GraphCut(NPPImage_32fC1 Terminals, NPPImage_32fC1 LeftTransposed, NPPImage_32fC1 RightTransposed, NPPImage_32fC1 Top, NPPImage_32fC1 TopLeft, NPPImage_32fC1 TopRight, NPPImage_32fC1 Bottom, NPPImage_32fC1 BottomLeft, NPPImage_32fC1 BottomRight, NPPImage_8uC1 Label) { status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut8_32f8u(Terminals.DevicePointer, LeftTransposed.DevicePointer, RightTransposed.DevicePointer, Top.DevicePointer, TopLeft.DevicePointer, TopRight.DevicePointer, Bottom.DevicePointer, BottomLeft.DevicePointer, BottomRight.DevicePointer, Terminals.Pitch, LeftTransposed.Pitch, _size, Label.DevicePointer, Label.Pitch, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut8_32f8u", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// Inverse DCT in WebP decoding. Input is the bitstream that contains the coefficients of 16x16 blocks. /// These coefficients are based on a 4x4 sub-block unit, e.g., /// Coeffs in 0th 4x4 block, 1st 4x4 block 2nd 4x4 block, etc. /// Output is the coefficients after inverse DCT transform. /// The output is put in an image format (i.e. raster scan order), different from the input order. /// </summary> /// <param name="src">Source image.</param> /// <param name="dst">Destination image</param> /// <param name="oSizeRoi">Roi size (in pixels).</param> public void DCTQuant16Fwd8x8LS(NPPImage_16sC1 src, NPPImage_16sC1 dst, NppiSize oSizeRoi) { status = NPPNativeMethods.NPPi.CompressionDCT.nppiDCTInv4x4_WebP_16s_C1R(src.DevicePointer, src.Pitch, dst.DevicePointer, dst.Pitch, oSizeRoi); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiDCTInv4x4_WebP_16s_C1R", status)); NPPException.CheckNppStatus(status, this); }
/// <summary> /// Huffman Encoding of the JPEG Encoding.<para/> /// Input is expected to be 64x1 macro blocks and output is expected as byte stuffed huffman encoded JPEG scan. /// </summary> /// <param name="pSrc">Source image.</param> /// <param name="restartInterval">Restart Interval, see JPEG standard.</param> /// <param name="Ss">Start Coefficient, see JPEG standard.</param> /// <param name="Se">End Coefficient, see JPEG standard.</param> /// <param name="Ah">Bit Approximation High, see JPEG standard.</param> /// <param name="Al">Bit Approximation Low, see JPEG standard.</param> /// <param name="pDst">Byte-stuffed huffman encoded JPEG scan.</param> /// <param name="nLength">Byte length of the huffman encoded JPEG scan.</param> /// <param name="pHuffmanTableDC">DC Huffman table.</param> /// <param name="pHuffmanTableAC">AC Huffman table.</param> /// <param name="oSizeROI">ROI</param> /// <param name="buffer">Scratch buffer</param> public static void EnodeHuffmanScan(NPPImage_16sC1 pSrc, int restartInterval, int Ss, int Se, int Ah, int Al, CudaDeviceVariable<byte> pDst, ref int nLength, NppiEncodeHuffmanSpec pHuffmanTableDC, NppiEncodeHuffmanSpec pHuffmanTableAC, NppiSize oSizeROI, CudaDeviceVariable<byte> buffer) { NppStatus status; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanScan_JPEG_8u16s_P1R(pSrc.DevicePointer, pSrc.Pitch, restartInterval, Ss, Se, Ah, Al, pDst.DevicePointer, ref nLength, pHuffmanTableDC, pHuffmanTableAC, oSizeROI, buffer.DevicePointer); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanScan_JPEG_8u16s_P1R", status)); NPPException.CheckNppStatus(status, null); }
/// <summary> /// Returns the length of the NppiEncodeHuffmanSpec structure. /// </summary> /// <returns>length of the NppiEncodeHuffmanSpec structure.</returns> public static int EncodeHuffmanSpecGetBufSize_JPEG() { NppStatus status; int res = 0; status = NPPNativeMethods.NPPi.CompressionDCT.nppiEncodeHuffmanSpecGetBufSize_JPEG(ref res); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiEncodeHuffmanSpecGetBufSize_JPEG", status)); NPPException.CheckNppStatus(status, null); return res; }
/// <summary> /// Graphcut of a flow network (32bit floating point edge capacities). The /// function computes the minimal cut (graphcut) of a 2D regular 8-connected /// graph. <para/> /// The inputs are the capacities of the horizontal (in transposed form), /// vertical and terminal (source and sink) edges. The capacities to source and /// sink /// are stored as capacity differences in the terminals array /// ( terminals(x) = source(x) - sink(x) ). The implementation assumes that the /// edge capacities /// for boundary edges that would connect to nodes outside the specified domain /// are set to 0 (for example left(0,*) == 0). If this is not fulfilled the /// computed labeling may be wrong!<para/> /// The computed binary labeling is encoded as unsigned 8bit values (0 and >0). /// </summary> /// <param name="Terminals">Pointer to differences of terminal edge capacities</param> /// <param name="LeftTransposed">Pointer to transposed left edge capacities</param> /// <param name="RightTransposed">Pointer to transposed right edge capacities</param> /// <param name="Top">Pointer to top edge capacities (top(*,0) must be 0)</param> /// <param name="TopLeft">Pointer to top left edge capacities (topleft(*,0) </param> /// <param name="TopRight">Pointer to top right edge capacities (topright(*,0)</param> /// <param name="Bottom">Pointer to bottom edge capacities (bottom(*,height-1)</param> /// <param name="BottomLeft">Pointer to bottom left edge capacities </param> /// <param name="BottomRight">Pointer to bottom right edge capacities </param> /// <param name="Label">Pointer to destination label image </param> /// <returns></returns> public void GraphCut(CudaPitchedDeviceVariable<float> Terminals, CudaPitchedDeviceVariable<float> LeftTransposed, CudaPitchedDeviceVariable<float> RightTransposed, CudaPitchedDeviceVariable<float> Top, CudaPitchedDeviceVariable<float> TopLeft, CudaPitchedDeviceVariable<float> TopRight, CudaPitchedDeviceVariable<float> Bottom, CudaPitchedDeviceVariable<float> BottomLeft, CudaPitchedDeviceVariable<float> BottomRight, CudaPitchedDeviceVariable<byte> Label) { status = NPPNativeMethods.NPPi.ImageLabeling.nppiGraphcut8_32f8u(Terminals.DevicePointer, LeftTransposed.DevicePointer, RightTransposed.DevicePointer, Top.DevicePointer, TopLeft.DevicePointer, TopRight.DevicePointer, Bottom.DevicePointer, BottomLeft.DevicePointer, BottomRight.DevicePointer, Terminals.Pitch, LeftTransposed.Pitch, _size, Label.DevicePointer, Label.Pitch, _state); Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nppiGraphcut8_32f8u", status)); NPPException.CheckNppStatus(status, this); }