Operator JPEG_Encoder_Gray

Operator Library: Compression

The operator performs a JPEG compression of grayscale 8-bit images.

[Important] Availability

To use the JPEG_Encoder_Gray operator, you need either a JPEG Compression Library license, or the VisualApplets 4 license.

[Important] Input Data in 8x8 pixels blocks required

On its input, the operator needs to receive image data that have been remapped into blocks of 8x8 pixels.

If you use a microEnable IV frame grabber, you can use operator ImageBuffer_JPEG_Gray for this remapping. For microEnable IV designs, simply use operator ImageBuffer_JPEG_Gray in front of operator JPEG_Encoder_Gray. Operator ImageBuffer_JPEG_Gray is designed to perform this reordering.

If you use a microEnable 5 frame grabber, make sure you remap the image data into blocks of 8x8 pixels (using the general VisualApplet options) before you use operator JPEG_Encoder_Gray.

The operator's output is a Huffman stream without JPEG headers. The compression rate depends on the selected quantization table which is changeable during runtime. For Huffman coding the standard luminance table is used. Besides the quantization table, the compression rate i.e. the output stream size depends on the input image. Therefore, the operator's output width is changeable to the desired output size.

The JPEG encoder is able to process around 2.5 input pixels per clock cycle. The clock frequency depends on the used frame grabber. microEnable IV frame grabbers have a base clock frequency of 62.5MHz. Therefore, the operator can process 158MPixels/s on a microEnable IV frame grabber. If quantization tables that cause a high quality compression are used, the data rate can be reduced. This is at quality levels of approximately more than 95%. Please refer to the JPEG application notes for further details.

The operator allows the selection of the quantization table using two parameters representing two different ways of configuration.

  • If desired, each of the quantization table values can be set individually. Use parameter quantization_matrix in this case.

  • In alternative, the quantization table can be determined from percentage values. Use parameter quality_in_percent in this case.

The standard luminance quantization table is shown in the following and is used as the default setting of the operator.

If a percentage quality is used, the quantization table is calculated by the following equation

As described, the operator's output is a Huffman Stream of the encoded image data. The underlying DC coefficients and AC coefficients are fixed and taken from literature, namely W. P. Pennbaker and J. L. Mitchell, JPEG Still Image Data Compression Standard, Van Nostrand Rheinhold, 1993. See beyond for the listing. The generated Huffman Stream generated by the encoder does not contain the required JPEG headers to generate a JPEG image file. Furthermore, the generated data stream is of 32Bbit width. The last word i.e. the four last byte of the JPEG data stream provide status information of the following format:

  • Bytes zero and one of the last word represent the JPEG EOI marker which is 0xff and 0xd9.

  • Byte no. two represents the number of bytes used in the second last data word in the range [1, 4] i.e. the true end of the JPEG data stream.

  • The last byte no. three represents an error code. If the JPEG data stream is larger than the maximum image width specified for the output link, the output will be truncated. If this happens, the last byte will be set to one which allows the detection of this truncation.

An example of the end of a JPEG output data stream is given in the following:

Second last word: 0xffff5fed

Last word: 0x0002d9ff

Hence, the JPEG output data stream ends with the second byte of the second last word. The data stream is not truncated.

Operator Restrictions

  • The operator does not support empty images i.e. images with no pixels.

  • The lines of each input image at port I must have the same length. Thus images with varying line lengths are not allowed.

I/O Properties

Property Value
Operator Type M
Input Link I, data input
Output Link O, data output

Supported Link Format

Link Parameter Input Link I Output Link O
Bit Width 8 32
Arithmetic unsigned as I
Parallelism 8 1
Kernel Columns 1 as I
Kernel Rows 1 as I
Img Protocol VALT_IMAGE2D as I
Color Format VAF_GRAY as I
Color Flavor FL_NONE as I
Max. Img Width any1 any
Max. Img Height any2 1

1 2

The input width and height have to be multiples of 8.

Parameters

quality_in_percent
Type dynamic read/write parameter
Default 50
Range [-1, 100]

Using this parameter the quality of the JPEG compression can be changed. The quantization matrix is determined from the percentage values using the equation given above. The determined quantization values can be read from parameter quantization_matrix. The parameter is dynamic and should only be changed during idle time of the applet.

Quality settings between 0 and 100 can be defined. Writing to this parameter overwrites manual chnages of the quantization matrix made by parameter quantization_matrix. If -1 is read from quality_in_percent, manual change of the quantization matrix has been made.

quantization_matrix
Type static/dynamic read/write parameter
Default standard matrix (see above)
Range [1, 255]

This parameter is a dynamic read and write matrix paramter. If the JPEG quality is set in percentage values. This parameter can be used to read the determined quantization matrix values.

The parameter can also be used to specify a user defined quantization matrix. This can be done by writing to any of the quantization matrix values. Note that a write to parameter qulity_in_percent will discard the user specified quantization values. For convenience, parameter quality_in_percent is set to -1 after a user specified value has been written.

Examples of Use

The use of operator JPEG_Encoder_Gray is shown in the following examples:

More Information

The following Huffman DC- and AC Coefficients are used.

typedef char DCHuffTableType[12][17]; // huffman-table for luminance-DC-coefficients

DCHuffTableType Lum_DC_HuffmanTable= {
"00",
"010",
"011",
"100",
"101",
"110",
"1110",
"11110",
"111110",
"1111110",
"11111110",
"111111110" };

typedef char ACHuffTableType[16][11][17]; // Huffman-Tabelle für Luminance-AC-Koeffizienten

ACHuffTableType Lum_AC_HuffmanTable= {
{ //Run == 0
"1010",//EOB
"00",
"01",
"100",
"1011",
"11010",
"1111000",
"11111000",
"1111110110",
"1111111110000010",
"1111111110000011"
},
{ //Run == 1
"1010",//EOB
"1100",
"11011",
"1111001",
"111110110",
"11111110110",
"1111111110000100",
"1111111110000101",
"1111111110000110",
"1111111110000111",
"1111111110001000"
},
{ //Run == 2
"1010",//EOB
"11100",
"11111001",
"1111110111",
"111111110100",
"1111111110001001",
"1111111110001010",
"1111111110001011",
"1111111110001100",
"1111111110001101",
"1111111110001110"
},
{ //Run == 3
"1010",//EOB
"111010",
"111110111",
"111111110101",
"1111111110001111",
"1111111110010000",
"1111111110010001",
"1111111110010010",
"1111111110010011",
"1111111110010100",
"1111111110010101"
},
{ //Run == 4
"1010",//EOB
"111011",
"1111111000",
"1111111110010110",
"1111111110010111",
"1111111110011000",
"1111111110011001",
"1111111110011010",
"1111111110011011",
"1111111110011100",
"1111111110011101",
},
{ //Run == 5
"1010",//EOB
"1111010",
"11111110111",
"1111111110011110",
"1111111110011111",
"1111111110100000",
"1111111110100001",
"1111111110100010",
"1111111110100011",
"1111111110100100",
"1111111110100101"
},
{ //Run == 6
"1010",//EOB
"1111011",
"111111110110",
"1111111110100110",
"1111111110100111",
"1111111110101000",
"1111111110101001",
"1111111110101010",
"1111111110101011",
"1111111110101100",
"1111111110101101"
},
{ //Run == 7
"1010",//EOB
"11111010",
"111111110111",
"1111111110101110",
"1111111110101111",
"1111111110110000",
"1111111110110001",
"1111111110110010",
"1111111110110011",
"1111111110110100",
"1111111110110101",
},
{ //Run == 8
"1010",//EOB
"111111000",
"111111111000000",
"1111111110110110",
"1111111110110111",
"1111111110111000",
"1111111110111001",
"1111111110111010",
"1111111110111011",
"1111111110111100",
"1111111110111101"
},
{ //Run == 9
"1010",//EOB
"111111001",
"1111111110111110",
"1111111110111111",
"1111111111000000",
"1111111111000001",
"1111111111000010",
"1111111111000011",
"1111111111000100",
"1111111111000101",
"1111111111000110"
},
{ //Run == 0xA
"1010",//EOB
"111111010",
"1111111111000111",
"1111111111001000",
"1111111111001001",
"1111111111001010",
"1111111111001011",
"1111111111001100",
"1111111111001101",
"1111111111001110",
"1111111111001111"
},
{ //Run == 0xB
"1010",//EOB
"1111111001",
"1111111111010000",
"1111111111010001",
"1111111111010010",
"1111111111010011",
"1111111111010100",
"1111111111010101",
"1111111111010110",
"1111111111010111",
"1111111111011000"
},
{ //Run == 0xC
"1010",//EOB
"1111111010",
"1111111111011001",
"1111111111011010",
"1111111111011011",
"1111111111011100",
"1111111111011101",
"1111111111011110",
"1111111111011111",
"1111111111100000",
"1111111111100001"
},
{ //Run == 0xD
"1010",//EOB
"11111111000",
"1111111111100010",
"1111111111100011",
"1111111111100100",
"1111111111100101",
"1111111111100110",
"1111111111100111",
"1111111111101000",
"1111111111101001",
"1111111111101010"
},
{ //Run == 0xE
"1010",//EOB
"1111111111101011",
"1111111111101100",
"1111111111101101",
"1111111111101110",
"1111111111101111",
"1111111111110000",
"1111111111110001",
"1111111111110010",
"1111111111110011",
"1111111111110100"
},
{ //Run == 0xF
"11111111001", //ZRL
"1111111111110101",
"1111111111110110",
"1111111111110111",
"1111111111111000",
"1111111111111001",
"1111111111111010",
"1111111111111011",
"1111111111111100",
"1111111111111101",
"1111111111111110"
}
};