aboutsummaryrefslogtreecommitdiffstats
path: root/packet-image-gif.c
blob: d1d2add93a269396cf18fb6bd88c85c19715c8fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
/* packet-image-gif.c
 *
 * Routines for image/gif media dissection
 * Copyright 2003, 2004, Olivier Biot.
 *
 * $Id: packet-image-gif.c,v 1.4 2004/03/08 22:03:58 obiot Exp $
 *
 * Refer to the AUTHORS file or the AUTHORS section in the man page
 * for contacting the author(s) of this file.
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * Compuserve GIF media decoding functionality provided by Olivier Biot.
 * 
 * The two GIF specifications are found at several locations, such as W3C:
 * http://www.w3.org/Graphics/GIF/spec-gif87.txt
 * http://www.w3.org/Graphics/GIF/spec-gif89a.txt
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

/* Edit this file with 4-space tabulation */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <glib.h>

#ifdef NEED_SNPRINTF_H
# include "snprintf.h"
#endif

#include <epan/packet.h>

/* General-purpose debug logger.
 * Requires double parentheses because of variable arguments of printf().
 *
 * Enable debug logging for GIF by defining AM_CFLAGS
 * so that it contains "-DDEBUG_image_gif" or "-DDEBUG_image"
 */
#if (defined(DEBUG_image_gif) || defined(DEBUG_image))
#define DebugLog(x) \
	printf("%s:%u: ", __FILE__, __LINE__); \
	printf x; \
	fflush(stdout)
#else
#define DebugLog(x) ;
#endif

#define PLURALIZE(x) ((x) == 1 ? "" : "s")

#define IMG_GIF "image-gif"

/************************** Variable declarations **************************/

static const value_string vals_true_false[] = {
	{ 0, "False" },
	{ 1, "True" },
	{ 0, NULL },
};

static const value_string vals_extensions[] = {
	{ 0xF9, "Graphics Control" },
	{ 0xFE, "Comment" },
	{ 0xFF, "Application" },
	{ 0x01, "Plain Text" },
	{ 0x00, NULL, },
};

enum {
	GIF_UNKNOWN = 0,
	GIF_87a = 0x87,
	GIF_89a = 0x89,
	GIF_ERROR = 0xFF
};

/* Initialize the protocol and registered fields */
static int proto_gif = -1;

/* header fields */
/* GIF signature */
static gint hf_version = -1;
/* Screen descriptor */
static gint hf_screen_width = -1;
static gint hf_screen_height = -1;
static gint hf_global_color_map_present = -1;
static gint hf_global_color_resolution = -1;
static gint hf_global_color_map_ordered = -1; /* GIF89a */
static gint hf_global_image_bpp = -1;
/* Only makes sense if the global color map is present: */
static gint hf_background_color = -1;
static gint hf_pixel_aspect_ratio = -1; /* GIF89a */
static gint hf_global_color_map = -1;

/* Image descriptor */
static gint hf_image_left = -1;
static gint hf_image_top = -1;
static gint hf_image_width = -1;
static gint hf_image_height = -1;
static gint hf_local_color_map_present = -1;
static gint hf_local_color_resolution = -1;
static gint hf_local_color_map_ordered = -1; /* GIF89a */
static gint hf_local_image_bpp = -1;
static gint hf_local_color_map = -1;

static gint hf_extension = -1;
static gint hf_extension_label = -1;
static gint hf_image = -1;
static gint hf_image_code_size = -1;

/* Trailer (end of GIF data stream) */
static gint hf_trailer = -1;

/* Initialize the subtree pointers */
static gint ett_gif = -1;
static gint ett_global_flags = -1;
static gint ett_local_flags = -1;
static gint ett_extension = -1;
static gint ett_image = -1;


/**************** GIF related declarations and definitions ****************/


/************************** Function prototypes **************************/


static void
dissect_gif(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);

void
proto_register_gif(void);


/****************** GIF protocol dissection functions ******************/

/* There are two Compuserve GIF standards: GIF87a and GIF89a. GIF image files
 * always convey their version in the first 6 bytes, written as an US-ASCII
 * string representation of the version: "GIF87a" or "GIF89a".
 */

static void
dissect_gif(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
{
	proto_item *ti;
	proto_tree *gif_tree; /* Main GIF tree */
	proto_tree *subtree; /* Main GIF tree */
	guint offset = 0, len = 0;
	guint8 peek;
	gboolean color_map_present;
	guint8 color_resolution;
	guint8 image_bpp;
	guint tvb_len = tvb_reported_length(tvb);
	char *str = tvb_get_string(tvb, 0, 6);
	guint8 version;

	/* Check whether we're processing a GIF object */
	if (strcmp(str, "GIF87a") == 0) {
		version = GIF_87a;
	} else if (strcmp(str, "GIF89a") == 0) {
		version = GIF_89a;
	} else if (strncmp(str,"GIF", 3) == 0) {
		version = GIF_UNKNOWN;
	} else {
		/* Not a GIF image! */
		version = GIF_ERROR;
		g_free(str);
		return;
	}
	/* Add summary to INFO column if it is enabled */
	if (check_col(pinfo->cinfo, COL_INFO))
		col_append_fstr(pinfo->cinfo, COL_INFO, " (%s)", str);

	/* In order to speed up dissection, do not add items to the protocol tree
	 * if it is not visible. However, compute the values that are needed for
	 * correct protocol dissection if they have more meaning than just adding
	 * items to the protocol tree.
	 */
	if (tree) {
		ti = proto_tree_add_item(tree, proto_gif, tvb, 0, -1, TRUE);
		proto_item_append_text(ti, ", Version: %s", str);
		g_free(str);
		gif_tree = proto_item_add_subtree(ti, ett_gif);
		/* GIF signature */
		ti = proto_tree_add_item(gif_tree, hf_version, tvb, 0, 6, TRUE);
		if (version == GIF_UNKNOWN) {
			proto_item_append_text(ti, " <Error: unknown GIF version>");
		}
		/* Screen descriptor */
		proto_tree_add_item(gif_tree, hf_screen_width, tvb, 6, 2, TRUE);
		proto_tree_add_item(gif_tree, hf_screen_height, tvb, 8, 2, TRUE);

		peek = tvb_get_guint8(tvb, 10);
		/* Bitfield gccc 0ppp
		 * 			g... .... : global color map present
		 * 			.ccc .... : color resolution in bits (add one)
		 * 			.... 0... : GIF87a - reserved (no use)
		 * 						GIF89a - ordered (most important color 1st)
		 * 			.... .ppp : bits per pixel in image (add one)
		 */
		color_map_present = peek & 0x80;
		color_resolution = 1 + ((peek & 0x60) >> 4);
		image_bpp = 1 + (peek & 0x07);
	
		ti = proto_tree_add_text(gif_tree, tvb, 10, 1,
				"Global settings:");
		if (color_map_present)
			proto_item_append_text(ti, " (Global color table present)");
		proto_item_append_text(ti,
				" (%u bit%s per color) (%u bit%s per pixel)",
				color_resolution, PLURALIZE(color_resolution),
				image_bpp, PLURALIZE(image_bpp));
		subtree = proto_item_add_subtree(ti, ett_global_flags);
		proto_tree_add_item(subtree, hf_global_color_map_present,
				tvb, 10, 1, TRUE);
		proto_tree_add_item(subtree, hf_global_color_resolution,
				tvb, 10, 1, TRUE);
		if (version == GIF_89a) {
			proto_tree_add_item(subtree, hf_global_color_map_ordered,
					tvb, 10, 1, TRUE);
		}
		proto_tree_add_item(subtree, hf_global_image_bpp,
				tvb, 10, 1, TRUE);

		/* Background color */
		proto_tree_add_item(gif_tree, hf_background_color,
				tvb, 11, 1, TRUE);

		/* byte at offset 12 is 0x00 - reserved in GIF87a but encodes the
		 * pixel aspect ratio in GIF89a as:
		 *		aspect-ratio = (15 + pixel-aspect-ratio) / 64
		 * where the aspect-ratio is not computed if pixel-aspect-ratio == 0
		 */
		if (version == GIF_89a) {
			peek = tvb_get_guint8(tvb, 12);
			if (peek) {
				/* Only display if different from 0 */
				proto_tree_add_uint_format(gif_tree, hf_pixel_aspect_ratio,
						tvb, 12, 1, peek,
						"%u, yields an aspect ratio of (15 + %u) / 64 = %.2f",
						peek, peek, (float)(15 + peek) / 64.0);
			}
		}

		/* Global color map
		 * If present, it takes 2 ^ (image_bpp) byte tuples (R, G, B)
		 * that contain the Red, Green and Blue intensity of the colors
		 * in the Global Color Map */
		if (color_map_present) {
			len = 3 * (1 << image_bpp);
			proto_tree_add_item(gif_tree, hf_global_color_map,
					tvb, 13, len, TRUE);
		} else {
			len = 0;
		}
		offset = 13 + len;
		/* From now on, a set of images prefixed with the image separator
		 * character 0x2C (',') will appear in the byte stream. Each image
		 * hence consists of:
		 * - The image separator character 0x2C
		 * - Image left (16 bits LSB first): pixels from left border
		 * - Image top (16 bits LSB first): pixels from to border
		 * - Image width (16 bits LSB first)
		 * - Image height (16 bits LSB first)
		 * - A bitfield	MI00 0ppp
		 *				M... .... : Use global color map if unset (ignore ppp);
		 *							if set a local color map will be defined.
		 *				.I.. .... : Image formatted in interlaced order if set;
		 *							otherwise it is plain sequential order
		 *				..0. .... : GIF87a - Reserved
		 *				..s. ....	GIF89a - Set if local color map is ordered
		 *				...0 0... : Reserved
		 *				.... .ppp : bits per pixel in image (add one)
		 * - If the local color map bit is set, then a local color table follows
		 *   with length = 3 x 2 ^ (1 + bits per pixel)
		 * - The raster data
		 *
		 * NOTE that the GIF specification only requires that:
		 *		image left + image width  <= screen width
		 *		image top  + image height <= screen height
		 *
		 * The Raster Data is encoded as follows:
		 * - Code size (1 byte)
		 * - Blocks consisting of
		 *		o Byte count (1 byte): number of bytes in the block
		 *		o Data bytes: as many as specified in the byte count
		 *	 End of data is given with an empty block (byte count == 0).
		 *
		 *
		 * GIF terminator
		 * This is a synchronization method, based on the final character 0xB3
		 * (';') at the end of an image
		 *
		 *
		 * GIF extension
		 * This is a block of data encoded as:
		 * - The GIF extension block introducer 0x21 ('!')
		 * - The extension function code (1 byte)
		 * - Blocks consisting of
		 *		o Byte count (1 byte): number of bytes in the block
		 *		o Data bytes: as many as specified in the byte count
		 *	 End of data is given with an empty block (byte count == 0).
		 *
		 * NOTE that the GIF extension block can only appear at the following
		 * locations:
		 * - Immediately before an Image Descriptor
		 * - Before the GIF termination character
		 */
		while (offset < tvb_len) {
			peek = tvb_get_guint8(tvb, offset);
			if (peek == 0x21) { /* GIF extension block */
				guint32 item_len = 2;	/* Fixed header consisting of:
										 *	1 byte : 0x21
										 *	1 byte : extension_label
										 */

				ti = proto_tree_add_item(gif_tree, hf_extension,
						tvb, offset, 1, TRUE);
				subtree = proto_item_add_subtree(ti, ett_extension);
				offset++;
				proto_tree_add_item(subtree, hf_extension_label,
						tvb, offset, 1, TRUE);
				peek = tvb_get_guint8(tvb, offset);
				proto_item_append_text(ti, ": %s",
						val_to_str(peek, vals_extensions,
							"<Warning: Unknown extension 0x%02X>"));
				offset++;
				do {
					/* Read length of data block */
					len = tvb_get_guint8(tvb, offset);
					proto_tree_add_text(subtree, tvb,
							offset, 1 + len,
							"Data block (length = %u)", len);
					offset += (1 + len);
					item_len += (1 + len);
				} while (len > 0);
				proto_item_set_len(ti, item_len);
			} else if (peek == 0x2C) { /* Image separator */
				proto_tree *subtree2;
				proto_item *ti2;
				guint32 item_len = 11;	/* Fixed header consisting of:
										 *	1 byte : 0x2C
										 *	2 bytes: image_left
										 *	2 bytes: image_top
										 *	2 bytes: image_width
										 *	2 bytes: image height
										 *	1 byte : packed bit field
										 *	1 byte : image code size
										 */

				ti = proto_tree_add_item(gif_tree, hf_image,
						tvb, offset, 1, TRUE);
				subtree = proto_item_add_subtree(ti, ett_image);
				offset++;
				/* Screen descriptor */
				proto_tree_add_item(subtree, hf_image_left,
						tvb, offset, 2, TRUE); offset += 2;
				proto_tree_add_item(subtree, hf_image_top,
						tvb, offset, 2, TRUE); offset += 2;
				proto_tree_add_item(subtree, hf_image_width,
						tvb, offset, 2, TRUE); offset += 2;
				proto_tree_add_item(subtree, hf_image_height,
						tvb, offset, 2, TRUE); offset += 2;
				/* bit field */
				peek = tvb_get_guint8(tvb, offset);
				color_map_present = peek & 0x80;
				color_resolution = 1 + ((peek & 0x60) >> 4);
				image_bpp = 1 + (peek & 0x07);
	
				ti2 = proto_tree_add_text(subtree, tvb, offset, 1,
						"Local settings:");
				if (color_map_present)
					proto_item_append_text(ti2, " (Local color table present)");
				proto_item_append_text(ti2,
						" (%u bit%s per color) (%u bit%s per pixel)",
						color_resolution, PLURALIZE(color_resolution),
						image_bpp, PLURALIZE(image_bpp));
				subtree2 = proto_item_add_subtree(ti2, ett_local_flags);
				proto_tree_add_item(subtree2, hf_local_color_map_present,
						tvb, offset, 1, TRUE);
				proto_tree_add_item(subtree2, hf_local_color_resolution,
						tvb, offset, 1, TRUE);
				if (version == GIF_89a) {
					proto_tree_add_item(subtree2, hf_local_color_map_ordered,
							tvb, offset, 1, TRUE);
				}
				proto_tree_add_item(subtree2, hf_global_image_bpp,
						tvb, offset, 1, TRUE);
				offset++;

				/* Local color map
				 * If present, it takes 2 ^ (image_bpp) byte tuples (R, G, B)
				 * that contain the Red, Green and Blue intensity of the colors
				 * in the Local Color Map */
				if (color_map_present) {
					len = 3 * (1 << image_bpp);
					proto_tree_add_item(subtree, hf_local_color_map,
							tvb, offset, len, TRUE);
				} else {
					len = 0;
				}
				offset += len;
				item_len += len;

				proto_tree_add_item(subtree, hf_image_code_size,
						tvb, offset, 1, TRUE);
				offset++;
				do {
					/* Read length of data block */
					len = tvb_get_guint8(tvb, offset);
					proto_tree_add_text(subtree, tvb,
							offset, 1 + len,
							"Data block (length = %u)", len);
					offset += 1 + len;
					item_len += (1 + len);
				} while (len > 0);
				proto_item_set_len(ti, item_len);
			} else {
				/* GIF processing stops at this very byte */
				proto_tree_add_item(gif_tree, hf_trailer,
						tvb, offset, 1, TRUE);
				break;
			}
		} /* while */
	}
}


/****************** Register the protocol with Ethereal ******************/


/* This format is required because a script is used to build the C function
 * that calls the protocol registration. */

void
proto_register_gif(void)
{
	/*
	 * Setup list of header fields.
	 */
	static hf_register_info hf[] = {
		/*
		 * GIF signature and version
		 */
		{ &hf_version,
			{	"Version",
				IMG_GIF ".version",
				FT_STRING, BASE_NONE, NULL, 0x00,
				"GIF Version",
				HFILL
			}
		},

		/*
		 * Logical screen descriptor
		 */
		{ &hf_screen_width,
			{	"Screen width",
				IMG_GIF ".screen.width",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Screen width",
				HFILL
			}
		},
		{ &hf_screen_height,
			{	"Screen height",
				IMG_GIF ".screen.height",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Screen height",
				HFILL
			}
		},
		{ &hf_global_color_map_present,
			{	"Global color map is present",
				IMG_GIF ".global.color_map.present",
				FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
				"Indicates if the global color map is present",
				HFILL
			}
		},
		{ &hf_global_color_resolution,
			{	"Bits per color minus 1",
				IMG_GIF ".global.color_bpp",
				FT_UINT8, BASE_DEC, NULL, 0x70,
				"The number of bits per color is one plus the field value.",
				HFILL
			}
		},
		{ &hf_global_color_map_ordered,
			{	"Global color map is ordered",
				IMG_GIF ".global.color_map.ordered",
				FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
				"Indicates whether the global color map is ordered.",
				HFILL
			}
		},
		{ &hf_global_image_bpp,
			{	"Image bits per pixel minus 1",
				IMG_GIF ".global.bpp",
				FT_UINT8, BASE_DEC, NULL, 0x07,
				"The number of bits per pixel is one plus the field value.",
				HFILL
			}
		},
		{ &hf_background_color,
			{	"Background color index",
				IMG_GIF ".image_background_index",
				FT_UINT8, BASE_DEC, NULL, 0x00,
				"Index of the background color in the color map.",
				HFILL
			}
		},
		{ &hf_pixel_aspect_ratio,
			{	"Global pixel aspect ratio",
				IMG_GIF ".global.pixel_aspect_ratio",
				FT_UINT8, BASE_DEC, NULL, 0x00,
				"Gives an approximate value of the aspect ratio of the pixels.",
				HFILL
			}
		},
		{ &hf_global_color_map,
			{	"Global color map",
				IMG_GIF ".global.color_map",
				FT_BYTES, BASE_NONE, NULL, 0x00,
				"Global color map.",
				HFILL
			}
		},

		/*
		 * Local color map (part of image)
		 */
		{ &hf_local_color_map_present,
			{	"Local color map is present",
				IMG_GIF ".local.color_map.present",
				FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x80,
				"Indicates if the local color map is present",
				HFILL
			}
		},
		{ &hf_local_color_resolution,
			{	"Bits per color minus 1",
				IMG_GIF ".local.color_bpp",
				FT_UINT8, BASE_DEC, NULL, 0x70,
				"The number of bits per color is one plus the field value.",
				HFILL
			}
		},
		{ &hf_local_color_map_ordered,
			{	"Local color map is ordered",
				IMG_GIF ".local.color_map.ordered",
				FT_UINT8, BASE_DEC, VALS(vals_true_false), 0x08,
				"Indicates whether the local color map is ordered.",
				HFILL
			}
		},
		{ &hf_local_image_bpp,
			{	"Image bits per pixel minus 1",
				IMG_GIF ".local.bpp",
				FT_UINT8, BASE_DEC, NULL, 0x07,
				"The number of bits per pixel is one plus the field value.",
				HFILL
			}
		},
		{ &hf_local_color_map,
			{	"Local color map",
				IMG_GIF ".local.color_map",
				FT_BYTES, BASE_NONE, NULL, 0x00,
				"Local color map.",
				HFILL
			}
		},

		/*
		 * Extension
		 */
		{ &hf_extension,
			{	"Extension",
				IMG_GIF ".extension",
				FT_NONE, BASE_NONE, NULL, 0x00,
				"Extension.",
				HFILL
			}
		},
		{ &hf_extension_label,
			{	"Extension label",
				IMG_GIF ".extension.label",
				FT_UINT8, BASE_HEX, VALS(vals_extensions), 0x00,
				"Extension label.",
				HFILL
			}
		},

		/*
		 * Image
		 */
		{ &hf_image,
			{	"Image",
				IMG_GIF ".image",
				FT_NONE, BASE_NONE, NULL, 0x80,
				"Image.",
				HFILL
			}
		},
		{ &hf_image_left,
			{	"Image left position",
				IMG_GIF ".image.left",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Offset between left of Screen and left of Image.",
				HFILL
			}
		},
		{ &hf_image_top,
			{	"Image top position",
				IMG_GIF ".image.top",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Offset between top of Screen and top of Image.",
				HFILL
			}
		},
		{ &hf_image_width,
			{	"Image width",
				IMG_GIF ".image.width",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Image width.",
				HFILL
			}
		},
		{ &hf_image_height,
			{	"Image height",
				IMG_GIF ".image.height",
				FT_UINT16, BASE_DEC, NULL, 0x00,
				"Image height.",
				HFILL
			}
		},
		{ &hf_image_code_size,
			{	"LZW minimum code size",
				IMG_GIF ".image.code_size",
				FT_UINT8, BASE_DEC, NULL, 0x00,
				"Minimum code size for the LZW compression.",
				HFILL
			}
		},
		/*
		 * Trailer
		 */
		{ &hf_trailer,
			{	"Trailer (End of the GIF stream)",
				IMG_GIF ".end",
				FT_NONE, BASE_NONE, NULL, 0x00,
				"This byte tells the decoder that the data stream is finished.",
				HFILL
			}
		},
	};

	/* Setup protocol subtree array */
	static gint *ett[] = {
		&ett_gif,
		&ett_global_flags,
		&ett_local_flags,
		&ett_extension,
		&ett_image,
	};

	/* Register the protocol name and description */
	proto_gif = proto_register_protocol(
			"Compuserve GIF",
			"GIF image",
			IMG_GIF
	);

	/* Required function calls to register the header fields
	 * and subtrees used */
	proto_register_field_array(proto_gif, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));

	register_dissector("image-gif", dissect_gif, proto_gif);
}


void
proto_reg_handoff_gif(void)
{
	dissector_handle_t gif_handle;

	gif_handle = create_dissector_handle(dissect_gif, proto_gif);

	/* Register the GIF media type */
	dissector_add_string("media_type", "image/gif", gif_handle);
}