A few editorial comments
The last statement in Listing 1 creates an onscreen window.
The window width must be a multiple of 4.
(At least that is true on my HP laptop computer running Windows Vista Home Premium.)
The width of the window should be greater than or equal to the width of the image.
The height of the window should be greater than or equal to twice the height of the image.
Otherwise, the window won't be large enough to contain two copies of the image as shown in Figure 1.