Commit 5c990fa0 authored by Adrian Ratiu's avatar Adrian Ratiu Committed by Mauro Carvalho Chehab

media: coda: jpeg: support optimized huffman tables

Each jpeg can have the huffman tables optimized for its specific content
meaning that the table lenghts and values don't match the standard table
of substitutions so there's no reason to hardcode and expect the standard
lengths, otherwise we just end up rejecting optimized jpegs altogether.

Tested on CODA960.
Signed-off-by: default avatarAdrian Ratiu <adrian.ratiu@collabora.com>
Reviewed-by: default avatarPhilipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent 15c3d5aa
......@@ -339,7 +339,10 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb)
v4l2_err(&dev->v4l2_dev, "missing Huffman table\n");
return -EINVAL;
}
if (huffman_tables[i].length != ((i & 2) ? 178 : 28)) {
/* AC tables should be between 17 -> 178, DC between 17 -> 28 */
if (huffman_tables[i].length < 17 ||
huffman_tables[i].length > 178 ||
((i & 2) == 0 && huffman_tables[i].length > 28)) {
v4l2_err(&dev->v4l2_dev,
"invalid Huffman table %d length: %zu\n",
i, huffman_tables[i].length);
......@@ -353,10 +356,12 @@ int coda_jpeg_decode_header(struct coda_ctx *ctx, struct vb2_buffer *vb)
return -ENOMEM;
ctx->params.jpeg_huff_tab = huff_tab;
}
memcpy(huff_tab->luma_dc, huffman_tables[0].start, 16 + 12);
memcpy(huff_tab->chroma_dc, huffman_tables[1].start, 16 + 12);
memcpy(huff_tab->luma_ac, huffman_tables[2].start, 16 + 162);
memcpy(huff_tab->chroma_ac, huffman_tables[3].start, 16 + 162);
memset(huff_tab, 0, sizeof(*huff_tab));
memcpy(huff_tab->luma_dc, huffman_tables[0].start, huffman_tables[0].length);
memcpy(huff_tab->chroma_dc, huffman_tables[1].start, huffman_tables[1].length);
memcpy(huff_tab->luma_ac, huffman_tables[2].start, huffman_tables[2].length);
memcpy(huff_tab->chroma_ac, huffman_tables[3].start, huffman_tables[3].length);
/* check scan header */
for (i = 0; i < scan_header.num_components; i++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment