50
How pictures are stored in computers

How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

  • View
    220

  • Download
    0

Embed Size (px)

Citation preview

Page 1: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How pictures are stored in computers

Page 2: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How pictures are stored in computers

• While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures are stored in computers

• This is important in its own right• But it will also be important when you start writing

programs in PHP to create pictures• In what follows, you will

– learn something about the format of image files– discover that picture editing software can contain bugs– discover that many programs do not adhere strictly to the image

format standards

Page 3: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How pictures are stored in computers

• Understanding computer storage of pictures involves several main points:

• a picture is a collection of dots, called pixels• the colour of each dot in a picture must be

stored• any colour can be represented as a mixture of

certain proportions of red, green and blue• in computers, all information is stored as a

sequence of zeros and ones• there is frequently a lot of repetition in a picture,

so the zeros and ones can often be compressed

Page 4: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Representation of information as zeros and ones

• In computers, all information is stored as a sequence of zeros and ones– since only two symbols are used, this is called

binary representation• the Latin prefix, bi-, means two

• Why are only two symbols used?• Because most forms of electronic storage device

have only two easily-distinguishable states• A clear example can be seen by looking at early

computer technology

Page 5: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

The CDC 6600 computer

• The CDC 6600 computer

• designed by Seymour Cray

• first delivered in 1964

• was considered a "supercomputer"

– three times faster than the fastest computer before it

• cost $10 million each– at a time when a 3-

bedroom house in Ireland cost about $2500

– so it cost the same as 4000 houses

Page 6: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

CDC 6600 memory

• Memory boards from a CDC 6600 computer

• Let's look more closely

Page 7: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

A single memory board

Page 8: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Closer view of a CDC 600 memory board

• Memory boards were then called "mats"

• It's easy to see why• A mat consisted of

wires woven through rings

• Each ring was called a core

Page 9: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Closer view (of a different board)

• Each core was several millimetres in diameter

Page 10: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Core memory was used for a long time

• Core memory was developed around 1950

• It was the fastest memory available until the late 1980s

Page 11: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Why cores were used

• Each core was actually a circular magnet

Page 12: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Why cores were used

• A core could be magnetized in one of two directions, clockwise or anti-clockwise

Page 13: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Two states means only two values

• These two direction could be used to represent two different symbols– Clockwise, say, can

represent a 0, – while anti-clockwise

can represent a 1

Page 14: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How cores are magnetized• The direction of magnetization in a core can be changed by temporarily

running a current along a wire that runs through the core

Page 15: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Direction of current• The final direction of magnetization in the core depends on the

direction of the current along the wire

Page 16: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Threshold current

• To change the direction of magnetization in a core the current must exceed a threshold

current, I

Page 17: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Threshold current

• If the current is less than the threshold current, the state of the core is not changed

Page 18: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How cores were controlled

• It's worth seeing how individual cores in a mat were controlled

• Similar principles are still used in newer memory technologies

Page 19: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Several wires through each core

• There were actually three wires running through each core

• Two wires ran in each of two perpendicular directions– These are called the address

wires

• The third wire ran diagonally– this is called the sense wire

Page 20: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Wires in a core mat

• The perpendicular and diagonal wires on a core-memory mat from 1951

Page 21: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Selecting (addressing) a specific core

• The fact that the current must exceed a threshold is used to select the core we want to change

• To change a specific core, we send half the threshold current along each of the two address wires that pass through the target core

Page 22: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How to write information into a core

• To achieve a specific state in the core, – we send the currents

in a specific direction

• One direction creates 0• The other direction

creates 1

Page 23: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

How to read from a core

• To read a core, we set it to 0 and see if that causes a pulse along the sense wire

• Then, if necessary, we reset the core to the correct value

• If the core originally contained 0, we need to do nothing

• But if the core originally contained 1, we must write that 1 back into the core

Page 24: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Memory locations

• The address wires run in two perpendicular directions• One direction, say the horizontal, is more significant than the other• Each wire in this direction selects a group of cores that belong to

one memory location• Wires in the other direction can select individual bits in the location

Page 25: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Sizes of memory location

• Early computers had locations of different sizes

• In the top board shown here, each location had 16 bits

• In the bottom board, each location had 8 bits

• In most (all?) modern computers, each memory location has 8 bits

• A group of 8 bits is called a byte• So modern computer memory is

what is called byte-addressable

Page 26: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Contents of a memory byte

• A memory byte can contain 256 different patterns, ranging from 00000000 to 11111111

Page 27: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Contents of a memory byte

• It is easier to write a byte pattern as two groups of four bits, with a space in the middle

• So, a memory byte can contain 256 different patterns, ranging from

0000 0000 to

1111 1111

Page 28: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Shorthand notation

• A group of 4 bits is sometimes called a nibble

• A nibble can contain 16 different patterns

Page 29: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Shorthand notation

• A group of 4 bits is sometimes called a nibble

• A nibble can contain 16 different patterns

• It is common to use a shorthand notation for these 16 different patterns

Page 30: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Shorthand notation

• A group of 4 bits is sometimes called a nibble

• A nibble can contain 16 different patterns

• It is common to use a shorthand notation for these 16 different patterns

• This notation is called hexadecimal notation

Page 31: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Shorthand notation for bytes

• So, a byte can contains 256 different hexadecimal patterns, ranging from

Page 32: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Shorthand notation for bytes

• So, a byte can contains 256 different hexadecimal patterns, ranging from

00 to FF

Page 33: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Image files• Binary representation is not confined to

the internal memory of a computer

• It is also used in files that are stored on disks

• So, image files also use binary representation

• We can see this by using a program which shows us the raw contents of an image file

Page 34: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Hex editors• A hex editor is a program which can be

used to examine and edit the raw contents of any file on a computer disk

• They are called hex editors because they display the contents of the file using hexadecimal notation

• We will use a freely-available hex editor called XVI32

• But many others are available

Page 35: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

An example image file

• Consider the following file:http://www.cs.ucc.ie/j.bowen/cs1107/imageFormats/test.bmp

• It is in the BMP format - the Windows bitmap format

• It was created using PhotoShop, not PhotoPlus – as we will see later, this is not unimportant

• We will examine this file with XVI32• But, first, let's see what image the file contains• Download the file to your computer• And open it in PhotoPlus

Page 36: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

test.bmp• It is a very small image

Page 37: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

test.bmp• Use menu Image -> Image Size to check the size

Page 38: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

test.bmp• It is 4 pixels wide by 4 pixels high

Page 39: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

test.bmp• Even though the picture contains only 16 pixels, the file is quite big

– it contains 1,094 bytes

Page 40: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Using XVI32 to examine test.bmp

• XVI32 is on your workstation desktop

Page 41: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Using XVI32

• The initial display, when no file has been opened

Page 42: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• The display when test.bmp has been opened

Page 43: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• The display when test.bmp has been opened

Page 44: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• The highlighted area is used to show the binary contents of the file

• Each byte is shown in hexadecimal notation

Page 45: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• Consider the first byte in the file, byte 0

• It contains 42hex

• That is

0100 0010

Page 46: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• Consider the fortieth byte in the file, byte 28hex

• It contains 0Bhex

• That is

0000 1011

Page 47: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• The highlighted area gives a different view of the contents of the file

• It interprets the bytes as characters using the ASCII code

Page 48: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

• The ASCII code interprets a byte as one 256 different characters

• This slide shows the first 128 of these

Page 49: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

• The ASCII code interprets a byte as one 256 different characters

• This slide shows the second 128 of these

Page 50: How pictures are stored in computers. While it is useful to know how to use picture editing software, Computer Scientists should understand how pictures

Viewing test.bmp in XVI32

• The first three bytes in the file contain 42hex 4Dhex 46hex

• If these were interpreted as ASCI character codes, they would represent BMF

• However, most of the time, we will not be interested in the ASCII interpretations