28
Computer Science 101 Picture Files

Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Embed Size (px)

Citation preview

Page 1: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Computer Science 101

Picture Files

Page 2: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Computer Representationof Pictures

Common representation is as a bitmap.

• Two dimensional array of dots called pixels (picture element).

• The array consists of rows and columns of pixels.

• With the RGB system, each pixel has associated a 3-byte RGB value.

Page 3: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Picture from W&L Home Page(stored as bmp file)

Page 4: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two
Page 5: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

At 800%

Page 6: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

At 2400%

Page 7: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

How does the software know?

We know that all of the information stored in a computer file is stored as bits, broken into 8-bit bytes.

How does the software know whether this binary data is to be interpreted as text, picture, music, program instructions, etc.

Page 8: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

File extensions

As you know, files are usually stored as

• Name of file

• A dot (or period)

• An extension that indicates the general category of the file.

Page 9: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Some common extensions

.txt Plain text.doc Microsoft word document.docx Microsoft Word Open XML Document.pdf Portable Document Format File.msgOutlook mail message.ppt Powerpoint presentation.xls Excel spreadsheet.bmpBitmap image file.jpg JPEG image file.mp3Mp3 audio file.wav Wave audio file

Page 10: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Some common extensions (cont.)

.log Log file.movApple QuickTime movie.mpgMPEG video file.exe Executable file.html Hypertext Markup Language file.zip Zipped file.java Java source file.py Python source file

Page 11: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Extension is not enough Often the software needs more information

than is conveyed by the extension.

A .bmp file stores the RGB values for each pixel, thus 24 bits in 3 bytes for eachpixel.

Suppose there is RGB information for 100 pixels. Is the picture a 10 by 10, 25 by 4,5 by 20 or what? Many other such questions.

Page 12: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

File headers Many file formats specify how some needed

information is to be stored in the beginning of the file.

The extension tells the type of format being used; the file header encodes additional information needed by the software accessing the file.

File has• Header information• File data

Page 13: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP File Header

For more on this topic see

• http://www.fastgraph.com/help/bmp_header_format.html

• http://en.wikipedia.org/wiki/BMP_file_format#BMP_File_Header

Page 14: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header (from Fastgraph)

Page 15: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header (cont.)

Offset:• How many bytes into the file the specified

information is located. Here we have 0; so this information is at the very beginning of the file.

• In this table the offset is given in decimal; we’ll need to use hexadecimal. Get ready to convert.

Size: How many bytes are used for the information.

Page 16: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header (cont.)

Signature:• Identifies the kind of file data• Often 2 byte information has the information in

“right to left” order.• Here the 42 in hex is 66 in decimal. The 4D is

77 in decimal. • 66 is ASCII for B, and 77 is ASCII for M.• BM is confirming that the data is bitmap data.

Page 17: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header (cont.)

Start of image data: • Where the RGB values are found.• Let’s remember that the offset 10 is A in hex.• Also remember that this information is 4 bytes

long.

Page 18: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header (cont.)

Width:• At offset 18 decimal or 12 hex.• 4 bytes.

Height• At offset 22 decimal or 16 hex.• 4 bytes.

Page 19: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

BMP Header Summary

Some of the header info (offsets in hex):

• Signature at offset 0 – 2 bytes• File size at offset 2 – 4 bytes• Offset for start of image data at offset A

– 4 bytes• Width in pixels at offset 12 - 4 bytes• Height in pixels at offset 16 – 4 bytes

Page 20: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

96 pixelsSo each square is 24 by 24

Page 21: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Colored Squares with Hex Editor

We see the 42 4D at offset 0

Page 22: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

File Size (offset 2)

We see 366C for size. • Actually bytes are right to left so 6C36.

Converting this to decimal gives 27702 bytes.• We have 96 by 96 or 9216 pixels• 3 bytes per pixel for RGB; so 27648 data bytes• Plus the 54 bytes in the header giving 27702

Page 23: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Width and Height (offset 12 and 16)

We see 60 for both the width and height. In decimal this would be 96.

Page 24: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Bitmap Data Location (offset A)

We see 36 at location A. This means that the bitmap data begins in location 36.

Page 25: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Bitmap Data (offset 36)

At location 36, we see values FF 00 FF.• But the upper left square has red pixels.• The BMP documents specify bottom row first.• Red and Blue give the purple color.

Page 26: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two

Bitmap Data – Color Change

In the bottom row, there are 24 purple pixels, FF 00 FF. Then we see FF 00 00 24 times.• This would seem to indicate Red.• Again, the BMP specifications indicate the colors will be

in BGR order.

Page 28: Computer Science 101 Picture Files. Computer Representation of Pictures Common representation is as a bitmap. Common representation is as a bitmap. Two