2 * This file is part of FFmpeg.
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 static int FUNC(frame_header)(CodedBitstreamContext *ctx, RWContext *rw,
20 JPEGRawFrameHeader *current)
24 HEADER("Frame Header");
26 u(16, Lf, 8, 8 + 3 * JPEG_MAX_COMPONENTS);
29 u(16, Y, 0, JPEG_MAX_HEIGHT);
30 u(16, X, 1, JPEG_MAX_WIDTH);
31 u(8, Nf, 1, JPEG_MAX_COMPONENTS);
33 for (i = 0; i < current->Nf; i++) {
34 us(8, C[i], i, 0, JPEG_MAX_COMPONENTS);
37 us(8, Tq[i], i, 0, 3);
43 static int FUNC(quantisation_table)(CodedBitstreamContext *ctx, RWContext *rw,
44 JPEGRawQuantisationTable *current)
52 for (i = 0; i < 64; i++)
53 us(16, Q[i], i, 1, 255);
55 for (i = 0; i < 64; i++)
56 us(8, Q[i], i, 1, 255);
62 static int FUNC(dqt)(CodedBitstreamContext *ctx, RWContext *rw,
63 JPEGRawQuantisationTableSpecification *current)
67 HEADER("Quantisation Tables");
69 u(16, Lq, 2, 2 + 4 * 65);
72 for (i = 0; i < n; i++)
73 CHECK(FUNC(quantisation_table)(ctx, rw, ¤t->table[i]));
78 static int FUNC(huffman_table)(CodedBitstreamContext *ctx, RWContext *rw,
79 JPEGRawHuffmanTable *current)
86 for (i = 0; i < 16; i++)
87 us(8, L[i], i, 0, 224);
90 for (i = 0; i < 16; i++) {
91 for (j = 0; j < current->L[i]; j++) {
93 return AVERROR_INVALIDDATA;
94 us(8, V[ij], ij, 0, 255);
102 static int FUNC(dht)(CodedBitstreamContext *ctx, RWContext *rw,
103 JPEGRawHuffmanTableSpecification *current)
107 HEADER("Huffman Tables");
109 u(16, Lh, 2, 2 + 8 * (1 + 16 + 256));
112 for (i = 0; n < current->Lh; i++) {
114 return AVERROR_INVALIDDATA;
116 CHECK(FUNC(huffman_table)(ctx, rw, ¤t->table[i]));
119 for (j = 0; j < 16; j++)
120 n += 1 + current->table[i].L[j];
126 static int FUNC(scan_header)(CodedBitstreamContext *ctx, RWContext *rw,
127 JPEGRawScanHeader *current)
133 u(16, Ls, 6, 6 + 2 * JPEG_MAX_COMPONENTS);
136 for (j = 0; j < current->Ns; j++) {
137 us(8, Cs[j], j, 0, JPEG_MAX_COMPONENTS);
138 us(4, Td[j], j, 0, 3);
139 us(4, Ta[j], j, 0, 3);
150 static int FUNC(application_data)(CodedBitstreamContext *ctx, RWContext *rw,
151 JPEGRawApplicationData *current)
155 HEADER("Application Data");
159 if (current->Lp > 2) {
161 current->Ap_ref = av_buffer_alloc(current->Lp - 2);
162 if (!current->Ap_ref)
163 return AVERROR(ENOMEM);
164 current->Ap = current->Ap_ref->data;
167 for (i = 0; i < current->Lp - 2; i++)
168 us(8, Ap[i], i, 0, 255);
174 static int FUNC(comment)(CodedBitstreamContext *ctx, RWContext *rw,
175 JPEGRawComment *current)
183 if (current->Lc > 2) {
185 current->Cm_ref = av_buffer_alloc(current->Lc - 2);
186 if (!current->Cm_ref)
187 return AVERROR(ENOMEM);
188 current->Cm = current->Cm_ref->data;
191 for (i = 0; i < current->Lc - 2; i++)
192 us(8, Cm[i], i, 0, 255);