Class JPEGCompression
The JPEG standard defines a flow of level shift, DCT and quantization for forward JPEG transform and inverse level shift, IDCT and de-quantization for inverse JPEG transform. This group has the functions for both forward and inverse functions.
Inheritance
Implements
Inherited Members
Namespace: ManagedCuda.NPP
Assembly: NPP.dll
Syntax
public class JPEGCompression : IDisposable
Constructors
| Improve this Doc View SourceJPEGCompression()
Initializes DCT state structure and allocates additional resources
Declaration
public JPEGCompression()
Methods
| Improve this Doc View SourceDCTQuant16Fwd8x8LS(NPPImage_16sC1, NPPImage_16sC1, NppiSize)
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.
Declaration
public void DCTQuant16Fwd8x8LS(NPPImage_16sC1 src, NPPImage_16sC1 dst, NppiSize oSizeRoi)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1 | src | Source image. |
NPPImage_16sC1 | dst | Destination image |
NppiSize | oSizeRoi | Roi size (in pixels). |
DCTQuant16Fwd8x8LS(NPPImage_8uC1, NPPImage_16sC1, NppiSize, CudaDeviceVariable<UInt16>)
Forward DCT, quantization and level shift part of the JPEG encoding, 16-bit short integer. Input is expected in 8x8 macro blocks and output is expected to be in 64x1 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.
Declaration
public void DCTQuant16Fwd8x8LS(NPPImage_8uC1 src, NPPImage_16sC1 dst, NppiSize oSizeRoi, CudaDeviceVariable<ushort> pQuantizationTable)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_8uC1 | src | Source image. |
NPPImage_16sC1 | dst | Destination image |
NppiSize | oSizeRoi | Roi size (in pixels). |
CudaDeviceVariable<System.UInt16> | pQuantizationTable | Quantization Table in zig-zag order. |
DCTQuant16Inv8x8LS(NPPImage_16sC1, NPPImage_8uC1, NppiSize, CudaDeviceVariable<UInt16>)
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.
Declaration
public void DCTQuant16Inv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, NppiSize oSizeRoi, CudaDeviceVariable<ushort> pQuantizationTable)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1 | src | Source image. |
NPPImage_8uC1 | dst | Destination image |
NppiSize | oSizeRoi | Roi size (in pixels). |
CudaDeviceVariable<System.UInt16> | pQuantizationTable | Quantization Table in zig-zag order. |
DCTQuantFwd8x8LS(NPPImage_8uC1, NPPImage_16sC1, CudaDeviceVariable<UInt16>, NppiSize)
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.
Declaration
public static void DCTQuantFwd8x8LS(NPPImage_8uC1 src, NPPImage_16sC1 dst, CudaDeviceVariable<ushort> QuantFwdTable, NppiSize oSizeRoi)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_8uC1 | src | Source image. |
NPPImage_16sC1 | dst | Destination image |
CudaDeviceVariable<System.UInt16> | QuantFwdTable | Forward quantization tables for JPEG encoding created using QuantInvTableInit() |
NppiSize | oSizeRoi | Roi size (in macro blocks?). |
DCTQuantFwd8x8LS(NPPImage_8uC1, NPPImage_16sC1, NppiSize, CudaDeviceVariable<Byte>)
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. The new version of the primitive takes the ROI in image pixel size and works with DCT coefficients that are in zig-zag order.
Declaration
public void DCTQuantFwd8x8LS(NPPImage_8uC1 src, NPPImage_16sC1 dst, NppiSize oSizeRoi, CudaDeviceVariable<byte> QuantFwdTable)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_8uC1 | src | Source image. |
NPPImage_16sC1 | dst | Destination image |
NppiSize | oSizeRoi | Roi size (in pixels). |
CudaDeviceVariable<System.Byte> | QuantFwdTable | Quantization Table in zig-zag order |
DCTQuantInv8x8LS(NPPImage_16sC1, NPPImage_8uC1, CudaDeviceVariable<UInt16>, NppiSize)
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.
Declaration
public static void DCTQuantInv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, CudaDeviceVariable<ushort> QuantInvTable, NppiSize oSizeRoi)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1 | src | Source image. |
NPPImage_8uC1 | dst | Destination image |
CudaDeviceVariable<System.UInt16> | QuantInvTable | Inverse quantization tables for JPEG decoding created using QuantInvTableInit() |
NppiSize | oSizeRoi | Roi size (in macro blocks?). |
DCTQuantInv8x8LS(NPPImage_16sC1, NPPImage_8uC1, NppiSize, CudaDeviceVariable<Byte>)
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.
Declaration
public void DCTQuantInv8x8LS(NPPImage_16sC1 src, NPPImage_8uC1 dst, NppiSize oSizeRoi, CudaDeviceVariable<byte> QuantInvTable)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1 | src | Source image. |
NPPImage_8uC1 | dst | Destination image |
NppiSize | oSizeRoi | Roi size (in pixels). |
CudaDeviceVariable<System.Byte> | QuantInvTable | Quantization Table in zig-zag order. |
DecodeHuffmanScanHost(Byte[], Int32, Int32, Int32, Int32, Int32, Int16[], Int16[], Int16[], Int32[], NppiDecodeHuffmanSpec[], NppiDecodeHuffmanSpec[], NppiSize[])
Huffman Decoding of the JPEG decoding on the host.
Input is expected in byte stuffed huffman encoded JPEG scan and output is expected to be 64x1 macro blocks.
Declaration
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)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pSrc | Byte-stuffed huffman encoded JPEG scan. |
System.Int32 | restartInterval | Restart Interval, see JPEG standard. |
System.Int32 | Ss | Start Coefficient, see JPEG standard. |
System.Int32 | Se | End Coefficient, see JPEG standard. |
System.Int32 | Ah | Bit Approximation High, see JPEG standard. |
System.Int32 | Al | Bit Approximation Low, see JPEG standard. |
System.Int16[] | pDstY | Destination first image channel |
System.Int16[] | pDstCb | Destination second image channel |
System.Int16[] | pDstCr | Destination third image channel |
System.Int32[] | nDstStep | destination image line step. |
NppiDecodeHuffmanSpec[] | pHuffmanTableDC | DC Huffman table. |
NppiDecodeHuffmanSpec[] | pHuffmanTableAC | AC Huffman table. |
NppiSize[] | oSizeROI | ROI |
DecodeHuffmanScanHost(Byte[], Int32, Int32, Int32, Int32, Int32, Int16[], Int32, NppiDecodeHuffmanSpec, NppiDecodeHuffmanSpec, NppiSize)
Huffman Decoding of the JPEG decoding on the host.
Input is expected in byte stuffed huffman encoded JPEG scan and output is expected to be 64x1 macro blocks.
Declaration
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)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pSrc | Byte-stuffed huffman encoded JPEG scan. |
System.Int32 | restartInterval | Restart Interval, see JPEG standard. |
System.Int32 | Ss | Start Coefficient, see JPEG standard. |
System.Int32 | Se | End Coefficient, see JPEG standard. |
System.Int32 | Ah | Bit Approximation High, see JPEG standard. |
System.Int32 | Al | Bit Approximation Low, see JPEG standard. |
System.Int16[] | pDst | Destination image pointer |
System.Int32 | nDstStep | destination image line step. |
NppiDecodeHuffmanSpec | pHuffmanTableDC | DC Huffman table. |
NppiDecodeHuffmanSpec | pHuffmanTableAC | AC Huffman table. |
NppiSize | oSizeROI | ROI |
DecodeHuffmanSpecFreeHost(NppiDecodeHuffmanSpec)
Frees the host memory allocated by nppiDecodeHuffmanSpecInitAllocHost_JPEG.
Declaration
public static void DecodeHuffmanSpecFreeHost(NppiDecodeHuffmanSpec pHuffmanSpec)
Parameters
Type | Name | Description |
---|---|---|
NppiDecodeHuffmanSpec | pHuffmanSpec | Pointer to the Huffman table for the decoder |
DecodeHuffmanSpecGetBufSize()
Returns the length of the NppiDecodeHuffmanSpec structure.
Declaration
public static int DecodeHuffmanSpecGetBufSize()
Returns
Type | Description |
---|---|
System.Int32 | the length of the NppiDecodeHuffmanSpec structure. |
DecodeHuffmanSpecInitAllocHost(Byte[], NppiHuffmanTableType)
Allocates memory and creates a Huffman table in a format that is suitable for the decoder on the host.
Declaration
public static NppiDecodeHuffmanSpec DecodeHuffmanSpecInitAllocHost(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pRawHuffmanTable | Huffman table formated as specified in the JPEG standard. |
NppiHuffmanTableType | eTableType | Enum specifying type of table (nppiDCTable or nppiACTable). |
Returns
Type | Description |
---|---|
NppiDecodeHuffmanSpec | Huffman table for the decoder |
DecodeHuffmanSpecInitHost(Byte[], NppiHuffmanTableType, NppiDecodeHuffmanSpec)
Creates a Huffman table in a format that is suitable for the decoder on the host.
Declaration
public static void DecodeHuffmanSpecInitHost(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType, NppiDecodeHuffmanSpec pHuffmanSpec)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pRawHuffmanTable | Huffman table formated as specified in the JPEG standard. |
NppiHuffmanTableType | eTableType | Enum specifying type of table (nppiDCTable or nppiACTable) |
NppiDecodeHuffmanSpec | pHuffmanSpec | Pointer to the Huffman table for the decoder |
DecodeJobCreateFinalize(ref NppiJpegDecodeJob)
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.
Declaration
public void DecodeJobCreateFinalize(ref NppiJpegDecodeJob pJob)
Parameters
Type | Name | Description |
---|---|---|
NppiJpegDecodeJob | pJob | pJob.pFrame should point to valid frame description. pJob.pScan will be overwritten. |
Dispose()
Dispose
Declaration
public virtual void Dispose()
Dispose(Boolean)
For IDisposable
Declaration
protected virtual void Dispose(bool fDisposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | fDisposing |
EncodeHuffmanGetSize(NppiSize, Int32)
Calculates the size of the temporary buffer for huffman encoding.
Declaration
public static int EncodeHuffmanGetSize(NppiSize oSize, int nChannels)
Parameters
Type | Name | Description |
---|---|---|
NppiSize | oSize | Image Dimension |
System.Int32 | nChannels | Number of channels |
Returns
Type | Description |
---|---|
System.Int32 | the size of the temporary buffer |
EncodeHuffmanScan(NPPImage_16sC1, Int32, Int32, Int32, Int32, Int32, CudaDeviceVariable<Byte>, ref Int32, NppiEncodeHuffmanSpec, NppiEncodeHuffmanSpec, NppiSize, CudaDeviceVariable<Byte>)
Huffman Encoding of the JPEG Encoding.
Input is expected to be 64x1 macro blocks and output is expected as byte stuffed huffman encoded JPEG scan.
Declaration
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)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1 | pSrc | Source image. |
System.Int32 | restartInterval | Restart Interval, see JPEG standard. |
System.Int32 | Ss | Start Coefficient, see JPEG standard. |
System.Int32 | Se | End Coefficient, see JPEG standard. |
System.Int32 | Ah | Bit Approximation High, see JPEG standard. |
System.Int32 | Al | Bit Approximation Low, see JPEG standard. |
CudaDeviceVariable<System.Byte> | pDst | Byte-stuffed huffman encoded JPEG scan. |
System.Int32 | nLength | Byte length of the huffman encoded JPEG scan. |
NppiEncodeHuffmanSpec | pHuffmanTableDC | DC Huffman table. |
NppiEncodeHuffmanSpec | pHuffmanTableAC | AC Huffman table. |
NppiSize | oSizeROI | ROI |
CudaDeviceVariable<System.Byte> | buffer | Scratch buffer |
EncodeHuffmanScan(NPPImage_16sC1[], Int32, Int32, Int32, Int32, Int32, CudaDeviceVariable<Byte>, ref Int32, NppiEncodeHuffmanSpec[], NppiEncodeHuffmanSpec[], NppiSize[], CudaDeviceVariable<Byte>)
Huffman Encoding of the JPEG Encoding.
Input is expected to be 64x1 macro blocks and output is expected as byte stuffed huffman encoded JPEG scan.
Declaration
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)
Parameters
Type | Name | Description |
---|---|---|
NPPImage_16sC1[] | pSrc | Source image. |
System.Int32 | restartInterval | Restart Interval, see JPEG standard. |
System.Int32 | Ss | Start Coefficient, see JPEG standard. |
System.Int32 | Se | End Coefficient, see JPEG standard. |
System.Int32 | Ah | Bit Approximation High, see JPEG standard. |
System.Int32 | Al | Bit Approximation Low, see JPEG standard. |
CudaDeviceVariable<System.Byte> | pDst | Byte-stuffed huffman encoded JPEG scan. |
System.Int32 | nLength | Byte length of the huffman encoded JPEG scan. |
NppiEncodeHuffmanSpec[] | pHuffmanTableDC | DC Huffman table. |
NppiEncodeHuffmanSpec[] | pHuffmanTableAC | AC Huffman table. |
NppiSize[] | oSizeROI | ROI |
CudaDeviceVariable<System.Byte> | buffer | Scratch buffer |
EncodeHuffmanSpecFree(NppiEncodeHuffmanSpec)
Frees the memory allocated by nppiEncodeHuffmanSpecInitAlloc_JPEG.
Declaration
public static void EncodeHuffmanSpecFree(NppiEncodeHuffmanSpec pHuffmanSpec)
Parameters
Type | Name | Description |
---|---|---|
NppiEncodeHuffmanSpec | pHuffmanSpec | Pointer to the Huffman table for the encoder |
EncodeHuffmanSpecGetBufSize()
Returns the length of the NppiEncodeHuffmanSpec structure.
Declaration
public static int EncodeHuffmanSpecGetBufSize()
Returns
Type | Description |
---|---|
System.Int32 | length of the NppiEncodeHuffmanSpec structure. |
EncodeHuffmanSpecInit(Byte[], NppiHuffmanTableType, NppiEncodeHuffmanSpec)
Creates a Huffman table in a format that is suitable for the encoder.
Declaration
public static void EncodeHuffmanSpecInit(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType, NppiEncodeHuffmanSpec pHuffmanSpec)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pRawHuffmanTable | Huffman table formated as specified in the JPEG standard. |
NppiHuffmanTableType | eTableType | Enum specifying type of table (nppiDCTable or nppiACTable). |
NppiEncodeHuffmanSpec | pHuffmanSpec | Pointer to the Huffman table for the decoder |
EncodeHuffmanSpecInitAlloc(Byte[], NppiHuffmanTableType)
Allocates memory and creates a Huffman table in a format that is suitable for the encoder.
Declaration
public static NppiEncodeHuffmanSpec EncodeHuffmanSpecInitAlloc(byte[] pRawHuffmanTable, NppiHuffmanTableType eTableType)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | pRawHuffmanTable | Huffman table formated as specified in the JPEG standard. |
NppiHuffmanTableType | eTableType | Enum specifying type of table (nppiDCTable or nppiACTable). |
Returns
Type | Description |
---|---|
NppiEncodeHuffmanSpec | Huffman table for the encoder. |
GetDCTBufferSize(NppiSize)
Returns how much memory has to be allocated for DCT coefficient buffers
declared in \ref NppiJpegDecodeJobMemory. The returned value may be bigger than
simply number of blocks /// 64 /// sizeof (short)
, because decoder
may use slightly bigger temporary representation of data.
Declaration
public SizeT GetDCTBufferSize(NppiSize oBlocks)
Parameters
Type | Name | Description |
---|---|---|
NppiSize | oBlocks | Size of the interleaved component in blocks. |
Returns
Type | Description |
---|---|
SizeT |
GetScanDeadzoneSize()
This function returns how much additional memory has to be available
after the end of compressed scan data.
The following buffers: pCpuScan
and pGpuScan
in \ref NppiJpegDecodeJobMemory
should have size at least pScan->length + nppiJpegDecodeGetScanDeadzoneSize()
.
The additional memory is needed because the decoder may perform
some speculative reads after the end of compressed scan data.
Declaration
public SizeT GetScanDeadzoneSize()
Returns
Type | Description |
---|---|
SizeT |
JobCreateMemzero()
Initializes a job that has to be called at the beginning of decoding.
Declaration
public NppiJpegDecodeJob JobCreateMemzero()
Returns
Type | Description |
---|---|
NppiJpegDecodeJob |
JobMemorySize(NppiJpegDecodeJob)
Calculates sizes of additional buffers used by the job.
Declaration
public SizeT JobMemorySize(NppiJpegDecodeJob pJob)
Parameters
Type | Name | Description |
---|---|---|
NppiJpegDecodeJob | pJob | has to point to properly initialized job |
Returns
Type | Description |
---|---|
SizeT |
JpegDecodeJob(ref NppiJpegDecodeJob, ref NppiJpegDecodeJobMemory)
Executes a job -- part of decoding.
Declaration
public void JpegDecodeJob(ref NppiJpegDecodeJob pJob, ref NppiJpegDecodeJobMemory pMemory)
Parameters
Type | Name | Description |
---|---|---|
NppiJpegDecodeJob | pJob | has to be initialized by \ref nppiJpegDecodeJobCreateMemzero |
NppiJpegDecodeJobMemory | pMemory | has to point to valid structure, except for MEMZERO and FINALIZE |
QuantFwdRawTableInit(Byte[], Int32)
Apply quality factor to raw 8-bit quantization table.
This is effectively and in-place method that modifies a given raw quantization table based on a quality factor.
Note that this method is a host method and that the pointer to the raw quantization table is a host pointer.
Declaration
public static void QuantFwdRawTableInit(byte[] QuantRawTable, int nQualityFactor)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | QuantRawTable | Raw quantization table. |
System.Int32 | nQualityFactor | Quality factor for the table. Range is [1:100]. |
QuantFwdTableInit(Byte[], UInt16[])
Initializes a quantization table for DCTQuantFwd8x8LS().
The method creates a 16-bit version of the raw table and converts the data order from zigzag layout to original row-order layout since raw quantization tables are typically stored in zigzag format.
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 nppiDCTQuantFwd8x8LS() function.
Declaration
public static void QuantFwdTableInit(byte[] QuantRawTable, ushort[] QuantFwdRawTable)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | QuantRawTable | Host pointer to raw quantization table as returned by QuantFwdRawTableInit(). The raw quantization table is assumed to be in zigzag order. |
System.UInt16[] | QuantFwdRawTable | Forward quantization table for use with DCTQuantFwd8x8LS(). |
QuantInvTableInit(Byte[], UInt16[])
Initializes a quantization table for DCTQuantInv8x8LS().
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.
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.
Declaration
public static void QuantInvTableInit(byte[] QuantRawTable, ushort[] QuantInvRawTable)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | QuantRawTable | Raw quantization table. |
System.UInt16[] | QuantInvRawTable | Inverse quantization table. |