CS 258 Introduction to Graphics Spring Images: The Tiff Image Specification CS 258 Introduction to Graphics Fall Big-Endian and Little-Endian • Big-Endian: most significant byte to least significant byte both for 16-bit and 32-bit integers. This is the “normal” way we write numbers out. • Little-Endian: least significant byte to most significant, again for both 16- and 32-bit integers. CS 258 Introduction to Graphics Fall Some Sample Code void SwapShortBytes(unsigned short int * twobytes) { unsigned char * tmp = (unsigned char *)twobytes; unsigned int i; i = tmp[1]; tmp[1] = tmp[0]; tmp[0] = i; return; } CS 258 Introduction to Graphics Fall pooh.tif Color Image. 239 x 184 pixels. CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 Big-Endian or Little-Endian 4d4d = Big 4949 = Little CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 Magic Number = 42 (0x2a) CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 Address of the Image File Directory (IFD). Must begin on a WORD boundary CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 Address of the Image File Directory (IFD). Must begin on a WORD boundary CS 258 Introduction to Graphics Fall [501] seville & od -A x -t x1 pooh.tif | more 0000000 4d 4d 00 2a 00 00 00 08 00 11 00 fe 00 04 00 00 0000010 00 01 00 00 00 00 01 00 00 03 00 00 00 01 00 ef 0000020 00 00 01 01 00 03 00 00 00 01 00 b8 00 00 01 02 0000030 00 03 00 00 00 03 00 00 00 da 01 03 00 03 00 00 0000040 00 01 00 01 00 00 01 06 00 03 00 00 00 01 00 02 0000050 00 00 01 0e 00 02 00 00 00 10 00 00 00 e0 01 11 0000060 00 04 00 00 00 01 00 00 03 2e 01 15 00 03 00 00 0000070 00 01 00 03 00 00 01 16 00 03 00 00 00 01 00 b8 0000080 00 00 01 17 00 04 00 00 00 01 00 02 03 58 01 1a 0000090 00 05 00 00 00 01 00 00 00 f0 01 1b 00 05 00 00 00000a0 00 01 00 00 00 f8 01 1c 00 03 00 00 00 01 00 01 00000b0 00 00 01 28 00 03 00 00 00 01 00 02 00 00 86 49 00000c0 00 01 00 00 01 ea 00 00 01 00 83 bb 00 04 00 00 00000d0 00 11 00 00 02 ea 00 00 00 00 00 08 00 08 00 08 IFD – all data pertaining to the characteristics of the image. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 First two bytes: the count, that is, the number of entries in the IFD. Entries are sorted by TAG, in ascending numerical order. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Next, the IFD Entries. Each is 12 Bytes long. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Next, the IFD Entries. Each is 12 Bytes long. Bytes 0-1: The TAG that Identifies the field. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Next, the IFD Entries. Each is 12 Bytes long. Bytes 0-1: The TAG that Identifies the field. Bytes 2-3: The Type of the field. Types: 1 = Byte (8 bit) 2 = Ascii (8 bit) 3 = Short (2 byte) 4 = Long (4 byte) 5 = Rational (2 Longs) CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Next, the IFD Entries. Each is 12 Bytes long. Bytes 0-1: The TAG that Identifies the field. Bytes 2-3: The Type of the field. Bytes 4-7: The Count (no. of values) Types: 1 = Byte (8 bit) 2 = Ascii (8 bit) 3 = Short (2 byte) 4 = Long (4 byte) 5 = Rational (2 Longs) CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Bytes 8-11: the Value Offset. The offset in bytes of the value for the field. Must begin on a word boundary. Can point anywhere in the file. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 Bytes 8-11: the Value Offset. The offset in bytes of the value for the field. Must begin on a word boundary. Can point anywhere in the file. If the Value fits into 4 bytes (i.e. is 1 byte and has count les than 5, is a short and has count less than 2, or is one long, etc.) THEN the Value will be stored in bytes 8-11, and will be left justified. CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 ImageWidth CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 0000090 00 f0 01 1b 00 05 00 00 00 01 00 00 00 f8 01 1c 00000a0 00 03 00 00 00 01 00 01 00 00 01 28 00 03 00 00 00000b0 00 01 00 02 00 00 86 49 00 01 00 00 01 ea 00 00 00000c0 01 00 83 bb 00 04 00 00 00 11 00 00 02 ea 00 00 00000d0 00 00 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 ImageLength CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 [503] seville & od -A x -t x1 -j 0xda pooh.tif | more 0000000 00 08 00 08 00 08 50 6f 6f 68 20 61 6e 64 20 54 0000010 69 67 67 65 72 00 00 0a fc 80 00 00 27 10 00 0a BitsPerSample CS 258 Introduction to Graphics Fall Tiff Image Data Organized into strips. Three fields govern this: RowsPerStrip, StripOffsets, and StripBytecounts. Strips per Image = ÷÷ ø ö çç è æ + ipRowsPerStr 1- ipRowsPerStrh ImageLengtfloor CS 258 Introduction to Graphics Fall Tiff Image Data Each strip contains a number of rows of image data. Putting them all together gives you the image data for the image. RowPerStrip = How many rows for each strip StripOffsets = The location of each of the strips StripByteCounts = The number of bytes in each strip CS 258 Introduction to Graphics Fall [502] seville & od -A x -t x1 -j 0x8 pooh.tif | more 0000000 00 11 00 fe 00 04 00 00 00 01 00 00 00 00 01 00 0000010 00 03 00 00 00 01 00 ef 00 00 01 01 00 03 00 00 0000020 00 01 00 b8 00 00 01 02 00 03 00 00 00 03 00 00 0000030 00 da 01 03 00 03 00 00 00 01 00 01 00 00 01 06 0000040 00 03 00 00 00 01 00 02 00 00 01 0e 00 02 00 00 0000050 00 10 00 00 00 e0 01 11 00 04 00 00 00 01 00 00 0000060 03 2e 01 15 00 03 00 00 00 01 00 03 00 00 01 16 0000070 00 03 00 00 00 01 00 b8 00 00 01 17 00 04 00 00 0000080 00 01 00 02 03 58 01 1a 00 05 00 00 00 01 00 00 [504] seville & od -A x -t x1 -j 0x32e pooh.tif | more 0000000 bb aa ee bb aa ee bb aa ee bb aa ee bb aa ee bb 0000010 aa ee bb aa ee bb aa ee bb aa ee bb aa ee bb aa 0000020 ee bb aa ee bb aa ee bb aa ee bb aa ee bb aa ee 0000030 bb aa ee bb aa ee bb aa ee bb aa ee bb aa ee bb CS 258 Introduction to Graphics Fall [507] seville & od -A x -t x1 play2.tif | more 0000000 49 49 2a 00 08 00 04 00 61 3f a8 a3 8a 10 4b 0c 0000010 46 37 0a 16 16 0a 08 0a 08 08 16 9f 9f 9f 9f 9f 0000020 9f 14 58 9e 9e 9e 99 9f 9f 9f 86 9f 9f 9f 9f 9f [509] seville & od -A x -t x1 -j 0x40008 play2.tif 0040008 10 00 fe 00 04 00 01 00 00 00 00 00 00 00 00 01 0040018 03 00 01 00 00 00 00 02 00 00 01 01 03 00 01 00 0040028 00 00 00 02 00 00 02 01 03 00 01 00 00 00 08 00 0040038 00 00 03 01 03 00 01 00 00 00 01 00 00 00 06 01 0040048 03 00 01 00 00 00 01 00 00 00 0d 01 02 00 2b 00 0040058 00 00 ce 00 04 00 11 01 04 00 20 00 00 00 fa 00 0040068 04 00 12 01 03 00 01 00 00 00 01 00 00 00 15 01 0040078 03 00 01 00 00 00 01 00 00 00 16 01 03 00 01 00 0040088 00 00 10 00 00 00 17 01 04 00 20 00 00 00 7a 01 Little Endian #include
#include using namespace std; int main () { char buffer[3]; short magicno; // 2 byte quantity int ifdaddress; // 4 byte quantity short ifdcount; // 2 byte quantity ifstream imfile; imfile.open (“eeyore2.tif", ios::binary ); imfile.seekg (0, ios::beg); //not strictly necessary, but a good idea Binary File Input CS 3258 Introduction to Graphics Spring imfile.read (buffer,2); imfile.read ((char *)&magicno,2); imfile.read ((char *)&ifdaddress,4); imfile.seekg(ifdaddress,ios::beg); imfile.read((char *)&ifdcount,2); imfile.close(); buffer[2]='\0'; //Necessary because buffer is a C-style string cout << "Endian: " << buffer << "\n"; cout << "Magic: " << magicno << "\n"; cout << "IFD Address: " << ifdaddress << "\n"; cout << "IFD Count: " << ifdcount << "\n"; return 0; } CS 258 Introduction to Graphics Spring istream& read (char* s, streamsize n); Read block of data Extracts n characters from the stream and stores them in the array pointed to by s. imfile.read ((char *)&magicno,2); #define BIG_ENDIAN 0 #define LITTLE_ENDIAN 1 int IsLittleEndian() { short int one = 1; char *byte = (char *) &one; return(byte[0] ? LITTLE_ENDIAN : BIG_ENDIAN); } What’s the endian-ness of the machine? CS 3258 Introduction to Graphics Spring ofstream outFile(filename.c_str(), ios::binary); if (outFile.fail()) return 3; outFile.write("MM", 2); short magic(42); outFile.write((char*)&magic, 2); Binary File Output CS 3258 Introduction to Graphics Spring 欢迎咨询51作业君