3 * Routines for JFIF image/jpeg media dissection
4 * Copyright 2004, Olivier Biot <olivier.biot (ad) siemens.com>
6 * $Id: packet-image-jfif.c,v 1.2 2004/01/06 00:09:48 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * JFIF media decoding functionality provided by Olivier Biot.
14 * The JFIF specifications are found at several locations, such as:
15 * http://www.jpeg.org/public/jfif.pdf
16 * http://www.w3.org/Graphics/JPEG/itu-t81.pdf
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 /* Edit this file with 4-space tabulation */
45 #ifdef NEED_SNPRINTF_H
46 # include "snprintf.h"
49 #include <epan/packet.h>
51 /* General-purpose debug logger.
52 * Requires double parentheses because of variable arguments of printf().
54 * Enable debug logging for JFIF by defining AM_CFLAGS
55 * so that it contains "-DDEBUG_image_jfif" or "-DDEBUG_image"
57 #if (defined(DEBUG_image_jfif) || defined(DEBUG_image))
59 printf("%s:%u: ", __FILE__, __LINE__); \
66 #define PLURALIZE(x) ((x) == 1 ? "" : "s")
68 #define IMG_JFIF "image-jfif"
70 /************************** Variable declarations **************************/
72 #define MARKER_TEM 0xFF01
74 /* 0xFF02 -- 0xFFBF are reserved */
76 #define MARKER_SOF0 0xFFC0
77 #define MARKER_SOF1 0xFFC1
78 #define MARKER_SOF2 0xFFC2
79 #define MARKER_SOF3 0xFFC3
81 #define MARKER_DHT 0xFFC4
83 #define MARKER_SOF5 0xFFC5
84 #define MARKER_SOF6 0xFFC6
85 #define MARKER_SOF7 0xFFC7
86 #define MARKER_SOF8 0xFFC8
87 #define MARKER_SOF9 0xFFC9
88 #define MARKER_SOF10 0xFFCA
89 #define MARKER_SOF11 0xFFCB
91 #define MARKER_DAC 0xFFCC
93 #define MARKER_SOF13 0xFFCD
94 #define MARKER_SOF14 0xFFCE
95 #define MARKER_SOF15 0xFFCF
97 #define MARKER_RST0 0xFFD0
98 #define MARKER_RST1 0xFFD1
99 #define MARKER_RST2 0xFFD2
100 #define MARKER_RST3 0xFFD3
101 #define MARKER_RST4 0xFFD4
102 #define MARKER_RST5 0xFFD5
103 #define MARKER_RST6 0xFFD6
104 #define MARKER_RST7 0xFFD7
106 #define MARKER_FFDB 0xFFDB
107 #define MARKER_SOI 0xFFD8
108 #define MARKER_EOI 0xFFD9
109 #define MARKER_SOS 0xFFDA
110 #define MARKER_DQT 0xFFDB
111 #define MARKER_DNL 0xFFDC
112 #define MARKER_DRI 0xFFDD
113 #define MARKER_DHP 0xFFDE
114 #define MARKER_EXP 0xFFDF
116 #define MARKER_APP0 0xFFE0
117 #define MARKER_APP1 0xFFE1
118 #define MARKER_APP2 0xFFE2
119 #define MARKER_APP3 0xFFE3
120 #define MARKER_APP4 0xFFE4
121 #define MARKER_APP5 0xFFE5
122 #define MARKER_APP6 0xFFE6
123 #define MARKER_APP7 0xFFE7
124 #define MARKER_APP8 0xFFE8
125 #define MARKER_APP9 0xFFE9
126 #define MARKER_APP10 0xFFEA
127 #define MARKER_APP11 0xFFEB
128 #define MARKER_APP12 0xFFEC
129 #define MARKER_APP13 0xFFED
130 #define MARKER_APP14 0xFFEE
131 #define MARKER_APP15 0xFFEF
133 #define MARKER_JPG0 0xFFF0
134 #define MARKER_JPG1 0xFFF1
135 #define MARKER_JPG2 0xFFF2
136 #define MARKER_JPG3 0xFFF3
137 #define MARKER_JPG4 0xFFF4
138 #define MARKER_JPG5 0xFFF5
139 #define MARKER_JPG6 0xFFF6
140 #define MARKER_JPG7 0xFFF7
141 #define MARKER_JPG8 0xFFF8
142 #define MARKER_JPG9 0xFFF9
143 #define MARKER_JPG10 0xFFFA
144 #define MARKER_JPG11 0xFFFB
145 #define MARKER_JPG12 0xFFFC
146 #define MARKER_JPG13 0xFFFD
148 #define MARKER_COM 0xFFFE
150 #define marker_has_length(marker) ( ! ( \
151 ((marker) == MARKER_TEM) \
152 || ((marker) == MARKER_SOI) \
153 || ((marker) == MARKER_EOI) \
154 || ( ((marker) >= MARKER_RST0) && ((marker) <= MARKER_RST7) ) \
158 static const value_string vals_marker[] = {
159 { MARKER_TEM, "Reserved - For temporary private use in arithmetic coding" },
160 { MARKER_SOF0, "Start of Frame (non-differential, Huffman coding) - Baseline DCT" },
161 { MARKER_SOF1, "Start of Frame (non-differential, Huffman coding) - Extended sequential DCT" },
162 { MARKER_SOF2, "Start of Frame (non-differential, Huffman coding) - Progressive DCT" },
163 { MARKER_SOF3, "Start of Frame (non-differential, Huffman coding) - Lossless (sequential)" },
164 { MARKER_DHT, "Define Huffman table(s)" },
165 { MARKER_SOF5, "Start of Frame (differential, Huffman coding) - Differential sequential DCT" },
166 { MARKER_SOF6, "Start of Frame (differential, Huffman coding) - Differential progressive DCT" },
167 { MARKER_SOF7, "Start of Frame (differential, Huffman coding) - Differential lossless (sequential)" },
168 { MARKER_SOF8, "Start of Frame (non-differential, arithmetic coding) - Reserved for JPEG extensions" },
169 { MARKER_SOF9, "Start of Frame (non-differential, arithmetic coding) - Extended sequential DCT" },
170 { MARKER_SOF10, "Start of Frame (non-differential, arithmetic coding) - Progressive DCT" },
171 { MARKER_SOF11, "Start of Frame (non-differential, arithmetic coding) - Lossless (sequential)" },
172 { MARKER_DAC, "Define arithmetic coding conditioning(s)" },
173 { MARKER_SOF13, "Start of Frame (differential, arithmetic coding) - Differential sequential DCT" },
174 { MARKER_SOF14, "Start of Frame (differential, arithmetic coding) - Differential progressive DCT" },
175 { MARKER_SOF15, "Start of Frame (differential, arithmetic coding) - Differential lossless (sequential)" },
176 { MARKER_RST0, "Restart interval termination - Restart with modulo 8 count 0" },
177 { MARKER_RST1, "Restart interval termination - Restart with modulo 8 count 1" },
178 { MARKER_RST2, "Restart interval termination - Restart with modulo 8 count 2" },
179 { MARKER_RST3, "Restart interval termination - Restart with modulo 8 count 3" },
180 { MARKER_RST4, "Restart interval termination - Restart with modulo 8 count 4" },
181 { MARKER_RST5, "Restart interval termination - Restart with modulo 8 count 5" },
182 { MARKER_RST6, "Restart interval termination - Restart with modulo 8 count 6" },
183 { MARKER_RST7, "Restart interval termination - Restart with modulo 8 count 7" },
184 { MARKER_SOI, "Start of Image" },
185 { MARKER_EOI, "End of Image" },
186 { MARKER_SOS, "Start of Scan" },
187 { MARKER_DQT, "Define quantization table(s)" },
188 { MARKER_DNL, "Define number of lines" },
189 { MARKER_DRI, "Define restart interval" },
190 { MARKER_DHP, "Define hierarchical progression" },
191 { MARKER_EXP, "Expand reference component(s)" },
192 { MARKER_APP0, "Reserved for application segments - 0" },
193 { MARKER_APP1, "Reserved for application segments - 1" },
194 { MARKER_APP2, "Reserved for application segments - 2" },
195 { MARKER_APP3, "Reserved for application segments - 3" },
196 { MARKER_APP4, "Reserved for application segments - 4" },
197 { MARKER_APP5, "Reserved for application segments - 5" },
198 { MARKER_APP6, "Reserved for application segments - 6" },
199 { MARKER_APP7, "Reserved for application segments - 7" },
200 { MARKER_APP8, "Reserved for application segments - 8" },
201 { MARKER_APP9, "Reserved for application segments - 9" },
202 { MARKER_APP10, "Reserved for application segments - 10" },
203 { MARKER_APP11, "Reserved for application segments - 11" },
204 { MARKER_APP12, "Reserved for application segments - 12" },
205 { MARKER_APP13, "Reserved for application segments - 13" },
206 { MARKER_APP14, "Reserved for application segments - 14" },
207 { MARKER_APP15, "Reserved for application segments - 15" },
208 { MARKER_JPG0, "Reserved for JPEG extensions - 0" },
209 { MARKER_JPG1, "Reserved for JPEG extensions - 1" },
210 { MARKER_JPG2, "Reserved for JPEG extensions - 2" },
211 { MARKER_JPG3, "Reserved for JPEG extensions - 3" },
212 { MARKER_JPG4, "Reserved for JPEG extensions - 4" },
213 { MARKER_JPG5, "Reserved for JPEG extensions - 5" },
214 { MARKER_JPG6, "Reserved for JPEG extensions - 6" },
215 { MARKER_JPG7, "Reserved for JPEG extensions - 7" },
216 { MARKER_JPG8, "Reserved for JPEG extensions - 8" },
217 { MARKER_JPG9, "Reserved for JPEG extensions - 9" },
218 { MARKER_JPG10, "Reserved for JPEG extensions - 10" },
219 { MARKER_JPG11, "Reserved for JPEG extensions - 11" },
220 { MARKER_JPG12, "Reserved for JPEG extensions - 12" },
221 { MARKER_JPG13, "Reserved for JPEG extensions - 13" },
225 static const value_string vals_units[] = {
226 { 0, "No units; Xdensity and Ydensity specify the pixel aspect ratio" },
227 { 1, "Dots per inch" },
228 { 2, "Dots per centimeter" },
232 static const value_string vals_extension_code[] = {
233 { 0x10, "Thumbnail encoded using JPEG" },
234 { 0x11, "Thumbnail encoded using 1 byte (8 bits) per pixel" },
235 { 0x13, "Thumbnail encoded using 3 bytes (24 bits) per pixel" },
239 /* Initialize the protocol and registered fields */
240 static int proto_jfif = -1;
243 static gint hf_marker = -1;
245 static gint hf_marker_segment = -1;
246 static gint hf_len = -1;
248 static gint hf_identifier = -1;
249 /* MARKER_APP0 - JFIF */
250 static gint hf_version = -1;
251 static gint hf_version_major = -1;
252 static gint hf_version_minor = -1;
253 static gint hf_units = -1;
254 static gint hf_xdensity = -1;
255 static gint hf_ydensity = -1;
256 static gint hf_xthumbnail = -1;
257 static gint hf_ythumbnail = -1;
258 static gint hf_rgb = -1;
259 /* MARKER_APP0 - JFXX */
260 static gint hf_extension_code = -1;
262 static gint hf_sof_header = -1;
263 static gint hf_sof_precision = -1;
264 static gint hf_sof_lines = -1;
265 static gint hf_sof_samples_per_line = -1;
266 static gint hf_sof_nf = -1;
267 static gint hf_sof_c_i = -1;
268 static gint hf_sof_h_i = -1;
269 static gint hf_sof_v_i = -1;
270 static gint hf_sof_tq_i = -1;
273 static gint hf_sos_header = -1;
274 static gint hf_sos_ns = -1;
275 static gint hf_sos_cs_j = -1;
276 static gint hf_sos_td_j = -1;
277 static gint hf_sos_ta_j = -1;
278 static gint hf_sos_ss = -1;
279 static gint hf_sos_se = -1;
280 static gint hf_sos_ah = -1;
281 static gint hf_sos_al = -1;
283 /* Initialize the subtree pointers */
284 static gint ett_jfif = -1;
285 static gint ett_marker_segment = -1;
286 static gint ett_details = -1;
289 /**************** GIF related declarations and definitions ****************/
292 /************************** Function prototypes **************************/
296 dissect_jfif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
299 proto_register_jfif(void);
303 /****************** JFIF protocol dissection functions ******************/
305 #define ErrorInvalidJFIF "This is not a valid JFIF (JPEG) object"
309 * Process a marker segment (with length).
312 process_marker_segment(proto_tree *tree, tvbuff_t *tvb, guint32 len,
313 guint16 marker, const char *marker_name)
315 proto_item *ti = NULL;
316 proto_tree *subtree = NULL;
321 ti = proto_tree_add_item(tree, hf_marker_segment,
323 subtree = proto_item_add_subtree(ti, ett_marker_segment);
325 proto_item_append_text(ti, ": %s (0x%04X)", marker_name, marker);
326 proto_tree_add_item(subtree, hf_marker, tvb, 0, 2, FALSE);
328 proto_tree_add_item(subtree, hf_len, tvb, 2, 2, FALSE);
330 proto_tree_add_text(subtree, tvb, 4, -1,
331 "Remaining segment data (%u bytes)", len - 2);
335 * Process a Start of Frame header (with length).
338 process_sof_header(proto_tree *tree, tvbuff_t *tvb, guint32 len _U_,
339 guint16 marker, const char *marker_name)
341 proto_item *ti = NULL;
342 proto_tree *subtree = NULL;
347 ti = proto_tree_add_item(tree, hf_sof_header,
349 subtree = proto_item_add_subtree(ti, ett_marker_segment);
351 proto_item_append_text(ti, ": %s (0x%04X)", marker_name, marker);
352 proto_tree_add_item(subtree, hf_marker, tvb, 0, 2, FALSE);
354 proto_tree_add_item(subtree, hf_len, tvb, 2, 2, FALSE);
356 proto_tree_add_item(subtree, hf_sof_precision, tvb, 4, 1, FALSE);
358 proto_tree_add_item(subtree, hf_sof_lines, tvb, 5, 2, FALSE);
360 proto_tree_add_item(subtree, hf_sof_samples_per_line, tvb, 7, 2, FALSE);
362 proto_tree_add_item(subtree, hf_sof_nf, tvb, 9, 1, FALSE);
364 guint8 count = tvb_get_guint8(tvb, 9);
367 proto_tree_add_item(subtree, hf_sof_c_i, tvb, offset++, 1, FALSE);
368 proto_tree_add_item(subtree, hf_sof_h_i, tvb, offset, 1, FALSE);
369 proto_tree_add_item(subtree, hf_sof_v_i, tvb, offset++, 1, FALSE);
370 proto_tree_add_item(subtree, hf_sof_tq_i, tvb, offset++, 1, FALSE);
377 * Process a Start of Segment header (with length).
380 process_sos_header(proto_tree *tree, tvbuff_t *tvb, guint32 len _U_,
381 guint16 marker, const char *marker_name)
383 proto_item *ti = NULL;
384 proto_tree *subtree = NULL;
390 ti = proto_tree_add_item(tree, hf_sos_header,
392 subtree = proto_item_add_subtree(ti, ett_marker_segment);
394 proto_item_append_text(ti, ": %s (0x%04X)", marker_name, marker);
395 proto_tree_add_item(subtree, hf_marker, tvb, 0, 2, FALSE);
397 proto_tree_add_item(subtree, hf_len, tvb, 2, 2, FALSE);
399 proto_tree_add_item(subtree, hf_sos_ns, tvb, 4, 1, FALSE);
401 guint8 count = tvb_get_guint8(tvb, 4);
404 proto_tree_add_item(subtree, hf_sos_cs_j, tvb, offset++, 1, FALSE);
405 proto_tree_add_item(subtree, hf_sos_td_j, tvb, offset, 1, FALSE);
406 proto_tree_add_item(subtree, hf_sos_ta_j, tvb, offset++, 1, FALSE);
411 proto_tree_add_item(subtree, hf_sos_ss, tvb, offset++, 1, FALSE);
412 proto_tree_add_item(subtree, hf_sos_se, tvb, offset++, 1, FALSE);
414 proto_tree_add_item(subtree, hf_sos_ah, tvb, offset, 1, FALSE);
415 proto_tree_add_item(subtree, hf_sos_al, tvb, offset++, 1, FALSE);
418 /* Process an APP0 block.
420 * XXX - This code only works on US-ASCII systems!!!
423 process_app0_segment(proto_tree *tree, tvbuff_t *tvb, guint32 len,
424 guint16 marker, const char *marker_name)
426 proto_item *ti = NULL;
427 proto_tree *subtree = NULL;
428 proto_tree *subtree_details = NULL;
436 ti = proto_tree_add_item(tree, hf_marker_segment,
438 subtree = proto_item_add_subtree(ti, ett_marker_segment);
440 proto_item_append_text(ti, ": %s (0x%04X)", marker_name, marker);
441 proto_tree_add_item(subtree, hf_marker, tvb, 0, 2, FALSE);
443 proto_tree_add_item(subtree, hf_len, tvb, 2, 2, FALSE);
445 str = tvb_get_stringz(tvb, 4, &str_size);
446 ti = proto_tree_add_item(subtree, hf_identifier, tvb, 4, str_size, FALSE);
447 if (strcmp(str, "JFIF") == 0) {
449 ti = proto_tree_add_none_format(subtree, hf_version,
450 tvb, 9, 2, "Version: %u.%u",
451 tvb_get_guint8(tvb, 9),
452 tvb_get_guint8(tvb, 10));
453 subtree_details = proto_item_add_subtree(ti, ett_details);
454 proto_tree_add_item(subtree_details, hf_version_major,
456 proto_tree_add_item(subtree_details, hf_version_minor,
459 proto_tree_add_item(subtree, hf_units,
463 proto_tree_add_item(subtree, hf_xdensity,
465 proto_tree_add_item(subtree, hf_ydensity,
469 proto_tree_add_item(subtree, hf_xthumbnail,
471 proto_tree_add_item(subtree, hf_ythumbnail,
474 guint16 x = tvb_get_guint8(tvb, 16);
475 guint16 y = tvb_get_guint8(tvb, 17);
477 proto_tree_add_item(subtree, hf_rgb,
478 tvb, 18, 3 * (x * y), FALSE);
479 offset = 18 + (3 * (x * y));
484 } else if (strcmp(str, "JFXX") == 0) {
485 proto_tree_add_item(subtree, hf_extension_code,
488 guint8 code = tvb_get_guint8(tvb, 9);
490 case 0x10: /* Thumbnail coded using JPEG */
492 case 0x11: /* thumbnail stored using 1 byte per pixel */
494 case 0x13: /* thumbnail stored using 3 bytes per pixel */
500 } else { /* Unknown */
501 proto_item_append_text(ti, " (unknown identifier)");
502 offset = 4 + str_size;
504 proto_tree_add_text(subtree, tvb, offset, -1,
505 "Remaining segment data (%u bytes)", len - 2 - str_size);
512 dissect_jfif(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
514 proto_tree *subtree = NULL;
516 guint tvb_len = tvb_reported_length(tvb);
523 ti = proto_tree_add_item(tree, proto_jfif,
525 subtree = proto_item_add_subtree(ti, ett_jfif);
528 marker = tvb_get_ntohs(tvb, 0);
529 if (marker != MARKER_SOI) {
531 proto_tree_add_text(subtree, tvb, 0, 2, ErrorInvalidJFIF);
536 proto_tree_add_item(subtree, hf_marker, tvb, 0, 2, FALSE);
538 marker = tvb_get_ntohs(tvb, 2);
539 if (marker != MARKER_APP0) {
541 proto_tree_add_text(subtree, tvb, 2, 2, ErrorInvalidJFIF);
550 /* The APP0 segment has a length field */
551 len = tvb_get_ntohs(tvb, offset);
552 tmp_tvb = tvb_new_subset(tvb, offset - 2, 2 + len, 2 + len);
553 process_app0_segment(subtree, tmp_tvb, len, marker,
554 match_strval(marker, vals_marker));
558 * Process the remaining markers and marker segments
560 while (offset < tvb_len) {
562 marker = tvb_get_ntohs(tvb, offset);
563 str = match_strval(marker, vals_marker);
564 if (str) { /* Known marker */
565 if (marker_has_length(marker)) { /* Marker segment */
566 /* Length of marker segment = 2 + len */
567 len = tvb_get_ntohs(tvb, offset + 2);
568 tmp_tvb = tvb_new_subset(tvb, offset, 2 + len, 2 + len);
571 process_app0_segment(subtree, tmp_tvb, len, marker, str);
587 process_sof_header(subtree, tmp_tvb, len, marker, str);
590 process_sos_header(subtree, tmp_tvb, len, marker, str);
592 * TODO - dissect a scan; the scan data is encoded.
594 proto_tree_add_text(subtree, tvb, offset + 2 + len, -1,
595 "JFIF dissection stops here (dissection of a scan is not yet implemented)");
599 process_marker_segment(subtree, tmp_tvb, len, marker, str);
603 } else { /* Marker but no segment */
605 proto_tree_add_item(subtree, hf_marker,
606 tvb, offset, 2, FALSE);
609 } else { /* Reserved! */
610 ti = proto_tree_add_item(subtree, hf_marker,
611 tvb, offset, 2, FALSE);
612 proto_item_append_text(ti, " (Reserved)");
621 /****************** Register the protocol with Ethereal ******************/
624 /* This format is required because a script is used to build the C function
625 * that calls the protocol registration. */
628 proto_register_jfif(void)
631 * Setup list of header fields.
633 static hf_register_info hf[] = {
638 FT_UINT8, BASE_HEX, VALS(vals_marker), 0x00,
644 { &hf_marker_segment,
646 IMG_JFIF "marker_segment",
647 FT_NONE, BASE_NONE, NULL, 0x00,
655 FT_UINT16, BASE_DEC, 0, 0x00,
656 "Length of segment (including length field)",
663 IMG_JFIF ".identifier",
664 FT_STRINGZ, BASE_NONE, NULL, 0x00,
665 "Identifier of the segment",
669 /* MARKER_APP0 - JFIF */
673 FT_NONE, BASE_NONE, NULL, 0x00,
680 IMG_JFIF ".version.major",
681 FT_UINT8, BASE_DEC, NULL, 0x00,
682 "JFIF Major Version",
688 IMG_JFIF ".version.minor",
689 FT_UINT8, BASE_DEC, NULL, 0x00,
690 "JFIF Minor Version",
697 FT_UINT8, BASE_DEC, VALS(vals_units), 0x00,
698 "Units used in this segment",
704 IMG_JFIF ".Xdensity",
705 FT_UINT16, BASE_DEC, NULL, 0x00,
706 "Horizontal pixel density",
712 IMG_JFIF ".Ydensity",
713 FT_UINT16, BASE_DEC, NULL, 0x00,
714 "Vertical pixel density",
720 IMG_JFIF ".Xthumbnail",
721 FT_UINT16, BASE_DEC, NULL, 0x00,
722 "Thumbnail horizontal pixel count",
728 IMG_JFIF ".Ythumbnail",
729 FT_UINT16, BASE_DEC, NULL, 0x00,
730 "Thumbnail vertical pixel count",
735 { "RGB values of thumbnail pixels",
737 FT_BYTES, BASE_NONE, NULL, 0x00,
738 "RGB values of the thumbnail pixels (24 bit per pixel, Xthumbnail x Ythumbnail pixels)",
742 /* MARKER_APP0 - JFXX */
743 { &hf_extension_code,
745 IMG_JFIF ".extension.code",
746 FT_UINT8, BASE_HEX, VALS(vals_extension_code), 0x00,
747 "JFXX extension code for thumbnail encoding",
751 /* Header: Start of Frame (MARKER_SOF) */
753 { "Start of Frame header",
755 FT_NONE, BASE_NONE, NULL, 0x00,
756 "Start of Frame header",
761 { "Sample Precision (bits)",
762 IMG_JFIF ".sof.precision",
763 FT_UINT8, BASE_DEC, NULL, 0x00,
764 "Specifies the precision in bits for the samples of the components in the frame.",
770 IMG_JFIF ".sof.lines",
771 FT_UINT16, BASE_DEC, NULL, 0x00,
772 "Specifies the maximum number of lines in the source image.",
776 { &hf_sof_samples_per_line,
777 { "Samples per line",
778 IMG_JFIF ".sof.samples_per_line",
779 FT_UINT16, BASE_DEC, NULL, 0x00,
780 "Specifies the maximum number of samples per line in the source image.",
785 { "Number of image components in frame",
787 FT_UINT8, BASE_DEC, NULL, 0x00,
788 "Specifies the number of source image components in the frame.",
793 { "Component identifier",
795 FT_UINT8, BASE_DEC, NULL, 0x00,
796 "Assigns a unique label to the ith component in the sequence "
797 "of frame component specification parameters.",
802 { "Horizontal sampling factor",
804 FT_UINT8, BASE_DEC, NULL, 0xF0,
805 "Specifies the relationship between the component horizontal "
806 "dimension and maximum image dimension X.",
811 { "Vertical sampling factor",
813 FT_UINT8, BASE_DEC, NULL, 0x0F,
814 "Specifies the relationship between the component vertical "
815 "dimension and maximum image dimension Y.",
820 { "Quantization table destination selector",
821 IMG_JFIF ".sof.tq_i",
822 FT_UINT8, BASE_DEC, NULL, 0x00,
823 "Specifies one of four possible quantization table "
824 "destinations from which the quantization table to use "
825 "for dequantization of DCT coefficients of component Ci "
831 /* Header: Start of Segment (MARKER_SOS) */
833 { "Start of Segment header",
834 IMG_JFIF ".header.sos",
835 FT_NONE, BASE_NONE, NULL, 0x00,
836 "Start of Segment header",
841 { "Number of image components in scan",
843 FT_UINT8, BASE_DEC, NULL, 0x00,
844 "Specifies the number of source image components in the scan.",
849 { "Scan component selector",
850 IMG_JFIF ".sos.component_selector",
851 FT_UINT8, BASE_DEC, NULL, 0x00,
852 "Selects which of the Nf image components specified in the "
853 "frame parameters shall be the jth component in the scan.",
858 { "DC entropy coding table destination selector",
859 IMG_JFIF ".sos.dc_entropy_selector",
860 FT_UINT8, BASE_DEC, NULL, 0xF0,
861 "Specifies one of four possible DC entropy coding table "
862 "destinations from which the entropy table needed "
863 "for decoding of the DC coefficients of component Csj "
869 { "AC entropy coding table destination selector",
870 IMG_JFIF ".sos.ac_entropy_selector",
871 FT_UINT8, BASE_DEC, NULL, 0x0F,
872 "Specifies one of four possible AC entropy coding table "
873 "destinations from which the entropy table needed "
874 "for decoding of the AC coefficients of component Csj "
880 { "Start of spectral or predictor selection",
882 FT_UINT8, BASE_DEC, NULL, 0x00,
883 "In the DCT modes of operation, this parameter specifies the "
884 "first DCT coefficient in each block in zig-zag order which "
885 "shall be coded in the scan. This parameter shall be set to "
886 "zero for the sequential DCT processes. "
887 "In the lossless mode of operations this parameter is used "
888 "to select the predictor.",
893 { "End of spectral selection",
895 FT_UINT8, BASE_DEC, NULL, 0x00,
896 "Specifies the last DCT coefficient in each block in zig-zag "
897 "order which shall be coded in the scan. This parameter shall "
898 "be set to 63 for the sequential DCT processes. "
899 "In the lossless mode of operations this parameter has no "
900 "meaning. It shall be set to zero.",
905 { "Successive approximation bit position high",
907 FT_UINT8, BASE_DEC, NULL, 0xF0,
908 "This parameter specifies the point transform used in the "
909 "preceding scan (i.e. successive approximation bit position "
910 "low in the preceding scan) for the band of coefficients "
911 "specified by Ss and Se. This parameter shall be set to zero "
912 "for the first scan of each band of coefficients. "
913 "In the lossless mode of operations this parameter has no "
914 "meaning. It shall be set to zero.",
919 { "Successive approximation bit position low or point transform",
921 FT_UINT8, BASE_DEC, NULL, 0x0F,
922 "In the DCT modes of operation this parameter specifies the "
923 "point transform, i.e. bit position low, used before coding "
924 "the band of coefficients specified by Ss and Se. "
925 "This parameter shall be set to zero for the sequential DCT "
926 "processes. In the lossless mode of operations, this "
927 "parameter specifies the point transform, Pt.",
933 /* Setup protocol subtree array */
934 static gint *ett[] = {
940 /* Register the protocol name and description */
941 proto_jfif = proto_register_protocol(
942 "JPEG File Interchange Format",
947 /* Required function calls to register the header fields
948 * and subtrees used */
949 proto_register_field_array(proto_jfif, hf, array_length(hf));
950 proto_register_subtree_array(ett, array_length(ett));
952 register_dissector("image-jfif", dissect_jfif, proto_jfif);
957 proto_reg_handoff_jfif(void)
959 dissector_handle_t jfif_handle;
961 jfif_handle = create_dissector_handle(dissect_jfif, proto_jfif);
963 /* Register the GIF media type */
964 dissector_add_string("media_type", "image/jfif", jfif_handle);
965 dissector_add_string("media_type", "image/jpg", jfif_handle);
966 dissector_add_string("media_type", "image/jpeg", jfif_handle);