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
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
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
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
CDC 6600 memory Memory boards from a CDC 6600 computer Let's look more closely
A single memory board
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
Closer view (of a different board) Each core was several millimetres in diameter
Core memory was used for a long time Core memory was developed around 1950 It was the fastest memory available until the late 1980s
Why cores were used Each core was actually a circular magnet
Why cores were used A core could be magnetized in one of two directions, clockwise or anti- clockwise
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
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
Direction of current The final direction of magnetization in the core depends on the direction of the current along the wire
Threshold current To change the direction of magnetization in a core the current must exceed a threshold current, I
Threshold current If the current is less than the threshold current, the state of the core is not changed
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
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
Wires in a core mat The perpendicular and diagonal wires on a core-memory mat from 1951
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
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
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
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
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
Contents of a memory byte A memory byte can contain 256 different patterns, ranging from to
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 to
Shorthand notation A group of 4 bits is sometimes called a nibble A nibble can contain 16 different patterns
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
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
Shorthand notation for bytes So, a byte can contains 256 different hexadecimal patterns, ranging from
Shorthand notation for bytes So, a byte can contains 256 different hexadecimal patterns, ranging from 00 to FF
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
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
An example image file Consider the following file: 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
test.bmp It is a very small image
test.bmp Use menu Image -> Image Size to check the size
test.bmp It is 4 pixels wide by 4 pixels high
test.bmp Even though the picture contains only 16 pixels, the file is quite big –it contains 1,094 bytes
Using XVI32 to examine test.bmp XVI32 is on your workstation desktop
Using XVI32 The initial display, when no file has been opened
Viewing test.bmp in XVI32 The display when test.bmp has been opened
Viewing test.bmp in XVI32 The display when test.bmp has been opened
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
Viewing test.bmp in XVI32 Consider the first byte in the file, byte 0 It contains 42 hex That is
Viewing test.bmp in XVI32 Consider the fortieth byte in the file, byte 28 hex It contains 0B hex That is
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
The ASCII code interprets a byte as one 256 different characters This slide shows the first 128 of these
The ASCII code interprets a byte as one 256 different characters This slide shows the second 128 of these
Viewing test.bmp in XVI32 The first three bytes in the file contain 42 hex 4D hex 46 hex 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