Exemplo n.º 1
0
 /// <summary>
 /// Decodes a single image, and writes the decoded image in the desired format to the output buffers. This function is asynchronous with respect to the host. All GPU tasks for this function will be submitted to the provided stream.
 /// </summary>
 /// <param name="data">the encoded data.</param>
 /// <param name="length">Size of the encoded data in bytes.</param>
 /// <param name="output_format">Format in which the decoded output will be saved.</param>
 /// <param name="destination">Pointer to the structure that describes the output destination. This structure should be on the host (CPU), but the pointers in this structure should be pointing to the device (i.e., GPU) memory.</param>
 /// <param name="stream">The CUDA stream where all of the GPU work will be submitted.</param>
 public void Decode(IntPtr data, SizeT length, nvjpegOutputFormat output_format, ref nvjpegImage destination, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegDecode(_nvJpeg.Handle, _state, data, length, output_format, ref destination, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecode", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Decodes a single image, and writes the decoded image in the desired format to the output buffers. This function is asynchronous with respect to the host. All GPU tasks for this function will be submitted to the provided stream.<para/>
        /// Note: Synchronizes on stream. For async use IntPtr!
        /// </summary>
        /// <param name="data">the encoded data.</param>
        /// <param name="output_format">Format in which the decoded output will be saved.</param>
        /// <param name="destination">Pointer to the structure that describes the output destination. This structure should be on the host (CPU), but the pointers in this structure should be pointing to the device (i.e., GPU) memory.</param>
        /// <param name="stream">The CUDA stream where all of the GPU work will be submitted.</param>
        public void Decode(byte[] data, nvjpegOutputFormat output_format, ref nvjpegImage destination, CudaStream stream)
        {
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                IntPtr ptr = handle.AddrOfPinnedObject();
                res = NvJpegNativeMethods.nvjpegDecode(_nvJpeg.Handle, _state, ptr, data.Length, output_format, ref destination, stream.Stream);
                Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecode", res));
                stream.Synchronize();
            }
            finally
            {
                handle.Free();
            }

            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }
        }