Segments in Graphics

25,070 views 16 slides Feb 01, 2016
Slide 1
Slide 1 of 16
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16

About This Presentation

what a segment is, Segment Creation, deletion, rename and visibility


Slide Content

Unit III SEgments Prepared By Rajani Thite

Introduction To humans, an image is not just a random collection of pixels; it is a meaningful arrangement of regions and objects. There also exits a variety of images: natural scenes, paintings, etc. Despite the large variations of these images, humans have no problem to interpret them. The image information is stored in Display file. Existing structure of display file does not satisfy the requirements of viewing image. Display image is modified to reflect the sub picture structure. To achieve this display file is divided into segments.

The Segment table indicates the portion of the display file used to construct the picture Display File Segment Table Display

Segment table

The segment table is formed by using arrays. An alternative approach is linked list In case of arrays, maximum no. of segments that can be included in the segment table are equal to the length of the arrays. But with linked list there is no such limit on the maximum no. of segments; as list is dynamic In linked List ordering is achieved by simply adjusting the links. In case of arrays we have to move actual segment information in the process of sorting the segments. Segment Start Segment Size Scale X Scale Y Color Link 3 4 2 5 Null/ Segment Number 1 2 For ordering the segment 3 The Disadvantage of linked list is that it requires more storage to hold the links and that it is costly to locate arbitrary cells. In the linked list deleting the cell means changing two links.

Display file Linked List OP X Y Link 1 2 2 .1 .5 5 3 1 .1 .1 2 4 5 2 .5 .5 9 6 7 2 .1 .5 8 9 2 .7 .5 7 10 Start=3

Segment Creation We Must give the segment name so that we can identify it. For example say that there is segment no. 3, then all following MOVE and Line commands would belong to segment 3. We could then close segment 3 and open another. First thing to create a segment is to check whether some other segment is open. We can not open two segments at the same time because we would not know to which segment we should assign the drawing instructions. If there is segment open, we have an error Next we should select valid segment name and check whether there already exists a segment under this name. If so, we again have an error. The first instruction belonging to this segment will be located at the next free storage area in the display file. The current size of the segment is zero since we have not actually entered any instructions into it yet.

CREATE_SEGMENT(SEGMENT-NAME) Argument SEGMENT-NAME Global NOW-OPEN the name of currently open segment FREE the index of the next free display-file cell SEGMENT-START, SEGMENT-SEZE,VISIBILITY ANGLE, SCALE-X, SCALE-Y, TRANSLATE-X,TRANSLATE-Y Constant NUMBER-OF-SEGMENTS BEGIN IF NOW-OPEN>0 THEN RETURN ERROR ‘SEGMENT STILL OPEN’; IF SEGMENT-NAME < 1 OR SEGMENT-NAME > NUMBER-OF-SEGMENTS THEN RETURN ERROR ‘INVALID SEGMENT NAME’; IF SEGMENT-SIZE[SEGMENT-NAME]>0 THEN RETURN ERROR ‘SEGMENT ALREADY EXISTS’; SEGMENT-START[SEGMENT-NAME]<-FREE; SEGMENT-SIZE[SEGMENT-NAME]<-0; VISIBILITY[SEGMENT-NAME] <-VISIBILITY[0]; ANGLE[SEGMENT-NAME] <-ANGLE[0]; SCALE-X[SEGMENT-NAME]<-SCALE-X[0]; SCALE-Y[SEGMENT-NAME]<-SCALE-Y[0]; TRANSLATE-X[SEGMENT-NAME]<-TRANSLATE-X[0]; TRANSLATE-Y[SEGMENT-NAME]<-TRANSLATE-Y[0]; NOW-OPEN<-SEGMENT-NAME; RETURN; END;

Closing a Segment Once the drawing instructions are completed, we should close it. NOW-OPEN variable indicates the name of the currently open segment. To close a segment it is necessary to change the name of the currently open segment. It can be achieved by changing the name of currently open segment as 0. We don’t have two unnamed segments around because we shall show only one of them and the other would just waist storage. If there are two unnamed segments in the display file one has to be deleted.

Algorithm to close Segment Global NOW-OPEN the name of currently open segment FREE the index of the next free display-file cell SEGMENT-START, SEGMENT-SIZE start and size of the segment BEGIN IF NOW-OPEN=0 THEN RETURN ERROR ‘NO SEGMENT IS OPEN’; DELETE-SEGMENT[0]; SEGMENT-START[0]<-FREE; SEGMENT-SIZE[0]<-0; NOW-OPEN<-0; RETURN; END;

Deleting A Segment When we want to delete a particular segment from the display file then we must recover the storage space occupied by its instructions and make this space free for some other segment. To do this we must not destroy and re-form the entire display file, but we must delete just one segment, while preserving the rest of the display file. Here we have used arrays to store the display file information. Segment 1 Segment 2 Segment 3 Segment 4 Unused Space Segment 1 Segment 3 Segment 4 Unused Space

Delete Algorithm Read the name of the segment which is to be deleted. Check whether the segment name is valid; if not display error “Segment not valid” go to step 8 Check whether the segment is open, if yes, display error message “ Can’t delete open segment” go to step 8. Check whether the size of segment is greater than 0, if no, no processing is required as segment contains no instructions. Shift the display file elements which follow the segment which is to be deleted by it’s size. Recover the deleted space by resetting the index of the next free instruction. Adjust the starting positions of the shifted segments by subtracting the size of the deleted segment from it. Stop.

Renaming a Segment The display processor is continuously reading the display file and showing its contents Suppose we wish to use this device to show an animated character moving on the display. To display a new image in the sequence we have to delete the current segment and re-create it with the altered character. The problem in this process is that during the time after the first image is deleted and time before the second image is completely entered, only a partially completed character is displayed on the screen. We avoid this problem by keeping the next image ready in the display file before deleting the current segment. Segment which is to be deleted and segment which is to be replaced with must exist in display file at the same time. We do this by building the new invisible image under some temporary segment name. When it is completed, we can delete the original image, make the replacement image visible, and rename the new segment to become the old segment to achieve apparent motion. The idea of maintaining two images, one to show and one to build or alter, is called double buffering.

Algorithm to Rename Segment Check whether both old and new segment names are valid; if not display error message “Not valid segment names” and go to step 6. Check whether any of the two segments are open. If open, display error message “Segment still open ” and go to step 6. Check whether the new name we are going to give to the old segment is not already existing in the display file. If yes, display error message “Segment already exists” and go to step 6. Copy the old segment table entry into new position. Delete the old segment. 6. Stop.

Visibility -Each Segment is given a visibility attribute. -The segment’s visibility is stored in an array as part of the segment table. -By checking this array we can determine whether or not the segment should be displayed.
Tags