예제 #1
0
        /// <summary>
        /// Retrieves the compressed stream from the encoder state that was previously used in one of the encoder functions.<para/>
        /// Note: Synchronizes on stream. For async use IntPtr!
        /// </summary>
        /// <param name="stream">CUDA stream where all the required device operations will be placed.</param>
        /// <returns>Byte array containing the data.</returns>
        public byte[] RetrieveBitstream(CudaStream stream)
        {
            SizeT size = new SizeT();

            res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, IntPtr.Zero, ref size, stream.Stream);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res));
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }

            byte[]   data   = new byte[size];
            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            try
            {
                IntPtr ptr = handle.AddrOfPinnedObject();
                res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, ptr, ref size, stream.Stream);
                Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res));
                stream.Synchronize();
            }
            finally
            {
                handle.Free();
            }
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }

            return(data);
        }
예제 #2
0
 public void GetImageInfo(byte[] data, ref int nComponents, ref nvjpegChromaSubsampling subsampling, int[] widths, int[] heights)
 {
     res = NvJpegNativeMethods.nvjpegGetImageInfo(_handle, data, data.Length, ref nComponents, ref subsampling, widths, heights);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegGetImageInfo", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #3
0
 // works only with the hardware decoder backend
 public void SetScaleFactor(nvjpegScaleFactor scale_factor)
 {
     res = NvJpegNativeMethods.nvjpegDecodeParamsSetScaleFactor(_params, scale_factor);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeParamsSetScaleFactor", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #4
0
 public void SetSamplingFactors(nvjpegChromaSubsampling chroma_subsampling, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegEncoderParamsSetSamplingFactors(_params, chroma_subsampling, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncoderParamsSetSamplingFactors", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #5
0
 public void DecodeBatchedInitialize(int batch_size, int max_cpuhreads, nvjpegOutputFormat output_format)
 {
     res = NvJpegNativeMethods.nvjpegDecodeBatchedInitialize(_nvJpeg.Handle, _state, batch_size, max_cpuhreads, output_format);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeBatchedInitialize", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #6
0
 public void SetEncoding(nvjpegJpegEncoding etype, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegEncoderParamsSetEncoding(_params, etype, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncoderParamsSetEncoding", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #7
0
 // starts decoding on host and save decode parameters to the state
 public void DecodeJpegHost(DecodeParams param, JpegStream stream)
 {
     res = NvJpegNativeMethods.nvjpegDecodeJpegHost(_nvJpeg.Handle, _decoder.Decoder, _state, param.Params, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeJpegHost", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #8
0
 public void DecodeBatchedInitialize(IntPtr[] data, SizeT[] lengths, nvjpegImage[] destinations, CUstream stream)
 {
     res = NvJpegNativeMethods.nvjpegDecodeBatched(_nvJpeg.Handle, _state, data, lengths, destinations, stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeBatched", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #9
0
 public void Parse(IntPtr data, SizeT length, int save_metadata, int save_stream)
 {
     res = NvJpegNativeMethods.nvjpegJpegStreamParse(_nvJpeg.Handle, data, length, save_metadata, save_stream, _stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegJpegStreamParse", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #10
0
 public void SetOptimizedHuffman(int optimized, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegEncoderParamsSetOptimizedHuffman(_params, optimized, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncoderParamsSetOptimizedHuffman", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #11
0
 public void DecodeBatchedPreAllocate(int batch_size, int width, int height, nvjpegChromaSubsampling chroma_subsampling, nvjpegOutputFormat output_format)
 {
     res = NvJpegNativeMethods.nvjpegDecodeBatchedPreAllocate(_nvJpeg.Handle, _state, batch_size, width, height, chroma_subsampling, output_format);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeBatchedPreAllocate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #12
0
 public void ParseHeader(byte[] data)
 {
     res = NvJpegNativeMethods.nvjpegJpegStreamParseHeader(_nvJpeg.Handle, data, data.Length, _stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegJpegStreamParseHeader", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #13
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);
     }
 }
예제 #14
0
 // set to true to allow conversion from CMYK to RGB or YUV that follows simple subtractive scheme
 public void SetAllowCMYK(int allow_cmyk)
 {
     res = NvJpegNativeMethods.nvjpegDecodeParamsSetAllowCMYK(_params, allow_cmyk);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeParamsSetAllowCMYK", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #15
0
 public void EncodeImage(EncoderParams encoderParams, nvjpegImage source, nvjpegInputFormat input_format, int image_width, int image_height, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegEncodeImage(_nvJpeg.Handle, _state, encoderParams.Params, ref source, input_format, image_width, image_height, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeImage", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #16
0
 // set to desired ROI. set to (0, 0, -1, -1) to disable ROI decode (decode whole image)
 public void SetROI(int offset_x, int offset_y, int roi_width, int roi_height)
 {
     res = NvJpegNativeMethods.nvjpegDecodeParamsSetROI(_params, offset_x, offset_y, roi_width, roi_height);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeParamsSetROI", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #17
0
        ///////////////////////////////////////////////////////////////////////////////////
        // Decode parameters //
        ///////////////////////////////////////////////////////////////////////////////////

        // set output pixel format - same value as in nvjpegDecode()
        public void SetOutputFormat(nvjpegOutputFormat output_format)
        {
            res = NvJpegNativeMethods.nvjpegDecodeParamsSetOutputFormat(_params, output_format);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeParamsSetOutputFormat", res));
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }
        }
예제 #18
0
 // copies huffman tables from parsed stream. should require same scans structure
 public void CopyHuffmanTables(EncoderParams encoderParams, JpegStream jpeg, CudaStream stream)
 {
     res = NvJpegNativeMethods.nvjpegEncoderParamsCopyHuffmanTables(_state, encoderParams.Params, jpeg.Stream, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncoderParamsCopyHuffmanTables", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #19
0
 // finishing async operations on the device
 public void DecodeJpegDevice(ref nvjpegImage destination, CudaStream cudaStream)
 {
     res = NvJpegNativeMethods.nvjpegDecodeJpegDevice(_nvJpeg.Handle, _decoder.Decoder, _state, ref destination, cudaStream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeJpegDevice", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #20
0
 public void AttachBuffer(BufferDevice buffer)
 {
     res = NvJpegNativeMethods.nvjpegStateAttachDeviceBuffer(_state, buffer.Buffer);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegStateAttachDeviceBuffer", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #21
0
 /// <summary>
 /// </summary>
 public NvJpeg(nvjpegBackend backend, uint flags)
 {
     _handle = new nvjpegHandle();
     res     = NvJpegNativeMethods.nvjpegCreateEx(backend, IntPtr.Zero, IntPtr.Zero, flags, ref _handle);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegCreateEx", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #22
0
 /// <summary>
 /// </summary>
 public NvJpeg()
 {
     _handle = new nvjpegHandle();
     res     = NvJpegNativeMethods.nvjpegCreateSimple(ref _handle);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegCreateSimple", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #23
0
 /// <summary>
 /// </summary>
 internal EncoderState(NvJpeg nvJpeg, CudaStream stream)
 {
     _nvJpeg = nvJpeg;
     _state  = new nvjpegEncoderState();
     res     = NvJpegNativeMethods.nvjpegEncoderStateCreate(nvJpeg.Handle, ref _state, stream.Stream);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncoderStateCreate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #24
0
 /// <summary>
 /// </summary>
 internal JpegDecoder(NvJpeg nvJpeg, nvjpegBackend backend)
 {
     _nvJpeg  = nvJpeg;
     _decoder = new nvjpegJpegDecoder();
     res      = NvJpegNativeMethods.nvjpegDecoderCreate(nvJpeg.Handle, backend, ref _decoder);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecoderCreate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #25
0
        /// <summary>
        /// Retrieves the compressed stream from the encoder state that was previously used in one of the encoder functions.
        /// </summary>
        /// <param name="ptr">Pointer to the buffer in the host memory where the compressed stream will be stored. Can be NULL</param>
        /// <param name="length">input buffer size.</param>
        /// <param name="stream">CUDA stream where all the required device operations will be placed.</param>
        /// <returns>On return the NVJPEG library will give the actual compressed stream size in this value.</returns>
        public SizeT RetrieveBitstream(IntPtr ptr, SizeT length, CudaStream stream)
        {
            res = NvJpegNativeMethods.nvjpegEncodeRetrieveBitstream(_nvJpeg.Handle, _state, ptr, ref length, stream.Stream);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegEncodeRetrieveBitstream", res));
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }

            return(length);
        }
예제 #26
0
 /// <summary>
 /// </summary>
 internal DecodeParams(NvJpeg nvJpeg)
 {
     _nvJpeg = nvJpeg;
     _params = new nvjpegDecodeParams();
     res     = NvJpegNativeMethods.nvjpegDecodeParamsCreate(nvJpeg.Handle, ref _params);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeParamsCreate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #27
0
 /// <summary>
 /// </summary>
 internal BufferDevice(NvJpeg nvJpeg, nvjpegDevAllocator deviceAllocator)
 {
     _nvJpeg = nvJpeg;
     _buffer = new nvjpegBufferDevice();
     res     = NvJpegNativeMethods.nvjpegBufferDeviceCreate(nvJpeg.Handle, ref deviceAllocator, ref _buffer);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegBufferDeviceCreate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }
예제 #28
0
        public bool DecodeBatchedSupportedEx(nvjpegDecodeParams decodeParams)
        {
            int batchSupported = 0;

            res = NvJpegNativeMethods.nvjpegDecodeBatchedSupportedEx(_nvJpeg.Handle, _stream, decodeParams, ref batchSupported);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecodeBatchedSupportedEx", res));
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }
            return(batchSupported > 0);
        }
예제 #29
0
        public bool JpegSupported(DecodeParams param, JpegStream stream)
        {
            int result = 0;

            res = NvJpegNativeMethods.nvjpegDecoderJpegSupported(_decoder, stream.Stream, param.Params, ref result);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecoderJpegSupported", res));
            if (res != nvjpegStatus.Success)
            {
                throw new NvJpegException(res);
            }
            return(result > 0);
        }
예제 #30
0
 /// <summary>
 /// </summary>
 internal DecoderState(NvJpeg nvJpeg, JpegDecoder decoder)
 {
     _nvJpeg  = nvJpeg;
     _decoder = decoder;
     _state   = new nvjpegJpegState();
     res      = NvJpegNativeMethods.nvjpegDecoderStateCreate(nvJpeg.Handle, decoder.Decoder, ref _state);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvjpegDecoderStateCreate", res));
     if (res != nvjpegStatus.Success)
     {
         throw new NvJpegException(res);
     }
 }