Skip to contentSkip to conversation

media: Add controls for JPEG quantization tables

PATCH Superseded Ezequiel Garcia 3 participants 8 messages Aug 31, 2018 – Sep 3, 2018 7 messages not in the archive

Subsystems (3)

v4 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 5/6 media: Add controls for JPEG quantization tables

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
 include/uapi/linux/v4l2-controls.h            |  5 ++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +23 -0
index 9f7312bf3365..e0dd03e452de 100644
@@ -3354,7 +3354,30 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.
 
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +5 -0
index e4ee10ee917d..fcb288bb05c7 100644
@@ -987,6 +987,11 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	__u8	luma_quantization_matrix[64];
+	__u8	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +1 -0
index f271048c89c4..e998d07464cb 100644
@@ -1630,6 +1630,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
Signature · 1 line
2.18.0

A message that is not in the archive (sent off-list or not yet received): 20180831155245.19235-1-ezequiel-ZGY8ohtN/[email protected]

#2 lore raw
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
 .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
 .../media/videodev2.h.rst.exceptions          |  1 +
 drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
 include/uapi/linux/v4l2-controls.h            |  5 ++++
 include/uapi/linux/videodev2.h                |  1 +
 5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
     Specify which JPEG markers are included in compressed stream. This
     control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

Quoted 79 lines
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
 .. flat-table::
     :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
 replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
 # V4L2 capability defines
 replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
 	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
 	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
 	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
 	/* Image source controls */
 	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
 	case V4L2_CID_DETECT_MD_REGION_GRID:
 		*type = V4L2_CTRL_TYPE_U8;
 		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
 	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
 		*type = V4L2_CTRL_TYPE_U16;
 		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
 			return -ERANGE;
 		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
 	default:
 		return -EINVAL;
 	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
 	case V4L2_CTRL_TYPE_U32:
 		elem_size = sizeof(u32);
 		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
 	default:
 		if (type < V4L2_CTRL_COMPOUND_TYPES)
 			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +5 -0
index e4ee10ee917d..fcb288bb05c7 100644
@@ -987,6 +987,11 @@ enum v4l2_jpeg_chroma_subsampling {
 #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
 #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	__u8	luma_quantization_matrix[64];
+	__u8	chroma_quantization_matrix[64];
+};
 
 /* Image source controls */
 #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +0 -0
index f271048c89c4..e998d07464cb 100644

include/uapi/linux/videodev2.h enum v4l2_ctrl_type { · line 1636

Quoted 7 lines
include/uapi/linux/videodev2.h +1 -0
@@ -1630,6 +1630,7 @@ enum v4l2_ctrl_type {
 	V4L2_CTRL_TYPE_U8	     = 0x0100,
 	V4L2_CTRL_TYPE_U16	     = 0x0101,
 	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
 };
 
 /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */

Regards,

Hans

A message that is not in the archive (sent off-list or not yet received): ec1dab04-1890-5555-44cf-2cdadc79c1a6-qWit8jRvyhVmR6Xm/[email protected]

#4 lore raw

Hi,

Quoted 46 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
  .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
  .../media/videodev2.h.rst.exceptions          |  1 +
  drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
  include/uapi/linux/v4l2-controls.h            |  5 ++++
  include/uapi/linux/videodev2.h                |  1 +
  5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
      Specify which JPEG markers are included in compressed stream. This
      control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 12 lines
Documentation/media/uapi/v4l/extended-controls.rst +12 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
Quoted 8 lines

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 6 lines
Documentation/media/uapi/v4l/extended-controls.rst +6 -0
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

However there can be four sets of tables in non-baseline JPEG and it's not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would). Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

Regards,
Ian

Quoted 92 lines
Quoted 80 lines
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
  .. flat-table::
      :header-rows:  0
Documentation/media/videodev2.h.rst.exceptions +1 -0
index ca9f0edc579e..a0a38e92bf38 100644
@@ -129,6 +129,7 @@ replace symbol V4L2_CTRL_TYPE_STRING :c:type:`v4l2_ctrl_type`
  replace symbol V4L2_CTRL_TYPE_U16 :c:type:`v4l2_ctrl_type`
  replace symbol V4L2_CTRL_TYPE_U32 :c:type:`v4l2_ctrl_type`
  replace symbol V4L2_CTRL_TYPE_U8 :c:type:`v4l2_ctrl_type`
+replace symbol V4L2_CTRL_TYPE_JPEG_QUANTIZATION :c:type:`v4l2_ctrl_type`
 
  # V4L2 capability defines
  replace define V4L2_CAP_VIDEO_CAPTURE device-capabilities
drivers/media/v4l2-core/v4l2-ctrls.c +10 -0
index 599c1cbff3b9..305bd7a9b7f1 100644
@@ -999,6 +999,7 @@ const char *v4l2_ctrl_get_name(u32 id)
  	case V4L2_CID_JPEG_RESTART_INTERVAL:	return "Restart Interval";
  	case V4L2_CID_JPEG_COMPRESSION_QUALITY:	return "Compression Quality";
  	case V4L2_CID_JPEG_ACTIVE_MARKER:	return "Active Markers";
+	case V4L2_CID_JPEG_QUANTIZATION:	return "JPEG Quantization Tables";
 
  	/* Image source controls */
  	/* Keep the order of the 'case's the same as in v4l2-controls.h! */
@@ -1286,6 +1287,9 @@ void v4l2_ctrl_fill(u32 id, const char **name, enum v4l2_ctrl_type *type,
  	case V4L2_CID_DETECT_MD_REGION_GRID:
  		*type = V4L2_CTRL_TYPE_U8;
  		break;
+	case V4L2_CID_JPEG_QUANTIZATION:
+		*type = V4L2_CTRL_TYPE_JPEG_QUANTIZATION;
+		break;
  	case V4L2_CID_DETECT_MD_THRESHOLD_GRID:
  		*type = V4L2_CTRL_TYPE_U16;
  		break;
@@ -1612,6 +1616,9 @@ static int std_validate(const struct v4l2_ctrl *ctrl, u32 idx,
  			return -ERANGE;
  		return 0;
 
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		return 0;
+
  	default:
  		return -EINVAL;
  	}
@@ -2133,6 +2140,9 @@ static struct v4l2_ctrl *v4l2_ctrl_new(struct v4l2_ctrl_handler *hdl,
  	case V4L2_CTRL_TYPE_U32:
  		elem_size = sizeof(u32);
  		break;
+	case V4L2_CTRL_TYPE_JPEG_QUANTIZATION:
+		elem_size = sizeof(struct v4l2_ctrl_jpeg_quantization);
+		break;
  	default:
  		if (type < V4L2_CTRL_COMPOUND_TYPES)
  			elem_size = sizeof(s32);
include/uapi/linux/v4l2-controls.h +5 -0
index e4ee10ee917d..fcb288bb05c7 100644
@@ -987,6 +987,11 @@ enum v4l2_jpeg_chroma_subsampling {
  #define	V4L2_JPEG_ACTIVE_MARKER_DQT		(1 << 17)
  #define	V4L2_JPEG_ACTIVE_MARKER_DHT		(1 << 18)
 
+#define V4L2_CID_JPEG_QUANTIZATION		(V4L2_CID_JPEG_CLASS_BASE + 5)
+struct v4l2_ctrl_jpeg_quantization {
+	__u8	luma_quantization_matrix[64];
+	__u8	chroma_quantization_matrix[64];
+};
 
  /* Image source controls */
  #define V4L2_CID_IMAGE_SOURCE_CLASS_BASE	(V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
include/uapi/linux/videodev2.h +0 -0
index f271048c89c4..e998d07464cb 100644

include/uapi/linux/videodev2.h enum v4l2_ctrl_type { · line 1636

Quoted 7 lines
include/uapi/linux/videodev2.h +1 -0
@@ -1630,6 +1630,7 @@ enum v4l2_ctrl_type {
  	V4L2_CTRL_TYPE_U8	     = 0x0100,
  	V4L2_CTRL_TYPE_U16	     = 0x0101,
  	V4L2_CTRL_TYPE_U32	     = 0x0102,
+	V4L2_CTRL_TYPE_JPEG_QUANTIZATION = 0x0103,
  };
 
  /*  Used in the VIDIOC_QUERYCTRL ioctl for querying controls */

Regards,

Hans

A message that is not in the archive (sent off-list or not yet received): b5715198-eff0-30d2-6f84-cd1441d3f7ba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#6 lore raw

Hi Ian, Hans:

Quoted 58 lines · Ian Arkver

Hi,

Quoted 54 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
  .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
  .../media/videodev2.h.rst.exceptions          |  1 +
  drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
  include/uapi/linux/v4l2-controls.h            |  5 ++++
  include/uapi/linux/videodev2.h                |  1 +
  5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
      Specify which JPEG markers are included in compressed stream. This
      control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

I thought this was already discussed, but I think the only thing I've added is this comment in one of the driver's headers:

JPEG encoder
------------
The VPU JPEG encoder produces JPEG baseline sequential format. The quantization coefficients are 8-bit values, complying with the baseline specification. Therefore, it requires application-defined luma and chroma quantization tables. The hardware does entrophy encoding using internal Huffman tables, as specified in the JPEG specification.

Certainly controls should be specified better.

Quoted 4 lines

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

Paragraph 4.7 of that spec, indicates the "sample" precision:
8-bit for baseline; 8-bit or 12-bit for extended.

For the quantization coefficients, the DQT segment contains a bit that indicates if the quantization coefficients are 8-bit or 16-bit. See B.2.4.1 for details.

Quoted 1 line

However there can be four sets of tables in non-baseline JPEG and it's

You lost me here, which four sets of tables are you refering to?

Quoted 2 lines

not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would).

It seems it would. From B.2.4.1:

"An 8-bit DCT-based process shall not use a 16-bit precision quantization table."

Quoted 6 lines

Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

For quantization coefficients, I can only see two tables: one for luma one for chroma. Huffman coefficients are a different story and we are not really adding them here.

Thanks,
Eze

A message that is not in the archive (sent off-list or not yet received): 8d9cb4b73c4dc4af66ace5205bd6af5fc193d72a.camel-ZGY8ohtN/[email protected]

#8 lore raw
Quoted 106 lines · Ezequiel Garcia

Hi Ian, Hans:

Quoted 58 lines · Ian Arkver

Hi,

Quoted 54 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
  .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
  .../media/videodev2.h.rst.exceptions          |  1 +
  drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
  include/uapi/linux/v4l2-controls.h            |  5 ++++
  include/uapi/linux/videodev2.h                |  1 +
  5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
      Specify which JPEG markers are included in compressed stream. This
      control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

I thought this was already discussed, but I think the only thing I've added is this comment in one of the driver's headers:

JPEG encoder
------------
The VPU JPEG encoder produces JPEG baseline sequential format. The quantization coefficients are 8-bit values, complying with the baseline specification. Therefore, it requires application-defined luma and chroma quantization tables. The hardware does entrophy encoding using internal Huffman tables, as specified in the JPEG specification.

Certainly controls should be specified better.

Quoted 4 lines

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

Paragraph 4.7 of that spec, indicates the "sample" precision:
8-bit for baseline; 8-bit or 12-bit for extended.

For the quantization coefficients, the DQT segment contains a bit that indicates if the quantization coefficients are 8-bit or 16-bit. See B.2.4.1 for details.

Quoted 1 line

However there can be four sets of tables in non-baseline JPEG and it's

You lost me here, which four sets of tables are you refering to?

Quoted 2 lines

not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would).

It seems it would. From B.2.4.1:

"An 8-bit DCT-based process shall not use a 16-bit precision quantization table."

Quoted 6 lines

Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

Quoted 3 lines

For quantization coefficients, I can only see two tables: one for luma one for chroma. Huffman coefficients are a different story and we are not really adding them here.

Since (if I understand this correctly) we would need u16 for extended precision JPEG, shouldn't we use u16 instead of u8? That makes the control more generic.

BTW, are the coefficients always unsigned? I think so, but I never read the JPEG spec.

Regards,

Hans

Quoted 4 lines

Thanks,
Eze

A message that is not in the archive (sent off-list or not yet received): 0beecc48-6974-c12f-00a2-3823690108c0-qWit8jRvyhVmR6Xm/[email protected]

#10 lore raw

Hi Hans, Ezequiel,

Quoted 82 lines · Hans Verkuil
Quoted 81 lines · Ezequiel Garcia

Hi Ian, Hans:

Quoted 58 lines · Ian Arkver

Hi,

Quoted 54 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
   .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
   .../media/videodev2.h.rst.exceptions          |  1 +
   drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
   include/uapi/linux/v4l2-controls.h            |  5 ++++
   include/uapi/linux/videodev2.h                |  1 +
   5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
       Specify which JPEG markers are included in compressed stream. This
       control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

I thought this was already discussed, but I think the only thing I've added is this comment in one of the driver's headers:

JPEG encoder
------------
The VPU JPEG encoder produces JPEG baseline sequential format. The quantization coefficients are 8-bit values, complying with the baseline specification. Therefore, it requires application-defined luma and chroma quantization tables. The hardware does entrophy encoding using internal Huffman tables, as specified in the JPEG specification.

Certainly controls should be specified better.

Quoted 4 lines

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

Quoted 6 lines
Quoted 6 lines

Paragraph 4.7 of that spec, indicates the "sample" precision:
8-bit for baseline; 8-bit or 12-bit for extended.

For the quantization coefficients, the DQT segment contains a bit that indicates if the quantization coefficients are 8-bit or 16-bit. See B.2.4.1 for details.

See below (and Tq which follows the Pq field)

Quoted 19 lines
Quoted 19 lines
Quoted 2 lines

However there can be four sets of tables in non-baseline JPEG and it's

You lost me here, which four sets of tables are you refering to?

Quoted 2 lines

not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would).

It seems it would. From B.2.4.1:

"An 8-bit DCT-based process shall not use a 16-bit precision quantization table."

Quoted 6 lines

Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

Quoted 3 lines
Quoted 3 lines

For quantization coefficients, I can only see two tables: one for luma one for chroma. Huffman coefficients are a different story and we are not really adding them here.

I was looking at the definition of Tqi in the frame header in B.2.2 which seems to allow up to four (sets of?) quantization tables. Rereading it, it seems these are per component. Table B.2 implies that this applies to Baseline Sequential too. In the DQT marker description there's a Tq field to specify the destination for the new table. I think this means that an encoder can use up to four (sets of) tables and a decoder should be able to store four from the stream.

This may well not be relevant to the encoder under discussion, but if it's not allowed for in UAPI it's almost a given that it'll need to be added later.

BTW, my copy of the spec is dated 1993(E). Maybe it's out of date?

Quoted 3 lines

Since (if I understand this correctly) we would need u16 for extended precision JPEG, shouldn't we use u16 instead of u8? That makes the control more generic.

This seems like a safer option to me.

Regards,
Ian

Quoted 13 lines

BTW, are the coefficients always unsigned? I think so, but I never read the JPEG spec.

Regards,

Hans

Quoted 4 lines

Thanks,
Eze

A message that is not in the archive (sent off-list or not yet received): 1d0c0685-7d91-b422-7e34-b6472a090eb2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#12 lore raw
Quoted 124 lines · Ian Arkver

Hi Hans, Ezequiel,

Quoted 81 lines · Hans Verkuil
Quoted 80 lines · Ezequiel Garcia

Hi Ian, Hans:

Quoted 57 lines · Ian Arkver

Hi,

Quoted 54 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
   .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
   .../media/videodev2.h.rst.exceptions          |  1 +
   drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
   include/uapi/linux/v4l2-controls.h            |  5 ++++
   include/uapi/linux/videodev2.h                |  1 +
   5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
       Specify which JPEG markers are included in compressed stream. This
       control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

I thought this was already discussed, but I think the only thing I've added is this comment in one of the driver's headers:

JPEG encoder
------------
The VPU JPEG encoder produces JPEG baseline sequential format. The quantization coefficients are 8-bit values, complying with the baseline specification. Therefore, it requires application-defined luma and chroma quantization tables. The hardware does entrophy encoding using internal Huffman tables, as specified in the JPEG specification.

Certainly controls should be specified better.

Quoted 4 lines

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

Quoted 6 lines
Quoted 6 lines

Paragraph 4.7 of that spec, indicates the "sample" precision:
8-bit for baseline; 8-bit or 12-bit for extended.

For the quantization coefficients, the DQT segment contains a bit that indicates if the quantization coefficients are 8-bit or 16-bit. See B.2.4.1 for details.

See below (and Tq which follows the Pq field)

Quoted 19 lines
Quoted 19 lines
Quoted 2 lines

However there can be four sets of tables in non-baseline JPEG and it's

You lost me here, which four sets of tables are you refering to?

Quoted 2 lines

not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would).

It seems it would. From B.2.4.1:

"An 8-bit DCT-based process shall not use a 16-bit precision quantization table."

Quoted 6 lines

Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

Quoted 3 lines
Quoted 3 lines

For quantization coefficients, I can only see two tables: one for luma one for chroma. Huffman coefficients are a different story and we are not really adding them here.

I was looking at the definition of Tqi in the frame header in B.2.2 which seems to allow up to four (sets of?) quantization tables. Rereading it, it seems these are per component. Table B.2 implies that this applies to Baseline Sequential too. In the DQT marker description there's a Tq field to specify the destination for the new table. I think this means that an encoder can use up to four (sets of) tables and a decoder should be able to store four from the stream.

Quoted 4 lines

This may well not be relevant to the encoder under discussion, but if it's not allowed for in UAPI it's almost a given that it'll need to be added later.

Hm, I think it's not really relevant for us, either on the encoding or decoding side. Let me explain how I read the spec.

First of all, keep in mind it seems to be written with streams in mind, which explains different start-of-image and start-of-frames segments (SOI and SOF).

The way I read the four tables thing, the decoder expects to be first transmitted a set of quantization tables, via DQT segments. Each DQT segment contains a 4-bit index (0-3), allowing up to four quantization tables to be defined.

Then, each frame is transmitted in a SOF segment. The SOF header contains an 8-bit field (Tq_i) indicating which quantization table has to be used for this frame.

In Video4Linux, we are frame-based, and the JPEG segments have no meaning, because these controls are meant to be used with the JPEG RAW format, as specified.

For the decoder side, the application is expected to parse all the segments, and set quantization tables and compressed bitstream, via legacy or request APIs (probably the latter).

Same goes for encoding, the user will set a quantization table for the encoding process and then take care of the JPEG segments creation.

Quoted 2 lines

BTW, my copy of the spec is dated 1993(E). Maybe it's out of date?

My copy is also 1992, so even more dated :-)

Quoted 6 lines
Quoted 3 lines

Since (if I understand this correctly) we would need u16 for extended precision JPEG, shouldn't we use u16 instead of u8? That makes the control more generic.

This seems like a safer option to me.

Yes, I agree too.

Quoted 5 lines
Quoted 5 lines

BTW, are the coefficients always unsigned? I think so, but I never read the JPEG spec.

I don't think signed quantization coefficients make sense, so perhaps this is not explicitly specified?

Regards,
Eze

A message that is not in the archive (sent off-list or not yet received): f7f1249779d660a06b902bdaf3166cda910e48e1.camel-ZGY8ohtN/[email protected]

#14 lore raw

Hi Ezequiel,

Quoted 150 lines · Ezequiel Garcia
Quoted 124 lines · Ian Arkver

Hi Hans, Ezequiel,

Quoted 81 lines · Hans Verkuil
Quoted 80 lines · Ezequiel Garcia

Hi Ian, Hans:

Quoted 57 lines · Ian Arkver

Hi,

Quoted 54 lines · Hans Verkuil
Quoted 20 lines · Ezequiel Garcia

From: Shunqian Zheng <[email protected]>

Add V4L2_CID_JPEG_QUANTIZATION compound control to allow userspace configure the JPEG quantization tables.

---
    .../media/uapi/v4l/extended-controls.rst      | 23 +++++++++++++++++++
    .../media/videodev2.h.rst.exceptions          |  1 +
    drivers/media/v4l2-core/v4l2-ctrls.c          | 10 ++++++++
    include/uapi/linux/v4l2-controls.h            |  5 ++++
    include/uapi/linux/videodev2.h                |  1 +
    5 files changed, 40 insertions(+)
Documentation/media/uapi/v4l/extended-controls.rst +0 -0
index 9f7312bf3365..e0dd03e452de 100644

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3362

Quoted 9 lines
Documentation/media/uapi/v4l/extended-controls.rst +5 -0
@@ -3354,7 +3354,30 @@ JPEG Control IDs
        Specify which JPEG markers are included in compressed stream. This
        control is valid only for encoders.
 
+.. _jpeg-quant-tables-control:
 
+``V4L2_CID_JPEG_QUANTIZATION (struct)``
+    Specifies the luma and chroma quantization matrices for encoding
+    or decoding a V4L2_PIX_FMT_JPEG_RAW format buffer. The two matrices
+    must be set in JPEG zigzag order, as per the JPEG specification.

Can you change "JPEG specification" to a reference to the JPEG spec entry in bibio.rst?

Quoted 8 lines
Documentation/media/uapi/v4l/extended-controls.rst +8 -0
+
+
+.. c:type:: struct v4l2_ctrl_jpeg_quantization
+
+.. cssclass:: longtable
+
+.. flat-table:: struct v4l2_ctrl_jpeg_quantization
+    :header-rows:  0

Documentation/media/uapi/v4l/extended-controls.rst JPEG Control IDs · line 3380

Quoted 10 lines
Documentation/media/uapi/v4l/extended-controls.rst +10 -0
+    :stub-columns: 0
+    :widths:       1 1 2
+
+    * - __u8
+      - ``luma_quantization_matrix[64]``
+      - Sets the luma quantization table.
+
+    * - __u8
+      - ``chroma_quantization_matrix[64]``
+      - Sets the chroma quantization table.

Just checking: the JPEG standard specifies this as unsigned 8-bit values as well?

I thought this was already discussed, but I think the only thing I've added is this comment in one of the driver's headers:

JPEG encoder
------------
The VPU JPEG encoder produces JPEG baseline sequential format. The quantization coefficients are 8-bit values, complying with the baseline specification. Therefore, it requires application-defined luma and chroma quantization tables. The hardware does entrophy encoding using internal Huffman tables, as specified in the JPEG specification.

Certainly controls should be specified better.

Quoted 4 lines

As far as I can see ISO/IEC 10918-1 does not specify the precision or signedness of the quantisation value Qvu. The default tables for 8-bit baseline JPEG all fit into __u8 though.

Quoted 6 lines
Quoted 6 lines

Paragraph 4.7 of that spec, indicates the "sample" precision:
8-bit for baseline; 8-bit or 12-bit for extended.

For the quantization coefficients, the DQT segment contains a bit that indicates if the quantization coefficients are 8-bit or 16-bit. See B.2.4.1 for details.

See below (and Tq which follows the Pq field)

Quoted 19 lines
Quoted 19 lines
Quoted 2 lines

However there can be four sets of tables in non-baseline JPEG and it's

You lost me here, which four sets of tables are you refering to?

Quoted 2 lines

not clear (to me) whether 12-bit JPEG would need more precision (I'd guess it would).

It seems it would. From B.2.4.1:

"An 8-bit DCT-based process shall not use a 16-bit precision quantization table."

Quoted 6 lines

Since this patch is defining UAPI I think it might be good to build in some additional information, eg. number of tables, element size. Maybe this can all be inferred from the selected pixel format? If so then it would need documented that the above structure only applies to baseline.

Quoted 3 lines
Quoted 3 lines

For quantization coefficients, I can only see two tables: one for luma one for chroma. Huffman coefficients are a different story and we are not really adding them here.

I was looking at the definition of Tqi in the frame header in B.2.2 which seems to allow up to four (sets of?) quantization tables. Rereading it, it seems these are per component. Table B.2 implies that this applies to Baseline Sequential too. In the DQT marker description there's a Tq field to specify the destination for the new table. I think this means that an encoder can use up to four (sets of) tables and a decoder should be able to store four from the stream.

Quoted 4 lines

This may well not be relevant to the encoder under discussion, but if it's not allowed for in UAPI it's almost a given that it'll need to be added later.

Hm, I think it's not really relevant for us, either on the encoding or decoding side. Let me explain how I read the spec.

First of all, keep in mind it seems to be written with streams in mind, which explains different start-of-image and start-of-frames segments (SOI and SOF).

The way I read the four tables thing, the decoder expects to be first transmitted a set of quantization tables, via DQT segments. Each DQT segment contains a 4-bit index (0-3), allowing up to four quantization tables to be defined.

Then, each frame is transmitted in a SOF segment. The SOF header contains an 8-bit field (Tq_i) indicating which quantization table has to be used for this frame.

In Video4Linux, we are frame-based, and the JPEG segments have no meaning, because these controls are meant to be used with the JPEG RAW format, as specified.

Quoted 6 lines

For the decoder side, the application is expected to parse all the segments, and set quantization tables and compressed bitstream, via legacy or request APIs (probably the latter).

Same goes for encoding, the user will set a quantization table for the encoding process and then take care of the JPEG segments creation.

I hadn't got my head round only one table being in use at a time for this frame based API, nor had I appreciated that all the DQT parsing/creation etc was handled in userspace.

So, yeah, I agree that this JPEG control only needs a single luma and chroma pair of tables for this usage scenario.

Thanks for the explanation.
Ian.

Quoted 27 lines
Quoted 3 lines

BTW, my copy of the spec is dated 1993(E). Maybe it's out of date?

My copy is also 1992, so even more dated :-)

Quoted 6 lines
Quoted 3 lines

Since (if I understand this correctly) we would need u16 for extended precision JPEG, shouldn't we use u16 instead of u8? That makes the control more generic.

This seems like a safer option to me.

Yes, I agree too.

Quoted 5 lines
Quoted 5 lines

BTW, are the coefficients always unsigned? I think so, but I never read the JPEG spec.

I don't think signed quantization coefficients make sense, so perhaps this is not explicitly specified?

Regards,
Eze